forked from LupusNobilis/java-org.hwo
Neues Package: org.hwo.statistics
parent
242f0a0249
commit
74d159a23f
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue