MOA 12.03
Real Time Analytics for Data Streams
|
00001 /* 00002 * DataPoint.java 00003 * Copyright (C) 2010 RWTH Aachen University, Germany 00004 * @author Jansen ([email protected]) 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.gui.visualization; 00022 00023 import java.util.HashMap; 00024 import java.util.Iterator; 00025 import java.util.TreeSet; 00026 import weka.core.DenseInstance; 00027 import weka.core.Instance; 00028 00029 public class DataPoint extends DenseInstance{ 00030 protected int timestamp; 00031 private HashMap<String, String> measure_values; 00032 00033 public DataPoint(Instance nextInstance, Integer timestamp) { 00034 super(nextInstance); 00035 this.setDataset(nextInstance.dataset()); 00036 this.timestamp = timestamp; 00037 measure_values = new HashMap<String, String>(); 00038 00039 } 00040 00041 public void updateWeight(int cur_timestamp, double decay_rate){ 00042 setWeight(Math.pow(2,(-1.0)*decay_rate*(cur_timestamp-timestamp))); 00043 } 00044 00045 public void setMeasureValue(String measureKey, double value){ 00046 synchronized(measure_values){ 00047 measure_values.put(measureKey, Double.toString(value)); 00048 } 00049 } 00050 00051 public void setMeasureValue(String measureKey,String value){ 00052 synchronized(measure_values){ 00053 measure_values.put(measureKey, value); 00054 } 00055 } 00056 00057 public String getMeasureValue(String measureKey){ 00058 if(measure_values.containsKey(measureKey)) 00059 synchronized(measure_values){ 00060 return measure_values.get(measureKey); 00061 } 00062 else 00063 return ""; 00064 } 00065 00066 public int getTimestamp(){ 00067 return timestamp; 00068 } 00069 00070 public String getInfo(int x_dim, int y_dim) { 00071 StringBuffer sb = new StringBuffer(); 00072 sb.append("<html><table>"); 00073 sb.append("<tr><td>Point</td><td>"+timestamp+"</td></tr>"); 00074 for (int i = 0; i < m_AttValues.length-1; i++) { 00075 String label = "Dim "+i; 00076 if(i == x_dim) 00077 label = "<b>X</b>"; 00078 if(i == y_dim) 00079 label = "<b>Y</b>"; 00080 sb.append("<tr><td>"+label+"</td><td>"+value(i)+"</td></tr>"); 00081 } 00082 sb.append("<tr><td>Decay</td><td>"+weight()+"</td></tr>"); 00083 sb.append("<tr><td>True cluster</td><td>"+classValue()+"</td></tr>"); 00084 sb.append("</table>"); 00085 sb.append("<br>"); 00086 sb.append("<b>Evaluation</b><br>"); 00087 sb.append("<table>"); 00088 00089 TreeSet<String> sortedset; 00090 synchronized(measure_values){ 00091 sortedset = new TreeSet<String>(measure_values.keySet()); 00092 } 00093 00094 Iterator miterator = sortedset.iterator(); 00095 while(miterator.hasNext()) { 00096 String key = (String)miterator.next(); 00097 sb.append("<tr><td>"+key+"</td><td>"+measure_values.get(key)+"</td></tr>"); 00098 } 00099 00100 sb.append("</table></html>"); 00101 return sb.toString(); 00102 } 00103 00104 public double getDistance(DataPoint other){ 00105 double distance = 0.0; 00106 int numDims = numAttributes(); 00107 if(classIndex()!=0) numDims--; 00108 00109 for (int i = 0; i < numDims; i++) { 00110 double d = value(i) - other.value(i); 00111 distance += d * d; 00112 } 00113 return Math.sqrt(distance); 00114 } 00115 00116 }