コード例 #1
0
    def sample(self, y, x_prev, n):
        """
        draw a sample from the proposal conditioned on current y and
        previous x
        
        """
        SN = 1
        x_next = np.zeros(SN, dtype=model.DTYPE_LATENT_STATE).view(np.recarray)
        x_det = x_prev['x'] + x_prev['xdot'] * self.DELTA_T
        y_det = x_prev['y'] + x_prev['ydot'] * self.DELTA_T

        norm = np.random.normal

        x_next['x'] = x_det + norm(0, self.POS_NOISE_STD, size=SN)
        x_next['y'] = y_det + norm(0, self.POS_NOISE_STD, size=SN)

        x_next['xdot'] = norm(x_prev['xdot'], self.VELOCITY_NOISE_STD, size=SN)

        x_next['ydot'] = norm(x_prev['ydot'], self.VELOCITY_NOISE_STD, size=SN)

        x_next['phi'] = util.vonmises_rv(x_prev['phi'], self.PHI_NOISE_STD**2)

        val, failures = drift_reject.rej_sample(
            x_prev['theta'] - self.THETA_OFFSET, self.THETA_DRIFT_SIZE,
            self.THETA_ENVELOPE_SIZE)
        x_next['theta'] = self.THETA_OFFSET + val

        return x_next[0]
コード例 #2
0
    def sample(self, y, x_prev, n):
        """
        draw a sample from the proposal conditioned on current y and
        previous x
        
        """
        est_mu, est_var = self.cached_mean_var(y, n)

        SN = 1
        x_next = np.zeros(SN, dtype=model.DTYPE_LATENT_STATE).view(np.recarray)
        x_det = x_prev['x'] + x_prev['xdot'] * self.DELTA_T
        y_det = x_prev['y'] + x_prev['ydot'] * self.DELTA_T

        norm = np.random.normal
        if est_mu != None and (est_var > 0.001).all():
            x_next['x'] = norm(est_mu[0], np.sqrt(est_var[0]))
            x_next['y'] = norm(est_mu[1], np.sqrt(est_var[1]))
        else:
            x_next['x'] = x_det + norm(0, self.POS_NOISE_STD, size=SN)
            x_next['y'] = y_det + norm(0, self.POS_NOISE_STD, size=SN)

        x_next['xdot'] = norm(x_prev['xdot'], self.VELOCITY_NOISE_STD, size=SN)

        x_next['ydot'] = norm(x_prev['ydot'], self.VELOCITY_NOISE_STD, size=SN)

        x_next['phi'] = norm(x_prev['phi'], self.PHI_NOISE_STD, size=SN)

        val, failures = drift_reject.rej_sample(
            x_prev['theta'] - self.THETA_OFFSET, self.THETA_DRIFT_SIZE,
            self.THETA_ENVELOPE_SIZE)
        x_next['theta'] = self.THETA_OFFSET + val

        x_next['meta'] = 0

        return x_next[0]
コード例 #3
0
ファイル: model.py プロジェクト: ericmjonas/franktrack
    def sample_next_latent(self, xn, n):
        """
        Return X_{n+1} | x_n

        """
        # right now this is totally linear, gaussian with
        # an identity covariance matrix
        SN = 1
        x_next = np.zeros(SN, dtype=DTYPE_LATENT_STATE).view(np.recarray)
        x_det = xn["x"] + xn["xdot"] * self.DELTA_T
        y_det = xn["y"] + xn["ydot"] * self.DELTA_T

        x_next["x"] = x_det + np.random.normal(0, self.POS_NOISE_STD, size=SN)
        x_next["y"] = y_det + np.random.normal(0, self.POS_NOISE_STD, size=SN)

        x_next["xdot"] = np.random.normal(xn["xdot"], self.VELOCITY_NOISE_STD, size=SN)

        x_next["ydot"] = np.random.normal(xn["ydot"], self.VELOCITY_NOISE_STD, size=SN)

        x_next["phi"] = util.vonmises_rv(xn["phi"], self.PHI_NOISE_STD ** 2)

        val, failures = drift_reject.rej_sample(
            xn["theta"] - self.THETA_OFFSET, self.THETA_DRIFT_SIZE, self.THETA_ENVELOPE_SIZE
        )
        x_next["theta"] = self.THETA_OFFSET + val

        return x_next[0]
