本文整理汇总了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));
}
}
示例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));
}
}
示例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();
}
}