knn.itemToItem.neighbors.Neighbors Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cf4j-recsys Show documentation
Show all versions of cf4j-recsys Show documentation
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.itemToItem.neighbors;
import cf4j.Kernel;
import cf4j.TestItem;
import cf4j.TestItemsPartible;
import cf4j.utils.Methods;
/**
* This class calculates the neighbors of each test item. It saves in every test item map
* the key "neighbors" which references an array of integers containing the indexes of
* the items that are neighbors of the test item.
*
* Similarities between test items must be computed before the usage of this class.
*
* @author Fernando Ortega
*/
public class Neighbors implements TestItemsPartible {
/**
* 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 testItemIndex) {
TestItem testItem = Kernel.gi().getTestItems()[testItemIndex];
double [] similarities = testItem.getSimilarities();
int [] neighbors = Methods.findTopN(similarities, this.k);
testItem.setNeighbors(neighbors);
}
@Override
public void afterRun() { }
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy