示例#1
0
 def likelihood(self, y, x, observation_point, sigma = 2):
     """
     likelihood関数
     p(y|x) ~ exp(|g_inverse(y)-x|**2 / simga**2)で定義
     yは観測値,xは隠れマルコフ変数,sigmaはデータからつくる
     """
     x_from_y = self.g_inverse(y, observation_point)
     v = mymath.vector()
     distance = range(len(y))
     for i in range(len(y)):
          distance[i] = x[i] - x_from_y[i]
     norm = math.pow(v.norm(distance), 2) 
     return math.exp(-norm / math.pow(sigma, 2))  
示例#2
0
    def pf_sir_step(self, X, W, y, sigma, date):
        """One Step of Sampling Importance Resampling for Particle Filter
        
        Parameters
        ----------
        X : array of [float|array]
        状態 List of state set
        W : array of float
        重み List of weight
        y : float or array
        観測 Observation set
        
        Returns
        -------
        X_resampled : array of [float|array]
        次の状態 List updated state
        W_resampled : array of float
        次の重み List updated weight
        """
        
        # パーティクルの数 num of particles
        N = len(X)
        # 次元数
        D = len(X[0])
        # 初期化
        X_predicted = [[1. for j in range(D)] for i in range(N)]
        W_updated   = [1. for i in range(N)]
        # 観測点の取得
        obs = self.select_observation_point(date)

        # 推定 prediction
        for i in range(N):
            X_predicted[i] = self.state_transition(X[i])
        # 更新 update
        for i in range(N):
            W_updated[i] = self.importance_sampling(W[i], X_predicted[i], y, obs, sigma)
        
        # 正規化 normalization
        v = mymath.vector()
        W_updated = v.normalization(W_updated)
        # リサンプリング re-sampling (if necessary)
        X_resampled, W_resampled = self.resampling(X_predicted, W_updated)
 
        return X_resampled, W_resampled