Neues Package: org.hwo.statistics

thobaben_serialize
Harald Wolff 2015-02-04 01:09:53 +01:00
parent 242f0a0249
commit 74d159a23f
1 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,63 @@
package org.hwo.statistics;
public class Statistics {
Float[] values; // Wertereihe
boolean uKnown;
Float u; // Arithmetisches Mittel
Float s2; // Korrigierte Stichprobenvarianz
Float s; // Standardabweichung
public Statistics(Float[] values){
this.values = values;
uKnown = false;
}
private void calcU(){
float avg = 0;
for (int i=0;i<this.values.length;i++){
avg += this.values[i];
}
this.u = avg / this.values.length;
}
private void calcS2(){
if (u == null)
calcU();
s2 = 0.0f;
for (int i=0;i<this.values.length;i++){
s2 += (float)Math.pow(this.values[i] - this.u, 2.0f);
}
s2 /= uKnown ? this.values.length : (this.values.length - 1);
s = (float)Math.sqrt(s2);
}
public Float getU() {
if (u == null)
calcU();
return u;
}
public void setU(Float u) {
this.u = u;
this.uKnown = true;
this.s2 = null;
this.s = null;
}
public Float getS2() {
if (s2 == null)
calcS2();
return s2;
}
public Float getS() {
if (s == null)
calcS2();
return s;
}
}