当前位置: 首页>>代码示例>>Java>>正文


Java FastByIDMap.put方法代码示例

本文整理汇总了Java中org.apache.mahout.cf.taste.impl.common.FastByIDMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java FastByIDMap.put方法的具体用法?Java FastByIDMap.put怎么用?Java FastByIDMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mahout.cf.taste.impl.common.FastByIDMap的用法示例。


在下文中一共展示了FastByIDMap.put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBuildKNNRecommender

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
@Test
public void testBuildKNNRecommender() {
    GenericRecommenderBuilder rb = new GenericRecommenderBuilder();
    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
    userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
            new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
    userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
            new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));
    DataModel dm = new GenericDataModel(userData);

    Recommender rec = null;
    String recommenderType = "org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender";
    String similarityType = "org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity";
    try {
        rec = rb.buildRecommender(dm, recommenderType, similarityType);
    } catch (RecommenderException e) {
        e.printStackTrace();
    }
    assertTrue(rec instanceof GenericUserBasedRecommender);
}
 
开发者ID:recommenders,项目名称:rival,代码行数:21,代码来源:GenericRecommenderBuilderTest.java

示例2: loadInMemory

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
public DataModel loadInMemory() {
	// In-memory DataModel - GenericDataModels
	FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>();

	PreferenceArray prefsForUser1 = new GenericUserPreferenceArray(10);
	prefsForUser1.setUserID(0, 1L);
	prefsForUser1.setItemID(0, 101L);
	prefsForUser1.setValue(0, 3.0f);
	prefsForUser1.setItemID(1, 102L);
	prefsForUser1.setValue(1, 4.5F);
	preferences.put(1L, prefsForUser1); // use userID as the key
	
	//TODO: add others users

	
	// Return preferences as new data model
	DataModel dataModel = new GenericDataModel(preferences);
	
	return dataModel;

}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:22,代码来源:BookRecommender.java

示例3: getGenericDataModel

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
private DataModel getGenericDataModel() {
	FastByIDMap<PreferenceArray> preferences = 
			new FastByIDMap<PreferenceArray>();
	
	List<User> users = userService.getAllUsers();
	
	for (int j = 0; j < users.size(); j++) {
		
		List<Preference2d> preference2ds = 
				preference2dService.getPreferencesByUserId(users.get(j).getId());
		PreferenceArray prefsForUser = 
				new GenericUserPreferenceArray(preference2ds.size());
		prefsForUser.setUserID(j, users.get(j).getId());
		
		for (int i = 0; i < preference2ds.size(); i++) {
			prefsForUser.setItemID(i, preference2ds.get(i).getRestaurantId());
			prefsForUser.setValue(i, preference2ds.get(i).getScore().floatValue());
		}
		
		preferences.put(j, prefsForUser);
	}
	
	return new GenericDataModel(preferences);
}
 
开发者ID:tensorchen,项目名称:rrs,代码行数:25,代码来源:RecommendController.java

