gnu.trove.iterator.TIntIntIterator Java Examples

The following examples show how to use gnu.trove.iterator.TIntIntIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Similarity.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public  void duplicate(ArrayList<String> docs) throws Exception {
	this.docs = docs;
	dsMap = new TreeSet<DocSim>();
	feature();

	similarity();
	System.out.println("去重复");

	boolean[] dup = new boolean[docs.size()];
	for(int id1=0;id1<docs.size();id1++){
		if(dup[id1]||similarityMap[id1]==null)
			continue;


		ArrayList<Integer> ids = new ArrayList<Integer>();
		ids.add(id1);
		TIntIntIterator it = similarityMap[id1].iterator();
		for ( int i = similarityMap[id1].size(); i-- > 0; ) {
			it.advance();
			int id2 = it.key();				
			double sim = ((double)(it.value()* 2)) / (featureLen[id1] + featureLen[id2]);
			if(sim > thres ){
				dup[id2]= true;
				ids.add(id2);
			}
		}
		DocSim docSim = new DocSim(ids);
		dsMap.add(docSim);
	}
}
 
Example #2
Source File: MyArrays.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param freqmap
 * @return
 */
public static TreeMap<Integer, Integer> countFrequency(TIntIntHashMap freqmap) {
	TreeMap<Integer, Integer> map = new TreeMap<Integer,Integer>();
	TIntIntIterator it = freqmap.iterator();
	while(it.hasNext()){
		it.advance();
		int freq = it.value();
		if(map.containsKey(freq)){
			map.put(freq, map.get(freq)+1);
		}else
			map.put(freq, 1);
	}
	return map;		
}
 
Example #3
Source File: MaterialCounter.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public void addAll(MaterialCounter other) {
  for (TIntIntIterator iter = other.counts.iterator(); iter.hasNext(); ) {
    iter.advance();
    counts.adjustOrPutValue(iter.key(), iter.value(), iter.value());
  }
}
 
Example #4
Source File: MaterialCounter.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public void addAll(MaterialCounter other) {
    for(TIntIntIterator iter = other.counts.iterator(); iter.hasNext();) {
        iter.advance();
        counts.adjustOrPutValue(iter.key(), iter.value(), iter.value());
    }
}
 
Example #5
Source File: TIntIntHashMap.java    From baleen with Apache License 2.0 4 votes vote down vote up
/** See {@link gnu.trove.map.hash.TIntIntHashMap#iterator()} */
public TIntIntIterator iterator() {
  return delegate.iterator();
}
 
Example #6
Source File: HashFeatureAlphabet.java    From fnlp with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public TIntIntIterator iterator() {     
    return intdata.iterator();
}
 
Example #7
Source File: HigherOrderViterbiPAUpdate.java    From fnlp with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * data 每个元素为特征空间索引位置 1 ... T T列(模板个数) 1 N行(序列长度) 2 . data[r][t] N
 * 第t个模板作用在第r个位置 得到feature的起始位置
 * 
 * target[r],predict[r] label的编号
 * 
 * @param c
 * @param weights
 */
public float update(Instance inst, float[] weights, int k,
		float[] extraweight, Object predictLabel,
		Object goldenLabel, float c) {
	int[][] data = (int[][]) inst.getData();
	int[] target;
	if (goldenLabel == null)
		target = (int[]) inst.getTarget();
	else
		target = (int[]) goldenLabel;
	int[] predict = (int[]) predictLabel;
	// 当前clique中不同label的个数
	int ne = 0;
	/**
	 * 偏移索引
	 * 
	 */
	int tS = 0, pS = 0;

	float diffW = 0;

	int loss = 0;

	int L = data.length;
	// 稀疏矩阵表示(f(x,y)-f(x,\bar{y}))
	TIntIntHashMap diffF = new TIntIntHashMap(); // 最多有2*L*numTemplets个不同

	for (int o = -templets.maxOrder - 1, l = 0; l < L; o++, l++) {
		tS = tS * numLabels % templets.numStates + target[l]; // 目标值:计算当前状态组合的y空间偏移
		pS = pS * numLabels % templets.numStates + predict[l];// 预测值:计算当前状态组合的y空间偏移
		if (predict[l] != target[l])
			ne++;
		if (o >= 0 && (predict[o] != target[o]))
			ne--; // 减去移出clique的节点的label差异

		if (ne > 0) { // 当前clique有不相同label
			loss++; // L(y,ybar)
			for (int t = 0; t < numTemplets; t++) {
				if (data[l][t] == -1)
					continue;
				int tI = data[l][t] + templets.offset[t][tS]; // 特征索引:找到对应weights的维数
				int pI = data[l][t] + templets.offset[t][pS]; // 特征索引:找到对应weights的维数
				if (tI != pI) {
					diffF.adjustOrPutValue(tI, 1, 1);
					diffF.adjustOrPutValue(pI, -1, -1);
					diffW += weights[tI] - weights[pI]; // w^T(f(x,y)-f(x,ybar))
				}
			}
		}
	}

	float diff = 0;
	TIntIntIterator it = diffF.iterator();
	for (int i = diffF.size(); i-- > 0;) {
		it.advance();
		diff += it.value() * it.value();
	}
	it = null;
	float alpha;
	float delta;
	if (useLoss) {
		delta = loss;
	} else
		delta = 1;
	if (diffW < delta) {

		tS = 0;
		pS = 0;
		ne = 0;
		alpha = (delta - diffW) / diff;
		// System.out.println(alpha);
		alpha = Math.min(c, alpha);
		it = diffF.iterator();
		for (int i = diffF.size(); i-- > 0;) {
			it.advance();
			weights[it.key()] += it.value() * alpha;
		}

		return loss;
	} else {
		return 0;
	}
}