dimanche 1 mars 2015

CosineSimilarity [on hold]


I want to caculate the similarity in rows of a matrix such as D, but the results are not correct!! What is the problem of my codes?


private ArrayList cosineSimilarity(int rowIndex, Matrix D) {



double dotProduct = 0.0, firstNorm = 0.0, secondNorm = 0.0;
double cosinSimilarity;
ArrayList<Double> similarRows = new ArrayList<>();

for(int row = 0; row < D.getRowDimension(); row++){
for (int column = 0; column < D.getColumnDimension(); column++) {
dotProduct = + (D.get(rowIndex, column) * D.get(row, column));
firstNorm = + pow(D.get(rowIndex, column),2);
secondNorm = + pow(D.get(row, column), 2);
// Matrix f = D.getMatrix(row, column);
}
cosinSimilarity = (dotProduct / (sqrt(firstNorm) * sqrt(secondNorm)));
similarRows.add(row, cosinSimilarity);
}




Aucun commentaire:

Enregistrer un commentaire