本文整理汇总了Java中it.unimi.dsi.fastutil.ints.Int2DoubleMap类的典型用法代码示例。如果您正苦于以下问题:Java Int2DoubleMap类的具体用法?Java Int2DoubleMap怎么用?Java Int2DoubleMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Int2DoubleMap类属于it.unimi.dsi.fastutil.ints包,在下文中一共展示了Int2DoubleMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dot
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
private double dot(SparseDoubleVector other) {
double ret = 0.0;
Int2DoubleOpenHashMap smallMap = this.hashMap;
Int2DoubleOpenHashMap largeMap = other.hashMap;
if (smallMap.size() > largeMap.size()) {
smallMap = other.hashMap;
largeMap = this.hashMap;
}
ObjectIterator<Int2DoubleMap.Entry> iter = smallMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
if (largeMap.containsKey(entry.getIntKey())) {
ret += entry.getDoubleValue() * largeMap.get(entry.getIntKey());
}
}
return ret;
}
示例2: filter
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
@Override
public TIntDoubleVector filter(double x) {
Int2DoubleOpenHashMap newMap = new Int2DoubleOpenHashMap();
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
double value = entry.getDoubleValue();
if (Math.abs(value) > x) {
newMap.put(entry.getIntKey(), value);
}
}
SparseDoubleVector vector = new SparseDoubleVector(dim, newMap);
vector.setRowId(rowId).setMatrixId(matrixId).setClock(clock);
return vector;
}
示例3: writeTo
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
@Override public void writeTo(DataOutputStream output) throws IOException {
try {
lock.readLock().lock();
super.writeTo(output);
output.writeInt(hashMap.size());
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
output.writeInt(entry.getIntKey());
output.writeDouble(entry.getDoubleValue());
}
} finally {
lock.readLock().unlock();
}
}
示例4: serialize
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
@Override public void serialize(ByteBuf buf) {
try {
lock.readLock().lock();
super.serialize(buf);
buf.writeInt(hashMap.size());
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
buf.writeInt(entry.getIntKey());
buf.writeDouble(entry.getDoubleValue());
}
} finally {
lock.readLock().unlock();
}
}
示例5: mergeTo
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
/**
* Merge this sparse double vector split to a index/value array
* @param indexes index array
* @param values value array
* @param startPos write start position of the index/value array
* @param len write length
*/
public void mergeTo(int[] indexes, double[] values, int startPos, int len) {
try {
lock.readLock().lock();
int writeLen = len < hashMap.size() ? len : hashMap.size();
if (writeLen == 0) {
return;
}
int index = 0;
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
indexes[startPos + index] = entry.getIntKey();
values[startPos + index] = entry.getDoubleValue();
index++;
if (index == writeLen) {
return;
}
}
} finally {
lock.readLock().unlock();
}
}
示例6: cosine
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
/**
* Calculate the cosine of two vectors
* @param _v1 Vector 1
* @param _v2 Vector 2
* @return Sum(x*y)/(norm(x)*norm(y))
*/
public static double cosine(Vector _v1, Vector _v2) {
final Vector v1 = _v1.size() < _v2.size() ? _v1 : _v2;
final Vector v2 = _v1.size() < _v2.size() ? _v2 : _v1;
if(v1.len() != v2.len()) throw new LinearAlgebraException(String.format("Vector lengths do not match %d <-> %d", v1.len(), v2.len()));
double aa = 0, ab = 0;
for(Int2DoubleMap.Entry s : v1.sparseEntrySet()) {
aa += s.getDoubleValue()*s.getDoubleValue();
ab += s.getDoubleValue()*v2.getDouble(s.getIntKey());
}
final double bnorm = v2.norm();
if(aa == 0 && bnorm == 0) {
return 0.0;
} else {
return ab / Math.sqrt(aa) / bnorm;
}
}
示例7: truncateMapByHighestValue
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
public static void truncateMapByHighestValue(Int2DoubleMap map, int howMany) {
if (howMany >= map.size())
return;
double[] values = map.values().toDoubleArray();
Arrays.sort(values); // not best strategy, i know
org.apache.commons.lang.ArrayUtils.reverse(values);
double threshold = values[howMany+1];
ObjectIterator<Entry> mapIterator = map.int2DoubleEntrySet().iterator();
int inserted = 0;
while (mapIterator.hasNext())
if (mapIterator.next().getDoubleValue() < threshold || inserted >= howMany)
mapIterator.remove();
else
inserted++;
}
示例8: saveComparisons
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
public void saveComparisons(File f) throws IOException {
final Writer out = new FileWriter(f);
LOGGER.info("Computing and saving scores...");
for (int node : groundtruth.queries()) {
Int2DoubleMap[] scorersResults = new Int2DoubleMap[scorers.length];
for (int i = 0; i < scorers.length; i++)
scorersResults[i] = scorers[i].scores(node);
for (int succ : groundtruth.getEvaluatedDocs(node)) {
StringBuilder row = new StringBuilder();
for (Int2DoubleMap scorersResult : scorersResults)
row.append(scorersResult.get(succ) + "\t");
row.append(groundtruth.getRelevance(node, succ) + "\n");
out.write(row.toString());
}
}
LOGGER.info("Done.");
out.close();
}
示例9: getProductMap
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
private Int2DoubleMap getProductMap(int uidx) {
Int2DoubleOpenHashMap productMap = new Int2DoubleOpenHashMap();
productMap.defaultReturnValue(0.0);
if (data.useIteratorsPreferentially()) {
IntIterator iidxs = data.getUidxIidxs(uidx);
DoubleIterator ivs = data.getUidxVs(uidx);
while (iidxs.hasNext()) {
int iidx = iidxs.nextInt();
double iv = ivs.nextDouble();
IntIterator vidxs = data.getIidxUidxs(iidx);
DoubleIterator vvs = data.getIidxVs(iidx);
while (vidxs.hasNext()) {
productMap.addTo(vidxs.nextInt(), iv * vvs.nextDouble());
}
}
} else {
data.getUidxPreferences(uidx)
.forEach(ip -> data.getIidxPreferences(ip.v1)
.forEach(up -> productMap.addTo(up.v1, ip.v2 * up.v2)));
}
productMap.remove(uidx);
return productMap;
}
示例10: getRecommendation
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
@Override
public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) {
if (uidx == -1) {
return new FastRecommendation(uidx, new ArrayList<>(0));
}
Int2DoubleMap scoresMap = getScoresMap(uidx);
final IntDoubleTopN topN = new IntDoubleTopN(min(maxLength, scoresMap.size()));
scoresMap.int2DoubleEntrySet().forEach(e -> {
int iidx = e.getIntKey();
double score = e.getDoubleValue();
if (filter.test(iidx)) {
topN.add(iidx, score);
}
});
topN.sort();
List<Tuple2id> items = topN.reverseStream()
.collect(toList());
return new FastRecommendation(uidx, items);
}
示例11: newNumberVector
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
@Override
public SparseFloatVector newNumberVector(Int2DoubleOpenHashMap dvalues, int maxdim) {
int[] indexes = new int[dvalues.size()];
float[] values = new float[dvalues.size()];
// Import and sort the indexes
ObjectIterator<Int2DoubleMap.Entry> iter = dvalues.int2DoubleEntrySet().fastIterator();
for(int i = 0; iter.hasNext(); i++) {
indexes[i] = iter.next().getIntKey();
}
Arrays.sort(indexes);
// Import the values accordingly
for(int i = 0; i < dvalues.size(); i++) {
values[i] = (float) dvalues.get(indexes[i]);
}
return new SparseFloatVector(indexes, values, maxdim);
}
示例12: testIterationOrder
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
@Test
public void testIterationOrder() {
Vector v = new Vector();
v.put(0, 0);
v.put(1, 1);
v.put(2, 2);
v.put(3, 3);
v.put(4, 4);
BidirectionalIterator<Int2DoubleMap.Entry> it = v.int2DoubleEntrySet().fastIterator(v.int2DoubleEntrySet().last());
// for (int i = 0; i < v.size(); i++) {
int i = 4;
while (it.hasPrevious()) {
Entry e = it.previous();
int lastKey = e.getIntKey();
double lastValue = e.getDoubleValue();
assertEquals(i, lastKey);
assertEquals(i, lastValue, Double.MIN_NORMAL);
i--;
}
assertEquals(5, v.size());
assertEquals(0, v.int2DoubleEntrySet().first().getIntKey());
assertEquals(4, v.int2DoubleEntrySet().last().getIntKey());
}
示例13: dot
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
private double dot(SparseDoubleVector other) {
double ret = 0.0;
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
ret += values[entry.getIntKey()] * entry.getDoubleValue();
}
return ret;
}
示例14: plus
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
private TVector plus(SparseDoubleVector other) {
DenseFloatVector vector = new DenseFloatVector(dim);
System.arraycopy(values, 0, vector.values, 0, dim);
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
vector.values[entry.getIntKey()] += (float) entry.getDoubleValue();
}
return vector;
}
示例15: plusBy
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入依赖的package包/类
private TFloatVector plusBy(SparseDoubleVector other) {
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
values[entry.getIntKey()] += (float) entry.getDoubleValue();
}
return this;
}