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


Java SparseVector类代码示例

本文整理汇总了Java中librec.data.SparseVector的典型用法代码示例。如果您正苦于以下问题:Java SparseVector类的具体用法?Java SparseVector怎么用?Java SparseVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: predict

import librec.data.SparseVector; //导入依赖的package包/类
/**
 * @return a prediction without the contribution of excludede_item
 */
protected double predict(int u, int j, int excluded_item) throws Exception {

	Collection<Integer> nns = knn > 0 ? itemNNs.get(j) : allItems;
	SparseVector Ru = userCache.get(u);

	double pred = 0;
	for (int k : nns) {
		if (Ru.contains(k) && k != excluded_item) {
			double ruk = Ru.get(k);
			pred += ruk * W.get(k, j);
		}
	}

	return pred;
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:19,代码来源:SLIM.java

示例2: buildCorrs

import librec.data.SparseVector; //导入依赖的package包/类
/**
 * build user-user or item-item correlation matrix from training data
 * 
 * @param isUser
 *            whether it is user-user correlation matrix
 * 
 * @return a upper symmetric matrix with user-user or item-item coefficients
 * 
 */
protected SymmMatrix buildCorrs(boolean isUser, String similarityMeasure, int shrinkage) {
//	Logs.debug("Build {} similarity matrix ...", isUser ? "user" : "item");

	int count = isUser ? numUsers : numItems;
	SymmMatrix corrs = new SymmMatrix(count);

	for (int i = 0; i < count; i++) {
		SparseVector iv = isUser ? trainMatrix.row(i) : trainMatrix.column(i);
		if (iv.getCount() == 0)
			continue;
		// user/item itself exclusive
		for (int j = i + 1; j < count; j++) {
			SparseVector jv = isUser ? trainMatrix.row(j) : trainMatrix.column(j);

			double sim = correlation(iv, jv, similarityMeasure, shrinkage);

			if (!Double.isNaN(sim))
				corrs.set(i, j, sim);
		}
	}

	return corrs;
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:33,代码来源:Recommender.java

示例3: similarity

import librec.data.SparseVector; //导入依赖的package包/类
/**
 * compute similarity between users u and v
 */
protected double similarity(Integer u, Integer v) {
	if (userCorrs.contains(u, v))
		return userCorrs.get(u, v);

	if (userCorrs.contains(v, u))
		return userCorrs.get(v, u);

	double sim = Double.NaN;

	if (u < trainMatrix.numRows() && v < trainMatrix.numRows()) {
		SparseVector uv = trainMatrix.row(u);
		if (uv.getCount() > 0) {
			SparseVector vv = trainMatrix.row(v);
			sim = correlation(uv, vv, similarityMeasure, similarityShrinkage); // could change to other measures

			if (!Double.isNaN(sim))
				sim = (1.0 + sim) / 2;
		}
	}

	userCorrs.put(u, v, sim);

	return sim;
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:28,代码来源:SoReg.java

示例4: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
   public double predict(int u, int j, boolean bound) {
	double pred1 = DenseMatrix.rowMult(P, u, Q, j);
	double sum = 0.0, ws = 0.0;
	SparseVector tu = socialMatrix.row(u);

	for (int k : tu.getIndex()) {
		double tuk = tu.get(k);
		sum += tuk * DenseMatrix.rowMult(P, k, Q, j);
		ws += tuk;
	}

	double pred2 = ws > 0 ? sum / ws : 0;

	double pred = alpha * pred1 + (1 - alpha) * pred2;

	if (bound)
		return denormalize(g(pred));

	return pred;
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:22,代码来源:RSTE.java

示例5: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
protected double predict(int u, int i) {

	double sum = 0;
	int count = 0;

	SparseVector Ci = trainMatrix.column(i);
	for (VectorEntry ve : Ci) {
		int v = ve.index();
		// for test, i and j will be always unequal as j is unrated
		if (v != u) {
			sum += DenseMatrix.rowMult(P, v, Q, u);
			count++;
		}
	}
	double wi = count > 0 ? Math.pow(count, -alpha) : 0;

	return itemBias.get(i) + wi * sum;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:20,代码来源:FUSMauc.java

示例6: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
protected double predict(int u, int i) {

	double sum = 0;
	int count = 0;

	SparseVector Ci = trainMatrix.column(i);
	SparseVector Tu = S.row(u);
	for (VectorEntry ve : Ci) {
		int v = ve.index();
		// for test, i and j will be always unequal as j is unrated
		if (v != u) {
			sum += DenseMatrix.rowMult(P, v, Q, u);
			count++;

			if (Tu.contains(v))
				sum += DenseMatrix.rowMult(Y, v, Q, u);
		}
	}
	double wi = count > 0 ? Math.pow(count, -alpha) : 0;

	return itemBias.get(i) + wi * sum;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:24,代码来源:FUSTauc.java

示例7: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
protected double predict(int u, int i) {

	double sum = 0, sum_t = 0;

	SparseVector Ci = trainMatrix.column(i);
	for (VectorEntry ve : Ci) {
		int v = ve.index();
		// for test, i and j will be always unequal as j is unrated
		if (v != u) {
			double wt = Math.pow(1 + t(u, v), tau);
			sum += wt * DenseMatrix.rowMult(P, v, Q, u);
			sum_t += wt;
		}
	}
	double wi = sum_t > 0 ? Math.pow(sum_t, -alpha) : 0;

	return itemBias.get(i) + wi * sum;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:20,代码来源:FUSTauc_backup.java

示例8: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
protected double predict(int u, int j) {

	double sum = 0, sum_t = 0;

	SparseVector Cj = trainMatrix.column(j);
	for (VectorEntry ve : Cj) {
		int v = ve.index();
		// for test, i and j will be always unequal as j is unrated
		if (v != u) {
			double tuv = Math.pow(socialMatrix.get(u, v) + 1, tau);
			sum += tuv * DenseMatrix.rowMult(P, v, Q, u);
			sum_t += tuv;
		}
	}

	double kappa = sum_t > 0 ? Math.pow(sum_t, -alpha) : 0;

	return userBias.get(u) + itemBias.get(j) + kappa * sum;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:21,代码来源:FUSTrmse.java

示例9: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
protected double predict(int u, int j) {

	double pred = userBias.get(u) + itemBias.get(j);

	int k = 0;
	double sum = 0.0f;
	SparseVector uv = trainMatrix.row(u);
	for (int i : uv.getIndex()) {
		if (i != j) {
			double sji = DenseMatrix.rowMult(P, j, Q, i);
			if (sji > minSim) {
				sum += sji;
				k++;
			}
		}
	}
	if (k > 0)
		pred += sum / Math.sqrt(k);

	return pred;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:23,代码来源:BaseMF.java

示例10: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
protected double predict(int u, int j) {
	double sum = 0;
	int count = 0;

	SparseVector Cj = trainMatrix.column(j);
	for (VectorEntry ve : Cj) {
		int v = ve.index();
		// for test, i and j will be always unequal as j is unrated
		if (v != u) {
			sum += DenseMatrix.rowMult(P, v, Q, u);
			count++;
		}
	}

	double wj = count > 0 ? Math.pow(count, -alpha) : 0;

	return userBias.get(u) + itemBias.get(j) + wj * sum;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:20,代码来源:FUSMrmse.java

示例11: initModel

import librec.data.SparseVector; //导入依赖的package包/类
@Override
   public void initModel() throws Exception {
	itemCorrs = buildCorrs(false, similarityMeasure, similarityShrinkage);
	itemMeans = new DenseVector(numItems);
	for (int i = 0; i < numItems; i++) {
		SparseVector vs = trainMatrix.column(i);
		itemMeans.set(i, vs.getCount() > 0 ? vs.mean() : globalMean);
	}
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:10,代码来源:ItemKNN.java

示例12: initModel

import librec.data.SparseVector; //导入依赖的package包/类
@Override
   public void initModel() throws Exception {
	userCorrs = buildCorrs(true, similarityMeasure, similarityShrinkage);
	userMeans = new DenseVector(numUsers);
	for (int u = 0; u < numUsers; u++) {
		SparseVector uv = trainMatrix.row(u);
		userMeans.set(u, uv.getCount() > 0 ? uv.mean() : globalMean);
	}
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:10,代码来源:UserKNN.java

示例13: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
   public double predict(int u, int j) {
	if (!itemMeans.containsKey(j)) {
		SparseVector jv = trainMatrix.column(j);
		double mean = jv.getCount() > 0 ? jv.mean() : globalMean;
		itemMeans.put(j, mean);
	}

	return itemMeans.get(j);
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:11,代码来源:ItemAverage.java

示例14: predict

import librec.data.SparseVector; //导入依赖的package包/类
@Override
   public double predict(int u, int j) {
	if (!userMeans.containsKey(u)) {
		SparseVector uv = trainMatrix.row(u);
		userMeans.put(u, uv.getCount() > 0 ? uv.mean() : globalMean);
	}

	return userMeans.get(u);
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:10,代码来源:UserAverage.java

示例15: buildModel

import librec.data.SparseVector; //导入依赖的package包/类
@Override
   public void buildModel() throws Exception {

	// simple rule: X => Y, given that each user vector is regarded as a
	// transaction
	for (int x = 0; x < numItems; x++) {
		// all transactions for item x
		SparseVector qx = trainMatrix.column(x);
		int total = qx.getCount();

		for (int y = 0; y < numItems; y++) {
			// compute confidence where containing item y among qx
			int count = 0;
			for (VectorEntry ve : qx) {
				int u = ve.index();
				double ruy = trainMatrix.get(u, y);
				if (ruy > 0)
					count++;
			}

			if (count > 0) {
				double conf = (count + 0.0) / total;
				A.put(x, y, conf);
			}
		}
	}
}
 
开发者ID:mys3lf,项目名称:recalot.com,代码行数:28,代码来源:AR.java


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