Android Open Source - field-data-app Data Statistics






From Project

Back to project page field-data-app.

License

The source code is released under:

MIT License

If you think the Android project field-data-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package nz.cri.gns.springs.util;
//from   w ww  .  j  ava 2 s .com
/**
 * Used to calculate the average and standard deviation of an
 * array of integers.
 * @author duncanw
 *
 */
public class DataStatistics {

  private int[] values;
  private double mean;
  private double stdDeviation;
  private int weightedAverage;
  
  
  public DataStatistics(int[] values) {
    this.values = values;
  }
  
  public DataStatistics calculate() {
      int n = 0;
      mean = 0;
      double M2 = 0;
      
      
      for (int x : values) {
          n = n + 1;
          double delta = (double)x - mean;
          mean = mean + delta/(double)n;
          M2 = M2 + delta*(x - mean);
      }
   
      double variance = M2/(n - 1);
      stdDeviation = Math.sqrt(variance);
      weightedAverage = calculageWeightedAverage();
      
      return this;
  }
  
  private int calculageWeightedAverage() {
    
    // This is intended to produce an average less
    // affected by outliers. Not sure of it's statistical
    // validity, but seems to produce good results for
    // averaging pixel RGB colours around a point.
    double total = 1.0;
    int count = 0;
    for (int x : values) {
      if (Math.abs((double)x - mean) <= stdDeviation) {
        count++;
        total += x;
      }    
    }
    
    return (int)total/count;
  }

  public double getMean() {
    return mean;
  }

  public double getStdDeviation() {
    return stdDeviation;
  }

  /**
   * @return the average of values within one standard deviation of the mean. 
   */
  public int getWeightedAverage() {
    return weightedAverage;
  }
}




Java Source Code List

nz.cri.gns.springs.GpsLocation.java
nz.cri.gns.springs.SpringsApplication.java
nz.cri.gns.springs.activity.BioSampleActivity.java
nz.cri.gns.springs.activity.EditBiologicalSamplesActivity.java
nz.cri.gns.springs.activity.MainMenuActivity.java
nz.cri.gns.springs.activity.ManageBioSamplesActivity.java
nz.cri.gns.springs.activity.SettingsActivity.java
nz.cri.gns.springs.db.BiologicalSampleTest.java
nz.cri.gns.springs.db.BiologicalSample.java
nz.cri.gns.springs.db.ChecklistItem.java
nz.cri.gns.springs.db.Configuration.java
nz.cri.gns.springs.db.FeatureTest.java
nz.cri.gns.springs.db.Feature.java
nz.cri.gns.springs.db.PersistentObject.java
nz.cri.gns.springs.db.SpringsDbHelper.java
nz.cri.gns.springs.db.SurveyImage.java
nz.cri.gns.springs.db.SurveyTest.java
nz.cri.gns.springs.db.Survey.java
nz.cri.gns.springs.fragments.AppearanceFragment.java
nz.cri.gns.springs.fragments.BioSampleActivityFragment.java
nz.cri.gns.springs.fragments.BioSampleFragment.java
nz.cri.gns.springs.fragments.ChooseImageFragment.java
nz.cri.gns.springs.fragments.ExportSamplesFragment.java
nz.cri.gns.springs.fragments.FeatureIdFragment.java
nz.cri.gns.springs.fragments.ImageColourPickerFragment.java
nz.cri.gns.springs.fragments.ImageFragment.java
nz.cri.gns.springs.fragments.SpringsDialogFragment.java
nz.cri.gns.springs.fragments.SpringsFragment.java
nz.cri.gns.springs.util.CustomExceptionHandler.java
nz.cri.gns.springs.util.DataStatistics.java
nz.cri.gns.springs.util.DateTimePickerDialog.java
nz.cri.gns.springs.util.UiUtil.java
nz.cri.gns.springs.util.Util.java