Example usage for org.apache.commons.math3.linear ArrayRealVector cosine

List of usage examples for org.apache.commons.math3.linear ArrayRealVector cosine

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear ArrayRealVector cosine.

Prototype

public double cosine(RealVector v) throws DimensionMismatchException, MathArithmeticException 

Source Link

Document

Computes the cosine of the angle between this vector and the argument.

Usage

From source file:de.andreasschoknecht.LS3.Query.java

/**
 * Calculate the LSSM values with respect to a document collection.
 *
 * @param Sk The matrix Sk of singular values
 * @param Vtk The matrix Vtk of the singular value decomposition
 *///from w w  w . j  a  v a 2  s.  co m
void calculateLSSMValues(RealMatrix Sk, RealMatrix Vtk) {
    // scale Vtk with singular value matrix Sk
    RealMatrix scaledVtk = Sk.multiply(Vtk);

    // the query model as vector
    ArrayRealVector queryVector = new ArrayRealVector(pseudoDocument);

    int docsNumber = scaledVtk.getColumnDimension();
    lssmValues = new double[docsNumber];

    for (int i = 0; i < docsNumber; i++) {
        RealVector columnVector = scaledVtk.getColumnVector(i);
        lssmValues[i] = (queryVector.cosine(columnVector) + 1) / 2;
    }
}