forked from helengracehuang/MsCaviar
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMsUtil.h
More file actions
98 lines (80 loc) · 1.95 KB
/
MsUtil.h
File metadata and controls
98 lines (80 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef MUTIL_H
#define MUTIL_H
#include <cmath>
#include <string>
#include <vector>
#include <armadillo>
using namespace std;
using namespace arma;
struct data {
data(double num, int ind1, int ind2) {
number = num;
index1 = ind1;
index2 = ind2;
}
double number;
int index1;
int index2;
};
struct by_number {
bool operator()(data const &left, data const &right) {
return abs(left.number) > abs(right.number);
}
};
/*
convert int to string
*/
string convertInt(int number);
/*
find n factorial
*/
long int fact(int n) ;
/*
find minimum between a and b
*/
double min(double a, double b) ;
/*
find combinration n choose r
*/
long int nCr(int n, int r) ;
/*
import data from file
*/
void importData(string fileName, vector<double> *& vector);
/*
import second column of data from file
*/
void importDataSecondColumn(string fileName, vector<double>& vector);
/*
import first column of data from file
*/
void importDataFirstColumn(string fileName, vector<string>& list, int ignore=0);
/*
export data type char from file
*/
void exportVector2File(string fileName, char * data, int size);
/*
export data type double from file
*/
void exportVector2File(string fileName, double * data, int size);
/*
export data type int from file
*/
void export2File(string fileName, int data);
/*
export data type double from file
*/
void export2File(string fileName, double data);
/*
make a matrix semi-positive definite, ie. full rank
*/
void makeSigmaPositiveSemiDefinite(mat * sigma, int size);
/*
handles low rank case, performs eigenvalue decomposition on the matrix sigma = LDL(trans)
On output the diagonal of the input matrix sigma stores the diagonal elements of D,
and the lower triangular portion of A contains the matrix L.
Since L has ones on its diagonal these do not need to be explicitely stored.
The upper triangular portion of A is unmodified.
*/
mat* eigen_decomp(mat* sigma, int size);
#endif