This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public double ProbabilityOfInputIfPositive(double in[]){ | |
double prob = 1/Math.sqrt(2 * Math.PI) ; | |
for(int j=0; j<in.length;j++){ | |
prob*= Math.exp(- (in[j]-posmean[j])*(in[j]-posmean[j]) / (2*posvariance[j]) ) ; | |
} | |
return prob ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//constructs a naive Bayes binary classifier | |
public NaiveBayes(double in[][], boolean out[]){ | |
int inputs = in[0].length ; | |
//initialize sums and sums of squares for each class | |
double[] poss = new double[inputs], poss2 = new double[inputs]; | |
double[] negs = new double[inputs], negs2 = new double[inputs]; | |
//calculate amount of each class, sums, and sums of squares | |
for(int k=0;k<in.length;k++){//for each data point | |
if(out[k]){ | |
positives++;//keep track of total positives |
NewerOlder