Added (deep) clone() and merge() to the RunningAverage utility class
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5350 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
43567b7fe3
commit
570186fa42
|
|
@ -814,6 +814,22 @@ public class MathUtils {
|
|||
public double stddev() { return Math.sqrt(s/(obs_count - 1)); }
|
||||
public double var() { return s/(obs_count - 1); }
|
||||
public long observationCount() { return obs_count; }
|
||||
|
||||
public RunningAverage clone() {
|
||||
RunningAverage ra = new RunningAverage();
|
||||
ra.mean = this.mean;
|
||||
ra.s = this.s;
|
||||
ra.obs_count = this.obs_count;
|
||||
return ra;
|
||||
}
|
||||
|
||||
public void merge(RunningAverage other) {
|
||||
if ( this.obs_count > 0 || other.obs_count > 0 ) { // if we have any observations at all
|
||||
this.mean = ( this.mean * this.obs_count + other.mean * other.obs_count ) / ( this.obs_count + other.obs_count );
|
||||
this.s += other.s;
|
||||
}
|
||||
this.obs_count += other.obs_count;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in New Issue