本文整理汇总了Java中gnu.trove.iterator.TIntFloatIterator类的典型用法代码示例。如果您正苦于以下问题:Java TIntFloatIterator类的具体用法?Java TIntFloatIterator怎么用?Java TIntFloatIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TIntFloatIterator类属于gnu.trove.iterator包,在下文中一共展示了TIntFloatIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: oneStepStatistic
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
private boolean oneStepStatistic(Instance inst) {
if(inst==null)
return false;
int[] type;
Object t=inst.getTarget();
if(t instanceof Integer){
type=new int[1];
type[0]=Integer.parseInt(t.toString());
}
else{
return false;
}
HashSparseVector data = (HashSparseVector) inst.getData();
TIntFloatIterator it = data.data.iterator();
while (it.hasNext()) {
it.advance();
int feature=it.key();
for(int i=0;i<type.length;i++){
addItemFrequency(feature, type[i], (int)it.value());
}
}
return true;
}
示例2: distanceEuclidean
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
private float distanceEuclidean(int n, HashSparseVector sv, float baseDistance) {
HashSparseVector center = classCenter.get(n);
int count = classCount.get(n);
float dist = baseDistance / (count * count);
TIntFloatHashMap data = center.data;
TIntFloatIterator it = sv.data.iterator();
while (it.hasNext()) {
it.advance();
int key = it.key();
if (!data.containsKey(key)) {
dist += it.value() * it.value();
}
else {
float temp = data.get(key) / count;
dist -= temp * temp;
dist += (it.value() - temp) * (it.value() - temp);
}
}
return dist;
}
示例3: updateBaseDist
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
private void updateBaseDist(int classid, HashSparseVector vector) {
float base = baseDistList.get(classid);
TIntFloatHashMap center = classCenter.get(classid).data;
TIntFloatIterator it = vector.data.iterator();
while (it.hasNext()) {
it.advance();
if (!center.containsKey(it.key())) {
base += it.value() * it.value();
}
else {
float temp = center.get(it.key());
base -= temp * temp;
base += (it.value() - temp) * (it.value() - temp);
}
}
baseDistList.set(classid, base);
}
示例4: sort
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
/**
* 由大到小排序
* @param tmap
* @return 数组下标
*/
public static int[] sort(TIntFloatHashMap tmap) {
HashMap<Integer, Float> map = new HashMap<Integer, Float>();
TIntFloatIterator it = tmap.iterator();
while (it.hasNext()) {
it.advance();
int id = it.key();
float val = it.value();
map.put(id, Math.abs(val));
}
it = null;
List<Entry> list = sort(map);
int[] idx = new int[list.size()];
Iterator<Entry> it1 = list.iterator();
int i=0;
while (it1.hasNext()) {
Entry entry = it1.next();
idx[i++] = (Integer) entry.getKey();
}
return idx;
}
示例5: compare
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的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;
}
示例6: getSortedIndices
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的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;
}
示例7: normalizeVector
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的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;
}
示例8: statisticProb
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
/**
* 一次性统计概率,节约时间
*/
private void statisticProb() {
System.out.println("统计概率");
float totalword = alpahbet.size();
TIntFloatIterator it = wordProb.iterator();
while(it.hasNext()){
it.advance();
float v = it.value()/totalword;
it.setValue(v);
Cluster cluster = new Cluster(it.key(),v,alpahbet.lookupString(it.key()));
clusters.put(it.key(), cluster);
}
TIntObjectIterator<TIntFloatHashMap> it1 = pcc.iterator();
while(it1.hasNext()){
it1.advance();
TIntFloatHashMap map = it1.value();
TIntFloatIterator it2 = map.iterator();
while(it2.hasNext()){
it2.advance();
it2.setValue(it2.value()/totalword);
}
}
}
示例9: sort
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
/**
* 由大到小排序
* @param map
* @return 数组下标
*/
public static int[] sort(TIntFloatHashMap tmap) {
HashMap<Integer, Float> map = new HashMap<Integer, Float>();
TIntFloatIterator it = tmap.iterator();
while (it.hasNext()) {
it.advance();
int id = it.key();
float val = it.value();
map.put(id, Math.abs(val));
}
it = null;
List<Entry> list = sort(map);
int[] idx = new int[list.size()];
Iterator<Entry> it1 = list.iterator();
int i=0;
while (it1.hasNext()) {
Entry entry = it1.next();
idx[i++] = (Integer) entry.getKey();
}
return idx;
}
示例10: select
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
public HashSparseVector select(HashSparseVector vec){
HashSparseVector sv=new HashSparseVector();
TIntFloatIterator it=vec.data.iterator();
while(it.hasNext()){
it.advance();
if(isUseful[it.key()])
sv.put(it.key(), it.value());
}
return sv;
}
示例11: dotProduct
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
@Override
public float dotProduct(float[] vector) {
float v =0f;
TIntFloatIterator it = data.iterator();
while(it.hasNext()){
it.advance();
v += vector[it.key()]*it.value();
}
return v;
}
示例12: l2Norm2
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
public float l2Norm2() {
TIntFloatIterator it = data.iterator();
float norm = 0f;
while(it.hasNext()){
it.advance();
norm += it.value()*it.value();
}
return norm;
}
示例13: scaleDivide
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
/**
*
* @param c
*/
public void scaleDivide(float c) {
TIntFloatIterator it = data.iterator();
while(it.hasNext()){
it.advance();
float v = it.value()/c;
data.put(it.key(), v);
}
}
示例14: distanceEuclidean
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
/**
* 欧氏距离
* @param sv1
* @param sv2
* @return
*/
public static float distanceEuclidean(HashSparseVector sv1 ,HashSparseVector sv2) {
float dist = 0.0f;
TIntFloatIterator it1 = sv1.data.iterator();
TIntFloatIterator it2 = sv2.data.iterator();
int increa = 0;
while(it1.hasNext()&&it2.hasNext()){
if(increa==0){
it1.advance();
it2.advance();
}else if(increa==1){
it1.advance();
}else if(increa==2){
it2.advance();
}
if(it1.key()<it2.key()){
dist += it1.value()*it1.value();
increa = 1;
}else if(it1.key()>it2.key()){
dist += it2.value()*it2.value();
increa = 2;
}else{
float t = it1.value() - it2.value();
dist += t*t;
increa = 0;
}
}
while(it1.hasNext()){
it1.advance();
dist += it1.value()*it1.value();
}
while(it2.hasNext()){
it2.advance();
dist += it2.value()*it2.value();
}
return dist;
}
示例15: toString
import gnu.trove.iterator.TIntFloatIterator; //导入依赖的package包/类
public String toString(){
StringBuilder sb = new StringBuilder();
TIntFloatIterator it = data.iterator();
while(it.hasNext()){
it.advance();
sb.append(it.key());
sb.append(":");
sb.append(it.value());
if(it.hasNext())
sb.append(", ");
}
return sb.toString();
}