The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Classification Sampling
Posted by: Simon | February 1, 2011 @ 12:06pm
Other Code
[
Download
]
public double[][] sampleGibbsClassificationsIG(double[] observations, double[][] parameters) { Random ran = new Random(); double[][] observationClass = new double[observations.length][2]; Double[][] probabilities = new Double[parameters.length][2]; double[] IGparams = new double[2]; Double constant = 0.0; double random = 0.0; for (int i = 0; i < observations.length; i++) { random = ran.nextDouble(); observationClass[i][0] = observations[i]; for (int k = 0; k < parameters.length; k++) { IGparams[0] = parameters[k][0]; IGparams[1] = parameters[k][1]; probabilities[k][0] = (Double) (Distribution.computeIGDensityGeneral(observations[i], IGparams) * parameters[k][2]); constant += probabilities[k][0]; //System.out.println("Probabilities: " + probabilities[k][0]); } //Comparator sorts the fields in descending order Arrays.sort(probabilities, new DoubleArrayComparator(0)); //Look now if the argumentum minimum over the sequence of the sum of the probabilities ist smaller than the random draw. for (int k = 0; k < parameters.length; k++) { if (k == 0) { probabilities[k][1] = probabilities[k][0] / constant; } else { probabilities[k][1] = probabilities[k - 1][1] + probabilities[k][0]/constant; } //System.out.println("Probability: " + probabilities[k][1] + " random number: " + random); if(probabilities[k][1].compareTo((Double) random) >= 0) { observationClass[i][1] = k; break; } else continue; } constant = 0.0; } return observationClass; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.56 / 8
68 Votes