All Downloads are FREE. Search and download functionalities are using the official Maven repository.

knn.userToUser.neighbors.Neighbors Maven / Gradle / Ivy

Go to download

A Java's Collaborative Filtering library to carry out experiments in research of Collaborative Filtering based Recommender Systems. The library has been designed from researchers to researchers.

The newest version!
package cf4j.knn.userToUser.neighbors;

import cf4j.Kernel;
import cf4j.TestUser;
import cf4j.TestUsersPartible;
import cf4j.utils.Methods;

/**
 * 

This class calculates the neighbors of each test user. It saves in every test user map * the key "neighbors" which references an array of integers containing the indexes of * the users that are neighbors of the test user.

* *

Similarities between test users must be computed before the usage of this class.

* * @author Fernando Ortega */ public class Neighbors implements TestUsersPartible { /** * Number of neighbors to be calculated */ int k; /** * Class constructor * @param k Number of neighbors to calculate */ public Neighbors (int k) { this.k = k; } @Override public void beforeRun() { } @Override public void run (int testUserIndex) { TestUser testUser = Kernel.getInstance().getTestUsers()[testUserIndex]; double [] similarities = testUser.getSimilarities(); int [] neighbors = Methods.findTopN(similarities, this.k); testUser.setNeighbors(neighbors); } @Override public void afterRun() { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy