Ejemplo n.º 1
0
 def setUp(self):
     X = np.random.randn(100, 3)
     self.Data = XData(X=X)
     aPDict = dict(alpha0=1.0)
     oPDict = dict(min_covar=1e-9)
     self.hmodel = HModel.CreateEntireModel('EM', 'MixModel', 'ZMGauss',
                                            aPDict, oPDict, self.Data)
Ejemplo n.º 2
0
 def setUp(self):
     X = np.random.randn(100, 3)
     self.Data = XData(X=X)
     aPDict = dict(alpha0=1.0)
     oPDict = dict(dF=5, ECovMat='eye', sF=1.0)
     self.hmodel = HModel.CreateEntireModel('VB', 'MixModel', 'ZMGauss',
                                            aPDict, oPDict, self.Data)
Ejemplo n.º 3
0
  def setUp(self):
    PRNG = np.random.RandomState(867)
    X = PRNG.randn(100,2)
    self.Data = XData(X=X)

    aPDict = dict(alpha0=1.0)
    oPDict = dict(min_covar=1e-9)
    self.hmodel = HModel.CreateEntireModel('EM','MixModel','ZMGauss', aPDict, oPDict, self.Data)
    initParams = dict(initname='randexamples', seed=0, K=5)
    self.hmodel.init_global_params(self.Data, **initParams)
Ejemplo n.º 4
0
 def MakeModelWithTrueComps(self):
     ''' Create DPMix-Gauss model of self.Data, with K=3 *true* components.
     Store result as "hmodel" in self.
 '''
     aDict = dict(alpha0=1.0, truncType='z')
     oDict = dict(kappa=1e-7, dF=1, ECovMat='eye', sF=1e-3)
     self.hmodel = HModel.CreateEntireModel('VB', 'DPMixModel', 'Gauss',
                                            aDict, oDict, self.Data)
     LP = dict(resp=self.TrueResp)
     SS = self.hmodel.get_global_suff_stats(self.Data, LP)
     self.hmodel.update_global_params(SS)
Ejemplo n.º 5
0
 def MakeModelWithTrueComps(self):
     ''' Create hmodel with "true" components as self.Data, add to self
     Also create representative suff stats SS, add to self
 '''
     aDict = dict(alpha0=1.0, truncType='z')
     oDict = dict(kappa=1e-5, dF=1, ECovMat='eye', sF=1e-3)
     self.hmodel = HModel.CreateEntireModel('VB', 'DPMixModel', 'Gauss',
                                            aDict, oDict, self.Data)
     LP = dict(resp=self.TrueResp)
     SS = self.hmodel.get_global_suff_stats(self.Data, LP)
     self.hmodel.update_global_params(SS)
     LP = self.hmodel.calc_local_params(self.Data)
     flagDict = dict(doPrecompEntropy=True, doPrecompMergeEntropy=True)
     self.SS = self.hmodel.get_global_suff_stats(self.Data, LP, **flagDict)
Ejemplo n.º 6
0
 def MakeModelWithOneComp(self):
     ''' Create DPMix-Gauss model of self.Data, with K=1 components.
     Store result as "oneModel" in self,
        with updated suff stats field "oneSS"
 '''
     aDict = dict(alpha0=1.0, truncType='z')
     oDict = dict(kappa=1e-7, dF=1, ECovMat='eye', sF=1e-3)
     self.oneModel = HModel.CreateEntireModel('VB', 'DPMixModel', 'Gauss',
                                              aDict, oDict, self.Data)
     LP = dict(resp=np.ones((self.Data.nObs, 1)))
     SS = self.oneModel.get_global_suff_stats(self.Data, LP)
     assert SS.x.size == self.Data.dim
     assert self.oneModel.obsModel.obsPrior.D == self.Data.dim
     self.oneModel.update_global_params(SS)
     LP = self.oneModel.calc_local_params(self.Data)
     self.oneSS = self.oneModel.get_global_suff_stats(self.Data, LP)
Ejemplo n.º 7
0
  def setUp(self, K=7):
    ''' Create random data, and a K component MixModel to go with it
        Call this original model "hmodel".
        We copy hmodel into "modelB", and then save to file via save_model()
    '''
    self.K = K
    PRNG = np.random.RandomState(867)
    X = PRNG.randn(100,2)
    self.Data = XData(X=X)

    aPDict = dict(alpha0=1.0)
    oPDict = dict(min_covar=1e-9)
    self.hmodel = HModel.CreateEntireModel('EM','MixModel','ZMGauss', 
                                            aPDict, oPDict, self.Data)
    modelB = self.hmodel.copy()    
    initParams = dict(initname='randexamples', seed=0, K=self.K)
    modelB.init_global_params(self.Data, **initParams)
    ModelWriter.save_model(modelB, '/tmp/', 'Test')
    self.modelB = modelB
Ejemplo n.º 8
0
    def MakeModelWithDuplicatedComps(self):
        ''' Create model with "duplicated" components"
          For each true component k, we have "two" versions of it, k1 and k2.
            Half of the data generated by k is assigned to k1 
            and the other half is assigned to k2.
          These assignments are done via "dupResp" local parameter,
            and so by feeding that LP into SS and update_global_params.
    '''
        aDict = dict(alpha0=1.0, truncType='z')
        oDict = dict(kappa=1e-5, dF=1, ECovMat='eye', sF=1e-3)
        self.dupModel = HModel.CreateEntireModel('VB', 'DPMixModel', 'Gauss',
                                                 aDict, oDict, self.Data)

        LP = dict(resp=self.DupResp)
        SS = self.hmodel.get_global_suff_stats(self.Data, LP)
        self.dupModel.update_global_params(SS)

        LP = self.dupModel.calc_local_params(self.Data)
        flagDict = dict(doPrecompEntropy=True, doPrecompMergeEntropy=True)
        self.dupSS = self.dupModel.get_global_suff_stats(
            self.Data, LP, **flagDict)
Ejemplo n.º 9
0
 def MakeHModel(self):
     aPDict = dict(alpha0=1.0)
     oPDict = dict(min_covar=1e-9)
     self.hmodel = HModel.CreateEntireModel('EM', 'MixModel', 'ZMGauss',
                                            aPDict, oPDict, self.Data)
Ejemplo n.º 10
0
 def MakeHModel(self):
     aPDict = dict(alpha0=1.0)
     oPDict = dict(dF=5, ECovMat='eye', sF=1.0)
     self.hmodel = HModel.CreateEntireModel('VB', 'MixModel', 'ZMGauss',
                                            aPDict, oPDict, self.Data)