Example usage for weka.core.matrix DoubleVector norm2

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

Introduction

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

Prototype

public double norm2() 

Source Link

Document

Returns the L2-norm of the vector

Usage

From source file:tml.utils.DistanceLib.java

License:Apache License

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

    double dotXY = x.times(y).norm1();
    double cosim = dotXY / (x.norm2() * y.norm2());

    return cosim;
}