Here you can find the source of dotProduct(double[] fv1, double[] fv2)
Parameter | Description |
---|---|
fv1 | a parameter |
fv2 | a parameter |
public static double dotProduct(double[] fv1, double[] fv2)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from www. j a v a 2s. c o m*/ * Compute the dot product between two feature vectors represented as double arrays * * @param fv1 * @param fv2 * @return the dot product between fv1 and fv2 */ public static double dotProduct(double[] fv1, double[] fv2) { double sum = 0.0; for (int i = 0; i < fv1.length && i < fv2.length; i++) { //sum += (fv1[i] != 0 && fv2[i] != 0) ? fv1[i] * fv2[i]: 0; sum += fv1[i] * fv2[i]; } return sum; } }