示例4: intializeDelegate

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
private void intializeDelegate() {
    try {
    //iterate over all user ids
    LongPrimitiveIterator it = easyrecDataModelDelegate.getUserIDs();
    FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>(easyrecDataModelDelegate.getNumUsers());
    FastByIDMap<FastByIDMap<Long>> timestamps = new FastByIDMap<FastByIDMap<Long>>(easyrecDataModelDelegate.getNumUsers());
    while (it.hasNext()) {
        Long userId = it.next();
        //get preferences for each user
        PreferenceArray prefs = easyrecDataModelDelegate.getPreferencesFromUser(userId);
        preferences.put(userId,prefs);
        //get preference times for each user
        FastByIDMap<Long> timestampsForUser = new FastByIDMap<Long>(prefs.getIDs().length);
        for (Long itemId: prefs.getIDs()) {
            timestampsForUser.put(itemId,easyrecDataModelDelegate.getPreferenceTime(userId, itemId));
        }
        timestamps.put(userId, timestampsForUser);
    }
    //generate GenericDataModel
    setMaxPreference(easyrecDataModelDelegate.getMaxPreference());
    setMinPreference(easyrecDataModelDelegate.getMinPreference());
    this.inMemoryDelegate = new GenericDataModel(preferences,timestamps);
    } catch (TasteException e) {
        logger.warn("caught exception while reading preference data", e);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:27,代码来源:EasyrecInMemoryDataModel.java

示例5: DataModelWrapper

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
/**
 * Constructs the wrapper using the provided model.
 *
 * @param model the model to be used to create the wrapped model
 */
public DataModelWrapper(final net.recommenders.rival.core.TemporalDataModelIF<Long, Long> model) {
    FastByIDMap<Collection<Preference>> data = new FastByIDMap<Collection<Preference>>();
    FastByIDMap<FastByIDMap<Long>> timestampData = new FastByIDMap<FastByIDMap<Long>>();
    for (Long u : model.getUsers()) {
        List<Preference> prefs = new ArrayList<Preference>();
        FastByIDMap<Long> userTimestamps = new FastByIDMap<Long>();
        timestampData.put(u, userTimestamps);
        for (Long i : model.getUserItems(u)) {
            Iterable<Long> timestamps = model.getUserItemTimestamps(u, i);
            long t = -1;
            if (timestamps != null) {
                for (Long tt : timestamps) {
                    t = tt;
                    break;
                }
            }
            userTimestamps.put(i, t);
            prefs.add(new GenericPreference(u, i, model.getUserItemPreference(u, i).floatValue()));
        }
        data.put(u, prefs);
    }

    FastByIDMap<PreferenceArray> userData = GenericDataModel.toDataMap(data, true);
    wrapper = new GenericDataModel(userData, timestampData);
}
 
开发者ID:recommenders,项目名称:rival,代码行数:31,代码来源:DataModelWrapper.java

示例6: testBuildDefaultRecommender

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
@Test
public void testBuildDefaultRecommender() {

    RecommenderBuilder rb = new GenericRecommenderBuilder();
    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
    userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
            new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
    userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
            new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));
    DataModel dm = new GenericDataModel(userData);

    Recommender rec = null;
    try {
        rec = rb.buildRecommender(dm);
    } catch (TasteException e) {
        e.printStackTrace();
    }
    assertTrue(rec instanceof RandomRecommender);
}
 
开发者ID:recommenders,项目名称:rival,代码行数:20,代码来源:GenericRecommenderBuilderTest.java

示例7: getPrefDataByFileFast

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
public static DataModel getPrefDataByFileFast() throws Exception {		
	String data = EEG_INTEREST_LEVEL_DATASET_FILE;
	FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>();
	BufferedReader br = new BufferedReader(new FileReader(data));

	List<Preference> list = new ArrayList<Preference>();
	String line = br.readLine();
	long uid_init = Long.parseLong(line.split(",")[0]);
	while (line != null) {
		String[] arr = line.split(",");
		long uid = Long.parseLong(arr[0]);
		if (uid_init == uid) {
			list.add(new GenericPreference(uid, Long.parseLong(arr[1]),
					Float.parseFloat(arr[2])));
		} else {
			preferences.put(uid_init, new GenericUserPreferenceArray(list));
			list = new ArrayList<Preference>();
			list.add(new GenericPreference(uid, Long.parseLong(arr[1]),
					Float.parseFloat(arr[2])));
			uid_init = uid;
		}
		line = br.readLine();

		if (line == null) {
			preferences.put(uid_init, new GenericUserPreferenceArray(list));
		}
	}
	br.close();
	return new GenericDataModel(preferences);
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:31,代码来源:InterestLevelDataModel.java

示例8: addTimestamp

import org.apache.mahout.cf.taste.impl.common.FastByIDMap; //导入方法依赖的package包/类
@Override
public void addTimestamp(Long u, Long i, Long t) {
    if (model != null) {
        throw new IllegalArgumentException("DataModel already generated. It is not possible to add more information.");
    }
    FastByIDMap<Long> prefs = null;
    if (!timestampData.containsKey(u)) {
        prefs = new FastByIDMap<Long>();
        timestampData.put(u, prefs);
    } else {
        prefs = timestampData.get(u);
    }
    prefs.put(i, t);
}
 
开发者ID:recommenders,项目名称:rival,代码行数:15,代码来源:MahoutDataModel.java


注:本文中的org.apache.mahout.cf.taste.impl.common.FastByIDMap.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。