Dear Wiki user, You have subscribed to a wiki page or wiki category on "Hama Wiki" for change notification.
The following page has been changed by udanax: http://wiki.apache.org/hama/TraditionalCollaborativeFiltering ------------------------------------------------------------------------------ public static void main(String[] args) { HamaConfiguration conf = new HamaConfiguration(); - Matrix tmpMatrix = new Matrix(conf, "input"); + Matrix userByItem = new Matrix(conf, "input"); // Build an user by item matrix for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { - tmpMatrix.set(i, j, data[i][j]); + userByItem.set(i, j, data[i][j]); } } // Get the pair set of all row key combinations Combination x = new Combination(data.length, 2); - // Calculate |a|·|b|cos(q) + // |a|·|b|cos(q) calculation while (x.hasMore()) { int[] pair = x.getNext(); System.out.print("Similarity: (" + pair[0] + ", " + pair[1] + ") = "); - Vector v1 = tmpMatrix.getRow(pair[0]); + Vector v1 = userByItem.getRow(pair[0]); - Vector v2 = tmpMatrix.getRow(pair[1]); + Vector v2 = userByItem.getRow(pair[1]); double similarity = v1.dot(v2); - // Collect result + // Collect the similarity result of the two users System.out.println(similarity); }
