(self, m)
Calculate new step sizes.
        Args:
            m: Condition
Calculate new step sizes.
        Args:
            m: Condition
Calculate new step sizes . Args : m : Condition
def _stepadjust(self, m):
        """
        Calculate new step sizes.
        Args:
            m: Condition
        """
        # Cost estimate under prev dynamics, prev controller
        pdpc = self.traj_opt.estimate_cost(
                self.prev[m].traj_distr, self.prev[m].traj_info
        )
        # Cost estimate under prev dynamics, curr controller
        pdcc = self.traj_opt.estimate_cost(
                self.cur[m].traj_distr, self.prev[m].traj_info
        )
        # Cost estimate under curr dynamics, curr controller
        cdcc = self.traj_opt.estimate_cost(
                self.cur[m].traj_distr, self.cur[m].traj_info
        )

        ent = self._measure_ent(m)

        pmc = np.mean(np.sum(self.prev[m].cs, axis=1), axis=0)
        cmc = np.mean(np.sum(self.cur[m].cs, axis=1), axis=0)

        LOGGER.debug('Trajectory step: ent: %f cost: %f -> %f',
                     ent, pmc, cmc)

        _, cur_c_approx = approximated_cost(
                self.cur[m].sample_list, self.cur[m].traj_distr,
                self.cur[m].traj_info
        )
        cur_res = cur_c_approx - self.cur[m].cs

        LOGGER.debug('Previous cost: Laplace: %f MC: %f', np.sum(pdpc), pmc)
        LOGGER.debug('Predicted new cost: Laplace: %f MC: %f', np.sum(pdcc), cmc)
        LOGGER.debug('Actual new cost: Laplace: %f MC: %f', np.sum(cdcc), cmc)

        max_mult = self._hyperparams['max_step_mult']
        min_mult = self._hyperparams['min_step_mult']

        if self._hyperparams['step_rule'] == 'const':
            self.cur[m].step_mult = self.prev[m].step_mult
        elif self._hyperparams['step_rule'] == 'res_percent':
            cur_res_sum = np.mean(np.sum(np.abs(cur_res), axis=1))
            act_sum = np.mean(np.sum(np.abs(self.cur[m].cs), axis=1))
            # Print cost details.
            LOGGER.debug(
                    'Cur residuals: %f. Residuals percentage: %f',
                    cur_res_sum, cur_res_sum/act_sum*100
            )
            if self.traj_opt.cons_per_step:
                T = cur_res.shape[1]
                new_mult = np.ones(T)
                for t in range(T):
                    res = np.mean(np.sum(np.abs(cur_res[:, t:]), axis=1))
                    act = np.mean(np.sum(np.abs(self.cur[m].cs[:, t:]), axis=1))
                    if res / act > self._hyperparams['step_rule_res_ratio_dec']:
                        new_mult[t] = 0.5
                    elif res / act < self._hyperparams['step_rule_res_ratio_inc']:
                        new_mult[t] = 2.0
            else:
                if cur_res_sum / act_sum > self._hyperparams['step_rule_res_ratio_dec']:
                    new_mult = 0.5
                elif cur_res_sum / act_sum < self._hyperparams['step_rule_res_ratio_inc']:
                    new_mult = 2.0
                else:
                    new_mult = 1
            new_step = np.maximum(
                    np.minimum(new_mult * self.cur[m].step_mult, max_mult),
                    min_mult
            )
            self.cur[m].step_mult = new_step
        else:
            raise NotImplementedError('Unknown step adjustment rule.')
def _stepadjust ( self , m ) : # Cost estimate under prev dynamics, prev controller pdpc = self . traj_opt . estimate_cost ( self . prev [ m ] . traj_distr , self . prev [ m ] . traj_info ) # Cost estimate under prev dynamics, curr controller pdcc = self . traj_opt . estimate_cost ( self . cur [ m ] . traj_distr , self . prev [ m ] . traj_info ) # Cost estimate under curr dynamics, curr controller cdcc = self . traj_opt . estimate_cost ( self . cur [ m ] . traj_distr , self . cur [ m ] . traj_info ) ent = self . _measure_ent ( m ) pmc = np . mean ( np . sum ( self . prev [ m ] . cs , axis = 1 ) , axis = 0 ) cmc = np . mean ( np . sum ( self . cur [ m ] . cs , axis = 1 ) , axis = 0 ) LOGGER . debug ( 'Trajectory step: ent: %f cost: %f -> %f' , ent , pmc , cmc ) _ , cur_c_approx = approximated_cost ( self . cur [ m ] . sample_list , self . cur [ m ] . traj_distr , self . cur [ m ] . traj_info ) cur_res = cur_c_approx - self . cur [ m ] . cs LOGGER . debug ( 'Previous cost: Laplace: %f MC: %f' , np . sum ( pdpc ) , pmc ) LOGGER . debug ( 'Predicted new cost: Laplace: %f MC: %f' , np . sum ( pdcc ) , cmc ) LOGGER . debug ( 'Actual new cost: Laplace: %f MC: %f' , np . sum ( cdcc ) , cmc ) max_mult = self . _hyperparams [ 'max_step_mult' ] min_mult = self . _hyperparams [ 'min_step_mult' ] if self . _hyperparams [ 'step_rule' ] == 'const' : self . cur [ m ] . step_mult = self . prev [ m ] . step_mult elif self . _hyperparams [ 'step_rule' ] == 'res_percent' : cur_res_sum = np . mean ( np . sum ( np . abs ( cur_res ) , axis = 1 ) ) act_sum = np . mean ( np . sum ( np . abs ( self . cur [ m ] . cs ) , axis = 1 ) ) # Print cost details. LOGGER . debug ( 'Cur residuals: %f. Residuals percentage: %f' , cur_res_sum , cur_res_sum / act_sum * 100 ) if self . traj_opt . cons_per_step : T = cur_res . shape [ 1 ] new_mult = np . ones ( T ) for t in range ( T ) : res = np . mean ( np . sum ( np . abs ( cur_res [ : , t : ] ) , axis = 1 ) ) act = np . mean ( np . sum ( np . abs ( self . cur [ m ] . cs [ : , t : ] ) , axis = 1 ) ) if res / act > self . _hyperparams [ 'step_rule_res_ratio_dec' ] : new_mult [ t ] = 0.5 elif res / act < self . _hyperparams [ 'step_rule_res_ratio_inc' ] : new_mult [ t ] = 2.0 else : if cur_res_sum / act_sum > self . _hyperparams [ 'step_rule_res_ratio_dec' ] : new_mult = 0.5 elif cur_res_sum / act_sum < self . _hyperparams [ 'step_rule_res_ratio_inc' ] : new_mult = 2.0 else : new_mult = 1 new_step = np . maximum ( np . minimum ( new_mult * self . cur [ m ] . step_mult , max_mult ) , min_mult ) self . cur [ m ] . step_mult = new_step else : raise NotImplementedError ( 'Unknown step adjustment rule.' )