(self, policy, condition, verbose=True, save=True, noisy=True)
return new_sample
Runs a trial and constructs a new sample containing information
        about the trial.
        Args:
            policy: Policy to to used in the trial.
            condition: Which condition setup to run.
            verbose: Whether or not to plot the trial.
            save: Whether or not to store the trial into the samples.
            noisy: Whether or not to use noise during sampling.
Runs a trial and constructs a new sample containing information
        about the trial.
        Args:
            policy: Policy to to used in the trial.
            condition: Which condition setup to run.
            verbose: Whether or not to plot the trial.
            save: Whether or not to store the trial into the samples.
            noisy: Whether or not to use noise during sampling.
Runs a trial and constructs a new sample containing information about the trial . Args : policy : Policy to to used in the trial . condition : Which condition setup to run . verbose : Whether or not to plot the trial . save : Whether or not to store the trial into the samples . noisy : Whether or not to use noise during sampling .
def sample(self, policy, condition, verbose=True, save=True, noisy=True):
        """
        Runs a trial and constructs a new sample containing information
        about the trial.
        Args:
            policy: Policy to to used in the trial.
            condition: Which condition setup to run.
            verbose: Whether or not to plot the trial.
            save: Whether or not to store the trial into the samples.
            noisy: Whether or not to use noise during sampling.
        """
        # Create new sample, populate first time step.
        feature_fn = None
        if 'get_features' in dir(policy):
            feature_fn = policy.get_features
        new_sample = self._init_sample(condition, feature_fn=feature_fn)
        mj_X = self._hyperparams['x0'][condition]
        U = np.zeros([self.T, self.dU])
        if noisy:
            noise = generate_noise(self.T, self.dU, self._hyperparams)
        else:
            noise = np.zeros((self.T, self.dU))
        if np.any(self._hyperparams['x0var'][condition] > 0):
            x0n = self._hyperparams['x0var'] * \
                    np.random.randn(self._hyperparams['x0var'].shape)
            mj_X += x0n
        noisy_body_idx = self._hyperparams['noisy_body_idx'][condition]
        if noisy_body_idx.size > 0:
            for i in range(len(noisy_body_idx)):
                idx = noisy_body_idx[i]
                var = self._hyperparams['noisy_body_var'][condition][i]
                self._model[condition]['body_pos'][idx, :] += \
                        var * np.random.randn(1, 3)
        # Take the sample.
        for t in range(self.T):
            X_t = new_sample.get_X(t=t)
            obs_t = new_sample.get_obs(t=t)
            mj_U = policy.act(X_t, obs_t, t, noise[t, :])
            U[t, :] = mj_U
            if verbose:
                self._world[condition].plot(mj_X)
            if (t + 1) < self.T:
                for _ in range(self._hyperparams['substeps']):
                    mj_X, _ = self._world[condition].step(mj_X, mj_U)
                self._data = self._world[condition].get_data()
                self._set_sample(new_sample, mj_X, t, condition, feature_fn=feature_fn)
        new_sample.set(ACTION, U)
        new_sample.set(NOISE, noise)
        if save:
            self._samples[condition].append(new_sample)
        return new_sample
def sample ( self , policy , condition , verbose = True , save = True , noisy = True ) : # Create new sample, populate first time step. feature_fn = None if 'get_features' in dir ( policy ) : feature_fn = policy . get_features new_sample = self . _init_sample ( condition , feature_fn = feature_fn ) mj_X = self . _hyperparams [ 'x0' ] [ condition ] U = np . zeros ( [ self . T , self . dU ] ) if noisy : noise = generate_noise ( self . T , self . dU , self . _hyperparams ) else : noise = np . zeros ( ( self . T , self . dU ) ) if np . any ( self . _hyperparams [ 'x0var' ] [ condition ] > 0 ) : x0n = self . _hyperparams [ 'x0var' ] * np . random . randn ( self . _hyperparams [ 'x0var' ] . shape ) mj_X += x0n noisy_body_idx = self . _hyperparams [ 'noisy_body_idx' ] [ condition ] if noisy_body_idx . size > 0 : for i in range ( len ( noisy_body_idx ) ) : idx = noisy_body_idx [ i ] var = self . _hyperparams [ 'noisy_body_var' ] [ condition ] [ i ] self . _model [ condition ] [ 'body_pos' ] [ idx , : ] += var * np . random . randn ( 1 , 3 ) # Take the sample. for t in range ( self . T ) : X_t = new_sample . get_X ( t = t ) obs_t = new_sample . get_obs ( t = t ) mj_U = policy . act ( X_t , obs_t , t , noise [ t , : ] ) U [ t , : ] = mj_U if verbose : self . _world [ condition ] . plot ( mj_X ) if ( t + 1 ) < self . T : for _ in range ( self . _hyperparams [ 'substeps' ] ) : mj_X , _ = self . _world [ condition ] . step ( mj_X , mj_U ) self . _data = self . _world [ condition ] . get_data ( ) self . _set_sample ( new_sample , mj_X , t , condition , feature_fn = feature_fn ) new_sample . set ( ACTION , U ) new_sample . set ( NOISE , noise ) if save : self . _samples [ condition ] . append ( new_sample ) return new_sample