-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvd_results.java
82 lines (66 loc) · 1.52 KB
/
svd_results.java
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
/**
* Simple class to store and organize results from SVD.
*
*/
public class svd_results{
double[][] _u;
double[] _s;
double[][] _vt;
/**
* Default constructors sets all arrays to null
*/
public svd_results(){
_u = null;
_s = null;
_vt = null;
}
/**
* Constructor when results are all provided in full 2D matrix form for U and Vt.
*/
public svd_results(double[][] _u, double[] _s, double[][] _vt) {
this._u = _u;
this._s = _s;
this._vt = _vt;
}
/**
* Constructor when results are all provided as 1D arrays. Sets up
* complete 2D matrix forms given the provided dimensions.
*/
public svd_results(double[] u1d, int u_nrows, int u_ncols,
double[] s,
double[] vt1d, int vt_nrows, int vt_ncols) {
double[][] u = new double[u_nrows][u_ncols];
double[][] vt = new double[vt_nrows][vt_ncols];
for(int i=0;i<u_nrows;i++){
for(int j=0;j<u_ncols;j++){
u[i][j] = u1d[i + j * u_nrows];
}
}
for(int i=0;i<vt_nrows;i++){
for(int j=0;j<vt_ncols;j++){
vt[i][j] = vt1d[i + j * vt_nrows];
}
}
this._u = u;
this._s = s;
this._vt = vt;
}
public double[][] get_u() {
return _u;
}
public void set_u(double[][] _u) {
this._u = _u;
}
public double[] get_s() {
return _s;
}
public void set_s(double[] _s) {
this._s = _s;
}
public double[][] get_vt() {
return _vt;
}
public void set_vt(double[][] _vt) {
this._vt = _vt;
}
}