Пример #1
0
/*
   logp += Math.log(Psi.det())*m*0.5;
   logp -= Math.log(PsiHat.det())*(m+n)*0.5;
   logp += GammaF.logGammaPRatio(p, m+n, m);
   logp -= 0.5*n*p*Math.log(Math.PI);
*/
func (this *IWPosterior) LogP() (ll float64) {
	if this.logP == 0 && this.S.Count != 0 {
		n := this.S.Count
		this.logP += math.Log(this.Psi.Det()) * float64(this.M) * 0.5
		this.logP -= math.Log(this.getPsiHat().Det()) * float64(this.M+n) * 0.5
		this.logP += stat.LnΓpRatio(this.Psi.Rows(), float64(this.M+n), float64(this.M))
		this.logP -= 0.5 * float64(n) * float64(this.Psi.Rows()) * math.Log(math.Pi)
	}

	return this.logP
}
Пример #2
0
func (this *IWPosterior) InsertLogRatio(x *matrix.DenseMatrix) (lr float64) {
	/*
				Matrix PsiHatPrime = Psi.plus(scatter.getPretendScatter(x));

		        int p = Psi.getColumnDimension();

		        double ll = 0;

		        ll -= 0.5*p*Math.log(Math.PI);

		        ll += Math.log(PsiHat.det())*(m+n)/2;
		        ll -= Math.log(PsiHatPrime.det())*(m+n+1)/2;

		        ll += GammaF.logGammaPRatio(p, m+n+1, m+n);
	*/
	//fmt.Printf("+IWPosterior.InsertLogRatio\n")
	//defer fmt.Printf("-IWPosterior.InsertLogRatio\n")
	insertScatter := this.S.Copy()
	insertScatter.Insert(x)
	psiHatPrime, _ := this.Psi.PlusDense(insertScatter.S)

	p := this.Psi.Rows()

	lr -= 0.5 * float64(p) * math.Log(math.Pi)
	//println(lr)

	n := this.S.Count
	psiHatDet := this.getPsiHat().Det()
	//fmt.Printf("psiHat = \n%v\n", this.getPsiHat())
	//fmt.Printf("psiHatDet = %f\n", psiHatDet)
	lr += math.Log(psiHatDet) * float64(this.M+n) / 2
	//println(lr)
	psiHatPrimeDet := psiHatPrime.Det()
	//fmt.Printf("psiHatPrime = \n%v\n", psiHatPrime)
	//fmt.Printf("psiHatPrimeDet = %f\n", psiHatPrimeDet)
	lr -= math.Log(psiHatPrimeDet) * float64(this.M+n+1) / 2
	//println(lr)

	lr += stat.LnΓpRatio(p, float64(this.M+n+1), float64(this.M+n))
	//println(lr)

	return
}