MOA 12.03
Real Time Analytics for Data Streams
RandomRBFGeneratorDrift.java
Go to the documentation of this file.
00001 /*
00002  *    RandomRBFGeneratorDrift.java
00003  *    Copyright (C) 2008 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.streams.generators;
00021 
00022 import java.util.Random;
00023 
00024 import moa.options.IntOption;
00025 import moa.options.FloatOption;
00026 import weka.core.Instance;
00027 
00034 public class RandomRBFGeneratorDrift extends RandomRBFGenerator {
00035 
00036     @Override
00037     public String getPurposeString() {
00038         return "Generates a random radial basis function stream with drift.";
00039     }
00040 
00041     private static final long serialVersionUID = 1L;
00042 
00043     public FloatOption speedChangeOption = new FloatOption("speedChange", 's',
00044             "Speed of change of centroids in the model.", 0, 0, Float.MAX_VALUE);
00045 
00046     public IntOption numDriftCentroidsOption = new IntOption("numDriftCentroids", 'k',
00047             "The number of centroids with drift.", 50, 0, Integer.MAX_VALUE);
00048 
00049     protected double[][] speedCentroids;
00050 
00051     @Override
00052     public Instance nextInstance() {
00053         //Update Centroids with drift
00054         int len = this.numDriftCentroidsOption.getValue();
00055         if (len > this.centroids.length) {
00056             len = this.centroids.length;
00057         }
00058         for (int j = 0; j < len; j++) {
00059             for (int i = 0; i < this.numAttsOption.getValue(); i++) {
00060                 this.centroids[j].centre[i] += this.speedCentroids[j][i] * this.speedChangeOption.getValue();
00061                 if (this.centroids[j].centre[i] > 1) {
00062                     this.centroids[j].centre[i] = 1;
00063                     this.speedCentroids[j][i] = -this.speedCentroids[j][i];
00064                 }
00065                 if (this.centroids[j].centre[i] < 0) {
00066                     this.centroids[j].centre[i] = 0;
00067                     this.speedCentroids[j][i] = -this.speedCentroids[j][i];
00068                 }
00069             }
00070         }
00071         return super.nextInstance();
00072     }
00073 
00074     @Override
00075     protected void generateCentroids() {
00076         super.generateCentroids();
00077         Random modelRand = new Random(this.modelRandomSeedOption.getValue());
00078         int len = this.numDriftCentroidsOption.getValue();
00079         if (len > this.centroids.length) {
00080             len = this.centroids.length;
00081         }
00082         this.speedCentroids = new double[len][this.numAttsOption.getValue()];
00083         for (int i = 0; i < len; i++) {
00084             double[] randSpeed = new double[this.numAttsOption.getValue()];
00085             double normSpeed = 0.0;
00086             for (int j = 0; j < randSpeed.length; j++) {
00087                 randSpeed[j] = modelRand.nextDouble();
00088                 normSpeed += randSpeed[j] * randSpeed[j];
00089             }
00090             normSpeed = Math.sqrt(normSpeed);
00091             for (int j = 0; j < randSpeed.length; j++) {
00092                 randSpeed[j] /= normSpeed;
00093             }
00094             this.speedCentroids[i] = randSpeed;
00095         }
00096     }
00097 
00098     @Override
00099     public void getDescription(StringBuilder sb, int indent) {
00100         // TODO Auto-generated method stub
00101     }
00102 }
 All Classes Namespaces Files Functions Variables Enumerations