View Javadoc
1 /* 2 * RunningBasicStatisticsTag.java 3 * 4 * Created on March 13, 2003, 10:19 PM 5 */ 6 7 package org.mrd.analysis; 8 9 /*** 10 * For each iteration of the model scan the list of agents, and determine the following 11 * number of agents/number survived. 12 * 13 * keep calculated running average and std 14 * 15 * @author Mark Diggory <mdiggory@latte.harvard.edu> 16 */ 17 public class RunningBasicStatistics { 18 19 protected double sum = 0; 20 21 protected double sumsq = 0; 22 23 protected double count = 0; 24 25 /*** Creates a new instance of RunningBasicStatisticsTag */ 26 public RunningBasicStatistics() { 27 } 28 29 public double getCurrentAverage() { 30 return sum / count; 31 } 32 33 public double getCurrentVariance() { 34 return (sumsq - (Math.pow(sum, 2) / count)) / count; 35 } 36 37 public double getCurrentStd() { 38 return Math.sqrt(getCurrentVariance()); 39 } 40 41 public void incriment(double value) { 42 if (value != Double.NaN) { 43 count++; 44 sum = sum + value; 45 sumsq = sumsq + Math.pow(value, 2); 46 } 47 } 48 49 /*** 50 * @param args the command line arguments 51 */ 52 public static void main(String[] args) throws java.lang.Exception { 53 54 RunningBasicStatistics probe = new RunningBasicStatistics(); 55 56 org.mrd.random.LimitedBeta beta = 57 new org.mrd.random.LimitedBeta( 58 .5, 59 .5, 60 new cern.jet.random.engine.MersenneTwister(), 61 true, 62 true); 63 for (int i = 1; i < 10000; i++) { 64 probe.incriment(beta.nextDouble()); 65 } 66 67 System.out.println("Mean: " + probe.getCurrentAverage()); 68 System.out.println("Std: " + probe.getCurrentStd()); 69 System.out.println("Variance: " + probe.getCurrentVariance()); 70 System.out.println(""); 71 } 72 }

This page was automatically generated by Maven