List of usage examples for weka.core Instance setDataset
public void setDataset(Instances instances);
From source file:tr.gov.ulakbim.jDenetX.streams.ConceptDriftRealStream.java
License:Open Source License
public Instance nextInstance() { numberInstanceStream++;/*from w ww . j ava 2s .c o m*/ double numclass = 0.0; double x = -4.0 * (double) (numberInstanceStream - this.positionOption.getValue()) / (double) this.widthOption.getValue(); double probabilityDrift = 1.0 / (1.0 + Math.exp(x)); if (this.random.nextDouble() > probabilityDrift) { if (!this.inputStream.hasMoreInstances()) { this.inputStream.restart(); } this.inputInstance = this.inputStream.nextInstance(); numclass = this.inputInstance.classValue(); } else { if (!this.driftStream.hasMoreInstances()) { this.driftStream.restart(); } this.driftInstance = this.driftStream.nextInstance(); numclass = this.driftInstance.classValue(); } int m = 0; double[] newVals = new double[this.inputInstance.numAttributes() + this.driftInstance.numAttributes() - 1]; for (int j = 0; j < this.inputInstance.numAttributes() - 1; j++, m++) { newVals[m] = this.inputInstance.value(j); } for (int j = 0; j < this.driftInstance.numAttributes() - 1; j++, m++) { newVals[m] = this.driftInstance.value(j); } newVals[m] = numclass; //return new Instance(1.0, newVals); Instance inst = new DenseInstance(1.0, newVals); inst.setDataset(this.getHeader()); inst.setClassValue(numclass); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.AgrawalGenerator.java
License:Open Source License
public Instance nextInstance() { double salary = 0, commission = 0, hvalue = 0, loan = 0; int age = 0, elevel = 0, car = 0, zipcode = 0, hyears = 0, group = 0; boolean desiredClassFound = false; while (!desiredClassFound) { // generate attributes salary = 20000.0 + 130000.0 * this.instanceRandom.nextDouble(); commission = (salary >= 75000.0) ? 0 : (10000.0 + 65000.0 * this.instanceRandom.nextDouble()); // true to c implementation: // if (instanceRandom.nextDouble() < 0.5 && salary < 75000.0) // commission = 10000.0 + 65000.0 * instanceRandom.nextDouble(); age = 20 + this.instanceRandom.nextInt(61); elevel = this.instanceRandom.nextInt(5); car = this.instanceRandom.nextInt(20); zipcode = this.instanceRandom.nextInt(9); hvalue = (9.0 - zipcode) * 100000.0 * (0.5 + this.instanceRandom.nextDouble()); hyears = 1 + this.instanceRandom.nextInt(30); loan = this.instanceRandom.nextDouble() * 500000.0; // determine class group = classificationFunctions[this.functionOption.getValue() - 1].determineClass(salary, commission, age, elevel, car, zipcode, hvalue, hyears, loan); if (!this.balanceClassesOption.isSet()) { desiredClassFound = true;//w w w .j ava2 s . c o m } else { // balance the classes if ((this.nextClassShouldBeZero && (group == 0)) || (!this.nextClassShouldBeZero && (group == 1))) { desiredClassFound = true; this.nextClassShouldBeZero = !this.nextClassShouldBeZero; } // else keep searching } } // perturb values if (this.peturbFractionOption.getValue() > 0.0) { salary = perturbValue(salary, 20000, 150000); if (commission > 0) { commission = perturbValue(commission, 10000, 75000); } age = (int) Math.round(perturbValue(age, 20, 80)); hvalue = perturbValue(hvalue, (9.0 - zipcode) * 100000.0, 0, 135000); hyears = (int) Math.round(perturbValue(hyears, 1, 30)); loan = perturbValue(loan, 0, 500000); } // construct instance InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); inst.setValue(0, salary); inst.setValue(1, commission); inst.setValue(2, age); inst.setValue(3, elevel); inst.setValue(4, car); inst.setValue(5, zipcode); inst.setValue(6, hvalue); inst.setValue(7, hyears); inst.setValue(8, loan); inst.setDataset(header); inst.setClassValue(group); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.HyperplaneGenerator.java
License:Open Source License
public Instance nextInstance() { int numAtts = this.numAttsOption.getValue(); double[] attVals = new double[numAtts + 1]; double sum = 0.0; double sumWeights = 0.0; for (int i = 0; i < numAtts; i++) { attVals[i] = this.instanceRandom.nextDouble(); sum += this.weights[i] * attVals[i]; sumWeights += this.weights[i]; }//from w w w .j a v a 2 s. c o m int classLabel; if (sum >= sumWeights * 0.5) { classLabel = 1; } else { classLabel = 0; } //Add Noise if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) { classLabel = (classLabel == 0 ? 1 : 0); } Instance inst = new DenseInstance(1.0, attVals); inst.setDataset(getHeader()); inst.setClassValue(classLabel); addDrift(); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.LEDGenerator.java
License:Open Source License
public Instance nextInstance() { InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); inst.setDataset(header); int selected = this.instanceRandom.nextInt(10); for (int i = 0; i < 7; i++) { if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) { inst.setValue(i, originalInstances[selected][i] == 0 ? 1 : 0); } else {//from w ww .j av a 2s. c o m inst.setValue(i, originalInstances[selected][i]); } } if (!this.suppressIrrelevantAttributesOption.isSet()) { for (int i = 0; i < NUM_IRRELEVANT_ATTRIBUTES; i++) { inst.setValue(i + 7, this.instanceRandom.nextInt(2)); } } inst.setClassValue(selected); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.multilabel.MetaMultilabelGenerator.java
License:Open Source License
/** * GenerateMLInstance.// w w w .j a v a 2 s. com */ private Instance generateMLInstance(ArrayList<Integer> lbls) throws Exception { // create a multi-label instance : Instance ml_x = new SparseInstance(this.multilabelStreamTemplate.numAttributes()); ml_x.setDataset(this.multilabelStreamTemplate); // set classes for (int i = 0; i < m_N; i++) ml_x.setValue(i, 0.0); for (int i = 0; i < lbls.size(); i++) { ml_x.setValue(lbls.get(i), 1.0); } // generate binary instances Instance binary0 = getNextWithBinary(0); Instance binary1 = getNextWithBinary(1); // Loop through each feature attribute @warning: assumes class is last index for (int a = 0; a < m_A; a++) { // The combination is present: use a positive value if (lbls.containsAll(m_FeatureEffects[a % m_FeatureEffects.length])) { ml_x.setValue(m_N + a, binary1.value(a)); } // The combination is absent: use a negative value else { ml_x.setValue(m_N + a, binary0.value(a)); } } return ml_x; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.RandomRBFGenerator.java
License:Open Source License
public Instance nextInstance() { Centroid centroid = this.centroids[MiscUtils.chooseRandomIndexBasedOnWeights(this.centroidWeights, this.instanceRandom)]; int numAtts = this.numAttsOption.getValue(); double[] attVals = new double[numAtts + 1]; for (int i = 0; i < numAtts; i++) { attVals[i] = (this.instanceRandom.nextDouble() * 2.0) - 1.0; }//from w w w . j a va 2 s .co m double magnitude = 0.0; for (int i = 0; i < numAtts; i++) { magnitude += attVals[i] * attVals[i]; } magnitude = Math.sqrt(magnitude); double desiredMag = this.instanceRandom.nextGaussian() * centroid.stdDev; double scale = desiredMag / magnitude; for (int i = 0; i < numAtts; i++) { attVals[i] = centroid.centre[i] + attVals[i] * scale; } Instance inst = new DenseInstance(1.0, attVals); inst.setDataset(getHeader()); inst.setClassValue(centroid.classLabel); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.RandomTreeGenerator.java
License:Open Source License
public Instance nextInstance() { double[] attVals = new double[this.numNominalsOption.getValue() + this.numNumericsOption.getValue()]; InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); for (int i = 0; i < attVals.length; i++) { attVals[i] = i < this.numNominalsOption.getValue() ? this.instanceRandom.nextInt(this.numValsPerNominalOption.getValue()) : this.instanceRandom.nextDouble(); inst.setValue(i, attVals[i]);/* ww w . j a va2 s . co m*/ } inst.setDataset(header); inst.setClassValue(classifyInstance(this.treeRoot, attVals)); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.SEAGenerator.java
License:Open Source License
public Instance nextInstance() { double attrib1 = 0, attrib2 = 0, attrib3 = 0; int group = 0; boolean desiredClassFound = false; while (!desiredClassFound) { // generate attributes attrib1 = 10 * this.instanceRandom.nextDouble(); attrib2 = 10 * this.instanceRandom.nextDouble(); attrib3 = 10 * this.instanceRandom.nextDouble(); // determine class group = classificationFunctions[this.functionOption.getValue() - 1].determineClass(attrib1, attrib2, attrib3);/*from www.j av a2 s . co m*/ if (!this.balanceClassesOption.isSet()) { desiredClassFound = true; } else { // balance the classes if ((this.nextClassShouldBeZero && (group == 0)) || (!this.nextClassShouldBeZero && (group == 1))) { desiredClassFound = true; this.nextClassShouldBeZero = !this.nextClassShouldBeZero; } // else keep searching } } //Add Noise if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) { group = (group == 0 ? 1 : 0); } // construct instance InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); inst.setValue(0, attrib1); inst.setValue(1, attrib2); inst.setValue(2, attrib3); inst.setDataset(header); inst.setClassValue(group); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.STAGGERGenerator.java
License:Open Source License
public Instance nextInstance() { int size = 0, color = 0, shape = 0, group = 0; boolean desiredClassFound = false; while (!desiredClassFound) { // generate attributes size = this.instanceRandom.nextInt(3); color = this.instanceRandom.nextInt(3); shape = this.instanceRandom.nextInt(3); // determine class group = classificationFunctions[this.functionOption.getValue() - 1].determineClass(size, color, shape); if (!this.balanceClassesOption.isSet()) { desiredClassFound = true;//from w w w .j av a 2 s. com } else { // balance the classes if ((this.nextClassShouldBeZero && (group == 0)) || (!this.nextClassShouldBeZero && (group == 1))) { desiredClassFound = true; this.nextClassShouldBeZero = !this.nextClassShouldBeZero; } // else keep searching } } // construct instance InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); inst.setValue(0, size); inst.setValue(1, color); inst.setValue(2, shape); inst.setDataset(header); inst.setClassValue(group); return inst; }
From source file:tr.gov.ulakbim.jDenetX.streams.generators.WaveformGenerator.java
License:Open Source License
public Instance nextInstance() { InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); inst.setDataset(header); int waveform = this.instanceRandom.nextInt(NUM_CLASSES); int choiceA = 0, choiceB = 0; switch (waveform) { case 0:// ww w. j a v a 2 s.c o m choiceA = 0; choiceB = 1; break; case 1: choiceA = 0; choiceB = 2; break; case 2: choiceA = 1; choiceB = 2; break; default: break; } double multiplierA = this.instanceRandom.nextDouble(); double multiplierB = 1.0 - multiplierA; for (int i = 0; i < NUM_BASE_ATTRIBUTES; i++) { inst.setValue(i, (multiplierA * hFunctions[choiceA][i]) + (multiplierB * hFunctions[choiceB][i]) + this.instanceRandom.nextGaussian()); } if (this.addNoiseOption.isSet()) { for (int i = NUM_BASE_ATTRIBUTES; i < TOTAL_ATTRIBUTES_INCLUDING_NOISE; i++) { inst.setValue(i, this.instanceRandom.nextGaussian()); } } inst.setClassValue(waveform); return inst; }