Example #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]
Example #2
0
    def sample(self, y, x_prev, n):
        """
        draw a sample from the proposal conditioned on current y and
        previous x
        
        """
        candidate_points = self.cached_candidate_points(y, x_prev, n)

        MIX_COMP = len(candidate_points)
        if MIX_COMP == 0 or n > self.DEBUG_STOP_PROPOSING:
            return self.base_proposal.sample(y, x_prev, n)
        mix_i = np.random.randint(0, MIX_COMP)

        prop = candidate_points[mix_i]
        SN = 1
        x_next = np.zeros(SN, dtype=model.DTYPE_LATENT_STATE).view(np.recarray)

        norm = np.random.normal

        x_next['x'] = norm(prop['x'], self.POS_STD)
        x_next['y'] = norm(prop['y'], self.POS_STD)

        x_next['phi'] = util.vonmises_rv(prop['phi'], self.PHI_STD**2)

        x_next['xdot'] = x_prev['xdot']
        x_next['ydot'] = x_prev['ydot']
        x_next['theta'] = x_prev['theta']
        x_next['meta'] = 1

        return x_next[0]
Example #3
0
    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]
Example #4
0
    def sample(self, y, x_prev, n):
        """
        draw a sample from the proposal conditioned on current y and
        previous x
        
        """
        candidate_points = self.cached_candidate_points(y, x_prev, n)

        MIX_COMP = len(candidate_points)        
        if MIX_COMP == 0 or n > self.DEBUG_STOP_PROPOSING:
            return self.base_proposal.sample(y, x_prev, n)
        mix_i = np.random.randint(0, MIX_COMP)
        
        prop = candidate_points[mix_i]
        SN = 1
        x_next = np.zeros(SN, dtype=model.DTYPE_LATENT_STATE).view(np.recarray)

        norm = np.random.normal
        
        x_next['x']= norm(prop['x'], self.POS_STD)
        x_next['y'] = norm(prop['y'], self.POS_STD)
    
        x_next['phi'] = util.vonmises_rv(prop['phi'], 
                                         self.PHI_STD**2)


        x_next['xdot'] = x_prev['xdot']
        x_next['ydot'] = x_prev['ydot']
        x_next['theta'] = x_prev['theta']
        x_next['meta'] = 1
        
        return x_next[0]
Example #5
0
    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]
Example #6
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]