All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.core.neighboursearch.balltrees.BallSplitter Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

The newest version!
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 * BallSplitter.java
 * Copyright (C) 2007-2012 University of Waikato
 */

package weka.core.neighboursearch.balltrees;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;

import weka.core.EuclideanDistance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.RevisionHandler;
import weka.core.RevisionUtils;

/**
 * Abstract class for splitting a ball tree's BallNode.
 * 
 * @author Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
 * @version $Revision: 10203 $
 */
public abstract class BallSplitter implements Serializable, OptionHandler,
  RevisionHandler {

  /** ID to avoid warning */
  private static final long serialVersionUID = -2233739562654159948L;

  /** The instance on which the tree is built. */
  protected Instances m_Instances;

  /**
   * The distance function (metric) from which the tree is (OR is to be) built.
   */
  protected EuclideanDistance m_DistanceFunction;

  /**
   * The master index array that'll be reshuffled as nodes are split (and the
   * tree is constructed).
   */
  protected int[] m_Instlist;

  /**
   * default constructor.
   */
  public BallSplitter() {
  }

  /**
   * Creates a new instance of BallSplitter.
   * 
   * @param instList The master index array.
   * @param insts The instances on which the tree is (or is to be) built.
   * @param e The Euclidean distance function to use for splitting.
   */
  public BallSplitter(int[] instList, Instances insts, EuclideanDistance e) {
    m_Instlist = instList;
    m_Instances = insts;
    m_DistanceFunction = e;
  }

  /**
   * Checks whether if this ball splitter is correctly intialized or not (i.e.
   * master index array, instances, and distance function is supplied or not)
   * 
   * @throws Exception If the object is not correctly initialized.
   */
  protected void correctlyInitialized() throws Exception {
    if (m_Instances == null) {
      throw new Exception("No instances supplied.");
    } else if (m_Instlist == null) {
      throw new Exception("No instance list supplied.");
    } else if (m_DistanceFunction == null) {
      throw new Exception("No Euclidean distance function supplied.");
    } else if (m_Instances.numInstances() != m_Instlist.length) {
      throw new Exception("The supplied instance list doesn't seem to match "
        + "the supplied instances");
    }
  }

  /**
   * Returns an enumeration describing the available options.
   * 
   * @return an enumeration of all the available options.
   */
  @Override
  public Enumeration




© 2015 - 2024 Weber Informatics LLC | Privacy Policy