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


Java SparseVector.setValueAtLocation方法代码示例

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


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

示例1: log

import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
static void log(SparseVector v, double factor) {
	for (int i = 0; i < v.numLocations(); i++) {
		double value = factor * v.valueAtLocation(i);
		v.setValueAtLocation(i, Math.log(value));
	}
}
 
开发者ID:siqil,项目名称:udaner,代码行数:7,代码来源:CRFOptimizableByLikelihoodAndExpectationDistance.java

示例2: square

import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
static void square(SparseVector v) {
	for (int i = 0; i < v.numLocations(); i++) {
		v.setValueAtLocation(i, v.valueAtLocation(i) * v.valueAtLocation(i));
	}
}
 
开发者ID:siqil,项目名称:udaner,代码行数:6,代码来源:CRFOptimizableByLikelihoodAndExpectationDistance.java

示例3: train

import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
public void train(InstanceList instances) {
	this.instances = instances;
	SparseVector[] ws;
	if (getThreads() > 1) {
		ws = trainByMultiThread(getThreads());
	} else {
		ws = trainBySingleThread();
	}

	int dim = instances.getDataAlphabet().size();

	for (int i = 0; i < ws.length; i++) {
		SparseVector w = ws[i];
		int count = 0;
		for (int l = 0; l < w.numLocations(); l++) {
			double val = w.valueAtLocation(l);
			if (val < 0) {
				w.setValueAtLocation(l, 0);
				count++;
			}
		}
		logger.info("Turn " + count + " negative values to 0 for w_" + i);
	}

	// svd the weight matrix [w_1 w_2 ... w_m]

	// for each group SVD
	// each group has a map from its name to its indices[]
	// after SVD, read values[] from Ut, and build SparseVector with
	// indices[]
	try {
		SVDLIBC svd = new SVDLIBC();
		File matF = svd.newFile(svd.input);
		// write the matrix
		// it's not necessary
		// but it saves time for trying different h
		List<SparseVector> mat = Arrays.asList(ws);
		svd.writeSparse(matF, mat, dim, ws.length);
		// do the SVD
		svd(mat);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:siqil,项目名称:udaner,代码行数:45,代码来源:SCL.java


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