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


Java MutableSparseVector.fill方法代码示例

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


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

示例1: globalScore

import org.grouplens.lenskit.vectors.MutableSparseVector; //导入方法依赖的package包/类
/**
 * Score items with respect to a set of reference items.
 * 
 * @param items
 *            The reference items.
 * @param scores
 *            The score vector. Its domain is the items to be scored, and the scores should be stored into this vector.
 */
@Override
public void globalScore(@Nonnull Collection<Long> items, @Nonnull MutableSparseVector scores) {
	scores.fill(0);
	// each item's score is the sum of its similarity to each item in items, if they are
	// neighbors in the model.

	for (VectorEntry e : scores.fast(VectorEntry.State.EITHER)) {
		long item = e.getKey();
		List<ScoredId> neighbors = model.getNeighbors(item);
		double sumScore = 0;
		for (ScoredId thisNghbr : neighbors) {
			if (items.contains(thisNghbr.getId()))
				sumScore += thisNghbr.getScore();
		}
		scores.set(item, sumScore);
	}
}
 
开发者ID:rohitsinha54,项目名称:Coursera-Introduction-to-Recommender-Systems-Programming-Assignment-5,代码行数:26,代码来源:SimpleGlobalItemScorer.java

示例2: makeUserVector

import org.grouplens.lenskit.vectors.MutableSparseVector; //导入方法依赖的package包/类
private SparseVector makeUserVector(long user) {
    // Get the user's ratings
    List<Rating> userRatings = dao.getEventsForUser(user, Rating.class);
    if (userRatings == null) {
        // the user doesn't exist
        return SparseVector.empty();
    }

    // Create a new vector over tags to accumulate the user profile
    MutableSparseVector profile = model.newTagVector();
    // Fill it with 0's initially - they don't like anything
    profile.fill(0);

    // Iterate over the user's ratings to build their profile
    for (Rating r: userRatings) {
        // In LensKit, ratings are expressions of preference
        Preference p = r.getPreference();
        // We'll never have a null preference. But in LensKit, ratings can have null
        // preferences to express the user unrating an item
        if (p != null && p.getValue() >= 3.5) {
            // The user likes this item!
            // Get the item's vector and add it to the user's profile
            SparseVector iv = model.getItemVector(p.getItemId());
            profile.add(iv);
        }
    }

    // The profile is accumulated, return it.
    // It is good practice to return a frozen vector.
    return profile.freeze();
}
 
开发者ID:4DD8A19D69F5324F9D49D17EF78BBBCC,项目名称:Introd_uction_to_Recom_mander_S_ystem,代码行数:32,代码来源:TFIDFItemScorer.java

示例3: globalScore

import org.grouplens.lenskit.vectors.MutableSparseVector; //导入方法依赖的package包/类
/**
 * Score items with respect to a set of reference items.
 * @param items The reference items.
 * @param scores The score vector. Its domain is the items to be scored, and the scores should
 *               be stored into this vector.
 */
@Override
public void globalScore(@Nonnull Collection<Long> items, @Nonnull MutableSparseVector scores) {
    scores.fill(0);
    // TODO score items in the domain of scores
    // each item's score is the sum of its similarity to each item in items, if they are
    // neighbors in the model.
}
 
开发者ID:4DD8A19D69F5324F9D49D17EF78BBBCC,项目名称:Introd_uction_to_Recom_mander_S_ystem,代码行数:14,代码来源:SimpleGlobalItemScorer.java

示例4: makeUserVector

import org.grouplens.lenskit.vectors.MutableSparseVector; //导入方法依赖的package包/类
private SparseVector makeUserVector(long user) {
    // Get the user's ratings
    List<Rating> userRatings = dao.getEventsForUser(user, Rating.class);
    if (userRatings == null) {
        // the user doesn't exist
        return SparseVector.empty();
    }

    // Create a new vector over tags to accumulate the user profile
    MutableSparseVector profile = model.newTagVector();
    // Fill it with 0's initially - they don't like anything
    profile.fill(0);

    // Iterate over the user's ratings to build their profile
    for (Rating r: userRatings) {
        // In LensKit, ratings are expressions of preference
        Preference p = r.getPreference();
        // We'll never have a null preference. But in LensKit, ratings can have null
        // preferences to express the user unrating an item
        if (p != null && p.getValue() >= 3.5) {
            
        	SparseVector sparseVectorForItem = model.getItemVector(p.getItemId());
        	profile.add(sparseVectorForItem);
        }
    }

    // The profile is accumulated, return it.
    // It is good practice to return a frozen vector.
    return profile.freeze();
}
 
开发者ID:paolobarbaglia,项目名称:coursera_recommender_systems,代码行数:31,代码来源:TFIDFItemScorer.java

示例5: globalScore

import org.grouplens.lenskit.vectors.MutableSparseVector; //导入方法依赖的package包/类
/**
 * Score items with respect to a set of reference items.
 * @param items The reference items.
 * @param scores The score vector. Its domain is the items to be scored, and the scores should
 *               be stored into this vector.
 */
@Override
public void globalScore(@Nonnull Collection<Long> items, @Nonnull MutableSparseVector scores) {
	scores.fill(0);
	// score items in the domain of scores
	for (VectorEntry e: scores.fast(VectorEntry.State.EITHER)) {
		// each item's score is the sum of its similarity to each item in items, if they are
		// neighbors in the model.
		long itemId = e.getKey();
		
		// getting neighbors
		List<ScoredId> neighbors = model.getNeighbors(itemId);
		Map<Long, Double> neighMap = new HashMap<Long, Double>();
		for (ScoredId scoredId : neighbors) {
			neighMap.put(scoredId.getId(), scoredId.getScore());
		}
		
		// scoring similarity
		double score = 0.0;
		for(Long basketItem: items){
			Double similarity = 0.0;
			if(neighMap.containsKey(basketItem)) similarity = neighMap.get(basketItem);
			score += similarity;
		}
		
		// asserting score
		scores.set(e, score);
	}
}
 
开发者ID:paolobarbaglia,项目名称:coursera_recommender_systems,代码行数:35,代码来源:SimpleGlobalItemScorer.java


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