/** * Builds the Cover Tree on the given set of instances. * * @param instances The insts on which the Cover Tree is to be built. * @throws Exception If some error occurs while building the Cover Tree */ @Override public void setInstances(Instances instances) throws Exception { super.setInstances(instances); buildCoverTree(instances); }
/** * Returns an enumeration of the additional measure names * produced by the neighbour search algorithm. * @return an enumeration of the measure names */ public Enumeration<String> enumerateMeasures() { return m_NNSearch.enumerateMeasures(); }
/** * Returns the distances for the nearest neighbours in the FILTERED space * * @return the array of distances for the nearest neighbours * * @see weka.core.neighboursearch.NearestNeighbourSearch#getDistances() */ @Override public double[] getDistances() throws Exception { return m_ModifiedSearchMethod.getDistances(); }
StringBuffer item; m_NearestNeighbourSearch.setInstances(m_Instances); + m_Instances.instance(i).toString() + ": "); for (n = 1; n <= m_NumNeighbors; n++) { inst = m_NearestNeighbourSearch.kNearestNeighbours( m_Instances.instance(i), n); item.append(" neighbors=" + n + ": ");
m_NNSearch.setInstances(m_Train); m_NNSearch.addInstanceInfo(instance); Instances neighbours = m_NNSearch.kNearestNeighbours(instance, m_kNN); double [] distances = m_NNSearch.getDistances(); double [] distribution = makeDistribution( neighbours, distances );
m_NNSearch.addInstanceInfo(instance); Instances neighbours = m_NNSearch.kNearestNeighbours(instance, k); double distances[] = m_NNSearch.getDistances();
/** * Adds the supplied instance to the training set. * * @param instance the instance to add * @throws Exception if instance could not be incorporated * successfully */ public void updateClassifier(Instance instance) throws Exception { if (m_Train.equalHeaders(instance.dataset()) == false) { throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset())); } if (instance.classIsMissing()) { return; } m_Train.add(instance); m_NNSearch.update(instance); m_kNNValid = false; if ((m_WindowSize > 0) && (m_Train.numInstances() > m_WindowSize)) { boolean deletedInstance=false; while (m_Train.numInstances() > m_WindowSize) { m_Train.delete(0); deletedInstance=true; } //rebuild datastructure KDTree currently can't delete if(deletedInstance==true) m_NNSearch.setInstances(m_Train); } }
super.setInstances(data); m_ModifiedSearchMethod.getDistanceFunction().setAttributeIndices( "1-" + m_IndexOfID); m_ModifiedSearchMethod.getDistanceFunction().setInvertSelection(false); m_ModifiedSearchMethod.setInstances(filteredData); } catch (Exception e) { e.printStackTrace();
neighbours = m_NNSearch.kNearestNeighbours(instance, m_kNN); origDistances = m_NNSearch.getDistances();
/** * Gets the current settings. * * @return an array of strings suitable for passing to setOptions() */ public String[] getOptions() { Vector<String> result = new Vector<String>(); Collections.addAll(result, super.getOptions()); if (getSkipIdentical()) result.add("-S"); return result.toArray(new String[result.size()]); }
/** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration<Option> listOptions() { Vector<Option> newVector = new Vector<Option>(); newVector.addElement(new Option("\tSet base of the expansion constant\n" + "\t(default = 1.3).", "B", 1, "-B <value>")); newVector.addAll(Collections.list(super.listOptions())); return newVector.elements(); }
/** * Returns the nearest neighbours for the given instance based on distance * measured in the filtered space. * * @param target the instance for which to find the nearest neighbour * @param k the number of nearest neighbours to return * @return the nearest Neighbours * * @see weka.core.neighboursearch.NearestNeighbourSearch#kNearestNeighbours(weka.core.Instance, * int) */ @Override public Instances kNearestNeighbours(Instance target, int k) throws Exception { // Get neighbors in filtered space getFilter().input(target); m_AddID.input(getFilter().output()); Instances neighboursInFilteredSpace = m_ModifiedSearchMethod .kNearestNeighbours(m_AddID.output(), k); // Collect corresponding instances in original space Instances neighbours = new Instances(getInstances(), k); for (Instance inst : neighboursInFilteredSpace) { neighbours .add(getInstances().instance((int) inst.value(m_IndexOfID) - 1)); } return neighbours; }
/** * Returns the value of the named measure from the * neighbour search algorithm. * @param additionalMeasureName the name of the measure to query for its value * @return the value of the named measure * @throws IllegalArgumentException if the named measure is not supported */ public double getMeasure(String additionalMeasureName) { return m_NNSearch.getMeasure(additionalMeasureName); }
/** * Gets the current settings. * * @return an array of strings suitable for passing to setOptions() */ @Override public String[] getOptions() { Vector<String> result; result = new Vector<String>(); result.add("-A"); result.add((m_DistanceFunction.getClass().getName() + " " + Utils .joinOptions(m_DistanceFunction.getOptions())).trim()); if (getMeasurePerformance()) { result.add("-P"); } return result.toArray(new String[result.size()]); }
/** * Updates the instance info in the underlying search method, once the * instance has been filtered. * * @param ins The instance to add the information of. */ @Override public void addInstanceInfo(Instance ins) { if (m_Instances != null) try { getFilter().input(ins); m_AddID.input(getFilter().output()); m_ModifiedSearchMethod.addInstanceInfo(m_AddID.output()); } catch (Exception ex) { ex.printStackTrace(); } } }
StringBuffer item; m_NearestNeighbourSearch.setInstances(m_Instances); + m_Instances.instance(i).toString() + ": "); for (n = 1; n <= m_NumNeighbors; n++) { inst = m_NearestNeighbourSearch.kNearestNeighbours( m_Instances.instance(i), n); item.append(" neighbors=" + n + ": ");
m_NNSearch.setInstances(m_Train); m_NNSearch.addInstanceInfo(instance); Instances neighbours = m_NNSearch.kNearestNeighbours(instance, m_kNN); double [] distances = m_NNSearch.getDistances(); double [] distribution = makeDistribution( neighbours, distances );
m_NNSearch.addInstanceInfo(instance); Instances neighbours = m_NNSearch.kNearestNeighbours(instance, k); double distances[] = m_NNSearch.getDistances();
/** * Adds the supplied instance to the training set. * * @param instance the instance to add * @throws Exception if instance could not be incorporated * successfully */ public void updateClassifier(Instance instance) throws Exception { if (m_Train.equalHeaders(instance.dataset()) == false) { throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset())); } if (instance.classIsMissing()) { return; } m_Train.add(instance); m_NNSearch.update(instance); m_kNNValid = false; if ((m_WindowSize > 0) && (m_Train.numInstances() > m_WindowSize)) { boolean deletedInstance=false; while (m_Train.numInstances() > m_WindowSize) { m_Train.delete(0); deletedInstance=true; } //rebuild datastructure KDTree currently can't delete if(deletedInstance==true) m_NNSearch.setInstances(m_Train); } }
super.setInstances(data); m_ModifiedSearchMethod.getDistanceFunction().setAttributeIndices( "1-" + m_IndexOfID); m_ModifiedSearchMethod.getDistanceFunction().setInvertSelection(false); m_ModifiedSearchMethod.setInstances(filteredData); } catch (Exception e) { e.printStackTrace();