From ee734029e95532781b03f04bee4d1450e82e5d5f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Sat, 21 May 2011 10:56:27 +0000
Subject: [PATCH] - added a few statistic primitive in BasicAlignment

---
 .../exmo/align/impl/BasicAlignment.java       | 35 ++++++++++++++++++-
 test/src/BasicAlignmentTest.java              |  4 +++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java
index c6bc77b9..d9a9ffd8 100644
--- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java
+++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java
@@ -127,6 +127,40 @@ public class BasicAlignment implements Alignment {
 	return sum;
     }
 
+    /** A few statistical primitives, undocumented **/
+    public double maxConfidence() {
+	double result = 0.;
+	for ( Cell c : this ) {
+	    if ( c.getStrength() > result ) result = c.getStrength();
+	}
+	return result;
+    }
+    public double minConfidence() {
+	double result = 1.;
+	for ( Cell c : this ) {
+	    if ( c.getStrength() < result ) result = c.getStrength();
+	}
+	return result;
+    }
+    public double avgConfidence() {
+	double result = 0.;
+	for ( Cell c : this ) {
+	    result += c.getStrength();
+	}
+	return result/(double)nbCells();
+    }
+    public double varianceConfidence() {
+	double total = 0.;
+	double var = 0.;
+	for ( Cell c : this ) {
+	    var += c.getStrength() * c.getStrength();
+	    total += c.getStrength();
+	}
+	double avg = total / (double)nbCells();
+	return ( var / (double)nbCells() ) - (avg*avg) ;
+    }
+    // For standard deviation, take the square root of variance
+
     /** Alignment methods * */
     public Object getOntology1() {
 	return onto1.getOntology();
@@ -722,7 +756,6 @@ public class BasicAlignment implements Alignment {
     public void cleanUp() {}
 }
 
-
 class MEnumeration<T> implements Enumeration<T> {
     private Enumeration<Set<T>> set = null; // The enumeration of sets
     private Iterator<T> current = null; // The current set's enumeration
diff --git a/test/src/BasicAlignmentTest.java b/test/src/BasicAlignmentTest.java
index c84da338..6bf8ac91 100644
--- a/test/src/BasicAlignmentTest.java
+++ b/test/src/BasicAlignmentTest.java
@@ -64,6 +64,10 @@ public class BasicAlignmentTest {
 	assertNotNull( result, "URIAlignment(result) was null" );
 	assertTrue( result instanceof URIAlignment );
 	assertEquals( result.nbCells(), 2, "Alignment should contain 2 cells" );
+	assertEquals( ((BasicAlignment)result).minConfidence(), 0.4666666666666667 );
+	assertEquals( ((BasicAlignment)result).maxConfidence(), 1. );
+	assertEquals( ((BasicAlignment)result).avgConfidence(), 0.7333333333333334 );
+	assertEquals( ((BasicAlignment)result).varianceConfidence(), .07111111111111101 );
 	result.cut( "hard", .5 );
 	assertEquals( result.nbCells(), 1, "Alignment should contain 1 cell" );
     }
-- 
GitLab