Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 82aa8621 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- implemented MAP (Mean Average Precision) measure

parent b619c459
No related branches found
No related tags found
No related merge requests found
/* /*
* $Id$ * $Id$
* *
* Copyright (C) INRIA Rhne-Alpes, 2004-2005, 2007-2008 * Copyright (C) INRIA Rhône-Alpes, 2004-2005, 2007-2009
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
...@@ -57,6 +57,15 @@ import java.net.URI; ...@@ -57,6 +57,15 @@ import java.net.URI;
* [R=0%] What should be P when R is 0% (obviously 100%) * [R=0%] What should be P when R is 0% (obviously 100%)
* [R=100%] What should be P when R=100% is unreachable * [R=100%] What should be P when R=100% is unreachable
* [Interp.] How is a chaotic curve interpolated * [Interp.] How is a chaotic curve interpolated
*
* Note: a very interesting measure is the MAP (mean average precision)
* which is figuratively the area under the curve and more precisely
* the average precision obtained for each correspondence in the reference
* alignment.
* The problem is that it can only be valid if the compared alignment has
* provided all the correspondences in the reference.
* Otherwise, it would basically be:
* SUM_c\in correct( P( c ) ) / nbexpected
*/ */
public class PRGraphEvaluator extends BasicEvaluator { public class PRGraphEvaluator extends BasicEvaluator {
...@@ -66,6 +75,8 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -66,6 +75,8 @@ public class PRGraphEvaluator extends BasicEvaluator {
// The eleven values of precision and recall // The eleven values of precision and recall
private double[] precisions = null; private double[] precisions = null;
private double map = 0.0; // For MAP
private Vector<Pair> points; private Vector<Pair> points;
/** Creation: /** Creation:
...@@ -94,6 +105,7 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -94,6 +105,7 @@ public class PRGraphEvaluator extends BasicEvaluator {
int nbexpected = align1.nbCells(); int nbexpected = align1.nbCells();
int nbfound = 0; int nbfound = 0;
int nbcorrect = 0; int nbcorrect = 0;
double sumprecisions = 0.; // For MAP
// unchecked // unchecked
if( params.getParameter("step") != null ){ if( params.getParameter("step") != null ){
...@@ -109,7 +121,6 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -109,7 +121,6 @@ public class PRGraphEvaluator extends BasicEvaluator {
throws ClassCastException{ throws ClassCastException{
try { try {
//System.err.println(((Cell)o1).getObject1()+" -- "+((Cell)o1).getObject2()+" // "+((Cell)o2).getObject1()+" -- "+((Cell)o2).getObject2()); //System.err.println(((Cell)o1).getObject1()+" -- "+((Cell)o1).getObject2()+" // "+((Cell)o2).getObject1()+" -- "+((Cell)o2).getObject2());
//*/3.0
if ( o1 instanceof Cell && o2 instanceof Cell ) { if ( o1 instanceof Cell && o2 instanceof Cell ) {
if ( ((Cell)o1).getStrength() > ((Cell)o2).getStrength() ){ if ( ((Cell)o1).getStrength() > ((Cell)o2).getStrength() ){
return -1; return -1;
...@@ -157,6 +168,7 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -157,6 +168,7 @@ public class PRGraphEvaluator extends BasicEvaluator {
nbcorrect++; nbcorrect++;
double recall = (double)nbcorrect / (double)nbexpected; double recall = (double)nbcorrect / (double)nbexpected;
double precision = (double)nbcorrect / (double)nbfound; double precision = (double)nbcorrect / (double)nbfound;
sumprecisions += precision; // For MAP
// Create a new pair to put in the list // Create a new pair to put in the list
// It records real precision and recall at that point // It records real precision and recall at that point
points.add( new Pair( recall, precision ) ); points.add( new Pair( recall, precision ) );
...@@ -194,8 +206,9 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -194,8 +206,9 @@ public class PRGraphEvaluator extends BasicEvaluator {
} }
precisions[0] = best; // It should be 1. that's why it is now added in points. [R=0%] precisions[0] = best; // It should be 1. that's why it is now added in points. [R=0%]
return 0.0; // useless map = sumprecisions / nbexpected; // For MAP
} return map;
}
/** /**
* This output the result * This output the result
...@@ -211,6 +224,7 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -211,6 +224,7 @@ public class PRGraphEvaluator extends BasicEvaluator {
writer.print(precisions[i]); writer.print(precisions[i]);
writer.print("</precision>\n </step>\n"); writer.print("</precision>\n </step>\n");
} }
writer.print(" <MAP>"+map+"</MAP>\n");
writer.print(" </output>\n</rdf:RDF>\n"); writer.print(" </output>\n</rdf:RDF>\n");
writePlot( writer ); writePlot( writer );
} }
...@@ -238,6 +252,10 @@ public class PRGraphEvaluator extends BasicEvaluator { ...@@ -238,6 +252,10 @@ public class PRGraphEvaluator extends BasicEvaluator {
public double getPrecision( int i ){ public double getPrecision( int i ){
return precisions[i]; return precisions[i];
} }
public double getMAP(){
return map;
}
} }
class Pair { class Pair {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment