public Instance formatInstance(Instance original) { //Copy the original instance Instance converted = (Instance) original.copy(); converted.setDataset(null); //Delete all class attributes for (int j = 0; j < m_L; j++) { converted.deleteAttributeAt(0); } //Add one of those class attributes at the begginning converted.insertAttributeAt(0); //Hopefully setting the dataset will configure that attribute properly converted.setDataset(m_InstancesTemplate); return converted; }
/** * Predicts the class memberships for a given instance. If an instance is * unclassified, the returned array elements must be all zero. * * @param inst the instance to be classified * @return an array containing the estimated membership probabilities of the * test instance in each class */ @Override public double[] getVotesForInstance(Instance inst) { double[] ret; inst.setDataset(dataset); if (this.isInit == false) { ret = new double[dataset.numClasses()]; } else { ret = learner.getVotesForInstance(inst); } return ret; }
/** * Read instance. * * @param fileReader the file reader * @return true, if successful */ public boolean readInstance(Reader fileReader) { //ArffReader arff = new ArffReader(reader, this, m_Lines, 1); Instance inst = arff.readInstance(); if (inst != null) { inst.setDataset(this); add(inst); return true; } else { return false; } }
/** * Predicts the class memberships for a given instance. If an instance is * unclassified, the returned array elements must be all zero. * * @param inst the instance to be classified * @return an array containing the estimated membership probabilities of the * test instance in each class */ @Override public double[] getVotesForInstance(Instance inst) { double[] ret; inst.setDataset(dataset); if (!this.isInit) { ret = new double[dataset.numClasses()]; } else { ret = learner.getVotesForInstance(inst); } return ret; }
/** * Predicts the class memberships for a given instance. If an instance is * unclassified, the returned array elements must be all zero. * * @param inst the instance to be classified * @return an array containing the estimated membership probabilities of the * test instance in each class */ @Override public double[] getVotesForInstance(Instance inst) { double[] ret; inst.setDataset(dataset); if (this.isInit == false) { ret = new double[dataset.numClasses()]; } else { ret = learner.getVotesForInstance(inst); } return ret; }
/** * Predicts the class memberships for a given instance. If an instance is * unclassified, the returned array elements must be all zero. * * @param inst the instance to be classified * @return an array containing the estimated membership probabilities of the * test instance in each class */ @Override public double[] getVotesForInstance(Instance inst) { double[] ret; inst.setDataset(dataset); if (this.isInit == false) { ret = new double[dataset.numClasses()]; } else { ret = learner.getVotesForInstance(inst); } return ret; }
public boolean readInstance(Reader fileReader) { // ArffReader arff = new ArffReader(reader, this, m_Lines, 1); if (arff == null) { arff = new ArffLoader(fileReader,0,this.classAttribute); } Instance inst = arff.readInstance(fileReader); if (inst != null) { inst.setDataset(this); add(inst); return true; } else { return false; } }
/** * Delete attribute at. * * @param integer the integer */ public void deleteAttributeAt(Integer integer) { this.instanceInformation.deleteAttributeAt(integer); for (int i = 0; i < numInstances(); i++) { instance(i).setDataset(null); instance(i).deleteAttributeAt(integer); instance(i).setDataset(this); } }
/** * Insert attribute at. * * @param attribute the attribute * @param position the position */ public void insertAttributeAt(Attribute attribute, int position) { if (this.instanceInformation == null) { this.instanceInformation = new InstanceInformation(); } this.instanceInformation.insertAttributeAt(attribute, position); for (int i = 0; i < numInstances(); i++) { instance(i).setDataset(null); instance(i).insertAttributeAt(i); instance(i).setDataset(this); } }
public Instance extendWithOldLabels(Instance instance) { if (this.header == null) { initHeader(instance.dataset()); this.baseLearner.setModelContext(new InstancesHeader(this.header)); } int numLabels = this.oldLabels.length; if (numLabels == 0) { return instance; } double[] x = instance.toDoubleArray(); double[] x2 = Arrays.copyOfRange(this.oldLabels, 0, numLabels + x.length); System.arraycopy(x, 0, x2, numLabels, x.length); Instance extendedInstance = new DenseInstance(instance.weight(), x2); extendedInstance.setDataset(this.header); //System.out.println( extendedInstance); return extendedInstance; }
/** * Trains this classifier incrementally using the given instance. * * @param inst the instance to be used for training */ @Override public void trainOnInstance(Instance inst) { if (this.isInit == false) { this.isInit = true; InstancesHeader instances = new InstancesHeader(dataset); this.learner.setModelContext(instances); this.learner.prepareForUse(); } if (inst.weight() > 0) { inst.setDataset(dataset); learner.trainOnInstance(inst); } }
/** * Trains this classifier incrementally using the given instance. * * @param inst the instance to be used for training */ @Override public void trainOnInstance(Instance inst) { if (!this.isInit) { this.isInit = true; InstancesHeader instances = new InstancesHeader(dataset); this.learner.setModelContext(instances); this.learner.prepareForUse(); } if (inst.weight() > 0) { inst.setDataset(dataset); learner.trainOnInstance(inst); } }
/** * Trains this classifier incrementally using the given instance. * * @param inst the instance to be used for training */ @Override public void trainOnInstance(Instance inst) { if (this.isInit == false) { this.isInit = true; InstancesHeader instances = new InstancesHeader(dataset); this.learner.setModelContext(instances); this.learner.prepareForUse(); } if (inst.weight() > 0) { inst.setDataset(dataset); learner.trainOnInstance(inst); } }
/** * Trains this classifier incrementally using the given instance. * * @param inst the instance to be used for training */ @Override public void trainOnInstance(Instance inst) { if (this.isInit == false) { this.isInit = true; InstancesHeader instances = new InstancesHeader(dataset); this.learner.setModelContext(instances); this.learner.prepareForUse(); } if (inst.weight() > 0) { inst.setDataset(dataset); learner.trainOnInstance(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); }
@Override public Instance sourceInstanceToTarget(Instance sourceInstance) { double [] attValues = new double[targetInstances.numAttributes()]; Instance newInstance=new InstanceImpl(sourceInstance.weight(),attValues); for (int i=0; i<this.targetInputIndices.length; i++){ newInstance.setValue(i, sourceInstance.valueInputAttribute(targetInputIndices[i])); } for (int i=0; i<this.targetOutputIndices.length; i++){ newInstance.setValue(i, sourceInstance.valueOutputAttribute(targetOutputIndices[i])); } newInstance.setDataset(targetInstances); return newInstance; }
@Override public Instance sourceInstanceToTarget(Instance sourceInstance) { double [] attValues = new double[targetInstances.numAttributes()]; Instance newInstance=new InstanceImpl(sourceInstance.weight(),attValues); int numInputs=this.targetInstances.numInputAttributes(); for (int i=0; i<numInputs; i++){ newInstance.setValue(i, sourceInstance.valueInputAttribute(i)); } for (int i=0; i<this.targetOutputIndices.length; i++){ newInstance.setValue(numInputs+i, sourceInstance.valueOutputAttribute(targetOutputIndices[i])); } newInstance.setDataset(targetInstances); return newInstance; }
public InstanceExample nextInstance() { this.numInstances++; InstancesHeader header = getHeader(); Instance inst = new DenseInstance(header.numAttributes()); inst.setDataset(header); double nextValue = this.nextValue(); if (this.notBinaryStreamOption.isSet()) { inst.setValue(0, nextValue); } else { inst.setValue(0, this.nextbinaryValue(nextValue)); } //Ground truth inst.setValue(1, this.getChange() ? 1 : 0); if (this.getChange() == true) { //this.clusterEvents.add(new ClusterEvent(this, this.numInstances, "Change", "Drift")); } inst.setValue(2, nextValue); return new InstanceExample(inst); }