本文整理汇总了Java中cc.mallet.types.MatrixOps.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java MatrixOps.normalize方法的具体用法?Java MatrixOps.normalize怎么用?Java MatrixOps.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.MatrixOps
的用法示例。
在下文中一共展示了MatrixOps.normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toProbabilities
import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
private double[] toProbabilities(double weights[]) {
double probs[] = new double[weights.length];
for (int i = 0; i < weights.length; i++)
probs[i] = Math.exp(weights[i]);
// TODO this shouldn't be necessary
MatrixOps.normalize(probs);
return probs;
}
示例2: split
import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
/**
* Shuffles the elements of this list among several smaller
* lists. Overrides InstanceList.split to add instances in original
* order, to prevent thrashing.
* @param proportions A list of numbers (not necessarily summing to 1) which,
* when normalized, correspond to the proportion of elements in each returned
* sublist.
* @param r The source of randomness to use in shuffling.
* @return one <code>InstanceList</code> for each element of <code>proportions</code>
*/
public InstanceList[] split (java.util.Random r, double[] proportions) {
InstanceList[] ret = new InstanceList[proportions.length];
double maxind[] = proportions.clone();
int size = size();
int[] shuffled = new int[size];
int[] splits = new int[size];
// build a list of shuffled instance indexes
for (int i = 0; i < size; i++) {
shuffled[i] = i;
}
shuffleArray(r, shuffled);
MatrixOps.normalize(maxind);
for (int i = 0; i < maxind.length; i++) {
ret[i] = this.cloneEmpty(); // Note that we are passing on featureSelection here.
if (i > 0)
maxind[i] += maxind[i-1];
}
for (int i = 0; i < maxind.length; i++) {
// Fill maxind[] with the highest instance index to go in each corresponding returned InstanceList
maxind[i] = Math.rint (maxind[i] * size);
}
for (int i = 0, j = 0; i < size; i++) {
// This gives a slight bias toward putting an extra instance in the last InstanceList.
while (i >= maxind[j] && j < ret.length)
j++;
splits[shuffled[i]] = j;
}
for (int i = 0; i < size; i++) {
//logger.info ("adding instance " + i + " to split ilist " + splits[i]);
ret[splits[i]].add(this.get(i));
}
return ret;
}