/** * Gets the filter specification string, which contains the class name of the * filter and any options to the filter * * @return the filter string. */ protected String getFilterSpec() { Filter c = getFilter(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); } return c.getClass().getName(); }
/** * Gets the current settings. Returns empty array. * * @return an array of strings suitable for passing to setOptions() */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-F"); result.add("" + getFilterSpec()); result.add("-S"); result.add("" + getSearchMethodSpec()); return result.toArray(new String[result.size()]); }
/** * Gets the search method specification string, which contains the class name * of the search method and any options to the search method * * @return the search method string. */ protected String getSearchMethodSpec() { NearestNeighbourSearch c = getSearchMethod(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); } return c.getClass().getName(); }
getCapabilities().testWithFail(data); Instances filteredData = new Instances(data); getFilter().setInputFormat(filteredData); filteredData = Filter.useFilter(data, getFilter()); if (data.numInstances() != filteredData.numInstances()) { throw new IllegalArgumentException( getSearchMethod()).getObject(); m_ModifiedSearchMethod.getDistanceFunction().setAttributeIndices( "1-" + m_IndexOfID);
/** * Returns the nearest neighbour for the given instance based on distance * measured in the filtered space. * * @param target the instance for which to find the nearest neighbour * @return the nearest neighbour * * @see weka.core.neighboursearch.NearestNeighbourSearch#nearestNeighbour(weka.core.Instance) */ @Override public Instance nearestNeighbour(Instance target) throws Exception { getFilter().input(target); m_AddID.input(getFilter().output()); return getInstances().instance( (int) m_ModifiedSearchMethod.nearestNeighbour(m_AddID.output()).value( m_IndexOfID) - 1); }
searchMethodSpec[0] = ""; setSearchMethod((NearestNeighbourSearch) Utils.forName( NearestNeighbourSearch.class, className, searchMethodSpec)); } else { setSearchMethod(new LinearNNSearch()); filterSpec[0] = ""; setFilter((Filter) Utils.forName(Filter.class, className, filterSpec)); } else { setFilter(new AllFilter());
getCapabilities().testWithFail(data); Instances filteredData = new Instances(data); getFilter().setInputFormat(filteredData); filteredData = Filter.useFilter(data, getFilter()); if (data.numInstances() != filteredData.numInstances()) { throw new IllegalArgumentException( getSearchMethod()).getObject(); m_ModifiedSearchMethod.getDistanceFunction().setAttributeIndices( "1-" + m_IndexOfID);
/** * Returns the nearest neighbour for the given instance based on distance * measured in the filtered space. * * @param target the instance for which to find the nearest neighbour * @return the nearest neighbour * * @see weka.core.neighboursearch.NearestNeighbourSearch#nearestNeighbour(weka.core.Instance) */ @Override public Instance nearestNeighbour(Instance target) throws Exception { getFilter().input(target); m_AddID.input(getFilter().output()); return getInstances().instance( (int) m_ModifiedSearchMethod.nearestNeighbour(m_AddID.output()).value( m_IndexOfID) - 1); }
searchMethodSpec[0] = ""; setSearchMethod((NearestNeighbourSearch) Utils.forName( NearestNeighbourSearch.class, className, searchMethodSpec)); } else { setSearchMethod(new LinearNNSearch()); filterSpec[0] = ""; setFilter((Filter) Utils.forName(Filter.class, className, filterSpec)); } else { setFilter(new AllFilter());
/** * 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; }
/** * Gets the filter specification string, which contains the class name of the * filter and any options to the filter * * @return the filter string. */ protected String getFilterSpec() { Filter c = getFilter(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); } return c.getClass().getName(); }
/** * Gets the current settings. Returns empty array. * * @return an array of strings suitable for passing to setOptions() */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-F"); result.add("" + getFilterSpec()); result.add("-S"); result.add("" + getSearchMethodSpec()); return result.toArray(new String[result.size()]); }
/** * Gets the search method specification string, which contains the class name * of the search method and any options to the search method * * @return the search method string. */ protected String getSearchMethodSpec() { NearestNeighbourSearch c = getSearchMethod(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); } return c.getClass().getName(); }
/** * 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; }
/** * Updates ranges based on the given instance, once it has been filtered. * * @see weka.core.neighboursearch.NearestNeighbourSearch#update(weka.core.Instance) */ @Override public void update(Instance ins) throws Exception { getFilter().input(ins); m_AddID.input(getFilter().output()); m_ModifiedSearchMethod.update(m_AddID.output()); }
/** * Updates ranges based on the given instance, once it has been filtered. * * @see weka.core.neighboursearch.NearestNeighbourSearch#update(weka.core.Instance) */ @Override public void update(Instance ins) throws Exception { getFilter().input(ins); m_AddID.input(getFilter().output()); m_ModifiedSearchMethod.update(m_AddID.output()); }
/** * Returns default capabilities of the classifier. * * @return the capabilities of this classifier */ public Capabilities getCapabilities() { Capabilities result = getFilter().getCapabilities(); // set dependencies for (Capability cap : Capability.values()) result.enableDependency(cap); return result; }
/** * 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(); } } }
/** * 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(); } } }
/** * Returns default capabilities of the classifier. * * @return the capabilities of this classifier */ public Capabilities getCapabilities() { Capabilities result = getFilter().getCapabilities(); // set dependencies for (Capability cap : Capability.values()) result.enableDependency(cap); return result; }