MOA 12.03
Real Time Analytics for Data Streams
LEDGeneratorDrift.java
Go to the documentation of this file.
00001 /*
00002  *    LEDGeneratorDrift.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 LEDGeneratorDrift extends LEDGenerator {
00037 
00038     @Override
00039     public String getPurposeString() {
00040         return "Generates a problem of predicting the digit displayed on a 7-segment LED display with drift.";
00041     }
00042 
00043     private static final long serialVersionUID = 1L;
00044 
00045     public IntOption numberAttributesDriftOption = new IntOption("numberAttributesDrift",
00046             'd', "Number of attributes with drift.", 1, 0, 7);
00047 
00048     protected int[] numberAttribute;
00049 
00050     @Override
00051     protected void prepareForUseImpl(TaskMonitor monitor,
00052             ObjectRepository repository) {
00053         super.prepareForUseImpl(monitor, repository);
00054         this.numberAttribute = new int[7 + NUM_IRRELEVANT_ATTRIBUTES];
00055         for (int i = 0; i < 7 + NUM_IRRELEVANT_ATTRIBUTES; i++) {
00056             this.numberAttribute[i] = i;
00057         }
00058         //Change atributes
00059         if (!this.suppressIrrelevantAttributesOption.isSet() && this.numberAttributesDriftOption.getValue() > 0) {
00060             int randomInt = 0;//this.instanceRandom.nextInt(7);
00061             int offset = 0;//this.instanceRandom.nextInt(NUM_IRRELEVANT_ATTRIBUTES);
00062             for (int i = 0; i < this.numberAttributesDriftOption.getValue(); i++) {
00063                 int value1 = (i + randomInt) % 7;
00064                 int value2 = 7 + ((i + offset) % (NUM_IRRELEVANT_ATTRIBUTES));
00065                 this.numberAttribute[value1] = value2;
00066                 this.numberAttribute[value2] = value1;
00067             }
00068         }
00069     }
00070 
00071     @Override
00072     public Instance nextInstance() {
00073         InstancesHeader header = getHeader();
00074         Instance inst = new DenseInstance(header.numAttributes());
00075         inst.setDataset(header);
00076         int selected = this.instanceRandom.nextInt(10);
00077         for (int i = 0; i < 7; i++) {
00078             if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) {
00079                 inst.setValue(this.numberAttribute[i], originalInstances[selected][i] == 0 ? 1 : 0);
00080             } else {
00081                 inst.setValue(this.numberAttribute[i], originalInstances[selected][i]);
00082             }
00083         }
00084         if (!this.suppressIrrelevantAttributesOption.isSet()) {
00085             for (int i = 0; i < NUM_IRRELEVANT_ATTRIBUTES; i++) {
00086                 inst.setValue(this.numberAttribute[i + 7], this.instanceRandom.nextInt(2));
00087             }
00088         }
00089         inst.setClassValue(selected);
00090         return inst;
00091     }
00092 
00093     @Override
00094     public void getDescription(StringBuilder sb, int indent) {
00095         // TODO Auto-generated method stub
00096     }
00097 }
 All Classes Namespaces Files Functions Variables Enumerations