コード例 #1
0
ファイル: trigaussian.py プロジェクト: Solvi/pyhrf
 def __init__(self, parameters=None, xmlHandler=NumpyXMLHandler(),
              xmlLabel=None, xmlComment=None):
     BiGaussMixtureParamsSampler.__init__(self, parameters, xmlHandler,
                                          xmlLabel, xmlComment)
     
     self.varCDPrAlpha = self.parameters[self.P_VAR_CD_PR_ALPHA] 
     self.varCDPrBeta = self.parameters[self.P_VAR_CD_PR_BETA]
     self.meanCDPrMean = self.parameters[self.P_MEAN_CD_PR_MEAN]
     self.meanCDPrVar = self.parameters[self.P_MEAN_CD_PR_VAR]
コード例 #2
0
ファイル: trigaussian.py プロジェクト: pmesejo/pyhrf
    def checkAndSetInitValue(self, variables):

        if self.currentValue is None:
            curValWasNone = True
        else:
            curValWasNone = False
        BiGaussMixtureParamsSampler.checkAndSetInitValue(self, variables)
        #TODO : retrieve simulated components ...

        if curValWasNone:
            if not self.useTrueValue:
                nc = self.nbConditions
                self.currentValue[self.I_MEAN_CD] = zeros(nc) -10.
                self.currentValue[self.I_VAR_CD] = zeros(nc) + 1.
コード例 #3
0
ファイル: trigaussian.py プロジェクト: pmesejo/pyhrf
 def linkToData(self, dataInput):
     BiGaussMixtureParamsSampler.linkToData(self, dataInput)
     self.nrlCD = range(self.nbConditions)
     if self.dataInput.simulData is not None :
         mixtures = self.dataInput.simulData.nrls.getMixture()
         itemsCond = mixtures.items()
         meanCD = zeros(self.nbConditions, dtype=float)
         varCD = zeros(self.nbConditions, dtype=float)
         for cn,mixt in mixtures.iteritems():
             genDeactiv = mixt.generators['deactiv']
             indCond = self.dataInput.simulData.nrls.condIds[cn]
             meanCD[indCond] = genDeactiv.mean
             varCD[indCond] = genDeactiv.std**2
         self.trueValue[self.I_MEAN_CD] = meanCD
         self.trueValue[self.I_VAR_CD] = varCD
コード例 #4
0
ファイル: trigaussian.py プロジェクト: pmesejo/pyhrf
 def __init__(self, do_sampling=True, use_true_value=False,
              val_ini=None, hyper_prior_type='Jeffreys', activ_thresh=4.,
              var_ci_pr_alpha=2.04, var_ci_pr_beta=.5,
              var_ca_pr_alpha=2.01, var_ca_pr_beta=.5,
              var_cd_pr_alpha=2.01, var_cd_pr_beta=.5,
              mean_ca_pr_mean=5., mean_ca_pr_var=20.,
              mean_cd_pr_mean=-20., mean_cd_pr_var=20.):
     
     BiGaussMixtureParamsSampler.__init__(self, do_sampling, use_true_value,
                                          val_ini, hyper_prior_type,
                                          activ_thresh, var_ci_pr_alpha,
                                          var_ci_pr_beta, var_ca_pr_alpha,
                                          var_ca_pr_beta, mean_ca_pr_mean,
                                          mean_ca_pr_var)
     self.varCDPrAlpha = var_cd_pr_alpha
     self.varCDPrBeta = var_cd_pr_beta
     self.meanCDPrMean = mean_cd_pr_mean
     self.meanCDPrVar = mean_cd_pr_var
コード例 #5
0
ファイル: trigaussian.py プロジェクト: pmesejo/pyhrf
 def finalizeSampling(self):
     BiGaussMixtureParamsSampler.finalizeSampling(self)
     del self.nrlCD
コード例 #6
0
ファイル: trigaussian.py プロジェクト: pmesejo/pyhrf
    def sampleNextInternal(self, variables):
        #BiGaussMixtureParamsSampler.sampleNextInternal(self, variables)
        nrlsSmpl = variables[self.samplerEngine.I_NRLS]
        cardCD = nrlsSmpl.cardClass[self.L_CD,:]

        if self.hyperPriorFlag:
            for j in xrange(self.nbConditions):
                vICD = nrlsSmpl.voxIdx[nrlsSmpl.L_CD][j]
                self.nrlCD[j] = nrlsSmpl.currentValue[j, vICD]


                if cardCD[j] > 0:
                    etaj = mean(self.nrlCD[j])
                    nrlCDCentered = self.nrlCD[j] - etaj
                    nuj = .5 * dot(nrlCDCentered, nrlCDCentered)
                    #r = random.gamma(0.5*(cardCA[j]-1),2/nu1j)
                    varCDj = 1.0/random.gamma(0.5*cardCD[j] + self.varCDPrAlpha,
                                              1/(nuj + self.varCDPrBeta))
                    #meanCAj = random.normal(eta1j, (varCAj/cardCA[j])**0.5)
                else :
                    etaj = 0.0
                    varCDj = 1.0/random.gamma(self.varCDPrAlpha, 1/self.varCDPrBeta)

                invVarLikelihood = cardCD[j]/varCDj
                meanCDVarAPost = 1/(invVarLikelihood + 1/self.meanCDPrVar)
                rPrMV = self.meanCDPrMean/self.meanCDPrVar
                meanCDMeanAPost = meanCDVarAPost * (etaj*invVarLikelihood + rPrMV)
                meanCDj = random.normal(meanCDMeanAPost, meanCDVarAPost**0.5)

                self.currentValue[self.I_MEAN_CD, j] = meanCDj
                self.currentValue[self.I_VAR_CD, j] = varCDj

        else:
            nrlsSmpl = variables[self.samplerEngine.I_NRLS]

            #for j in xrange(self.nbConditions):

            for j in random.permutation(self.nbConditions):
                ca = nrlsSmpl.cardClass[self.L_CA,j]
                ci = nrlsSmpl.cardClass[self.L_CI,j]
                cd = nrlsSmpl.cardClass[self.L_CD,j]
                vICI = nrlsSmpl.voxIdx[nrlsSmpl.L_CI][j]
                vICA = nrlsSmpl.voxIdx[nrlsSmpl.L_CA][j]
                vICD = nrlsSmpl.voxIdx[nrlsSmpl.L_CD][j]
                self.nrlCI[j] = nrlsSmpl.currentValue[j, vICI]
                self.nrlCA[j] = nrlsSmpl.currentValue[j, vICA]
                self.nrlCD[j] = nrlsSmpl.currentValue[j, vICD]

                r = BiGaussMixtureParamsSampler.computeWithJeffreyPriors(self,j,
                                                                         ci,ca)
                varCIj, meanCAj, varCAj = r
                meanCD, varCD = self.computeWithJeffreyPriors(j,cd)


                self.currentValue[self.I_VAR_CI, j] = varCIj
                self.currentValue[self.I_MEAN_CA, j] = meanCAj #absolute(meanCAj)
                self.currentValue[self.I_VAR_CA, j] = varCAj
                self.currentValue[self.I_MEAN_CD,j] = meanCD
                self.currentValue[self.I_VAR_CD,j] = varCD

                pyhrf.verbose(4, 'meanCD,%d = %f' \
                                  %(j,self.currentValue[self.I_MEAN_CD,j]))

                pyhrf.verbose(4, 'varCD,%d = %f' \
                                  %(j,self.currentValue[self.I_VAR_CD,j]))