MOA 12.03
Real Time Analytics for Data Streams
WaveformGeneratorDrift.java
Go to the documentation of this file.
00001 /*
00002  *    WaveformGeneratorDrift.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 weka.core.DenseInstance;
00023 import weka.core.Instance;
00024 
00025 import moa.core.InstancesHeader;
00026 import moa.core.ObjectRepository;
00027 import moa.options.IntOption;
00028 import moa.tasks.TaskMonitor;
00029 
00036 public class WaveformGeneratorDrift extends WaveformGenerator {
00037 
00038     private static final long serialVersionUID = 1L;
00039 
00040     public IntOption numberAttributesDriftOption = new IntOption("numberAttributesDrift",
00041             'd', "Number of attributes with drift.", 0, 0, TOTAL_ATTRIBUTES_INCLUDING_NOISE);
00042 
00043     protected int[] numberAttribute;
00044 
00045     @Override
00046     public String getPurposeString() {
00047         return "Generates a problem of predicting one of three waveform types with drift.";
00048     }
00049 
00050     @Override
00051     protected void prepareForUseImpl(TaskMonitor monitor,
00052             ObjectRepository repository) {
00053         super.prepareForUseImpl(monitor, repository);
00054         int numAtts = this.addNoiseOption.isSet() ? TOTAL_ATTRIBUTES_INCLUDING_NOISE
00055                 : NUM_BASE_ATTRIBUTES;
00056         this.numberAttribute = new int[numAtts];
00057         for (int i = 0; i < numAtts; i++) {
00058             this.numberAttribute[i] = i;
00059         }
00060         //Change atributes
00061         int randomInt = this.instanceRandom.nextInt(numAtts);
00062         int offset = this.instanceRandom.nextInt(numAtts);
00063         for (int i = 0; i < this.numberAttributesDriftOption.getValue(); i++) {
00064             this.numberAttribute[(i + randomInt) % numAtts] = (i + offset) % numAtts;
00065             this.numberAttribute[(i + offset) % numAtts] = (i + randomInt) % numAtts;
00066         }
00067     }
00068 
00069     @Override
00070     public Instance nextInstance() {
00071         InstancesHeader header = getHeader();
00072         Instance inst = new DenseInstance(header.numAttributes());
00073         inst.setDataset(header);
00074         int waveform = this.instanceRandom.nextInt(NUM_CLASSES);
00075         int choiceA = 0, choiceB = 0;
00076         switch (waveform) {
00077             case 0:
00078                 choiceA = 0;
00079                 choiceB = 1;
00080                 break;
00081             case 1:
00082                 choiceA = 0;
00083                 choiceB = 2;
00084                 break;
00085             case 2:
00086                 choiceA = 1;
00087                 choiceB = 2;
00088                 break;
00089 
00090         }
00091         double multiplierA = this.instanceRandom.nextDouble();
00092         double multiplierB = 1.0 - multiplierA;
00093         for (int i = 0; i < NUM_BASE_ATTRIBUTES; i++) {
00094             inst.setValue(this.numberAttribute[i], (multiplierA * hFunctions[choiceA][i])
00095                     + (multiplierB * hFunctions[choiceB][i])
00096                     + this.instanceRandom.nextGaussian());
00097         }
00098         if (this.addNoiseOption.isSet()) {
00099             for (int i = NUM_BASE_ATTRIBUTES; i < TOTAL_ATTRIBUTES_INCLUDING_NOISE; i++) {
00100                 inst.setValue(this.numberAttribute[i], this.instanceRandom.nextGaussian());
00101             }
00102         }
00103         inst.setClassValue(waveform);
00104         return inst;
00105     }
00106 
00107     @Override
00108     public void getDescription(StringBuilder sb, int indent) {
00109         // TODO Auto-generated method stub
00110     }
00111 }
 All Classes Namespaces Files Functions Variables Enumerations