1+
2+ """
3+ Various utility functions for mapping constrained sensors locations with the column indices for class GQR.
4+ """
5+
6+ import numpy as np
7+
8+
9+ def get_constraind_sensors_indices (x_min , x_max , y_min , y_max , nx , ny , all_sensors ):
10+ """
11+ Function for mapping constrained sensor locations on the grid with the column indices of the basis_matrix.
12+
13+ Parameters
14+ ----------
15+ x_min: int,
16+ Lower bound for the x-axis constraint
17+ x_max : int,
18+ Upper bound for the x-axis constraint
19+ y_min : int,
20+ Lower bound for the y-axis constraint
21+ y_max : int
22+ Upper bound for the y-axis constraint
23+ nx : int
24+ Image pixel (x dimensions of the grid)
25+ ny : int
26+ Image pixel (y dimensions of the grid)
27+ all_sensors : np.ndarray, shape [n_features]
28+ Ranked list of sensor locations.
29+
30+ Returns
31+ -------
32+ idx_constrained : np.darray, shape [No. of constrained locations]
33+ Array which contains the constrained locationsof the grid in terms of column indices of basis_matrix.
34+ """
35+ n_features = len (all_sensors )
36+ image_size = int (np .sqrt (n_features ))
37+ a = np .unravel_index (all_sensors , (nx ,ny ))
38+ constrained_sensorsx = []
39+ constrained_sensorsy = []
40+ for i in range (n_features ):
41+ if (a [0 ][i ] >= x_min and a [0 ][i ] <= x_max ) and (a [1 ][i ] >= y_min and a [1 ][i ] <= y_max ):
42+ constrained_sensorsx .append (a [0 ][i ])
43+ constrained_sensorsy .append (a [1 ][i ])
44+
45+ constrained_sensorsx = np .array (constrained_sensorsx )
46+ constrained_sensorsy = np .array (constrained_sensorsy )
47+ constrained_sensors_array = np .stack ((constrained_sensorsy , constrained_sensorsx ), axis = 1 )
48+ constrained_sensors_tuple = np .transpose (constrained_sensors_array )
49+ if len (constrained_sensorsx ) == 0 : ##Check to handle condition when number of sensors in the constrained region = 0
50+ idx_constrained = []
51+ else :
52+ idx_constrained = np .ravel_multi_index (constrained_sensors_tuple , (nx ,ny ))
53+ return idx_constrained
54+
55+ def get_constrained_sensors_indices_linear (x_min ,x_max ,y_min ,y_max ,df ):
56+ """
57+ Function for obtaining constrained column indices from already existing linear sensor locations on the grid.
58+
59+ Parameters
60+ ----------
61+ x_min: int,
62+ Lower bound for the x-axis constraint
63+ x_max : int,
64+ Upper bound for the x-axis constraint
65+ y_min : int,
66+ Lower bound for the y-axis constraint
67+ y_max : int
68+ Upper bound for the y-axis constraint
69+ df : pandas.DataFrame
70+ A dataframe containing the features and samples
71+
72+ Returns
73+ -------
74+ idx_constrained : np.darray, shape [No. of constrained locations]
75+ Array which contains the constrained locationsof the grid in terms of column indices of basis_matrix.
76+ """
77+ x = df ['X (m)' ].to_numpy ()
78+ n_features = x .shape [0 ]
79+ y = df ['Y (m)' ].to_numpy ()
80+ idx_constrained = []
81+ for i in range (n_features ):
82+ if (x [i ] >= x_min and x [i ] <= x_max ) and (y [i ] >= y_min and y [i ] <= y_max ):
83+ idx_constrained .append (i )
84+ return idx_constrained
85+
86+ def box_constraints (position ,lower_bound ,upper_bound ,):
87+ """
88+ Function for mapping constrained sensor locations on the grid with the column indices of the basis_matrix. ##TODO : BETTER DEFINITION
89+
90+ Parameters
91+ ----------
92+ position: ##TODO: FILL
93+
94+ lower_bound : ##TODO: FILL
95+
96+ upper_bound : ##TODO: FILL
97+
98+ Returns
99+ -------
100+ idx_constrained : np.darray, shape [No. of constrained locations] ##TODO: CHECK IF CORRECT
101+ Array which contains the constrained locationsof the grid in terms of column indices of basis_matrix.
102+ """
103+ for i ,xi in enumerate (position ):
104+ f1 = position [i ] - lower_bound [i ]
105+ f2 = upper_bound [i ] - position [i ]
106+ return + 1 if (f1 and f2 > 0 ) else - 1
107+
108+ def functional_constraints (position , func_response ,func_input , free_term ):
109+ """
110+ Function for mapping constrained sensor locations on the grid with the column indices of the basis_matrix. ##TODO: BETTER DEFINITION
111+
112+ Parameters
113+ ----------
114+ position: ##TODO : FILL
115+
116+ func_response : ##TODO : FILL
117+
118+ func_input: ##TODO : FILL
119+
120+ free_term : ##TODO : FILL
121+
122+ Returns
123+ -------
124+ g : ##TODO : FILL
125+
126+ """
127+ g = func_response + func_input + free_term
128+ return g
0 commit comments