Skip to content

Commit 69a5511

Browse files
author
niharika2999
committed
Adding predtermined_norm_calc to gqr
1 parent 885add4 commit 69a5511

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

pysensors/optimizers/_gqr.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def fit(
9595
dlens_updated = norm_calc_max_n_const_sensors(self.constrainedIndices,dlens,p,j, self.nConstrainedSensors,self.all_sensorloc,self.nSensors)
9696
elif self.constraint_option == "exact_n_const_sensors" :
9797
dlens_updated = norm_calc_exact_n_const_sensors(self.constrainedIndices,dlens,p,j,self.nConstrainedSensors)
98+
elif self.constraint_option == "predetermined_end":
99+
dlens_updated = predetermined_norm_calc(self.constrainedIndices, dlens, p, j, self.nConstrainedSensors, self.nSensors)
98100

99101
# Choose pivot
100102
i_piv = np.argmax(dlens_updated)
@@ -202,6 +204,38 @@ def norm_calc_max_n_const_sensors(lin_idx, dlens, piv, j, const_sensors,all_sens
202204
dlens[didx] = 0
203205
return dlens
204206

207+
def predetermined_norm_calc(lin_idx, dlens, piv, j, n_const_sensors, n_sensors):
208+
"""
209+
Function for mapping constrained sensor locations with the QR procedure.
210+
211+
Parameters
212+
----------
213+
lin_idx: np.ndarray, shape [No. of constrained locations]
214+
Array which contains the constrained locationsof the grid in terms of column indices of basis_matrix.
215+
dlens: np.ndarray, shape [Variable based on j]
216+
Array which contains the norm of columns of basis matrix.
217+
piv: np.ndarray, shape [n_features]
218+
Ranked list of sensor locations.
219+
n_const_sensors: int,
220+
Number of sensors to be placed in the constrained area.
221+
j: int,
222+
Iterative variable in the QR algorithm.
223+
224+
Returns
225+
-------
226+
dlens : np.darray, shape [Variable based on j] with constraints mapped into it.
227+
"""
228+
if (n_sensors - n_const_sensors) <= j <= n_sensors: # force sensors into constraint region
229+
#idx = np.arange(dlens.shape[0])
230+
#dlens[np.delete(idx, lin_idx)] = 0
231+
232+
didx = np.isin(piv[j:],lin_idx,invert=True)
233+
dlens[didx] = 0
234+
else:
235+
didx = np.isin(piv[j:],lin_idx,invert=False)
236+
dlens[didx] = 0
237+
return dlens
238+
205239

206240

207241
if __name__ == '__main__':

pysensors/utils/_validation.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ def determinant(top_sensors, n_features, basis_matrix):
2323
"""
2424

2525
c = np.zeros([len(top_sensors),n_features])
26-
print(c.shape)
2726
for i in range(len(top_sensors)):
2827
c[i,top_sensors[i]] = 1
29-
print(c)
3028
phi = basis_matrix
3129
optimality = np.linalg.det((c@phi).T @ (c@phi))
32-
print(optimality)
33-
return (c,phi,optimality)
30+
return optimality
3431

3532
def relative_reconstruction_error(data, prediction):
3633
"""
@@ -47,6 +44,5 @@ def relative_reconstruction_error(data, prediction):
4744
error_val : Float,
4845
The relative error calculated.
4946
"""
50-
error_val = (np.linalg.norm((data - prediction)/np.linalg.norm(data)))*100
51-
print(error_val)
47+
error_val = (np.linalg.norm((data - prediction)/(data)))*100
5248
return (error_val)

0 commit comments

Comments
 (0)