类weka.core.neighboursearch.NearestNeighbourSearch源码实例Demo

下面列出了怎么用weka.core.neighboursearch.NearestNeighbourSearch的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: AILibs   文件: KNNAugSpaceSampler.java
/**
 * @param nearestNeighbour The nearest neighbour search algorithm to use.
 * @author Michael
 *
 */
public KNNAugSpaceSampler(final Instances preciseInsts, final Random rng, final int k, final NearestNeighbourSearch nearestNeighbour) {
	super(preciseInsts, rng);
	this.k = k;
	DistanceFunction dist = new EuclideanDistance(preciseInsts);
	String distOptionColumns = String.format("-R first-%d", preciseInsts.numAttributes() - 1);
	String[] distOptions = {distOptionColumns};

	try {
		dist.setOptions(distOptions);
		nearestNeighbour.setDistanceFunction(dist);
		nearestNeighbour.setInstances(preciseInsts);
	} catch (Exception e) {
		logger.error("Could not configure distance function or setup nearest neighbour: {}", e);
	}
	nearestNeighbour.setMeasurePerformance(false);
	this.nearestNeighbour = nearestNeighbour;
}
 
源代码2 项目: tsml   文件: kNN.java
public final void setDistanceFunction(DistanceFunction df){
	dist=df;
	NearestNeighbourSearch s = super.getNearestNeighbourSearchAlgorithm();
	try{
		s.setDistanceFunction(df);
	}catch(Exception e){
		System.err.println(" Exception thrown setting distance function ="+e+" in "+this);
                       e.printStackTrace();
                       System.exit(0);
	}
}
 
源代码3 项目: tsml   文件: IBk.java
/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -I
 *  Weight neighbours by the inverse of their distance
 *  (use when k &gt; 1)</pre>
 * 
 * <pre> -F
 *  Weight neighbours by 1 - their distance
 *  (use when k &gt; 1)</pre>
 * 
 * <pre> -K &lt;number of neighbors&gt;
 *  Number of nearest neighbours (k) used in classification.
 *  (Default = 1)</pre>
 * 
 * <pre> -E
 *  Minimise mean squared error rather than mean absolute
 *  error when using -X option with numeric prediction.</pre>
 * 
 * <pre> -W &lt;window size&gt;
 *  Maximum number of training instances maintained.
 *  Training instances are dropped FIFO. (Default = no window)</pre>
 * 
 * <pre> -X
 *  Select the number of nearest neighbours between 1
 *  and the k value specified using hold-one-out evaluation
 *  on the training data (use when k &gt; 1)</pre>
 * 
 * <pre> -A
 *  The nearest neighbour search algorithm to use (default: weka.core.neighboursearch.LinearNNSearch).
 * </pre>
 * 
 <!-- options-end -->
 *
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
  
  String knnString = Utils.getOption('K', options);
  if (knnString.length() != 0) {
    setKNN(Integer.parseInt(knnString));
  } else {
    setKNN(1);
  }
  String windowString = Utils.getOption('W', options);
  if (windowString.length() != 0) {
    setWindowSize(Integer.parseInt(windowString));
  } else {
    setWindowSize(0);
  }
  if (Utils.getFlag('I', options)) {
    setDistanceWeighting(new SelectedTag(WEIGHT_INVERSE, TAGS_WEIGHTING));
  } else if (Utils.getFlag('F', options)) {
    setDistanceWeighting(new SelectedTag(WEIGHT_SIMILARITY, TAGS_WEIGHTING));
  } else {
    setDistanceWeighting(new SelectedTag(WEIGHT_NONE, TAGS_WEIGHTING));
  }
  setCrossValidate(Utils.getFlag('X', options));
  setMeanSquared(Utils.getFlag('E', options));

  String nnSearchClass = Utils.getOption('A', options);
  if(nnSearchClass.length() != 0) {
    String nnSearchClassSpec[] = Utils.splitOptions(nnSearchClass);
    if(nnSearchClassSpec.length == 0) { 
      throw new Exception("Invalid NearestNeighbourSearch algorithm " +
                          "specification string."); 
    }
    String className = nnSearchClassSpec[0];
    nnSearchClassSpec[0] = "";

    setNearestNeighbourSearchAlgorithm( (NearestNeighbourSearch)
                Utils.forName( NearestNeighbourSearch.class, 
                               className, 
                               nnSearchClassSpec)
                                      );
  }
  else 
    this.setNearestNeighbourSearchAlgorithm(new LinearNNSearch());
  
  Utils.checkForRemainingOptions(options);
}
 
