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


Java TIntFloatIterator.advance方法代码示例

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


在下文中一共展示了TIntFloatIterator.advance方法的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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:26,代码来源:ItemFrequency.java

示例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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:21,代码来源:KMeansWordCluster.java

示例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);
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:18,代码来源:KMeansWordCluster.java

示例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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:28,代码来源:MyCollection.java

示例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;

}
 
开发者ID:pschuette22,项目名称:Zeppa-AppEngine,代码行数:27,代码来源:KLDivergence.java

示例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;
}
 
开发者ID:pschuette22,项目名称:Zeppa-AppEngine,代码行数:24,代码来源:SemSigUtils.java

示例7: 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);
		}
	}

}
 
开发者ID:joeywen,项目名称:fudannlp,代码行数:28,代码来源:WordCluster.java

示例8: 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;
}
 
开发者ID:joeywen,项目名称:fudannlp,代码行数:28,代码来源:MyCollection.java

示例9: 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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:11,代码来源:FeatureSelect.java

示例10: 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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:11,代码来源:HashSparseVector.java

示例11: 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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:10,代码来源:HashSparseVector.java

示例12: 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);
	}

}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:14,代码来源:HashSparseVector.java

示例13: 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;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:44,代码来源:HashSparseVector.java

示例14: 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();
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:14,代码来源:HashSparseVector.java

示例15: removeZero

import gnu.trove.iterator.TIntFloatIterator; //导入方法依赖的package包/类
/**
 * 统计信息,计算删除非0特征后,权重的长度
 */
public void removeZero() {
	boolean freeze = false;
	if (feature.isStopIncrement()) {
		feature.setStopIncrement(false);
		freeze = true;
	}
	TIntObjectHashMap<String> index = (TIntObjectHashMap<String>) feature.toInverseIndexMap();
	
	System.out.println("原字典大小"+index.size());
	System.out.println("原字典大小"+feature.size());
	StringFeatureAlphabet newfeat = new StringFeatureAlphabet();
	cl.factory.setDefaultFeatureAlphabet(newfeat);
	for(int i=0;i<weights.length;i++){
			TIntFloatIterator itt = weights[i].data.iterator();
			HashSparseVector ww = new HashSparseVector();
			while(itt.hasNext()){
				itt.advance();
				float v = itt.value();
				if(Math.abs(v)<1e-3f)
					continue;
				String fea = index.get(itt.key());
				int newidx = newfeat.lookupIndex(fea);
				ww.put(newidx, v);				
		}
		weights[i] = ww;	
	}
	
	newfeat.setStopIncrement(freeze);
	System.out.println("新字典大小"+newfeat.size());		
	System.out.println("新字典大小"+feature.size());		
	index.clear();		
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:36,代码来源:ModelAnalysis.java


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