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


Java TIntFloatIterator.key方法代码示例

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


在下文中一共展示了TIntFloatIterator.key方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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

示例5: 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

示例6: 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

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

示例8: 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

示例9: 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

示例10: 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

示例11: classify

import gnu.trove.iterator.TIntFloatIterator; //导入方法依赖的package包/类
@Override
public Predict classify(Instance instance, int n) {
	// TODO Auto-generated method stub

	int typeSize=tf.getTypeSize();
	float[] score=new float[typeSize];
	Arrays.fill(score, 0.0f);
	
	Object obj=instance.getData();
	if(!(obj instanceof HashSparseVector)){
		System.out.println("error 输入类型非HashSparseVector!");
		return null;
	}
	HashSparseVector data = (HashSparseVector) obj;
	if(fs!=null)
		data=fs.select(data);
	TIntFloatIterator it = data.data.iterator();
	float feaSize=tf.getFeatureSize();
	while (it.hasNext()) {
		it.advance();
		if(it.key()==0)
			continue;
		int feature=it.key();
		for(int type=0;type<typeSize;type++){
			float itemF=tf.getItemFrequency(feature, type);
			float typeF=tf.getTypeFrequency(type);
			score[type]+=it.value()*Math.log((itemF+0.1)/(typeF+feaSize));
		}
	}
	
	Predict<Integer> res=new Predict<Integer>(n);
	for(int type=0;type<typeSize;type++)
		res.add(type, score[type]);
	
	return res;
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:37,代码来源:BayesClassifier.java

示例12: statisticProb

import gnu.trove.iterator.TIntFloatIterator; //导入方法依赖的package包/类
/**
 * 一次性统计概率,节约时间
 */
private void statisticProb() {
	System.out.println("统计概率");
	TIntFloatIterator it = wordProb.iterator();
	while(it.hasNext()){
		it.advance();
		float v = it.value()/totalword;
		it.setValue(v);
		int key = it.key();
		if(key<0)
			continue;
		Cluster cluster = new Cluster(key,v,alpahbet.lookupString(key));
		clusters.put(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:FudanNLP,项目名称:fnlp,代码行数:30,代码来源:WordCluster.java

示例13: addThruPipe

import gnu.trove.iterator.TIntFloatIterator; //导入方法依赖的package包/类
@Override
public void addThruPipe(Instance inst) {
	HashSparseVector data = (HashSparseVector) inst.getData();
	TIntFloatIterator it = data.data.iterator();
	while (it.hasNext()) {
		it.advance();
		int id = it.key();
		if (idf[id] > 0) {
			float value = (float) (it.value()*Math.log(docNum / idf[id]));
			data.put(id, value);
		}
	}

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

示例14: addThruPipe

import gnu.trove.iterator.TIntFloatIterator; //导入方法依赖的package包/类
@Override
public void addThruPipe(Instance inst) {
	HashSparseVector data = (HashSparseVector) inst.getData();
	TIntFloatIterator it = data.data.iterator();
	while (it.hasNext()) {
		it.advance();
		idf[it.key()]++;
	}
}
 
开发者ID:FudanNLP,项目名称:fnlp,代码行数:10,代码来源:TF2IDF.java


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