def set_initial_gains(SS, K0_method, K0=None):
    # Initial gains
    if K0_method == 'random':
        K0 = randn(*SS.Kare.shape)
        SS.setK(K0)
        while not SS.c < np.inf:
            K0 = randn(*SS.Kare.shape)  # May take forever
            SS.setK(K0)
    elif K0_method == 'random_olmss':
        K0 = randn(*SS.Kare.shape)
        SS.setK(K0)
        while not SS.c < np.inf:
            K0 = 0.9 * K0  # Only guaranteed to work if sys open loop mean-square stable
            SS.setK(K0)
    elif K0_method == 'are':
        K0 = SS.Kare
        print('Initializing at the ARE solution')
    elif K0_method == 'are_perturbed':
        perturb_scale = 10.0 / SS.n  # scale with 1/n as rough heuristic
        safety_scale = 10.0
        Kp = randn(SS.Kare.shape[0], SS.Kare.shape[1])
        K0 = SS.Kare + perturb_scale * Kp
        SS.setK(K0)
        while not SS.c < safety_scale * SS.ccare:
            perturb_scale *= 0.2
            K0 = SS.Kare + perturb_scale * Kp
            SS.setK(K0)
        while not SS.c > safety_scale * SS.ccare:
            perturb_scale *= 1.01
            K0 = SS.Kare + perturb_scale * Kp
            SS.setK(K0)
        perturb_scale /= 1.01
        K0 = SS.Kare + perturb_scale * Kp
        SS.setK(K0)
    elif K0_method == 'zero':
        K0 = np.zeros([SS.m, SS.n])
        SS.setK(K0)
        P = dlyap_obj(SS, algo='iterative', show_warn=False)
        if P is not None:
            print('Initializing with zero gain solution')
        else:
            print(
                'System not open-loop mean-square stable, use a different initial gain setting'
            )
    elif K0_method == 'user':
        K0 = K0
    SS.setK(K0)
    return K0
def set_initial_gains(SS, K0_method):
    # Initial gains
    if K0_method == 'random':
        K0 = randn(SS.Kare.shape)
        SS.setK(K0)
        while not SS.c < np.inf:
            K0 = 0.9 * K0  # Only guaranteed to work if sys open loop mean-square stable
            SS.setK(K0)
    if K0_method == 'are':
        K0 = SS.Kare
        print('Initializing at the ARE solution')

    elif K0_method == 'perturbed_are_safe':
        perturb_scale = float(10) / float(
            SS.n)  # scale with 1/n as rough heuristic
        safety_scale = float(10)
        Kp = randn(SS.Kare.shape[0], SS.Kare.shape[1])
        K0 = SS.Kare + perturb_scale * Kp
        SS.setK(K0)
        while not SS.c < safety_scale * SS.ccare:
            perturb_scale *= 0.5
            K0 = SS.Kare + perturb_scale * Kp
    elif K0_method == 'zero':
        K0 = np.zeros([SS.m, SS.n])
        SS.setK(K0)
        P = dlyap_obj(SS, algo='iterative', show_warn=False)
        if P is not None:
            print('Initializing with zero gain solution')
        else:
            print(
                'System not open-loop mean-square stable, use a different initial gain setting'
            )
    elif K0_method == 'user':
        K0[K1_subs] = 7.2
        K0[K2_subs] = -0.37
    SS.setK(K0)
Example #3
0
 def sample_Brand(self):
     self._Brand = np.copy(self.B)
     for j in range(self.q):
         self._Brand += (self.b[j]**0.5) * randn() * self.Bb[:, :, j]
     return self._Brand
Example #4
0
 def sample_Arand(self):
     self._Arand = np.copy(self.A)
     for i in range(self.p):
         self._Arand += (self.a[i]**0.5) * randn() * self.Aa[:, :, i]
     return self._Arand