@Override protected boolean readNextInstanceFromFile() { try { if (this.instances.readInstance(this.fileReader)) { this.lastInstanceRead = new InstanceExample(this.instances.instance(0)); this.instances.delete(); // keep instances clean return true; } if (this.fileReader != null) { this.fileReader.close(); this.fileReader = null; } return false; } catch (IOException ioe) { throw new RuntimeException( "ArffFileStream failed to read instance from stream.", ioe); } }
protected boolean readNextInstanceFromFile() { try { if (this.instances.readInstance(this.fileReader)) { this.lastInstanceRead = new InstanceExample(this.instances.instance(0)); this.instances.delete(); // keep instances clean this.numInstancesRead++; return true; } if (this.fileReader != null) { this.fileReader.close(); this.fileReader = null; } return false; } catch (IOException ioe) { throw new RuntimeException( "ArffFileStream failed to read instance from stream.", ioe); } }
protected boolean readNextInstanceFromFile() { try { if (this.instances.readInstance(this.fileReader)) { this.lastInstanceRead = new InstanceExample(this.instances.instance(0)); this.instances.delete(); // keep instances clean this.numInstancesRead++; return true; } if (this.fileReader != null) { this.fileReader.close(); this.fileReader = null; } return false; } catch (IOException ioe) { throw new RuntimeException( "ArffFileStream failed to read instance from stream.", ioe); } }
private boolean getNextInstanceFromFile() throws RuntimeException { try { if (this.instances.readInstance(this.fileReader)) { this.lastInstanceRead = new InstanceExample(this.instances.instance(0)); this.instances.delete(); // keep instances clean this.numInstancesRead++; return true; } if (this.fileReader != null) { this.fileReader.close(); this.fileReader = null; } return false; } catch (IOException ioe) { throw new RuntimeException( "ArffFileStream failed to read instance from stream.", ioe); } } }
private boolean getNextInstanceFromFile() throws RuntimeException { try { if (this.instances.readInstance(this.fileReader)) { this.lastInstanceRead = new InstanceExample(this.instances.instance(0)); this.instances.delete(); // keep instances clean this.numInstancesRead++; return true; } if (this.fileReader != null) { this.fileReader.close(); this.fileReader = null; } return false; } catch (IOException ioe) { throw new RuntimeException( "ArffFileStream failed to read instance from stream.", ioe); } } }
@Override protected boolean readNextInstanceFromFile() { try { if (this.instances.readInstance(this.fileReader)) { this.lastInstanceRead = new InstanceExample(this.instances.instance(0)); this.instances.delete(); // keep instances clean this.numInstancesRead++; return true; } if (this.fileReader != null) { this.fileReader.close(); this.fileReader = null; } return false; } catch (IOException ioe) { throw new RuntimeException( "ArffFileStream failed to read instance from stream.", ioe); } }
instances.delete();
@Override public void trainOnInstanceImpl(Instance inst) { if (inst.classValue() > C) { C = (int) inst.classValue(); } if (this.window == null) { this.window = new Instances(inst.dataset()); } for (int i = 0; i < this.window.size(); i++) { if (this.classifierRandom.nextDouble() > this.prob) { this.window.delete(i); } } this.window.add(inst); }
this.instances.delete(); // keep instances clean this.numInstancesRead++; return true;
private void cleanSingle(Instances cleanAgainst, int cleanAgainstindex, Instances toClean){ Instances cleanAgainstTmp = new Instances(cleanAgainst); cleanAgainstTmp.delete(cleanAgainstindex); double distancesSTM[] = get1ToNDistances(cleanAgainst.get(cleanAgainstindex), cleanAgainstTmp); int nnIndicesSTM[] = nArgMin(Math.min(this.kOption.getValue(), distancesSTM.length), distancesSTM); double distancesLTM[] = get1ToNDistances(cleanAgainst.get(cleanAgainstindex), toClean); int nnIndicesLTM[] = nArgMin(Math.min(this.kOption.getValue(), distancesLTM.length), distancesLTM); double distThreshold = 0; for (int nnIdx: nnIndicesSTM){ if (cleanAgainstTmp.get(nnIdx).classValue() == cleanAgainst.get(cleanAgainstindex).classValue()){ if (distancesSTM[nnIdx] > distThreshold){ distThreshold = distancesSTM[nnIdx]; } } } List<Integer> delIndices = new ArrayList<>(); for (int nnIdx: nnIndicesLTM){ if (toClean.get(nnIdx).classValue() != cleanAgainst.get(cleanAgainstindex).classValue()) { if (distancesLTM[nnIdx] <= distThreshold){ delIndices.add(nnIdx); } } } Collections.sort(delIndices, Collections.reverseOrder()); for (Integer idx : delIndices) toClean.delete(idx); } /**
/** * Makes sure that the STM and LTM combined doe not surpass the maximum size. */ private void memorySizeCheck(){ if (this.stm.numInstances() + this.ltm.numInstances() > this.maxSTMSize + this.maxLTMSize){ if (this.ltm.numInstances() > this.maxLTMSize){ this.clusterDown(); }else{ //shift values from STM directly to LTM since STM is full int numShifts = this.maxLTMSize - this.ltm.numInstances() + 1; for (int i = 0; i < numShifts; i++){ this.ltm.add(this.stm.get(0).copy()); this.stm.delete(0); this.stmHistory.remove(0); this.ltmHistory.remove(0); this.cmHistory.remove(0); } this.clusterDown(); this.predictionHistories.clear(); for (int i = 0; i < this.stm.numInstances(); i++){ for (int j = 0; j < this.stm.numInstances(); j++){ this.distanceMatrixSTM[i][j] = this.distanceMatrixSTM[numShifts+i][numShifts+j]; } } } } }
if (this.ltm.get(i).classValue() == c) { classSamples.add(this.ltm.get(i).toDoubleArray()); this.ltm.delete(i);
@Override public void trainOnInstanceImpl(Instance inst) { if (inst.classValue() > C) C = (int)inst.classValue(); if (this.window == null) { this.window = new Instances(inst.dataset()); } if (this.limitOption.getValue() <= this.window.numInstances()) { this.window.delete(0); } this.window.add(inst); }
@Override public Example<Instance> nextInstance() { // a value between 0.0 and 1.0 uniformly distributed double p = random.nextDouble(); int iClass = -1; // loops over all class probabilities to see from which class the next instance should be from while(p > 0.0){ iClass++; p -= probPerClass[iClass]; } // keeps on creating and storing instances until we have an instance for the desired class while(instancesBuffer[iClass].size() == 0){ Example<Instance> inst = originalStream.nextInstance(); instancesBuffer[(int) inst.getData().classValue()].add(inst.getData()); } // retrieves the instance from the desired class Instance instance = instancesBuffer[iClass].get(0); // and also removes it from the buffer instancesBuffer[iClass].delete(0); return new InstanceExample(instance); }
this.stm.delete(0);