本文整理汇总了Java中gnu.trove.iterator.TIntFloatIterator.value方法的典型用法代码示例。如果您正苦于以下问题:Java TIntFloatIterator.value方法的具体用法?Java TIntFloatIterator.value怎么用?Java TIntFloatIterator.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.iterator.TIntFloatIterator
的用法示例。
在下文中一共展示了TIntFloatIterator.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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);
}
}
示例11: 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;
}
示例12: 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();
}
示例13: 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;
}
示例14: getBaseDist
import gnu.trove.iterator.TIntFloatIterator; //导入方法依赖的package包/类
private float getBaseDist(int classid) {
float base = 0.0f;
TIntFloatIterator it = classCenter.get(classid).data.iterator();
while (it.hasNext()) {
it.advance();
base += it.value() * it.value();
}
return base;
}
示例15: 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);
}
}
}