Commit in hps-java/src/main/java/org/lcsim/hps/util on MAIN
CompareHistograms.java+69added 1.1
Singleton class for histogram comparisons.

hps-java/src/main/java/org/lcsim/hps/util
CompareHistograms.java added at 1.1
diff -N CompareHistograms.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CompareHistograms.java	28 Nov 2012 06:36:29 -0000	1.1
@@ -0,0 +1,69 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.util;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.commons.math.MathException;
+import org.apache.commons.math.stat.descriptive.StatisticalSummaryValues;
+import org.apache.commons.math.stat.inference.TTestImpl;
+
+/**
+ *
+ * Class to do various comparisons of histograms
+ * Singleton instance with lazy instantiation
+ * 
+ * @author phansson
+ */
+public class CompareHistograms {
+    
+    public static CompareHistograms _instance = null;
+    TTestImpl tTest;
+    private CompareHistograms() {
+         tTest = new TTestImpl();
+    }
+    
+    public static CompareHistograms instance() {
+        if(_instance==null) {
+            _instance = new CompareHistograms();
+        }
+        return _instance;
+    }
+    
+    public double getTTestPValue(double m1, double m2, double v1, double v2, int n1, int n2) {
+        StatisticalSummaryValues stat1 = new StatisticalSummaryValues(m1, v1,n1, 1.,0., 0.);
+        StatisticalSummaryValues stat2 = new StatisticalSummaryValues(m2, v2,n2, 1.,0., 0.);
+
+        double p_value = -1; 
+        try {
+            p_value = tTest.tTest(stat1, stat2);
+        } catch (IllegalArgumentException ex) {
+            Logger.getLogger(CompareHistograms.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (MathException ex) {
+            Logger.getLogger(CompareHistograms.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        return p_value;
+        
+    }
+
+    public boolean getTTest(double alpha,double m1, double m2, double v1, double v2, int n1, int n2) {
+        StatisticalSummaryValues stat1 = new StatisticalSummaryValues(m1, v1,n1, 1.,0., 0.);
+        StatisticalSummaryValues stat2 = new StatisticalSummaryValues(m2, v2,n2, 1.,0., 0.);
+
+        boolean nullHypoIsRejected = false;
+        try {
+            nullHypoIsRejected = tTest.tTest(stat1, stat2, alpha);
+        } catch (IllegalArgumentException ex) {
+            Logger.getLogger(CompareHistograms.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (MathException ex) {
+            Logger.getLogger(CompareHistograms.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        return nullHypoIsRejected;
+    }
+    
+    
+
+    
+}
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1