Search in sources :

Example 16 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class DefaultPropertiesTest method testHashCode.

@Test
public void testHashCode() {
    DefaultProperties props = new DefaultProperties(graphFactory());
    props.put("p1", new LongValue(1L));
    props.put("p2", new DoubleValue(2.0D));
    Assert.assertEquals(1073748897, props.hashCode());
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Example 17 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class DefaultPropertiesTest method testOverwrite.

@Test
public void testOverwrite() {
    DefaultProperties properties = new DefaultProperties(graphFactory());
    Assert.assertEquals(0, properties.get().size());
    properties.put("p1", new LongValue(1L));
    properties.put("p2", new DoubleValue(2.0D));
    Assert.assertEquals(new LongValue(1L), properties.get("p1"));
    properties.put("p1", new LongValue(2L));
    Assert.assertEquals(new LongValue(2L), properties.get("p1"));
    Map<String, Value> props = properties.get();
    Assert.assertEquals(2, props.size());
    Assert.assertEquals(new LongValue(2L), props.get("p1"));
    Assert.assertEquals(new DoubleValue(2.0D), props.get("p2"));
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Value(com.baidu.hugegraph.computer.core.graph.value.Value) Test(org.junit.Test)

Example 18 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class PageRank method init.

@Override
public void init(Config config) {
    this.alpha = config.getDouble(OPTION_ALPHA, ALPHA_DEFAULT_VALUE);
    this.contribValue = new DoubleValue();
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue)

Example 19 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class PageRank4Master method compute.

@Override
public boolean compute(MasterComputationContext context) {
    LongValue danglingVerticesNum = context.aggregatedValue(AGGR_DANGLING_VERTICES_NUM);
    DoubleValue danglingProbability = context.aggregatedValue(AGGR_COMULATIVE_DANGLING_PROBABILITY);
    DoubleValue cumulativeProbability = context.aggregatedValue(AGGR_COMULATIVE_PROBABILITY);
    DoubleValue l1NormDifference = context.aggregatedValue(AGGR_L1_NORM_DIFFERENCE_KEY);
    StringBuilder sb = new StringBuilder();
    sb.append("[Superstep ").append(context.superstep()).append("]").append(", dangling vertices num = ").append(danglingVerticesNum).append(", cumulative dangling probability = ").append(danglingProbability.value()).append(", cumulative probability = ").append(cumulativeProbability).append(", l1 norm difference = ").append(l1NormDifference.value());
    LOG.info("PageRank running status: {}", sb);
    double l1Diff = l1NormDifference.value();
    if (context.superstep() > 1 && l1Diff <= this.l1DiffThreshold) {
        return false;
    } else {
        return true;
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue)

Example 20 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class ClosenessCentrality method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    // Set empty map as initial value
    vertex.value(new ClosenessValue());
    // Send messages to adjacent edges
    for (Edge edge : vertex.edges()) {
        Id senderId = vertex.id();
        // Get property value
        double value = this.weightValue(edge.property(this.weightProp));
        DoubleValue distance = new DoubleValue(value);
        ClosenessMessage message = new ClosenessMessage(senderId, senderId, distance);
        context.sendMessage(edge.targetId(), message);
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Aggregations

DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)49 Test (org.junit.Test)28 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)21 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)14 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)13 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)12 Id (com.baidu.hugegraph.computer.core.graph.id.Id)10 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)8 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)6 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 DefaultEdge (com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge)2 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)2 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 File (java.io.File)2