Package weka.classifiers.rules

Examples of weka.classifiers.rules.DecisionTableHashKey


    m_DistanceFunction.setInstances(instances);
   
    Random RandomO = new Random(getSeed());
    int instIndex;
    HashMap initC = new HashMap();
    DecisionTableHashKey hk = null;

    Instances initInstances = null;
    if(m_PreserveOrder)
      initInstances = new Instances(instances);
    else
      initInstances = instances;
   
    for (int j = initInstances.numInstances() - 1; j >= 0; j--) {
      instIndex = RandomO.nextInt(j+1);
      hk = new DecisionTableHashKey(initInstances.instance(instIndex),
                                    initInstances.numAttributes(), true);
      if (!initC.containsKey(hk)) {
        m_ClusterCentroids.add(initInstances.instance(instIndex));
  initC.put(hk, null);
      }
View Full Code Here


    }
   
    Random RandomO = new Random(getSeed());
    int instIndex;
    HashMap initC = new HashMap();
    DecisionTableHashKey hk = null;

    for (int j = instances.numInstances() - 1; j >= 0; j--) {
      instIndex = RandomO.nextInt(j+1);
      hk = new DecisionTableHashKey(instances.instance(instIndex),
             instances.numAttributes(), true);
      if (!initC.containsKey(hk)) {
  m_ClusterCentroids.add(instances.instance(instIndex));
  initC.put(hk, null);
      }
View Full Code Here

    m_DistanceFunction.setInstances(instances);
   
    Random RandomO = new Random(getSeed());
    int instIndex;
    HashMap initC = new HashMap();
    DecisionTableHashKey hk = null;

    Instances initInstances = null;
    if (m_PreserveOrder)
      initInstances = new Instances(instances);
    else
      initInstances = instances;

    if (m_initializeWithKMeansPlusPlus) {
      kMeansPlusPlusInit(initInstances);
    } else {
      for (int j = initInstances.numInstances() - 1; j >= 0; j--) {
        instIndex = RandomO.nextInt(j+1);
        hk = new DecisionTableHashKey(initInstances.instance(instIndex),
            initInstances.numAttributes(), true);
        if (!initC.containsKey(hk)) {
          m_ClusterCentroids.add(initInstances.instance(instIndex));
          initC.put(hk, null);
        }
View Full Code Here

    HashMap<DecisionTableHashKey, String> initC = new HashMap<DecisionTableHashKey, String>();
   
    // choose initial center uniformly at random
    int index = randomO.nextInt(data.numInstances());
    m_ClusterCentroids.add(data.instance(index));
    DecisionTableHashKey hk = new DecisionTableHashKey(data.instance(index),
        data.numAttributes(), true);
    initC.put(hk, null);
   
    int iteration = 0;
    int remainingInstances = data.numInstances() - 1;
    if (m_NumClusters > 1) {
      // proceed with selecting the rest

      // distances to the initial randomly chose center
      double[] distances = new double[data.numInstances()];
      double[] cumProbs = new double[data.numInstances()];
      for (int i = 0; i < data.numInstances(); i++) {
        distances[i] =
          m_DistanceFunction.distance(data.instance(i),
              m_ClusterCentroids.instance(iteration));
      }

      // now choose the remaining cluster centers
      for (int i = 1; i < m_NumClusters; i++) {

        // distances converted to probabilities
        double[] weights = new double[data.numInstances()];
        System.arraycopy(distances, 0, weights, 0, distances.length);
        Utils.normalize(weights);

        double sumOfProbs = 0;
        for (int k = 0; k < data.numInstances(); k++) {
          sumOfProbs += weights[k];
          cumProbs[k] = sumOfProbs;
        }

        cumProbs[data.numInstances() - 1] = 1.0; // make sure there are no rounding issues

        // choose a random instance
        double prob = randomO.nextDouble();
        for (int k = 0; k < cumProbs.length; k++) {
          if (prob < cumProbs[k]) {
            Instance candidateCenter = data.instance(k);
            hk = new DecisionTableHashKey(candidateCenter, data.numAttributes(), true);
            if (!initC.containsKey(hk)) {
              initC.put(hk, null);
              m_ClusterCentroids.add(candidateCenter);
            } else {
              // we shouldn't get here because any instance that is a duplicate of
View Full Code Here

TOP

Related Classes of weka.classifiers.rules.DecisionTableHashKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.