本文整理汇总了Java中it.unimi.dsi.fastutil.longs.Long2DoubleMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java Long2DoubleMap.put方法的具体用法?Java Long2DoubleMap.put怎么用?Java Long2DoubleMap.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.longs.Long2DoubleMap
的用法示例。
在下文中一共展示了Long2DoubleMap.put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: seedLeftSideForFirstIteration
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入方法依赖的package包/类
@VisibleForTesting
protected void seedLeftSideForFirstIteration() {
long queryNode = salsaInternalState.getSalsaRequest().getQueryNode();
salsaStats.setNumDirectNeighbors(
salsaInternalState.getBipartiteGraph().getLeftNodeDegree(queryNode));
Long2DoubleMap seedNodesWithWeight =
salsaInternalState.getSalsaRequest().getLeftSeedNodesWithWeight();
LongSet nonZeroSeedSet = salsaInternalState.getNonZeroSeedSet();
double totalWeight = 0.0;
for (Long2DoubleMap.Entry entry : seedNodesWithWeight.long2DoubleEntrySet()) {
if (salsaInternalState.getBipartiteGraph().getLeftNodeDegree(entry.getLongKey())
> 0) {
totalWeight += entry.getDoubleValue();
nonZeroSeedSet.add(entry.getLongKey());
}
}
// If there is a pre-specified weight, we let it take precedence, but if not, then we reset
// weights in accordance with the fraction of weight requested for the query node.
if (!seedNodesWithWeight.containsKey(queryNode)
&& salsaInternalState.getBipartiteGraph().getLeftNodeDegree(queryNode) > 0) {
double queryNodeWeight = 1.0;
if (totalWeight > 0.0) {
queryNodeWeight =
totalWeight * salsaInternalState.getSalsaRequest().getQueryNodeWeightFraction()
/ (1.0 - salsaInternalState.getSalsaRequest().getQueryNodeWeightFraction());
}
seedNodesWithWeight.put(queryNode, queryNodeWeight);
totalWeight += queryNodeWeight;
nonZeroSeedSet.add(queryNode);
}
for (long leftNode : nonZeroSeedSet) {
int numWalksToStart = (int) Math.ceil(
seedNodesWithWeight.get(leftNode) / totalWeight
* salsaInternalState.getSalsaRequest().getNumRandomWalks());
salsaInternalState.getCurrentLeftNodes().put(leftNode, numWalksToStart);
}
salsaStats.setNumSeedNodes(salsaInternalState.getCurrentLeftNodes().size());
}
示例2: setUp
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入方法依赖的package包/类
@Before
public void setUp() {
long queryNode = 1;
BipartiteGraph bipartiteGraph = BipartiteGraphTestHelper.buildSmallTestBipartiteGraph();
Long2DoubleMap seedSetWeights = new Long2DoubleOpenHashMap(3);
seedSetWeights.put(2, 10.0);
seedSetWeights.put(3, 1.0);
LongSet toBeFiltered = new LongOpenHashSet(new long[]{8});
int numIterations = 5;
double resetProbability = 0.3;
int numResults = 3;
int numRandomWalks = 1000;
int maxSocialProofSize = 2;
double queryNodeWeightFraction = 0.9;
int expectedNodesToHit = numRandomWalks * numIterations / 2;
random = new Random(541454153145614L);
socialProofTypes = new byte[]{0, 1};
SalsaStats salsaStats = new SalsaStats();
ResultFilterChain resultFilterChain = new ResultFilterChain(Lists.newArrayList(
new RequestedSetFilter(new NullStatsReceiver()),
new DirectInteractionsFilter(bipartiteGraph, new NullStatsReceiver())
));
salsaRequest =
new SalsaRequestBuilder(queryNode)
.withLeftSeedNodes(seedSetWeights)
.withToBeFiltered(toBeFiltered)
.withMaxNumResults(numResults)
.withResetProbability(resetProbability)
.withMaxRandomWalkLength(numIterations)
.withNumRandomWalks(numRandomWalks)
.withMaxSocialProofSize(maxSocialProofSize)
.withValidSocialProofTypes(socialProofTypes)
.withQueryNodeWeightFraction(queryNodeWeightFraction)
.withResultFilterChain(resultFilterChain)
.build();
salsaInternalState = new SalsaInternalState(
bipartiteGraph, salsaStats, expectedNodesToHit);
salsaInternalState.resetWithRequest(salsaRequest);
salsaRequestSmallSeed =
new SalsaRequestBuilder(queryNode)
// This seed set should be ignored
.withLeftSeedNodes(new Long2DoubleOpenHashMap(new long[]{5}, new double[]{1.0}))
.withToBeFiltered(toBeFiltered)
.withMaxNumResults(numResults)
.withResetProbability(resetProbability)
.withMaxRandomWalkLength(numIterations)
.withNumRandomWalks(numRandomWalks)
.withMaxSocialProofSize(maxSocialProofSize)
.withValidSocialProofTypes(new byte[]{0, 1})
.withQueryNodeWeightFraction(queryNodeWeightFraction)
.withResultFilterChain(resultFilterChain)
.build();
salsaInternalStateSmallSeed = new SalsaInternalState(
bipartiteGraph, salsaStats, expectedNodesToHit);
salsaInternalStateSmallSeed.resetWithRequest(salsaRequestSmallSeed);
}
示例3: testRandomMultiGraphNeighborsWithGraph
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入方法依赖的package包/类
@Test
public void testRandomMultiGraphNeighborsWithGraph() throws Exception {
BipartiteGraph bipartiteGraph = BipartiteGraphTestHelper.buildSmallTestBipartiteGraphSegment();
int maxNumNeighbors = 1000;
int maxNumResults = 3;
long randomSeed = 5298057403198457L;
Long2DoubleMap leftSeedNodesWithWeight = new Long2DoubleOpenHashMap(3);
leftSeedNodesWithWeight.put(1, 0.4);
leftSeedNodesWithWeight.put(2, 0.3);
leftSeedNodesWithWeight.put(3, 0.3);
RandomMultiGraphNeighborsRequest neighborRequest = new RandomMultiGraphNeighborsRequest(
leftSeedNodesWithWeight,
maxNumNeighbors,
maxNumResults);
final List<NeighborInfo> expectedResults =
Lists.newArrayList(
new NeighborInfo(5, 0.206, 3),
new NeighborInfo(2, 0.155, 2),
new NeighborInfo(10, 0.117, 2)
);
// Should be in sorted order of weight
RandomMultiGraphNeighbors randomMultiGraphNeighbors = new RandomMultiGraphNeighbors(
bipartiteGraph,
new NullStatsReceiver());
Random random = new Random(randomSeed);
RandomMultiGraphNeighborsResponse neighborResponse =
randomMultiGraphNeighbors.getRandomMultiGraphNeighbors(neighborRequest, random);
List<NeighborInfo> results =
Lists.newArrayList(neighborResponse.getNeighborNodes());
assertEquals(expectedResults, results);
final List<NeighborInfo> expectedFilteredResults =
Lists.newArrayList(
new NeighborInfo(5, 0.189, 3)
);
// also check whether minimum result degree filter is enforced
MinEngagementFilter minEngagementFilter = new MinEngagementFilter(3, bipartiteGraph,
new NullStatsReceiver());
ArrayList<RelatedTweetFilter> filters = new ArrayList<RelatedTweetFilter>(1);
filters.add(minEngagementFilter);
RelatedTweetFilterChain filterChain = new RelatedTweetFilterChain(filters);
RandomMultiGraphNeighborsResponse filteredResponse =
randomMultiGraphNeighbors.getRandomMultiGraphNeighbors(
neighborRequest, random, filterChain);
List<NeighborInfo> filteredResults =
Lists.newArrayList(filteredResponse.getNeighborNodes());
assertEquals(expectedFilteredResults, filteredResults);
}
示例4: testRandomMultiGraphNeighborsWithLargeGraph
import it.unimi.dsi.fastutil.longs.Long2DoubleMap; //导入方法依赖的package包/类
@Test
public void testRandomMultiGraphNeighborsWithLargeGraph() throws Exception {
int maxNumNeighbors = 100000;
int maxNumResults = 3;
int leftSize = 100;
int rightSize = 1000;
double edgeProbability = 0.3;
long randomSeed = 5298057403198457L;
Random random = new Random(randomSeed);
BipartiteGraph bipartiteGraph = BipartiteGraphTestHelper.buildRandomBipartiteGraph(
leftSize, rightSize, edgeProbability, random);
Long2DoubleMap leftSeedNodesWithWeight = new Long2DoubleOpenHashMap(3);
leftSeedNodesWithWeight.put(1, 0.4);
leftSeedNodesWithWeight.put(2, 0.3);
leftSeedNodesWithWeight.put(3, 0.2);
leftSeedNodesWithWeight.put(4, 0.1);
RandomMultiGraphNeighborsRequest neighborRequest = new RandomMultiGraphNeighborsRequest(
leftSeedNodesWithWeight,
maxNumNeighbors,
maxNumResults);
final List<NeighborInfo> expectedResults =
Lists.newArrayList(
new NeighborInfo(87, 0.00351, 32),
new NeighborInfo(157, 0.0033, 26),
new NeighborInfo(620, 0.00328, 30)
);
// Should be in sorted order of weight
RandomMultiGraphNeighbors randomMultiGraphNeighbors = new RandomMultiGraphNeighbors(
bipartiteGraph,
new NullStatsReceiver());
RandomMultiGraphNeighborsResponse neighborResponse =
randomMultiGraphNeighbors.getRandomMultiGraphNeighbors(neighborRequest, random);
List<NeighborInfo> results =
Lists.newArrayList(neighborResponse.getNeighborNodes());
assertEquals(expectedResults, results);
final List<NeighborInfo> expectedFilteredResults =
Lists.newArrayList(
new NeighborInfo(927, 0.00183, 45)
);
// also check whether minimum result degree filter is enforced
MinEngagementFilter minEngagementFilter = new MinEngagementFilter(45, bipartiteGraph,
new NullStatsReceiver());
ArrayList<RelatedTweetFilter> filters = new ArrayList<RelatedTweetFilter>(1);
filters.add(minEngagementFilter);
RelatedTweetFilterChain filterChain = new RelatedTweetFilterChain(filters);
RandomMultiGraphNeighborsResponse filteredResponse =
randomMultiGraphNeighbors.getRandomMultiGraphNeighbors(
neighborRequest, random, filterChain);
List<NeighborInfo> filteredResults =
Lists.newArrayList(filteredResponse.getNeighborNodes());
assertEquals(expectedFilteredResults, filteredResults);
}