@Override public Instance makeTrue(Instance intnc) { intnc.setValue(1, indexOfValue("high", priceValues)); intnc.setValue(3, indexOfValue("veryHigh", amountValues)); intnc.setValue(4, indexOfValue("high", deliveryDelayValues)); intnc.setClassValue(Arrays.asList(classValues).indexOf("interested")); return intnc; } },
private void setSparseValue(Instance instance, List<Integer> indexValues, List<Double> attributeValues, int numAttribute, double value, boolean isNumber) { double valueAttribute; if (isNumber && this.instanceInformation.attribute(numAttribute).isNominal) { valueAttribute = this.instanceInformation.attribute(numAttribute).indexOfValue(Double.toString(value)); } else { valueAttribute = value; } if (this.instanceInformation.classIndex() == numAttribute) { instance.setClassValue(valueAttribute); } else { //instance.setValue(numAttribute, valueAttribute); indexValues.add(numAttribute); attributeValues.add(valueAttribute); } //System.out.println(numAttribute+":"+valueAttribute+","+this.instanceInformation.classIndex()+","+value); }
@Override public Instance makeTrue(Instance intnc) { int part = r.nextInt(2); if (part == 0) { intnc.setValue(1, indexOfValue("veryLow", priceValues)); intnc.setValue(2, indexOfValue("0", paymentValues)); intnc.setValue(3, indexOfValue("high", amountValues)); } else { intnc.setValue(0, indexOfValue("red", colorValues)); intnc.setValue(1, indexOfValue("low", priceValues)); intnc.setValue(2, indexOfValue("30", paymentValues)); } intnc.setClassValue(Arrays.asList(classValues).indexOf("interested")); return intnc; } },
@Override public Instance makeTrue(Instance intnc) { int part = r.nextInt(2); if (part == 0) { intnc.setValue(0, indexOfValue("black", colorValues)); intnc.setValue(2, indexOfValue("90", paymentValues)); intnc.setValue(4, indexOfValue("veryLow", deliveryDelayValues)); } else { intnc.setValue(0, indexOfValue("magenta", colorValues)); intnc.setValue(1, indexOfValue("high", priceValues)); intnc.setValue(4, indexOfValue("veryLow", deliveryDelayValues)); } intnc.setClassValue(Arrays.asList(classValues).indexOf("interested")); return intnc; } },
@Override public Instance makeTrue(Instance intnc) { int part = r.nextInt(2); if (part == 0) { intnc.setValue(1, indexOfValue("normal", priceValues)); intnc.setValue(3, indexOfValue("high", amountValues)); } else { intnc.setValue(0, indexOfValue("brown", colorValues)); intnc.setValue(1, indexOfValue("veryLow", priceValues)); intnc.setValue(4, indexOfValue("high", deliveryDelayValues)); } intnc.setClassValue(indexOfValue("interested", classValues)); return intnc; }
@Override public Instance makeTrue(Instance intnc) { int part = r.nextInt(2); if (part == 0) { intnc.setValue(0, indexOfValue("blue", colorValues)); intnc.setValue(2, indexOfValue("60", paymentValues)); intnc.setValue(3, indexOfValue("low", amountValues)); intnc.setValue(4, indexOfValue("normal", deliveryDelayValues)); } else { intnc.setValue(0, indexOfValue("cyan", colorValues)); intnc.setValue(3, indexOfValue("low", amountValues)); intnc.setValue(4, indexOfValue("normal", deliveryDelayValues)); } intnc.setClassValue(Arrays.asList(classValues).indexOf("interested")); return intnc; } }
private void setValue(Instance instance, int numAttribute, double value, boolean isNumber) { double valueAttribute; if (isNumber && this.instanceInformation.attribute(numAttribute).isNominal) { valueAttribute = this.instanceInformation.attribute(numAttribute).indexOfValue(Double.toString(value)); //System.out.println(value +"/"+valueAttribute+" "); } else { valueAttribute = value; //System.out.println(value +"/"+valueAttribute+" "); } if (this.instanceInformation.classIndex() == numAttribute) { instance.setClassValue(valueAttribute); //System.out.println(value +"<"+this.instanceInformation.classIndex()+">"); } else { instance.setValue(numAttribute, valueAttribute); } }
@Override public InstanceExample 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; } 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 new InstanceExample(inst); }
@Override public Example<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]; } 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 new InstanceExample(inst); }
@Override public InstanceExample 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 { 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 new InstanceExample(inst); }
@Override public InstanceExample 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]; } 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 new InstanceExample(inst); }
@Override public Example<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]; } 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 new InstanceExample(inst); }
@Override public InstanceExample 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(this.numberAttribute[i], originalInstances[selected][i] == 0 ? 1 : 0); } else { inst.setValue(this.numberAttribute[i], originalInstances[selected][i]); } } if (!this.suppressIrrelevantAttributesOption.isSet()) { for (int i = 0; i < NUM_IRRELEVANT_ATTRIBUTES; i++) { inst.setValue(this.numberAttribute[i + 7], this.instanceRandom.nextInt(2)); } } inst.setClassValue(selected); return new InstanceExample(inst); }
@Override public InstanceExample 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]); } inst.setDataset(header); inst.setClassValue(classifyInstance(this.treeRoot, attVals)); return new InstanceExample(inst); }
@Override public InstanceExample 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]); } inst.setDataset(header); inst.setClassValue(classifyInstance(this.treeRoot, attVals)); return new InstanceExample(inst); }
@Override public InstanceExample 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]); } inst.setDataset(header); inst.setClassValue(classifyInstance(this.treeRoot, attVals)); return new InstanceExample(inst); }
public double[] getVotesForInstanceBinary(Instance inst) { double combinedVote[] = new double[(int) inst.numClasses()]; Instance weightedInst = (Instance) inst.copy(); if (this.initMatrixCodes == false) { for (int i = 0; i < this.ensemble.length; i++) { //Replace class by OC weightedInst.setClassValue((double) this.matrixCodes[i][(int) inst.classValue()]); double vote[]; vote = this.ensemble[i].getVotesForInstance(weightedInst); //Binary Case int voteClass = 0; if (vote.length == 2) { voteClass = (vote[1] > vote[0] ? 1 : 0); } //Update votes for (int j = 0; j < inst.numClasses(); j++) { if (this.matrixCodes[i][j] == voteClass) { combinedVote[j] += 1; } } } } return combinedVote; }
public double[] getVotesForInstanceBinary(Instance inst) { double combinedVote[] = new double[(int) inst.numClasses()]; Instance weightedInst = (Instance) inst.copy(); if (this.initMatrixCodes == false) { for (int i = 0; i < this.ensemble.length; i++) { //Replace class by OC weightedInst.setClassValue((double) this.matrixCodes[i][(int) inst.classValue()]); double vote[]; vote = this.ensemble[i].getVotesForInstance(weightedInst); //Binary Case int voteClass = 0; if (vote.length == 2) { voteClass = (vote[1] > vote[0] ? 1 : 0); } //Update votes for (int j = 0; j < inst.numClasses(); j++) { if (this.matrixCodes[i][j] == voteClass) { combinedVote[j] += getEnsembleMemberWeight(i); } } } } return combinedVote; }
public Clustering getClusteringResult() { Clustering clustering = null; weka.core.Instances wekaInstances= this.instanceConverter.wekaInstances(instances); try { clusterer.buildClusterer(wekaInstances); int numClusters = clusterer.numberOfClusters(); Instances dataset = getDataset(instances.numAttributes(), numClusters); List<Instance> newInstances = new ArrayList<Instance>() ; //Instances(dataset); for (int i = 0; i < wekaInstances.numInstances(); i++) { weka.core.Instance inst = wekaInstances.get(i); int cnum = clusterer.clusterInstance(inst); Instance newInst = new DenseInstance(instances.instance(cnum)); newInst.insertAttributeAt(inst.numAttributes()); newInst.setDataset(dataset); newInst.setClassValue(cnum); newInstances.add(newInst); } clustering = new Clustering(newInstances); } catch (Exception e) { e.printStackTrace(); } instances = null; return clustering; }
/** * Samoa instance from weka instance. * * @param inst the inst * @return the instance */ public Instance samoaInstance(weka.core.Instance inst) { Instance samoaInstance; if (inst instanceof weka.core.SparseInstance) { double[] attributeValues = new double[inst.numValues()]; int[] indexValues = new int[inst.numValues()]; for (int i = 0; i < inst.numValues(); i++) { if (inst.index(i) != inst.classIndex()) { attributeValues[i] = inst.valueSparse(i); indexValues[i] = inst.index(i); } } samoaInstance = new SparseInstance(inst.weight(), attributeValues, indexValues, inst.numAttributes()); } else { samoaInstance = new DenseInstance(inst.weight(), inst.toDoubleArray()); //samoaInstance.deleteAttributeAt(inst.classIndex()); } if (this.samoaInstanceInformation == null) { this.samoaInstanceInformation = this.samoaInstancesInformation(inst.dataset()); } samoaInstance.setDataset(samoaInstanceInformation); samoaInstance.setClassValue(inst.classValue()); return samoaInstance; }