本文整理汇总了Java中it.unimi.dsi.fastutil.longs.Long2DoubleMap类的典型用法代码示例。如果您正苦于以下问题:Java Long2DoubleMap类的具体用法?Java Long2DoubleMap怎么用?Java Long2DoubleMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Long2DoubleMap类属于it.unimi.dsi.fastutil.longs包,在下文中一共展示了Long2DoubleMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: plusBy
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private SparseLongKeyDoubleVector plusBy(SparseLongKeyDoubleVector other, double x) {
assert (dim == -1 || dim == other.getLongDim());
if(this.indexToValueMap.isEmpty()) {
this.indexToValueMap.putAll(other.getIndexToValueMap());
} else {
resize(other.size());
ObjectIterator<Long2DoubleMap.Entry> iter =
other.indexToValueMap.long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
indexToValueMap.addTo(entry.getLongKey(), entry.getDoubleValue() * x);
}
}
return this;
}
示例2: plus
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private SparseLongKeyDoubleVector plus(SparseLongKeyDoubleVector other, double x) {
assert (dim == -1 || dim == other.getLongDim());
SparseLongKeyDoubleVector baseVector = null;
SparseLongKeyDoubleVector streamVector = null;
if (size() < other.size()) {
baseVector = new SparseLongKeyDoubleVector(other);
streamVector = this;
} else {
baseVector = new SparseLongKeyDoubleVector(this);
streamVector = other;
}
ObjectIterator<Long2DoubleMap.Entry> iter =
streamVector.indexToValueMap.long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
baseVector.indexToValueMap.addTo(entry.getLongKey(), entry.getDoubleValue() * x);
}
return baseVector;
}
示例3: dot
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private double dot(SparseLongKeyDoubleVector other) {
assert (dim == -1 || dim == other.getLongDim());
double ret = 0.0;
if (size() <= other.size()) {
ObjectIterator<Long2DoubleMap.Entry> iter =
indexToValueMap.long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
ret += other.get(entry.getLongKey()) * entry.getDoubleValue();
}
return ret;
} else {
return other.dot(this);
}
}
示例4: filter
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
@Override public TVector filter(double x) {
SparseLongKeyDoubleVector vector = new SparseLongKeyDoubleVector(this.dim);
ObjectIterator<Long2DoubleMap.Entry> iter =
indexToValueMap.long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
double value = entry.getDoubleValue();
if (Math.abs(value) > x) {
vector.set(entry.getLongKey(), value);
}
}
vector.setRowId(rowId).setMatrixId(matrixId).setClock(clock);
return vector;
}
示例5: serialize
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
@Override
public void serialize(ByteBuf buf) {
try {
lock.readLock().lock();
super.serialize(buf);
buf.writeInt(index2ValueMap.size());
ObjectIterator<Long2DoubleMap.Entry> iter = index2ValueMap.long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
buf.writeLong(entry.getLongKey());
buf.writeDouble(entry.getDoubleValue());
}
} finally {
lock.readLock().unlock();
}
}
示例6: mergeTo
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
/**
* Put the elements in this vector partition to the given index and value arrays
* @param indexes index array
* @param values value array
* @param startPos the start position for the elements of this vector partition
* @param len the reserved length for this vector partition
*/
public void mergeTo(long[] indexes, double[] values, int startPos, int len) {
try {
lock.readLock().lock();
int writeLen = len < index2ValueMap.size() ? len : index2ValueMap.size();
if (writeLen == 0) {
return;
}
int index = 0;
ObjectIterator<Long2DoubleMap.Entry> iter = index2ValueMap.long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
indexes[startPos + index] = entry.getLongKey();
values[startPos + index] = entry.getDoubleValue();
index++;
if (index == writeLen) {
return;
}
}
} finally {
lock.readLock().unlock();
}
}
示例7: TopSecondDegreeByCountRequest
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
/**
* @param queryNode is the query node for running TopSecondDegreeByCount
* @param leftSeedNodesWithWeight is the set of seed nodes and their weights to use for
* TopSecondDegreeByCount
* @param toBeFiltered is the set of RHS nodes to be filtered from the output
* @param maxSocialProofTypeSize is the number of social proof types in the graph
* @param socialProofTypes Social proof types, masked into a byte array
* @param maxRightNodeAgeInMillis Max right node age in millisecond, such as tweet age
* @param maxEdgeAgeInMillis Max edge age in millisecond such as reply edge age
* @param resultFilterChain Filter chain to be applied after recommendation computation
*/
public TopSecondDegreeByCountRequest(
long queryNode,
Long2DoubleMap leftSeedNodesWithWeight,
LongSet toBeFiltered,
int maxSocialProofTypeSize,
byte[] socialProofTypes,
long maxRightNodeAgeInMillis,
long maxEdgeAgeInMillis,
ResultFilterChain resultFilterChain) {
super(queryNode, toBeFiltered, socialProofTypes);
this.leftSeedNodesWithWeight = leftSeedNodesWithWeight;
this.maxSocialProofTypeSize = maxSocialProofTypeSize;
this.maxRightNodeAgeInMillis = maxRightNodeAgeInMillis;
this.maxEdgeAgeInMillis = maxEdgeAgeInMillis;
this.resultFilterChain = resultFilterChain;
}
示例8: TopSecondDegreeByCountRequestForMoment
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
/**
* @param queryNode is the query node for running TopSecondDegreeByCountRequestForMoment
* @param leftSeedNodesWithWeight is the set of seed nodes and their weights to use for calculation
* @param toBeFiltered is the set of RHS nodes to be filtered from the output
* @param maxNumResults is the maximum number of recommendations returned in the response
* @param maxNumSocialProofs is the maximum number of social proofs per recommendation
* @param maxSocialProofTypeSize is the number of social proof types in the graph
* @param minUserPerSocialProof for each social proof, require a minimum number of users to be valid
* @param socialProofTypes is the list of valid social proofs, (i.e. Create, Like etc)
* @param maxRightNodeAgeInMillis Max right node age in millisecond, such as moment age
* @param maxEdgeAgeInMillis Max edge age in millisecond such as like edge age
* @param resultFilterChain is the chain of filters to be applied
*/
public TopSecondDegreeByCountRequestForMoment(
long queryNode,
Long2DoubleMap leftSeedNodesWithWeight,
LongSet toBeFiltered,
int maxNumResults,
int maxNumSocialProofs,
int maxSocialProofTypeSize,
Map<Byte, Integer> minUserPerSocialProof,
byte[] socialProofTypes,
long maxRightNodeAgeInMillis,
long maxEdgeAgeInMillis,
ResultFilterChain resultFilterChain) {
super(queryNode, leftSeedNodesWithWeight, toBeFiltered, maxSocialProofTypeSize,
socialProofTypes, maxRightNodeAgeInMillis, maxEdgeAgeInMillis, resultFilterChain);
this.maxNumResults = maxNumResults;
this.maxNumSocialProofs = maxNumSocialProofs;
this.minUserPerSocialProof = minUserPerSocialProof;
}
示例9: TopSecondDegreeByCountRequestForUser
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
/**
* @param queryNode is the query node for running TopSecondDegreeByCountForUser
* @param leftSeedNodesWithWeight is the set of seed nodes and their weights to use for calculation
* @param toBeFiltered is the list of users to be excluded from recommendations
* @param maxNumResults is the maximum number of recommendations returned in the response
* @param maxNumSocialProofs is the maximum number of social proofs per recommendation
* @param maxSocialProofTypeSize is the number of social proof types in the graph
* @param minUserPerSocialProof for each social proof, require a minimum number of users to be valid
* @param socialProofTypes is the list of valid social proofs, (i.e, Follow, Mention, Mediatag)
* @param maxRightNodeAgeInMillis is the max right node age in millisecond, such as tweet age
* @param maxEdgeAgeInMillis is the max edge age in millisecond such as reply edge age
* @param resultFilterChain is the chain of filters to be applied
*/
public TopSecondDegreeByCountRequestForUser(
long queryNode,
Long2DoubleMap leftSeedNodesWithWeight,
LongSet toBeFiltered,
int maxNumResults,
int maxNumSocialProofs,
int maxSocialProofTypeSize,
Map<Byte, Integer> minUserPerSocialProof,
byte[] socialProofTypes,
long maxRightNodeAgeInMillis,
long maxEdgeAgeInMillis,
ResultFilterChain resultFilterChain) {
super(queryNode, leftSeedNodesWithWeight, toBeFiltered, maxSocialProofTypeSize,
socialProofTypes, maxRightNodeAgeInMillis, maxEdgeAgeInMillis, resultFilterChain);
this.maxNumResults = maxNumResults;
this.maxNumSocialProofs = maxNumSocialProofs;
this.minUserPerSocialProof = minUserPerSocialProof;
}
示例10: constructAliasTableArray
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
/**
* Construct a index array and an alias table given the LHS seed nodes with weights.
* The probability for a LHS seed node u to be sampled should be proportional to
* degree(u) * Weight(u)
*
* @param seedsWithWeights the LHS seed nodes with weights
* @param indexArray the index array for the seeds
* @param aliasTableArray the alias table used for sampling from the seeds
*/
private void constructAliasTableArray(
Long2DoubleMap seedsWithWeights,
long[] indexArray,
int[] aliasTableArray) {
int index = 0;
int averageWeight = 0;
for (Long2DoubleMap.Entry entry: seedsWithWeights.long2DoubleEntrySet()) {
long seed = entry.getLongKey();
double seedWeight = entry.getDoubleValue();
indexArray[index] = seed;
int finalWeight = (int) (Math.round(MULTIPER_FOR_ALIASTABLE * seedWeight
* bipartiteGraph.getLeftNodeDegree(seed)));
IntArrayAliasTable.setEntry(aliasTableArray, index, index);
IntArrayAliasTable.setWeight(aliasTableArray, index, finalWeight);
averageWeight += finalWeight;
index++;
}
// finally set the size and weight
IntArrayAliasTable.setAliasTableSize(aliasTableArray, index);
IntArrayAliasTable.setAliasTableAverageWeight(aliasTableArray, averageWeight / index);
// now we can construct the alias table
AliasTableUtil.constructAliasTable(aliasTableArray);
}
示例11: verifyCandidates
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private final Long2DoubleOpenHashMap verifyCandidates(final Vector v, Long2DoubleOpenHashMap accumulator) {
Long2DoubleOpenHashMap matches = new Long2DoubleOpenHashMap();
for (Long2DoubleMap.Entry e : accumulator.long2DoubleEntrySet()) {
final long candidateID = e.getLongKey();
if (Double.compare(e.getDoubleValue() + ps.get(candidateID), theta) < 0) // A[y] = dot(x, y'')
continue; // l2 pruning
Vector residual = residuals.get(candidateID);
assert (residual != null);
final double ds1 = e.getDoubleValue()
+ Math.min(v.maxValue() * residual.sumValues(), residual.maxValue() * v.sumValues());
if (Double.compare(ds1, theta) < 0)
continue; // dpscore, eq. (5)
final double sz2 = e.getDoubleValue() + Math.min(v.maxValue() * residual.size(), residual.maxValue() * v.size());
if (Double.compare(sz2, theta) < 0)
continue; // dpscore, eq. (9)
final long deltaT = v.timestamp() - candidateID;
double score = e.getDoubleValue() + Vector.similarity(v, residual); // dot(x, y) = A[y] + dot(x, y')
score *= forgettingFactor(lambda, deltaT); // apply forgetting factor
numSimilarities++;
if (Double.compare(score, theta) >= 0) // final check
matches.put(candidateID, score);
}
numMatches += matches.size();
return matches;
}
示例12: verifyCandidates
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private final Long2DoubleOpenHashMap verifyCandidates(final Vector v, Long2DoubleOpenHashMap accumulator) {
Long2DoubleOpenHashMap matches = new Long2DoubleOpenHashMap();
for (Long2DoubleMap.Entry e : accumulator.long2DoubleEntrySet()) {
final long candidateID = e.getLongKey();
if (Double.compare(e.getDoubleValue() + ps.get(candidateID), theta) < 0) // A[y] = dot(x, y'')
continue; // l2 pruning
final Vector residual = residuals.get(candidateID);
assert (residual != null);
final double ds1 = e.getDoubleValue()
+ Math.min(v.maxValue() * residual.sumValues(), residual.maxValue() * v.sumValues());
if (Double.compare(ds1, theta) < 0)
continue; // dpscore, eq. (5)
final double sz2 = e.getDoubleValue() + Math.min(v.maxValue() * residual.size(), residual.maxValue() * v.size());
if (Double.compare(sz2, theta) < 0)
continue; // dpscore, eq. (9)
final long deltaT = v.timestamp() - candidateID;
double score = e.getDoubleValue() + Vector.similarity(v, residual); // dot(x, y) = A[y] + dot(x, y')
score *= forgettingFactor(lambda, deltaT); // apply forgetting factor
numSimilarities++;
if (Double.compare(score, theta) >= 0) // final check
matches.put(candidateID, score);
}
numMatches += matches.size();
return matches;
}
示例13: verifyCandidates
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private Long2DoubleOpenHashMap verifyCandidates(final Vector v, Long2DoubleOpenHashMap accumulator) {
Long2DoubleOpenHashMap matches = new Long2DoubleOpenHashMap();
for (Long2DoubleMap.Entry e : accumulator.long2DoubleEntrySet()) {
long candidateID = e.getLongKey();
Vector candidateResidual = residuals.get(candidateID);
assert (candidateResidual != null);
double score = e.getDoubleValue() + Vector.similarity(v, candidateResidual); // A[y] + dot(y',x)
long deltaT = v.timestamp() - candidateID;
score *= Commons.forgettingFactor(lambda, deltaT); // apply forgetting factor
numSimilarities++;
if (Double.compare(score, theta) >= 0) // final check
matches.put(candidateID, score);
}
numMatches += matches.size();
return matches;
}
示例14: iterator
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
@Override
public Iterator<Edge<LongWritable, DoubleWritable>> iterator() {
// Returns an iterator that reuses objects.
return new UnmodifiableIterator<Edge<LongWritable, DoubleWritable>>() {
/** Wrapped map iterator. */
private ObjectIterator<Long2DoubleMap.Entry> mapIterator =
edgeMap.long2DoubleEntrySet().fastIterator();
/** Representative edge object. */
private ReusableEdge<LongWritable, DoubleWritable> representativeEdge =
EdgeFactory.createReusable(new LongWritable(), new DoubleWritable());
@Override
public boolean hasNext() {
return mapIterator.hasNext();
}
@Override
public Edge<LongWritable, DoubleWritable> next() {
Long2DoubleMap.Entry nextEntry = mapIterator.next();
representativeEdge.getTargetVertexId().set(nextEntry.getLongKey());
representativeEdge.getValue().set(nextEntry.getDoubleValue());
return representativeEdge;
}
};
}
示例15: plusBy
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入依赖的package包/类
private TVector plusBy(SparseLongKeyDoubleVector other) {
ObjectIterator<Long2DoubleMap.Entry>
iter = other.getIndexToValueMap().long2DoubleEntrySet().fastIterator();
Long2DoubleMap.Entry entry = null;
while(iter.hasNext()) {
entry = iter.next();
plusBy(entry.getLongKey(), entry.getDoubleValue());
}
return this;
}