def sample_transition_full_rank(model, state, hyperparams, pseudo_dof=None, pseudo_sd=None):
    """
    MCMC iteration (Gibbs sampling) for transition matrix and covariance
    with full rank model
    """

    Q = model.transition_covariance()

    # Sampke a pseudo-observation to constrain the size of move
    if pseudo_dof is not None:
        extra_nu = pseudo_dof
        extra_Psi = smp.sample_wishart(pseudo_dof, Q)
    else:
        extra_nu = 0
        extra_Psi = 0

    # Calculate sufficient statistics
    suffStats = smp.evaluate_transition_sufficient_statistics(state)

    # Sample a new projected transition matrix and transition covariance
    nu0 = model.ds + extra_nu
    Psi0 = model.ds*hyperparams['rPsi0'] + extra_Psi
    nu,Psi,M,V = smp.hyperparam_update_basic_mniw_transition(
                                                suffStats,
                                                nu0,
                                                Psi0,
                                                hyperparams['M0'],
                                                hyperparams['V0'])
    Q = la.inv(smp.sample_wishart(nu, la.inv(Psi)))
    F = smp.sample_matrix_normal(M, Q, V)

    model.parameters['F'] = F
    model.parameters['Q']= Q

    return model
Exemple #2
0
def sample_transition_full_rank(model,
                                state,
                                hyperparams,
                                pseudo_dof=None,
                                pseudo_sd=None):
    """
    MCMC iteration (Gibbs sampling) for transition matrix and covariance
    with full rank model
    """

    Q = model.transition_covariance()

    # Sampke a pseudo-observation to constrain the size of move
    if pseudo_dof is not None:
        extra_nu = pseudo_dof
        extra_Psi = smp.sample_wishart(pseudo_dof, Q)
    else:
        extra_nu = 0
        extra_Psi = 0

    # Calculate sufficient statistics
    suffStats = smp.evaluate_transition_sufficient_statistics(state)

    # Sample a new projected transition matrix and transition covariance
    nu0 = model.ds + extra_nu
    Psi0 = model.ds * hyperparams['rPsi0'] + extra_Psi
    nu, Psi, M, V = smp.hyperparam_update_basic_mniw_transition(
        suffStats, nu0, Psi0, hyperparams['M0'], hyperparams['V0'])
    Q = la.inv(smp.sample_wishart(nu, la.inv(Psi)))
    F = smp.sample_matrix_normal(M, Q, V)

    model.parameters['F'] = F
    model.parameters['Q'] = Q

    return model
    def sample_transition(self):
        """
        MCMC iteration (Gibbs sampling) for transition matrix and covariance
        """

        # Calculate sufficient statistics using current state trajectory
        suffStats = smp.evaluate_transition_sufficient_statistics(self.state)

        # Update hyperparameters
        nu,Psi,M,V = smp.hyperparam_update_basic_mniw_transition(
                                                    suffStats,
                                                    self.hyperparams['nu0'],
                                                    self.hyperparams['Psi0'],
                                                    self.hyperparams['M0'],
                                                    self.hyperparams['V0'])

        # Sample new parameters
        Q = la.inv(smp.sample_wishart(nu, la.inv(Psi)))
        F = smp.sample_matrix_normal(M, Q, V)

        # Update the model
        self.model.parameters['F'] = F
        self.model.parameters['Q'] = Q

        # self.flt and self.lhood are no longer up-to-date
        self.filter_current = False
Exemple #4
0
    def sample_transition(self):
        """
        MCMC iteration (Gibbs sampling) for transition matrix and covariance
        """

        # Calculate sufficient statistics using current state trajectory
        suffStats = smp.evaluate_transition_sufficient_statistics(self.state)

        # Update hyperparameters
        nu, Psi, M, V = smp.hyperparam_update_basic_mniw_transition(
            suffStats, self.hyperparams['nu0'], self.hyperparams['Psi0'],
            self.hyperparams['M0'], self.hyperparams['V0'])

        # Sample new parameters
        Q = la.inv(smp.sample_wishart(nu, la.inv(Psi)))
        F = smp.sample_matrix_normal(M, Q, V)

        # Update the model
        self.model.parameters['F'] = F
        self.model.parameters['Q'] = Q

        # self.flt and self.lhood are no longer up-to-date
        self.filter_current = False