probtable.java

来自「java BayesianNetwork 源码」· Java 代码 · 共 55 行

JAVA
55
字号
/*
Jie Bao
2002-04-23
*/

// Condtional Probability Table
public class Probtable
{
	public int len;
	public int[] type; // of which class?
	public double[] Prob;
	
	public Probtable(int k)
	{
		len   = k;
		//Index = new int[k];
		Prob  = new double[k];
		type = new int[k];
		for (int i = 0 ; i < len ; i++)
		{	type[i] =0;  Prob[i] = 10e-10; }
	}
	
	public void Normalize(double sum)
	{
		if( sum == 0)
			return;
		double div = (sum+len*10e-10);
		for (int i = 0 ; i < len ; i++ )
		{
			Prob[i] /= div;
		}
	}
	
	// normallize by class
	// input: numClass: sample number of each class
	//        limit: the number of classes
	public void ClassNormalize(int[] numClass, int limit)
	{
		for (int j = 0 ; j < len ; j++ )
		{
			if (numClass[type[j]] != 0)
				Prob[j] /= numClass[type[j]];
		}
	}
	
	public void print()
	{
		System.out.println("\nlength of table ="+ len);
		
		for (int i = 0 ; i < len ; i++ )
		{
			System.out.println(i +": type ="+ type[i] + " Prob ="+Prob[i]);		
		}		
	}	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?