コード例 #4
0
    def sample_next_latent_model(self, xn, x):

        # right now this is totally linear, gaussian with
        # an identity covariance matrix
        SN = 1
        x_next = np.zeros(SN, dtype=DTYPE_LATENT_STATE).view(np.recarray)
        x_det = xn['x'] + xn['xdot'] * self.DELTA_T
        y_det = xn['y'] + xn['ydot'] * self.DELTA_T

        x_next['x'] = x_det + np.random.normal(0, self.POS_NOISE_STD, size=SN)
        x_next['y'] = y_det + np.random.normal(0, self.POS_NOISE_STD, size=SN)

        x_next['xdot'] = np.random.normal(xn['xdot'],
                                          self.VELOCITY_NOISE_STD,
                                          size=SN)

        x_next['ydot'] = np.random.normal(xn['ydot'],
                                          self.VELOCITY_NOISE_STD,
                                          size=SN)

        x_next['phi'] = np.random.normal(xn['phi'],
                                         self.PHI_NOISE_STD,
                                         size=SN)

        val, failures = drift_reject.rej_sample(
            xn['theta'] - self.THETA_OFFSET, self.THETA_DRIFT_SIZE,
            self.THETA_ENVELOPE_SIZE)
        x_next['theta'] = self.THETA_OFFSET + val

        return x_next[0]
コード例 #5
0
ファイル: proposals.py プロジェクト: ericmjonas/franktrack
    def sample(self, y, x_prev, n):
        """
        draw a sample from the proposal conditioned on current y and
        previous x
        
        """
        est_mu, est_var = self.cached_mean_var(y, n)

        SN = 1
        x_next = np.zeros(SN, dtype=model.DTYPE_LATENT_STATE).view(np.recarray)
        x_det = x_prev['x'] + x_prev['xdot'] * self.DELTA_T
        y_det = x_prev['y'] + x_prev['ydot'] * self.DELTA_T

        norm = np.random.normal
        if est_mu != None and (est_var > 0.001).all():
            x_next['x']= norm(est_mu[0], np.sqrt(est_var[0]))
            x_next['y'] = norm(est_mu[1], np.sqrt(est_var[1]))
        else:
            x_next['x']= x_det + norm(0, 
                                      self.POS_NOISE_STD, size=SN)
            x_next['y'] = y_det + norm(0, 
                                       self.POS_NOISE_STD, size=SN)
    
        x_next['xdot'] = norm(x_prev['xdot'], 
                                       self.VELOCITY_NOISE_STD, size=SN)

        x_next['ydot'] = norm(x_prev['ydot'], 
                                       self.VELOCITY_NOISE_STD, size=SN)

        x_next['phi'] = norm(x_prev['phi'], 
                                       self.PHI_NOISE_STD, size=SN)


        val, failures =  drift_reject.rej_sample(x_prev['theta'] - self.THETA_OFFSET, 
                                                 self.THETA_DRIFT_SIZE, 
                                                 self.THETA_ENVELOPE_SIZE)
        x_next['theta'] = self.THETA_OFFSET + val

        x_next['meta'] = 0
        
        
        return x_next[0]
コード例 #6
0
ファイル: proposals.py プロジェクト: ericmjonas/franktrack
    def sample(self, y, x_prev, n):
        """
        draw a sample from the proposal conditioned on current y and
        previous x
        
        """
        SN = 1
        x_next = np.zeros(SN, dtype=model.DTYPE_LATENT_STATE).view(np.recarray)
        x_det = x_prev['x'] + x_prev['xdot'] * self.DELTA_T
        y_det = x_prev['y'] + x_prev['ydot'] * self.DELTA_T

        norm = np.random.normal

        x_next['x']= x_det + norm(0, 
                                    self.POS_NOISE_STD, size=SN)
        x_next['y'] = y_det + norm(0, 
                                    self.POS_NOISE_STD, size=SN)
    
        x_next['xdot'] = norm(x_prev['xdot'], 
                                       self.VELOCITY_NOISE_STD, size=SN)

        x_next['ydot'] = norm(x_prev['ydot'], 
                                       self.VELOCITY_NOISE_STD, size=SN)

        x_next['phi'] = util.vonmises_rv(x_prev['phi'], 
                                         self.PHI_NOISE_STD**2)


        val, failures =  drift_reject.rej_sample(x_prev['theta'] - self.THETA_OFFSET, 
                                                 self.THETA_DRIFT_SIZE, 
                                                 self.THETA_ENVELOPE_SIZE)
        x_next['theta'] = self.THETA_OFFSET + val

        
        
        return x_next[0]