MOA 12.03
Real Time Analytics for Data Streams
SSQ.java
Go to the documentation of this file.
00001 /*
00002  *    SSQ.java
00003  *    Copyright (C) 2010 RWTH Aachen University, Germany
00004  *    @author Jansen (moa@cs.rwth-aachen.de)
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 
00021 package moa.evaluation;
00022 
00023 import java.util.ArrayList;
00024 import moa.cluster.Clustering;
00025 import moa.gui.visualization.DataPoint;
00026 
00027 public class SSQ extends MeasureCollection{
00028 
00029     public SSQ() {
00030         super();
00031     }
00032 
00033     @Override
00034     public String[] getNames() {
00035         String[] names = {"SSQ"};
00036         return names;
00037     }
00038     
00039   @Override
00040   protected boolean[] getDefaultEnabled() {
00041       boolean [] defaults = {false};
00042       return defaults;
00043   }
00044     
00045     public void evaluateClustering(Clustering clustering, Clustering trueClsutering, ArrayList<DataPoint> points) {
00046         double sum = 0.0;
00047         for (int p = 0; p < points.size(); p++) {
00048             //don't include noise
00049             if(points.get(p).classValue()==-1) continue;
00050 
00051             double minDistance = Double.MAX_VALUE;
00052             for (int c = 0; c < clustering.size(); c++) {
00053                 double distance = 0.0;
00054                 double[] center = clustering.get(c).getCenter();
00055                 for (int i = 0; i < center.length; i++) {
00056                     double d = points.get(p).value(i) - center[i];
00057                     distance += d * d;
00058                 }
00059                 minDistance = Math.min(distance, minDistance);
00060             }
00061             
00062             sum+=minDistance;
00063         }
00064         
00065         addValue(0,sum);
00066     }
00067 
00068 
00069 
00070 
00071 
00072 }
 All Classes Namespaces Files Functions Variables Enumerations