Example usage for weka.core.matrix DoubleVector norm1

List of usage examples for weka.core.matrix DoubleVector norm1

Introduction

In this page you can find the example usage for weka.core.matrix DoubleVector norm1.

Prototype

public double norm1() 

Source Link

Document

Returns the L1-norm of the vector

Usage

From source file:tml.utils.DistanceLib.java

License:Apache License

public static double jaccard(Instance inst1, Instance inst2) {
    DoubleVector x = new DoubleVector(inst1.toDoubleArray());
    DoubleVector y = new DoubleVector(inst2.toDoubleArray());

    double intersection = 0.0;

    for (int i = 0; i < x.size(); i++) {
        intersection += Math.min(x.get(i), y.get(i));
    }/*  www.  java2  s. c  o m*/
    if (intersection > 0.0) {
        double union = x.norm1() + y.norm1() - intersection;
        return intersection / union;
    } else {
        return 0.0;
    }
}