Beispiel #1
0
  public double GetTestErrorNN() {
    DataSet trainSet = new DataSet();
    trainSet.LoadMatrixes(S, Y, 0, numTrainInstances);

    DataSet testSet = new DataSet();
    testSet.LoadMatrixes(S, Y, numTrainInstances, numTotalInstances);

    NearestNeighbour nn = new NearestNeighbour("euclidean");

    return nn.Classify(trainSet, testSet);
  }
  // build the kernel datasets
  public void BuildKernels() {
    int n = trainSet.instances.size();
    int m = testSet.instances.size();

    trainKernel = new DataSet();
    trainKernel.name = trainSet.name;
    trainKernel.numFeatures = n;
    testKernel = new DataSet();
    testKernel.name = testSet.name;
    testKernel.numFeatures = n;

    for (int i = 0; i < n; i++) {
      DataInstance ins = new DataInstance();

      DataInstance train_i = trainSet.instances.get(i);

      for (int j = 0; j < n; j++) {
        DataInstance train_j = trainSet.instances.get(j);

        double k_ij = EuclideanDistance.getInstance().CalculateDistance(train_i, train_j);
        // double k_ij = DTW.getInstance().CalculateDistance(train_i, train_j);
        ins.features.add(new FeaturePoint(k_ij));
      }

      ins.target = train_i.target;

      trainKernel.instances.add(ins);
    }

    for (int i = 0; i < m; i++) {
      DataInstance ins = new DataInstance();

      DataInstance test_i = testSet.instances.get(i);

      for (int j = 0; j < n; j++) {
        DataInstance train_j = trainSet.instances.get(j);

        double k_ij = EuclideanDistance.getInstance().CalculateDistance(test_i, train_j);
        // double k_ij = DTW.getInstance().CalculateDistance(test_i, train_j);
        ins.features.add(new FeaturePoint(k_ij));
      }

      ins.target = test_i.target;
      testKernel.instances.add(ins);
    }
  }