本文整理汇总了Java中gnu.trove.map.TIntFloatMap.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java TIntFloatMap.iterator方法的具体用法?Java TIntFloatMap.iterator怎么用?Java TIntFloatMap.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.TIntFloatMap
的用法示例。
在下文中一共展示了TIntFloatMap.iterator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compare
import gnu.trove.map.TIntFloatMap; //导入方法依赖的package包/类
public double compare(
TIntFloatMap v1,
TIntFloatMap v2,
boolean sorted)
{
//it does not matter if the vectors are sorted or not
double DKL = 0.0;
TIntFloatIterator iter = v1.iterator();
while (iter.hasNext())
{
iter.advance();
int key = iter.key();
if (!v2.containsKey(key))
{
continue;
}
double P = iter.value();
double Q = v2.get(key);
DKL += Math.log(P/Q) * P;
}
return DKL;
}
示例2: getSortedIndices
import gnu.trove.map.TIntFloatMap; //导入方法依赖的package包/类
public static int[] getSortedIndices(TIntFloatMap vector)
{
// NOTE: it's probably possible to do this using purely primitive
// operations without having to resort to pushing things into an
// Index[]. However, this code is much cleaner to have and since we
// sort at most once per vector and the result is memoized, we don't
// lose too much from the Object-based sorting.
Index[] keyValPairs = new Index[vector.size()];
TIntFloatIterator iter = vector.iterator();
int i = 0;
while (iter.hasNext())
{
iter.advance();
keyValPairs[i++] = new Index(iter.key(), iter.value());
}
Arrays.sort(keyValPairs);
int[] sortedIndices = new int[keyValPairs.length];
for (i = 0; i < keyValPairs.length; ++i)
sortedIndices[i] = keyValPairs[i].key;
return sortedIndices;
}
示例3: normalizeVector
import gnu.trove.map.TIntFloatMap; //导入方法依赖的package包/类
/**
* Normalizes the probability values in a vector so that to sum to 1.0
* @param vector
* @return
*/
public static TIntFloatMap normalizeVector(TIntFloatMap vector)
{
float total = 0;
TFloatIterator iter = vector.valueCollection().iterator();
while (iter.hasNext())
total += iter.next();
TIntFloatMap normalized = new TIntFloatHashMap(vector.size());
TIntFloatIterator iter2 = vector.iterator();
while (iter2.hasNext())
{
iter2.advance();
normalized.put(iter2.key(), iter2.value() / total);
}
return normalized;
}
示例4: putAll
import gnu.trove.map.TIntFloatMap; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void putAll( TIntFloatMap map ) {
ensureCapacity( map.size() );
TIntFloatIterator iter = map.iterator();
while ( iter.hasNext() ) {
iter.advance();
this.put( iter.key(), iter.value() );
}
}
示例5: putAll
import gnu.trove.map.TIntFloatMap; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void putAll( TIntFloatMap map ) {
ensureCapacity( map.size() );
TIntFloatIterator iter = map.iterator();
while ( iter.hasNext() ) {
iter.advance();
this.put( iter.key(), iter.value() );
}
}