Java Code Examples for org.apache.commons.math3.stat.descriptive.SummaryStatistics#clear()

The following examples show how to use org.apache.commons.math3.stat.descriptive.SummaryStatistics#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomatoLinearClassifierDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compute the mean of the image
 *
 * @param frame
 * @param colourSpace
 * @return
 */
public double[] computeMean(MBFImage frame, ColourSpace colourSpace) {
	final Circle hc = circle.clone();
	hc.scale(0.5f);
	final Rectangle bounds = hc.calculateRegularBoundingBox();

	frame = ResizeProcessor.halfSize(frame);

	final MBFImage cvt = colourSpace.convert(frame);
	final double[] vector = new double[colourSpace.getNumBands()];

	final SummaryStatistics stats = new SummaryStatistics();
	final Pixel pt = new Pixel();
	for (int b = 0; b < colourSpace.getNumBands(); b++) {
		stats.clear();

		final float[][] pix = cvt.getBand(b).pixels;

		for (pt.y = (int) bounds.y; pt.y < bounds.y + bounds.height; pt.y++) {
			for (pt.x = (int) bounds.x; pt.x < bounds.x + bounds.width; pt.x++) {
				if (hc.isInside(pt)) {
					stats.addValue(pix[pt.y][pt.x]);
				}
			}
		}

		vector[b] = stats.getMean();
	}
	return vector;
}
 
Example 2
Source File: TomatoKNNClassifierDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compute the mean of the image
 *
 * @param frame
 * @param colourSpace
 * @return
 */
public double[] computeMean(MBFImage frame, ColourSpace colourSpace) {
	final Circle hc = circle.clone();
	hc.scale(0.5f);
	final Rectangle bounds = hc.calculateRegularBoundingBox();

	frame = ResizeProcessor.halfSize(frame);

	final MBFImage cvt = colourSpace.convert(frame);
	final double[] vector = new double[colourSpace.getNumBands()];

	final SummaryStatistics stats = new SummaryStatistics();
	final Pixel pt = new Pixel();
	for (int b = 0; b < colourSpace.getNumBands(); b++) {
		stats.clear();

		final float[][] pix = cvt.getBand(b).pixels;

		for (pt.y = (int) bounds.y; pt.y < bounds.y + bounds.height; pt.y++) {
			for (pt.x = (int) bounds.x; pt.x < bounds.x + bounds.width; pt.x++) {
				if (hc.isInside(pt)) {
					stats.addValue(pix[pt.y][pt.x]);
				}
			}
		}

		vector[b] = stats.getMean();
	}
	return vector;
}
 
Example 3
Source File: StlFitStatsTest.java    From stl-decomp-4j with Apache License 2.0 4 votes vote down vote up
@Test
public void noisySeasonalTest() {
	long seed = 1234567L; // System.nanoTime() // change this to do random stress test
	int numAverages = 1; // Increase to tighten the statistics on the sample statistics
	int trials = 100;
	double start = 1.5;
	double delta = 0.0;

	SummaryStatistics seasonalZScoreStats = new SummaryStatistics();
	SummaryStatistics varianceFractionStats = new SummaryStatistics();

	SummaryStatistics fractionClassifiedStats = new SummaryStatistics();
	SummaryStatistics sampleZScoreStats = new SummaryStatistics();
	SummaryStatistics sampleVarFracStats = new SummaryStatistics();

	for (int j = 0; j < numAverages; ++j) {
		int count = 0;
		double seasonalAmplitude = start + delta * j;
		double noiseSigma = 3.0;

		for (int i = 0; i < trials; ++i) {

			double[] data = testDataGenerator.createNoisySeasonalData(
					168 * 4, 168, seasonalAmplitude, 0.0, noiseSigma, seed++);

			Decomposition stl = SeasonalTrendLoess.performRobustPeriodicDecomposition(data, 168);

			StlFitStats stats = new StlFitStats(stl);

			assertTrue(stats.getTrendinessZScore() < 3.0);

			stl.smoothSeasonal(15);
			StlFitStats smoothedStats = new StlFitStats(stl);

			double vf = smoothedStats.getSeasonalVariance() / smoothedStats.getResidualVariance();
			varianceFractionStats.addValue(vf);

			double z = smoothedStats.getSeasonalZScore();
			seasonalZScoreStats.addValue(z);

			if (z > 3.0)
				++count;
		}

		double rate = ((double) count) / trials;

		fractionClassifiedStats.addValue(rate);

		sampleZScoreStats.addValue(seasonalZScoreStats.getMean());
		sampleVarFracStats.addValue(varianceFractionStats.getMean());

		seasonalZScoreStats.clear();
		varianceFractionStats.clear();
	}

	assertTrue("Min Average Z-Score", sampleZScoreStats.getMin() > 3.13);
	assertTrue("Avg Average Z-Score", Math.abs(sampleZScoreStats.getMean() - 3.64) < 0.06);
	assertTrue("Max Average Z-Score", sampleZScoreStats.getMax() < 4.13);

	assertTrue("Min Var Frac", sampleVarFracStats.getMin() > 0.173);
	assertTrue("Avg Var Frac", Math.abs(sampleVarFracStats.getMean() - 0.193) < 0.01);
	assertTrue("Max Var Frac", sampleVarFracStats.getMax() < 0.213);
}