@@ -71,9 +71,10 @@ class AccesRBF(
71
71
}
72
72
val _selected_features : IndexedSeq [Int ] = select_features(Y = Y , Y_min = _Y_min, Y_max = _Y_max,
73
73
cut_k_features.getOrElse(Y .cols), drop_redundant = drop_redundant_features)
74
- val _Y_normed = normalize_Y(
75
- Y = (Y (:: , _selected_features)).toDenseMatrix,
76
- Y_means = (_Y_means(_selected_features)).toDenseVector)
74
+ // val _Y_normed = normalize_Y(
75
+ // Y=(Y(::, _selected_features)).toDenseMatrix,
76
+ // Y_means=(_Y_means(_selected_features)).toDenseVector)
77
+ val _Y_normed = normalize_Y( Y = Y , Y_means = _Y_means)
77
78
78
79
println(" x_min" , _X_min)
79
80
println(" x_max" , _X_max)
@@ -113,7 +114,8 @@ class AccesRBF(
113
114
114
115
115
116
def select_features (Y : DenseMatrix [Double ], Y_min : DenseVector [Double ], Y_max : DenseVector [Double ],
116
- k_features : Int , drop_redundant : Boolean = true ): IndexedSeq [Int ] = {
117
+ k_features : Int , drop_redundant : Boolean = true ,
118
+ rtol : Double = 0.01 , atol : Double = 0.00001 ): IndexedSeq [Int ] = {
117
119
if (k_features <= 0 ) { throw new IllegalArgumentException (" k_features must be positive" )}
118
120
val k = if (k_features > Y .cols) Y .cols else k_features
119
121
@@ -122,7 +124,7 @@ class AccesRBF(
122
124
println(" select_features: Y_max" , Y_max )
123
125
val scores = DenseVector .zeros[Double ](k)
124
126
for (i <- 0 to k - 1 ) {
125
- scores(i) = meanAndVariance(Y (:: , i)).variance / (Y_max (i) - Y_min (i))
127
+ scores(i) = sqrt( meanAndVariance(Y (:: , i)).variance) / (Y_max (i) - Y_min (i))
126
128
}
127
129
var inds = argsort(scores).reverse
128
130
println(" scores" , scores)
@@ -134,35 +136,41 @@ class AccesRBF(
134
136
for (i <- 0 to inds.length - 1 ) {
135
137
val ind = inds(i)
136
138
println(" ind" , ind, " var" , scores(i))
137
- if (~= (scores(ind), 0.0 , 0.00001 ) ) {
139
+ if (~= (scores(ind), 0 , atol) || scores(ind) / scores(inds( 0 )) < rtol ) {
138
140
inds = inds.slice(0 , i)
139
141
println(inds)
140
142
break
141
143
}
144
+ // if (~=(scores(ind), 0.0, 0.00001)) {
145
+ // inds = inds.slice(0, i)
146
+ // println(inds)
147
+ // break
148
+ // }
142
149
}
143
150
}
144
151
}
145
152
inds = inds.slice(0 , min(inds.length, k))
146
153
inds = inds.sorted
147
154
148
- println(" new inds" , inds)
149
- println(" new scores" , scores(inds).toDenseVector)
155
+ // println("new inds", inds)
156
+ // println("new scores", scores(inds).toDenseVector)
150
157
151
158
return inds
152
159
}
153
160
154
161
def fit_gpr (estimate : Boolean = false , use_default_params : Boolean = false ) = {
155
162
val X : DenseMatrix [Double ] = this ._X_normed
156
163
val Y : DenseMatrix [Double ] = this ._Y_normed(:: , this ._selected_features).toDenseMatrix
157
- val X_min = this ._X_min
158
- val X_max = this ._X_max
164
+ val X_min = min( X ( :: , * )).t
165
+ val X_max = max( X ( :: , * )).t
159
166
val Y_min = this ._Y_min(this ._selected_features).toDenseVector
160
167
val Y_max = this ._Y_max(this ._selected_features).toDenseVector
161
168
162
169
val n = X .rows
163
170
val d = X .cols
164
171
val m = Y .cols
165
172
173
+ println(" X.rows, Y.rows: " , X .rows, Y .rows)
166
174
assert(X .rows == Y .rows)
167
175
168
176
if (estimate) {
@@ -176,7 +184,7 @@ class AccesRBF(
176
184
println(" use default parameters" , use_default_params)
177
185
178
186
val sf_0 : DenseVector [Double ] = 0.01 * (Y_max - Y_min )
179
- val l_0 : DenseVector [Double ] = 0.1 * DenseVector .ones[Double ](m)
187
+ val l_0 : DenseVector [Double ] = 0.1 * breeze.linalg.norm( X_max - X_min ) * DenseVector .ones[Double ](m)
180
188
val noise_0 : DenseVector [Double ] = sf_0.copy
181
189
182
190
println(" Default parameters" )
@@ -264,6 +272,7 @@ class AccesRBF(
264
272
}
265
273
266
274
def predict_gpr_scalar (X : DenseMatrix [Double ], component : Int ): (DenseVector [Double ],DenseVector [Double ]) = {
275
+ // WRONG INDEXING HERE, component for M and data is not the same, need to fix
267
276
if (! this ._selected_features.contains(component)) {
268
277
throw new IllegalArgumentException (" Feature %d is ignored" .format(component))
269
278
}
@@ -411,7 +420,7 @@ class AccesRBF(
411
420
// println("x", x)
412
421
// println("x_normed", x_normed)
413
422
val X_normed = this ._X_normed
414
- val Y_normed = this ._Y_normed
423
+ val Y_normed = this ._Y_normed( :: , this ._selected_features).toDenseMatrix
415
424
val m = Y_normed .cols
416
425
val n = X_normed .rows
417
426
val d = X_normed .cols
@@ -420,7 +429,7 @@ class AccesRBF(
420
429
// var FIM = DenseMatrix.zeros[Double](d,d)
421
430
val FIMs : Array [DenseMatrix [Double ]] = Array .ofDim[DenseMatrix [Double ]](this ._selected_features.length)
422
431
423
- for (i <- 0 to this ._selected_features.length - 1 ) {
432
+ for (i <- 0 until Y_normed .cols ) {
424
433
var FIM = DenseMatrix .zeros[Double ](d,d)
425
434
val M = this ._Ms.get(i)
426
435
val gamma = this ._gammas.get(i)
0 commit comments