Exemplo n.º 1
0
  /**
   * KMeans constructor: the cluster centroids are obtained for the given dataset. Firstly, the
   * cluster's centroids are randomly chosen. Then the centroids are updated as the mean vlaue of
   * nearest examples in the dataset. The updating is carried out until no changes in the centroids
   * is achieved.
   *
   * @param X The dataset to be clusterized
   * @param nclusters The desired number of clusters
   * @param vrand The Randomize object to be used
   */
  public KMeans(double[][] X, int nclusters, Randomize vrand) {

    rand = vrand;
    train = X;
    clusters = nclusters;
    cclusters = new double[nclusters][X[0].length];

    for (int i = 0; i < nclusters; i++) {
      int pos = (int) (rand.Rand() * X.length);
      for (int j = 0; j < cclusters[i].length; j++) cclusters[i][j] = X[pos][j];
    }

    int[] C = new int[X.length];
    int[] C_old = new int[X.length];
    for (int i = 0; i < X.length; i++) {
      C_old[i] = nearestCentroid(X[i]);
    }
    centroidsUpdating(C_old);

    int cambios = 0, iteracion = 0;
    do {

      iteracion++;
      System.out.println("Iter=" + iteracion + " changes=" + cambios);
      cambios = 0;
      for (int i = 0; i < X.length; i++) {
        C[i] = nearestCentroid(X[i]);
        if (C[i] != C_old[i]) cambios++;
        C_old[i] = C[i];
      }
      centroidsUpdating(C);
    } while (cambios > 0);
  }
Exemplo n.º 2
0
  /**
   * This public static method runs the algorithm that this class concerns with.
   *
   * @param args Array of strings to sent parameters to the main program. The path of the
   *     algorithm's parameters file must be given.
   */
  public static void main(String args[]) {

    boolean tty = false;
    ProcessConfig pc = new ProcessConfig();
    System.out.println("Reading configuration file: " + args[0]);
    if (pc.fileProcess(args[0]) < 0) return;
    int algo = pc.parAlgorithmType;
    rand = new Randomize();
    rand.setSeed(pc.parSeed);
    ModelFuzzyPittsBurgh pi = new ModelFuzzyPittsBurgh();
    pi.fuzzyPittsburghModelling(tty, pc);
  }
Exemplo n.º 3
0
  /**
   * This public static method runs the algorithm that this class concerns with.
   *
   * @param args Array of strings to sent parameters to the main program. The path of the
   *     algorithm's parameters file must be given.
   */
  public static void main(String args[]) {

    boolean tty = false;
    ProcessConfig pc = new ProcessConfig();
    System.out.println("Reading configuration file: " + args[0]);
    if (pc.fileProcess(args[0]) < 0) return;
    int algo = pc.parAlgorithmType;
    rand = new Randomize();
    rand.setSeed(pc.parSeed);
    ClusterKMeans km = new ClusterKMeans();
    km.clustering_kmeans(tty, pc);
  }
Exemplo n.º 4
0
  /**
   * This method reads a configuration file and calls statisticalTest with appropriate values to run
   * the Mann Whitney U test for classification problems, defined in StatTest class
   *
   * @param args A string that contains the command line arguments
   */
  public static void main(String args[]) {

    boolean tty = false;
    ProcessConfig pc = new ProcessConfig();
    System.out.println("Reading configuration file: " + args[0]);
    if (pc.fileProcess(args[0]) < 0) return;
    int algorithm = pc.parAlgorithmType;
    rand = new Randomize();
    rand.setSeed(pc.parSeed);

    ParseFileList pl = new ParseFileList();
    pl.statisticalTest(StatTest.MannWhitneyC, tty, pc);
  }