(self, X, U)
return self.Fm, self.fv, self.dyn_covar
Fit dynamics.
Fit dynamics.
Fit dynamics .
def fit(self, X, U):
        """ Fit dynamics. """
        N, T, dX = X.shape
        dU = U.shape[2]

        if N == 1:
            raise ValueError("Cannot fit dynamics on 1 sample")

        self.Fm = np.zeros([T, dX, dX+dU])
        self.fv = np.zeros([T, dX])
        self.dyn_covar = np.zeros([T, dX, dX])

        it = slice(dX+dU)
        ip = slice(dX+dU, dX+dU+dX)
        # Fit dynamics wih least squares regression.
        for t in range(T - 1):
            xux = np.c_[X[:, t, :], U[:, t, :], X[:, t+1, :]]
            xux_mean = np.mean(xux, axis=0)
            empsig = (xux - xux_mean).T.dot(xux - xux_mean) / N
            sigma = 0.5 * (empsig + empsig.T)
            sigma[it, it] += self._hyperparams['regularization']

            Fm = np.linalg.solve(sigma[it, it], sigma[it, ip]).T
            fv = xux_mean[ip] - Fm.dot(xux_mean[it])

            self.Fm[t, :, :] = Fm
            self.fv[t, :] = fv

            dyn_covar = sigma[ip, ip] - Fm.dot(sigma[it, it]).dot(Fm.T)
            self.dyn_covar[t, :, :] = 0.5 * (dyn_covar + dyn_covar.T)
        return self.Fm, self.fv, self.dyn_covar
def fit ( self , X , U ) : N , T , dX = X . shape dU = U . shape [ 2 ] if N == 1 : raise ValueError ( "Cannot fit dynamics on 1 sample" ) self . Fm = np . zeros ( [ T , dX , dX + dU ] ) self . fv = np . zeros ( [ T , dX ] ) self . dyn_covar = np . zeros ( [ T , dX , dX ] ) it = slice ( dX + dU ) ip = slice ( dX + dU , dX + dU + dX ) # Fit dynamics wih least squares regression. for t in range ( T - 1 ) : xux = np . c_ [ X [ : , t , : ] , U [ : , t , : ] , X [ : , t + 1 , : ] ] xux_mean = np . mean ( xux , axis = 0 ) empsig = ( xux - xux_mean ) . T . dot ( xux - xux_mean ) / N sigma = 0.5 * ( empsig + empsig . T ) sigma [ it , it ] += self . _hyperparams [ 'regularization' ] Fm = np . linalg . solve ( sigma [ it , it ] , sigma [ it , ip ] ) . T fv = xux_mean [ ip ] - Fm . dot ( xux_mean [ it ] ) self . Fm [ t , : , : ] = Fm self . fv [ t , : ] = fv dyn_covar = sigma [ ip , ip ] - Fm . dot ( sigma [ it , it ] ) . dot ( Fm . T ) self . dyn_covar [ t , : , : ] = 0.5 * ( dyn_covar + dyn_covar . T ) return self . Fm , self . fv , self . dyn_covar