源代码4 项目: tsml   文件: LWL.java
/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -A
 *  The nearest neighbour search algorithm to use (default: weka.core.neighboursearch.LinearNNSearch).
 * </pre>
 * 
 * <pre> -K &lt;number of neighbours&gt;
 *  Set the number of neighbours used to set the kernel bandwidth.
 *  (default all)</pre>
 * 
 * <pre> -U &lt;number of weighting method&gt;
 *  Set the weighting kernel shape to use. 0=Linear, 1=Epanechnikov,
 *  2=Tricube, 3=Inverse, 4=Gaussian.
 *  (default 0 = Linear)</pre>
 * 
 * <pre> -D
 *  If set, classifier is run in debug mode and
 *  may output additional info to the console</pre>
 * 
 * <pre> -W
 *  Full name of base classifier.
 *  (default: weka.classifiers.trees.DecisionStump)</pre>
 * 
 * <pre> 
 * Options specific to classifier weka.classifiers.trees.DecisionStump:
 * </pre>
 * 
 * <pre> -D
 *  If set, classifier is run in debug mode and
 *  may output additional info to the console</pre>
 * 
 <!-- options-end -->
 *
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {

  String knnString = Utils.getOption('K', options);
  if (knnString.length() != 0) {
    setKNN(Integer.parseInt(knnString));
  } else {
    setKNN(-1);
  }

  String weightString = Utils.getOption('U', options);
  if (weightString.length() != 0) {
    setWeightingKernel(Integer.parseInt(weightString));
  } else {
    setWeightingKernel(LINEAR);
  }
  
  String nnSearchClass = Utils.getOption('A', options);
  if(nnSearchClass.length() != 0) {
    String nnSearchClassSpec[] = Utils.splitOptions(nnSearchClass);
    if(nnSearchClassSpec.length == 0) { 
      throw new Exception("Invalid NearestNeighbourSearch algorithm " +
                          "specification string."); 
    }
    String className = nnSearchClassSpec[0];
    nnSearchClassSpec[0] = "";

    setNearestNeighbourSearchAlgorithm( (NearestNeighbourSearch)
                Utils.forName( NearestNeighbourSearch.class, 
                               className, 
                               nnSearchClassSpec)
                                      );
  }
  else 
    this.setNearestNeighbourSearchAlgorithm(new LinearNNSearch());

  super.setOptions(options);
}
 
源代码5 项目: tsml   文件: LWL.java
/**
 * Returns the current nearestNeighbourSearch algorithm in use.
 * @return the NearestNeighbourSearch algorithm currently in use.
 */
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm() {
  return m_NNSearch;
}
 
源代码6 项目: tsml   文件: LWL.java
/**
 * Sets the nearestNeighbourSearch algorithm to be used for finding nearest
 * neighbour(s).
 * @param nearestNeighbourSearchAlgorithm - The NearestNeighbourSearch class.
 */
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm) {
  m_NNSearch = nearestNeighbourSearchAlgorithm;
}
 
源代码7 项目: tsml   文件: IBk.java
/**
 * Returns the current nearestNeighbourSearch algorithm in use.
 * @return the NearestNeighbourSearch algorithm currently in use.
 */
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm() {
  return m_NNSearch;
}
 
源代码8 项目: tsml   文件: IBk.java
/**
 * Sets the nearestNeighbourSearch algorithm to be used for finding nearest
 * neighbour(s).
 * @param nearestNeighbourSearchAlgorithm - The NearestNeighbourSearch class.
 */
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm) {
  m_NNSearch = nearestNeighbourSearchAlgorithm;
}
 
/**
 * Returns the current nearestNeighbourSearch algorithm in use.
 * @return the NearestNeighbourSearch algorithm currently in use.
 */
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm() {
  return m_NNSearch;
}
 
/**
 * Sets the nearestNeighbourSearch algorithm to be used for finding nearest
 * neighbour(s).
 * @param value The NearestNeighbourSearch class.
 */
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch value) {
  m_NNSearch = value;
}
 
/**
 * Returns the current nearestNeighbourSearch algorithm in use.
 * 
 * @return 		the NearestNeighbourSearch algorithm currently in use.
 */
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm() {
  return m_Classifier.getNearestNeighbourSearchAlgorithm();
}
 
/**
 * Sets the nearestNeighbourSearch algorithm to be used for finding nearest
 * neighbour(s).
 * 
 * @param value 	The NearestNeighbourSearch class.
 */
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch value) {
  m_Classifier.setNearestNeighbourSearchAlgorithm(value);
}