Ejemplo n.º 1
0
    def __init__(self,
                 num_states=None,
                 alpha=None,
                 alphav=None,
                 trans_matrix=None):
        self.N = num_states

        if trans_matrix is not None:
            self._row_distns = [
                Multinomial(alpha_0=alpha,
                            K=self.N,
                            alphav_0=alphav,
                            weights=row) for row in trans_matrix
            ]
        elif None not in (alpha, self.N) or (alphav is not None
                                             and alphav.ndim < 2):
            self._row_distns = [
                Multinomial(alpha_0=alpha, K=self.N, alphav_0=alphav)
                for n in range(self.N)
            ]  # sample from prior
        # for the case where we pass a matrix for the alpha (used mainly for adding the stickiness)
        elif None not in (alpha, self.N) or (alphav is not None
                                             and alphav.ndim == 2):
            self._row_distns = [
                Multinomial(alpha_0=alpha, K=self.N, alphav_0=alphav[n, :])
                for n in range(self.N)
            ]  # sample from prior
Ejemplo n.º 2
0
    def __init__(self,num_states=None,alpha=None,alphav=None,trans_matrix=None):
        self.N = num_states

        if trans_matrix is not None:
            self._row_distns = [Multinomial(alpha_0=alpha,K=self.N,alphav_0=alphav,
                weights=row) for row in trans_matrix]
        elif None not in (alpha,self.N) or alphav is not None:
            self._row_distns = [Multinomial(alpha_0=alpha,K=self.N,alphav_0=alphav)
                    for n in xrange(self.N)] # sample from prior
Ejemplo n.º 3
0
 def trans_matrix(self, trans_matrix):
     N = self.N = trans_matrix.shape[0]
     if self.alphav.ndim < 2:
         self._row_distns = \
                 [Multinomial(alpha_0=self.alpha,K=N,alphav_0=self.alphav,weights=row)
                         for row in trans_matrix]
     elif self.alphav.ndim == 2:
         self._row_distns = \
                 [Multinomial(alpha_0=self.alpha,K=N,alphav_0=self.alphav[n,:],weights=row)
                         for n, row in enumerate(trans_matrix)]
Ejemplo n.º 4
0
    def __init__(self,gamma,alpha,num_states=None,beta=None,trans_matrix=None):
        if num_states is None:
            assert beta is not None or trans_matrix is not None
            self.N = len(beta) if beta is not None else trans_matrix.shape[0]
        else:
            self.N = num_states

        self.alpha = alpha
        self.beta_obj = Multinomial(alpha_0=gamma,K=self.N,weights=beta)

        super(_WeakLimitHDPHMMTransitionsBase,self).__init__(
                num_states=self.N,alpha=alpha,
                alphav=alpha*self.beta,trans_matrix=trans_matrix)
Ejemplo n.º 5
0
 def trans_matrix(self, trans_matrix):
     N = self.N = trans_matrix.shape[0]
     self._row_distns = [
         Multinomial(alpha_0=self.alpha,
                     K=N,
                     alphav_0=self.alphav,
                     weights=row) for row in trans_matrix
     ]
Ejemplo n.º 6
0
class _WeakLimitHDPHMMTransitionsBase(_HMMTransitionsBase):
    def __init__(self,
                 gamma,
                 alpha,
                 num_states=None,
                 beta=None,
                 trans_matrix=None):
        if num_states is None:
            assert beta is not None or trans_matrix is not None
            self.N = len(beta) if beta is not None else trans_matrix.shape[0]
        else:
            self.N = num_states

        self.alpha = alpha
        self.beta_obj = Multinomial(alpha_0=gamma, K=self.N, weights=beta)

        super(_WeakLimitHDPHMMTransitionsBase, self).__init__(
            num_states=self.N,
            alpha=alpha,
            alphav=alpha * self.beta,
            trans_matrix=trans_matrix,
        )

    @property
    def beta(self):
        return self.beta_obj.weights

    @beta.setter
    def beta(self, weights):
        self.beta_obj.weights = weights
        self.alphav = self.alpha * self.beta

    @property
    def gamma(self):
        return self.beta_obj.alpha_0

    @gamma.setter
    def gamma(self, val):
        self.beta_obj.alpha_0 = val

    @property
    def alpha(self):
        return self._alpha

    @alpha.setter
    def alpha(self, val):
        self._alpha = val

    def copy_sample(self):
        new = super(_WeakLimitHDPHMMTransitionsBase, self).copy_sample()
        new.beta_obj = self.beta_obj.copy_sample()
        return new
Ejemplo n.º 7
0
    def __init__(self,gamma,alpha,num_states=None,beta=None,trans_matrix=None):
        if num_states is None:
            assert beta is not None or trans_matrix is not None
            self.N = len(beta) if beta is not None else trans_matrix.shape[0]
        else:
            self.N = num_states

        self.alpha = alpha
        self.beta_obj = Multinomial(alpha_0=gamma,K=self.N,weights=beta)

        super(_WeakLimitHDPHMMTransitionsBase,self).__init__(
                num_states=self.N,alpha=alpha,
                alphav=alpha*self.beta,trans_matrix=trans_matrix)
Ejemplo n.º 8
0
class _WeakLimitHDPHMMTransitionsBase(_HMMTransitionsBase):
    def __init__(self,gamma,alpha,num_states=None,beta=None,trans_matrix=None):
        if num_states is None:
            assert beta is not None or trans_matrix is not None
            self.N = len(beta) if beta is not None else trans_matrix.shape[0]
        else:
            self.N = num_states

        self.alpha = alpha
        self.beta_obj = Multinomial(alpha_0=gamma,K=self.N,weights=beta)

        super(_WeakLimitHDPHMMTransitionsBase,self).__init__(
                num_states=self.N,alpha=alpha,
                alphav=alpha*self.beta,trans_matrix=trans_matrix)

    @property
    def beta(self):
        return self.beta_obj.weights

    @beta.setter
    def beta(self,weights):
        self.beta_obj.weights = weights
        self.alphav = self.alpha * self.beta

    @property
    def gamma(self):
        return self.beta_obj.alpha_0

    @gamma.setter
    def gamma(self,val):
        self.beta_obj.alpha_0 = val

    @property
    def alpha(self):
        return self._alpha

    @alpha.setter
    def alpha(self,val):
        self._alpha = val

    def copy_sample(self):
        new = super(_WeakLimitHDPHMMTransitionsBase,self).copy_sample()
        new.beta_obj = self.beta_obj.copy_sample()
        return new