Example usage for weka.core.neighboursearch LinearNNSearch setSkipIdentical

List of usage examples for weka.core.neighboursearch LinearNNSearch setSkipIdentical

Introduction

In this page you can find the example usage for weka.core.neighboursearch LinearNNSearch setSkipIdentical.

Prototype

public void setSkipIdentical(boolean skip) 

Source Link

Document

Sets the property to skip identical instances (with distance zero from the target) from the set of neighbours returned.

Usage

From source file:jjj.asap.sas.models1.job.BuildCosineModels.java

License:Open Source License

@Override
protected void run() throws Exception {

    // validate args
    if (!Bucket.isBucket("datasets", inputBucket)) {
        throw new FileNotFoundException(inputBucket);
    }/*from   www  .  j a  v  a2  s  . c  om*/
    if (!Bucket.isBucket("models", outputBucket)) {
        throw new FileNotFoundException(outputBucket);
    }

    // init multi-threading
    Job.startService();
    final Queue<Future<Object>> queue = new LinkedList<Future<Object>>();

    // get the input from the bucket
    List<String> names = Bucket.getBucketItems("datasets", this.inputBucket);
    for (String dsn : names) {

        int essaySet = Contest.getEssaySet(dsn);

        int k = -1;
        switch (essaySet) {

        case 3:
            k = 13;
            break;
        case 5:
        case 7:
            k = 55;
            break;
        case 2:
        case 6:
        case 10:
            k = 21;
            break;
        case 1:
        case 4:
        case 8:
        case 9:
            k = 34;
            break;
        }

        if (k == -1) {
            throw new IllegalArgumentException("not k defined for " + essaySet);
        }

        LinearNNSearch search = new LinearNNSearch();
        search.setDistanceFunction(new CosineDistance());
        search.setSkipIdentical(false);

        IBk knn = new IBk();
        knn.setKNN(k);
        knn.setDistanceWeighting(INVERSE);
        knn.setNearestNeighbourSearchAlgorithm(search);

        queue.add(Job.submit(new ModelBuilder(dsn, "KNN-" + k, knn, this.outputBucket)));
    }

    // wait on complete
    Progress progress = new Progress(queue.size(), this.getClass().getSimpleName());
    while (!queue.isEmpty()) {
        try {
            queue.remove().get();
        } catch (Exception e) {
            Job.log("ERROR", e.toString());
            e.printStackTrace(System.err);
        }
        progress.tick();
    }
    progress.done();
    Job.stopService();

}