4 """ This optimizer class handles the modal gain optimization related operations
5 using the CLOSE algorithm. Should be used with a modal integrator command law.
8 _config : (config) : Configuration parameters module
10 _rtc : (RtcCompass) : RtcCompass instance
12 _ntotact : (int) : total number of actuators used in the simulation
14 modal_basis : (np.ndarray) : KL2V modal basis
16 cmat_modal : (np.ndarray) : modal command matrix
18 _mask : (np.ndarray) : mask array (containig 0 or 1) filtering the modes
20 _ac_idx : (int) : autocorrelation index
22 _up_idx : (int) : update index (averaging length of AC estimator before modal gains update)
24 _lf : (float) : learning factor of the autocorrelation computation
26 _lfdownup : (float) : learning factors for modal gain update
28 _trgt : (float) : target value for the autocorrelation optimization
30 _initial_gain : (float) : initial value for the modal gains (same for all modes)
32 _modal_meas : (list) : list containing previous modal measurements to
33 be used for CLOSE optimization
35 _ac_est_0 : (np.ndarray) : autocorrelation estimation for no frames delay
37 _ac_est_dt : (np.ndarray) : autocorrelation estimation for _ac_idx delay
39 mgains : (np.ndarray) : modal gains that will be updated
41 close_iter : (int) : number of iteration of CLOSE optimizations
45 """ Instantiate a ModalGains optimizer object.
48 config : (config module) : Parameters configuration structure module
50 rtc : (sutraWrap.Rtc) : Sutra rtc instance
54 self.
_ntotact_ntotact = config.p_controllers[0].nactu
59 self.
_ac_idx_ac_idx = int(config.p_controllers[0].delay * 2 + 1)
60 self.
_up_idx_up_idx = config.p_controllers[0].get_close_update_index()
61 self.
_lf_lf = config.p_controllers[0].get_close_learning_factor()
62 self.
_lfdownup_lfdownup = np.array(config.p_controllers[0].get_lfdownup())
63 self.
_trgt_trgt = config.p_controllers[0].get_close_target()
64 self.
_initial_gain_initial_gain = config.p_controllers[0].get_mgain_init()
73 if (self.
_config_config.p_controllers[0].close_opti):
79 """Save the modal measurement of the current iter"""
81 raise Exception(
"Modal basis and cmat modal should be not None")
82 slp = self.
_rtc_rtc.get_slopes(0)
88 """Compute a new modal gains
89 This function computes and updates the modal gains according to the
93 ctrl_modes = np.where(self.
_mask_mask)[0]
95 raise Exception(
"Modal basis and cmat modal should be not None")
97 slp = self.
_rtc_rtc.get_slopes(0)
98 temp_modal_meas = self.
cmat_modalcmat_modal.dot(slp)
116 mean = np.mean(self.
_buffer_buffer, axis=0)
117 sign_ac = (mean > 0).astype(np.int8)
118 self.
mgainsmgains[ctrl_modes] = self.
mgainsmgains[ctrl_modes] * (1 + self.
_lfdownup_lfdownup[sign_ac] * x)
125 """Reset modal gain and computation variables"""
136 """Reset the modal gains only"""
140 """Set the flag indicating to use CLOSE optimization.
143 flag : (bool) : If true, update the modal gains value according to CLOSE algo
145 self.
_config_config.p_controllers[0].set_close_opti(flag)
148 """Set the modal basis to be used in CLOSE calculation.
151 modal_basis : (np.ndarray) : modal basis (KL2V) to be used (square)
153 if (modal_basis.shape[0] != modal_basis.shape[1]):
154 raise Exception(
"Modal basis should be square matrix")
156 self.
_rtc_rtc.set_E_matrix(0, modal_basis)
157 print(
"Modal basis is set")
160 """Get the modal basis
163 self.modal_basis : (np.ndarray) : modal basis (KL2V) used in the optimizer
171 cmat_modal : (np.ndarray) : modal command matrix
174 self.
_rtc_rtc.set_command_matrix(0, cmat_modal)
175 print(
"cmat_modal is set")
178 """Get the modal gains
181 self.mgains : (np.ndarray) : modal gains
186 """Sets manually the modal gains
189 mgains : (np.ndarray) : the modal gains array
191 self.
mgainsmgains = mgains
199 mask : (np.ndarray) : mask array (containig 0 or 1) filtering the modes
201 self.
_mask_mask = mask
202 self.
mgainsmgains[mask == 0] = 0
206 """Set the initial value for modal gains. This function reinitializes the modal gains.
209 gain: (float) : initial value for modal gains
215 self.
_config_config.p_controllers[0].set_mgain_init(gain)
217 def set_config(self, p, qminus, qplus, target, up_idx):
218 """Set the 4 parameters for the CLOSE optimization loop
221 p: (float) : learning factor for autocorrelation
223 qminus: (float) : learning factor for mgain optimization when lower than target
225 qplus: (float) : learning factor for mgain optimization when higher than target
227 target: (float) : autocorrelation target for optimization
229 up_idx: (int) : modal gains update rate [frame]
232 self.
_config_config.p_controllers[0].set_close_learning_factor(p)
234 self.
_config_config.p_controllers[0].set_lfdownup(qminus, qplus)
235 self.
_trgt_trgt = target
236 self.
_config_config.p_controllers[0].set_close_target(target)
238 self.
_config_config.p_controllers[0].set_close_update_index(up_idx)
This optimizer class handles the modal gain optimization related operations using the CLOSE algorithm...
def set_mask(self, mask)
Set the mode mask.
modal_basis
(np.ndarray) : KL2V modal basis
def set_initial_gain(self, gain)
Set the initial value for modal gains.
def set_modal_basis(self, modal_basis)
Set the modal basis to be used in CLOSE calculation.
def set_config(self, p, qminus, qplus, target, up_idx)
Set the 4 parameters for the CLOSE optimization loop.
def set_cmat_modal(self, cmat_modal)
Set cmat modal.
close_iter
(int) : number of iteration of CLOSE optimizations
def update_modal_meas(self)
Save the modal measurement of the current ite.
def reset_close(self)
Reset modal gain and computation variables.
def update_mgains(self)
Compute a new modal gains This function computes and updates the modal gains according to the CLOSE a...
def __init__(self, config, rtc)
Instantiate a ModalGains optimizer object.
mgains
(np.ndarray) : modal gains that will be updated
def get_modal_basis(self)
Get the modal basis.
def get_modal_gains(self)
Get the modal gains.
def reset_mgains(self)
Reset the modal gains only.
def set_modal_gains(self, mgains)
Sets manually the modal gains.
def adapt_modal_gains(self, flag)
Set the flag indicating to use CLOSE optimization.
cmat_modal
(np.ndarray) : modal command matrix