MOA 12.03
Real Time Analytics for Data Streams
BasicClusteringPerformanceEvaluator.java
Go to the documentation of this file.
00001 /*
00002  *    BasicClusteringPerformanceEvaluator.java
00003  *    Copyright (C) 2009 University of Waikato, Hamilton, New Zealand
00004  *    @author Albert Bifet (abifet at cs dot waikato dot ac dot nz)
00005  *
00006  *    This program is free software; you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation; either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    This program is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  *    
00019  */
00020 package moa.evaluation;
00021 
00022 import moa.AbstractMOAObject;
00023 import moa.core.Measurement;
00024 import weka.core.Utils;
00025 
00032 public class BasicClusteringPerformanceEvaluator extends AbstractMOAObject
00033         implements LearningPerformanceEvaluator {
00034 
00035     private static final long serialVersionUID = 1L;
00036 
00037     protected double weightObserved;
00038 
00039     protected double weightCorrect;
00040 
00041     @Override
00042     public void reset() {
00043         this.weightObserved = 0.0;
00044         this.weightCorrect = 0.0;
00045     }
00046 
00047     @Override
00048     public void addLearningAttempt(int trueClass, double[] classVotes,
00049             double weight) {
00050         if (weight > 0.0) {
00051             this.weightObserved += weight;
00052             if (Utils.maxIndex(classVotes) == trueClass) {
00053                 this.weightCorrect += weight;
00054             }
00055         }
00056     }
00057 
00058     @Override
00059     public Measurement[] getPerformanceMeasurements() {
00060         return new Measurement[]{
00061                     new Measurement("instances",
00062                     getTotalWeightObserved())
00063                 //,new Measurement("classifications correct (percent)",
00064                 //              getFractionCorrectlyClassified() * 100.0)
00065                 };
00066     }
00067 
00068     public double getTotalWeightObserved() {
00069         return this.weightObserved;
00070     }
00071 
00072     public double getFractionCorrectlyClassified() {
00073         return this.weightObserved > 0.0 ? this.weightCorrect
00074                 / this.weightObserved : 0.0;
00075     }
00076 
00077     public double getFractionIncorrectlyClassified() {
00078         return 1.0 - getFractionCorrectlyClassified();
00079     }
00080 
00081     @Override
00082     public void getDescription(StringBuilder sb, int indent) {
00083         Measurement.getMeasurementsDescription(getPerformanceMeasurements(),
00084                 sb, indent);
00085     }
00086 }
 All Classes Namespaces Files Functions Variables Enumerations