/**
   * sdf The test main
   *
   * @param args ignored
   */
  public static void main(String[] args) {
    //        Instance[] instances =  new Instance[100];
    //        for (int i = 0; i < instances.length; i++) {
    //            double[] data = new double[2];
    //            data[0] = Math.sin(i/2.0);
    //            data[1] = (Math.random() - .5)*2;
    //            instances[i] = new Instance(data);
    //        }
    DataSet set = new DataSet(trainInstances);
    System.out.println("Before randomizing");
    System.out.println(set);
    //        Matrix projection = new RectangularMatrix(new double[][]{ {.6, .6}, {.4, .6}});
    Matrix projection = new RectangularMatrix(new double[][] {{.1, .1}, {.1, .1}});

    for (int i = 0; i < set.size(); i++) {
      Instance instance = set.get(i);
      instance.setData(projection.times(instance.getData()));
    }
    System.out.println("Before ICA");
    System.out.println(set);
    IndependentComponentAnalysis filter = new IndependentComponentAnalysis(set, 1);
    filter.filter(set);
    System.out.println("After ICA");
    System.out.println(set);
  }
Exemplo n.º 2
0
 private static void computeReconstructionError(DataSet original, DataSet reconstructed) {
   EuclideanDistance distanceFunction = new EuclideanDistance();
   double totalDataSetsDistance = distanceFunction.value(original, reconstructed);
   double averageInstanceDistane = totalDataSetsDistance / original.size();
   System.out.println(
       "Total reconstruction error as Euclidean distance between data sets: "
           + totalDataSetsDistance);
   System.out.println("Average Instance reconstruction error: " + averageInstanceDistane);
 }
Exemplo n.º 3
0
  public void filter(DataSet data) {
    int foldSize = data.size() / foldCount;
    Random rand = new Random();

    for (int currentFold = 0; currentFold < foldCount; currentFold++) {
      DataSet currentSet = new DataSet(new Instance[foldSize], data.getDescription());
      int i = 0;
      while (i < foldSize) {
        int position = rand.nextInt(data.size());
        Instance instance = data.get(position);
        if (instance != null && instance.getData() != null) {
          currentSet.set(i, instance);
          data.set(position, null);
          i++;
        }
      }
      this.folds.add(currentSet);
    }
  }