本文整理汇总了Java中es.uam.eps.ir.ranksys.fast.index.FastUserIndex类的典型用法代码示例。如果您正苦于以下问题:Java FastUserIndex类的具体用法?Java FastUserIndex怎么用?Java FastUserIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastUserIndex类属于es.uam.eps.ir.ranksys.fast.index包,在下文中一共展示了FastUserIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SimpleFastPreferenceData
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor with custom IdxPref to IdPref converter.
*
* @param numPreferences number of total preferences
* @param uidxList list of lists of preferences by user index
* @param iidxList list of lists of preferences by item index
* @param uIndex user index
* @param iIndex item index
* @param uPrefFun user IdxPref to IdPref converter
* @param iPrefFun item IdxPref to IdPref converter
*/
protected SimpleFastPreferenceData(int numPreferences, List<List<IdxPref>> uidxList, List<List<IdxPref>> iidxList,
FastUserIndex<U> uIndex, FastItemIndex<I> iIndex,
Function<IdxPref, IdPref<I>> uPrefFun, Function<IdxPref, IdPref<U>> iPrefFun) {
super(uIndex, iIndex, uPrefFun, iPrefFun);
this.numPreferences = numPreferences;
this.uidxList = uidxList;
this.iidxList = iidxList;
uidxList.parallelStream()
.filter(Objects::nonNull)
.forEach(l -> l.sort(comparingInt(IdxPref::v1)));
iidxList.parallelStream()
.filter(Objects::nonNull)
.forEach(l -> l.sort(comparingInt(IdxPref::v1)));
}
示例2: main
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ClassNotFoundException {
String userPath = args[0];
String itemPath = args[1];
String dataPath = args[2];
// READING USER, ITEM AND RATINGS FILES
FastUserIndex<Long> users = SimpleFastUserIndex.load(UsersReader.read(userPath, lp));
FastItemIndex<Long> items = SimpleFastItemIndex.load(ItemsReader.read(itemPath, lp));
FastPreferenceData<Long, Long> simpleData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(dataPath, lp, lp), users, items);
// CREATING A COMPRESSED PREFERENCE DATA
CODEC<int[]> uCodec = new IntegratedFORVBCODEC();
CODEC<int[]> iCodec = new IntegratedFORVBCODEC();
// We assume here that the ratings are 1-5 stars
CODEC<byte[]> vCodec = new FixedLengthBitStreamCODEC(3);
FastPreferenceData<Long, Long> codecData = new RatingCODECPreferenceData<>(simpleData, users, items, uCodec, iCodec, vCodec);
// PRINTING COMPRESSION STATISTICS
System.out.println(uCodec.stats()[0] + "\t" + uCodec.stats()[1]);
System.out.println(iCodec.stats()[0] + "\t" + iCodec.stats()[1]);
System.out.println(vCodec.stats()[0] + "\t" + vCodec.stats()[1]);
System.out.println(codecData.numPreferences());
}
示例3: load
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
@Override
public <U, I> Factorization<U, I> load(InputStream in, FastUserIndex<U> uIndex, FastItemIndex<I> iIndex) throws IOException {
int K;
DenseDoubleMatrix2D userMatrix;
DenseDoubleMatrix2D itemMatrix;
try (ZipInputStream zip = new ZipInputStream(in)) {
zip.getNextEntry();
BufferedReader reader = new BufferedReader(new InputStreamReader(zip));
int numUsers = parseInt(reader.readLine());
int numItems = parseInt(reader.readLine());
K = parseInt(reader.readLine());
zip.closeEntry();
zip.getNextEntry();
userMatrix = loadDenseDoubleMatrix2D(zip, numUsers, K);
zip.closeEntry();
zip.getNextEntry();
itemMatrix = loadDenseDoubleMatrix2D(zip, numItems, K);
zip.closeEntry();
}
return new Factorization<>(uIndex, iIndex, userMatrix, itemMatrix, K);
}
示例4: run
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
@Override
public TemporalDataModelIF<Long, Long> run(final RUN_OPTIONS opts,
final net.recommenders.rival.core.TemporalDataModelIF<Long, Long> trainingModel,
final net.recommenders.rival.core.TemporalDataModelIF<Long, Long> testModel)
throws RecommenderException {
if (isAlreadyRecommended()) {
return null;
}
// transform from core's DataModels to RankSys's PreferenceData
FastUserIndex<Long> userIndex = new UserIndexWrapper(trainingModel, testModel);
FastItemIndex<Long> itemIndex = new ItemIndexWrapper(trainingModel, testModel);
FastPreferenceData<Long, Long> trainingModelRanksys = new PreferenceDataWrapper(trainingModel, userIndex, itemIndex);
FastPreferenceData<Long, Long> testModelRanksys = new PreferenceDataWrapper(testModel, userIndex, itemIndex);
return runRanksysRecommender(opts, userIndex, itemIndex, trainingModelRanksys, testModelRanksys);
}
示例5: AbstractCODECPreferenceData
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor with custom IdxPref to IdPref converters.
*
* @param users user index
* @param items item index
* @param u_codec user preferences CODEC
* @param i_codec item preferences CODEC
* @param uPrefFun user IdxPref to IdPref converter
* @param iPrefFun item IdxPref to IdPref converter
*/
@SuppressWarnings("unchecked")
protected AbstractCODECPreferenceData(FastUserIndex<U> users, FastItemIndex<I> items,
CODEC<Cu> u_codec, CODEC<Ci> i_codec,
Function<IdxPref, IdPref<I>> uPrefFun, Function<IdxPref, IdPref<U>> iPrefFun) {
super(users, items, uPrefFun, iPrefFun);
this.u_codec = u_codec;
this.i_codec = i_codec;
this.u_idxs = (Cu[]) new Object[users.numUsers()];
this.u_len = new int[users.numUsers()];
this.i_idxs = (Ci[]) new Object[items.numItems()];
this.i_len = new int[items.numItems()];
}
示例6: ExplicitFactorization
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
public ExplicitFactorization(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex,
FastFeatureData<I, F, ?> featureData, DoubleFunction initFunction) {
super(uIndex, iIndex, featureData.numFeatures(), initFunction);
iIndex.getAllIidx().forEach(iidx -> {
Set<Integer> itemFidxs = featureData.getIidxFeatures(iidx)
.map(f -> f.v1)
.collect(Collectors.toSet());
featureData.getAllFidx()
.filter(f -> !itemFidxs.contains(f))
.forEach(fidx -> this.itemMatrix.setQuick(iidx, fidx, 0.0));
});
}
示例7: Factorization
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor.
*
* @param uIndex fast user index
* @param iIndex fast item index
* @param K dimension of the latent feature space
* @param initFunction function to initialize the cells of the matrices
*/
public Factorization(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex, int K, DoubleFunction initFunction) {
this.userMatrix = new DenseDoubleMatrix2D(uIndex.numUsers(), K);
this.userMatrix.assign(initFunction);
this.itemMatrix = new DenseDoubleMatrix2D(iIndex.numItems(), K);
this.itemMatrix.assign(initFunction);
this.K = K;
this.uIndex = uIndex;
this.iIndex = iIndex;
}
示例8: MFRecommenderTest
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor that initialises some mock data.
*/
public MFRecommenderTest() {
FastUserIndex<String> uIndex = new SimpleFastUserIndex<String>() {
{
add("0");
}
};
FastItemIndex<String> iIndex = new SimpleFastItemIndex<String>() {
{
add("0");
add("1");
add("2");
add("3");
add("4");
add("5");
}
};
int K = 2;
DenseDoubleMatrix2D p = new DenseDoubleMatrix2D(new double[][]{
new double[]{0.1, 1.0}
});
DenseDoubleMatrix2D q = new DenseDoubleMatrix2D(new double[][]{
new double[]{1.0, 6.0},
new double[]{1.0, 5.0},
new double[]{1.0, 4.0},
new double[]{1.0, 3.0},
new double[]{1.0, 2.0},
new double[]{1.0, 1.0}
});
Factorization<String, String> factorization = new Factorization<String, String>(uIndex, iIndex, p, q, K) {
};
recommender = new MFRecommender<>(uIndex, iIndex, factorization);
}
示例9: main
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String userPath = args[0];
String itemPath = args[1];
String featurePath = args[2];
String trainDataPath = args[3];
String featureDataPath = args[4];
String recIn = args[5];
double lambda = 0.5;
int cutoff = 100;
int numIter = 100;
FastUserIndex<Long> userIndex = SimpleFastUserIndex.load(UsersReader.read(userPath, lp));
FastItemIndex<Long> itemIndex = SimpleFastItemIndex.load(ItemsReader.read(itemPath, lp));
FastFeatureIndex<String> featureIndex = SimpleFastFeatureIndex.load(FeatsReader.read(featurePath, sp));
FastPreferenceData<Long, Long> trainData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(trainDataPath, lp, lp), userIndex, itemIndex);
FastFeatureData<Long, String, Double> featureData = SimpleFastFeatureData.load(SimpleFeaturesReader.get().read(featureDataPath, lp, sp), itemIndex, featureIndex);
CPLSAIAFactorizationModelFactory<Long, Long, String> cPLSAModel = new CPLSAIAFactorizationModelFactory<>(numIter, trainData,featureData);
Reranker<Long, Long> reranker = new XQuAD<>(cPLSAModel.getAspectModel(), lambda, cutoff, true);
RecommendationFormat<Long, Long> format = new SimpleRecommendationFormat<>(lp, lp);
System.out.println("Running xQuAD with cPLSA aspect model");
String recOut = String.format("%s_xQuAD_cplsa_%.1f", recIn, lambda);
try (RecommendationFormat.Writer<Long, Long> writer = format.getWriter(recOut)) {
format.getReader(recIn).readAll()
.map(rec -> reranker.rerankRecommendation(rec, cutoff))
.forEach(Unchecked.consumer(writer::write));
}
}
示例10: AbstractFastRecommender
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor.
*
* @param uIndex user index
* @param iIndex item index
*/
public AbstractFastRecommender(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex) {
super();
this.uIndex = uIndex;
this.iIndex = iIndex;
}
示例11: RandomRecommender
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor.
*
* @param uIndex fast user index
* @param iIndex fast item index
*/
public RandomRecommender(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex) {
super(uIndex, iIndex);
random = new Random();
randomList = iIndex.getAllIidx()
.mapToObj(iidx -> tuple(iidx, Double.NaN))
.collect(toList());
shuffle(randomList);
}
示例12: load
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
@Override
public <U, I> PreferenceFM<U, I> load(InputStream in, FastUserIndex<U> users, FastItemIndex<I> items) throws IOException {
int N;
int K;
double b;
double[] w;
double[][] m;
try (ZipInputStream zip = new ZipInputStream(in)) {
zip.getNextEntry();
BufferedReader reader = new BufferedReader(new InputStreamReader(zip));
N = parseInt(reader.readLine());
K = parseInt(reader.readLine());
zip.closeEntry();
zip.getNextEntry();
reader = new BufferedReader(new InputStreamReader(zip));
b = parseDouble(reader.readLine());
zip.closeEntry();
zip.getNextEntry();
w = loadVector(zip, N);
zip.closeEntry();
zip.getNextEntry();
m = loadMatrix(zip, N, K);
zip.closeEntry();
}
return new PreferenceFM<>(users, items, new FM(b, w, m));
}
示例13: getFixedLength
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Get the bits required for identifiers and ratings for identifiers and ratings.
*
* @param path base path
* @param dataset name of dataset
* @return an array of number of bits for user identifiers, item identifiers and ratings
* @throws IOException when IO error
*/
public static int[] getFixedLength(String path, String dataset) throws IOException {
FastUserIndex<String> users = SimpleFastUserIndex.load(UsersReader.read(path + "/users.txt", sp));
FastItemIndex<String> items = SimpleFastItemIndex.load(ItemsReader.read(path + "/items.txt", sp));
int uFixedLength = 32 - Integer.numberOfLeadingZeros(users.numUsers() - 1);
int iFixedLength = 32 - Integer.numberOfLeadingZeros(items.numItems() - 1);
int vFixedLength;
switch (dataset) {
case "msd":
vFixedLength = 1;
break;
case "ml10M":
case "ml20M":
vFixedLength = 4;
break;
case "ml1M":
case "netflix":
case "ymusic":
vFixedLength = 3;
break;
default:
vFixedLength = 32;
}
return new int[]{uFixedLength, iFixedLength, vFixedLength};
}
示例14: PreferenceDataWrapper
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
public PreferenceDataWrapper(TemporalDataModelIF<Long, Long> data, FastUserIndex<Long> uIndex, FastItemIndex<Long> iIndex) {
List<Tuple3<Long, Long, Double>> tuples = new ArrayList<>();
for (Long u : data.getUsers()) {
for (Long i : data.getUserItems(u)) {
tuples.add(new Tuple3<>(u, i, data.getUserItemPreference(u, i)));
}
}
wrapper = SimpleFastPreferenceData.load(tuples.stream(), uIndex, iIndex);
}
示例15: AbstractFastRecommenderTest
import es.uam.eps.ir.ranksys.fast.index.FastUserIndex; //导入依赖的package包/类
/**
* Constructor that initialises some mock data.
*/
public AbstractFastRecommenderTest() {
FastUserIndex<String> uIndex = new SimpleFastUserIndex<String>() {
{
add("0");
}
};
FastItemIndex<String> iIndex = new SimpleFastItemIndex<String>() {
{
add("0");
add("1");
add("2");
add("3");
add("4");
add("5");
}
};
recs = Arrays.asList(
tuple(0, 6.0),
tuple(1, 5.0),
tuple(2, 4.0),
tuple(3, 3.0),
tuple(4, 2.0),
tuple(5, 1.0)
);
recommender = new AbstractFastRecommender<String, String>(uIndex, iIndex) {
@Override
public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) {
List<Tuple2id> recs0;
if (uidx == 0) {
recs0 = recs.stream()
.filter(p -> filter.test(p.v1))
.sorted(comparingDouble(Tuple2id::v2).reversed())
.limit(min(maxLength, recs.size()))
.collect(toList());
} else {
recs0 = emptyList();
}
return new FastRecommendation(uidx, recs0);
}
};
}