Example usage for org.apache.hadoop.io DoubleWritable DoubleWritable

List of usage examples for org.apache.hadoop.io DoubleWritable DoubleWritable

Introduction

In this page you can find the example usage for org.apache.hadoop.io DoubleWritable DoubleWritable.

Prototype

public DoubleWritable(double value) 

Source Link

Usage

From source file:ml.grafos.okapi.clustering.ap.AffinityPropagation.java

License:Apache License

private void initColumns(Vertex<APVertexID, APVertexValue, DoubleWritable> vertex,
        Iterable<APMessage> messages) {
    if (vertex.getId().type == APVertexType.I) {
        final long nVertices = getTotalNumVertices();
        for (int i = 1; i <= nVertices; i++) {
            APVertexID neighbor = new APVertexID(APVertexType.E, i);
            vertex.getValue().lastSentMessages.put(neighbor, new DoubleWritable(0));
            vertex.getValue().lastReceivedMessages.put(neighbor, new DoubleWritable(0));
            sendMessage(neighbor, new APMessage(vertex.getId(), 0));
            logger.trace("Init columns:{} -> {} : {}", vertex.getId(), neighbor, 0);
        }//w w  w .ja va2  s  .c  om
    }

    for (APMessage message : messages) {
        APVertexID neighbor = new APVertexID(message.from);
        vertex.getValue().lastSentMessages.put(neighbor, new DoubleWritable(0));
        sendMessage(neighbor, new APMessage(vertex.getId(), 0));
        logger.debug("Init columns:{} -> {} : {}", vertex.getId(), neighbor, 0);
    }
}

From source file:ml.grafos.okapi.common.graphs.TestSortedOutEdges.java

License:Apache License

@Test
public void testParallelEdges() {
    OutEdges<LongWritable, DoubleWritable> edges = instantiateOutEdges(SortedOutEdges.class);

    // Initial edges list contains parallel edges.
    List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
            EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
            EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
            EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
            EdgeFactory.create(new LongWritable(2), new DoubleWritable(20)));

    edges.initialize(initialEdges);// w w  w  .  j  a  v a2  s .  c  om

    // Only one of the two parallel edges should be left.
    assertEquals(3, edges.size());

    // Adding a parallel edge shouldn't change the number of edges.
    edges.add(EdgeFactory.create(new LongWritable(3), new DoubleWritable(30)));
    assertEquals(3, edges.size());
}

From source file:ml.grafos.okapi.common.graphs.TestSortedOutEdges.java

License:Apache License

@Test
public void testSortOrder() {
    OutEdges<LongWritable, DoubleWritable> edges = instantiateOutEdges(SortedOutEdges.class);

    List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
            EdgeFactory.create(new LongWritable(1), new DoubleWritable(3.0)),
            EdgeFactory.create(new LongWritable(2), new DoubleWritable(4.5)),
            EdgeFactory.create(new LongWritable(3), new DoubleWritable(1.0)),
            EdgeFactory.create(new LongWritable(4), new DoubleWritable(-2.0)));

    edges.initialize(initialEdges);/*from ww  w .ja  v  a2  s .  c  o m*/

    // edges should be ordered by value
    List<LongWritable> ids = new ArrayList<LongWritable>();
    for (Edge<LongWritable, DoubleWritable> edge : edges) {
        ids.add(edge.getTargetVertexId());
    }

    assertEquals(4, ids.get(0).get());
    assertEquals(3, ids.get(1).get());
    assertEquals(1, ids.get(2).get());
    assertEquals(2, ids.get(3).get());

}

From source file:ml.grafos.okapi.common.graphs.TestSortedOutEdges.java

License:Apache License

@Test
public void testGetValue() {
    OutEdges<LongWritable, DoubleWritable> edges = instantiateOutEdges(SortedOutEdges.class);

    List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
            EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
            EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
            EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
            EdgeFactory.create(new LongWritable(4), new DoubleWritable(4)));

    edges.initialize(initialEdges);// w w w .  ja  v  a2  s .co m

    // test edge.getValue
    List<DoubleWritable> values = new ArrayList<DoubleWritable>();
    for (Edge<LongWritable, DoubleWritable> edge : edges) {
        values.add(edge.getValue());
    }

    assertEquals(1, values.get(0).get(), E);
    assertEquals(2, values.get(1).get(), E);
    assertEquals(3, values.get(2).get(), E);
    assertEquals(4, values.get(3).get(), E);

}

From source file:ml.grafos.okapi.common.graphs.TestSortedOutEdges.java

License:Apache License

@Test
public void testAddRemove() {
    OutEdges<LongWritable, DoubleWritable> edges = instantiateOutEdges(SortedOutEdges.class);

    List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
            EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
            EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
            EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
            EdgeFactory.create(new LongWritable(4), new DoubleWritable(4)));

    edges.initialize(initialEdges);//from ww  w .  j av  a  2s  .  com

    // test add
    edges.add(EdgeFactory.create(new LongWritable(5), new DoubleWritable(5)));
    assertEquals(5, edges.size());

    // test remove
    LongWritable vertexID = edges.iterator().next().getTargetVertexId();
    edges.remove(vertexID);
    assertEquals(4, edges.size());

}

From source file:ml.grafos.okapi.common.graphs.TestSortedOutEdges.java

License:Apache License

@Test
public void testSerialize() {
    OutEdges<LongWritable, DoubleWritable> edges = instantiateOutEdges(SortedOutEdges.class);

    List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
            EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
            EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
            EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
            EdgeFactory.create(new LongWritable(4), new DoubleWritable(4)));

    edges.initialize(initialEdges);//from   w ww.jav a  2  s  .  co m

    // Serialize from
    byte[] data = WritableUtils.writeToByteArray(edges, edges);

    // De-serialize to
    OutEdges<LongWritable, DoubleWritable> to1 = instantiateOutEdges(SortedOutEdges.class);
    OutEdges<LongWritable, DoubleWritable> to2 = instantiateOutEdges(SortedOutEdges.class);

    WritableUtils.readFieldsFromByteArray(data, to1, to2);

    // all coordinates should be equal
    List<Edge<LongWritable, DoubleWritable>> to1Edges = new ArrayList<Edge<LongWritable, DoubleWritable>>();
    for (Edge<LongWritable, DoubleWritable> e : to1) {
        to1Edges.add(e);
    }

    List<Edge<LongWritable, DoubleWritable>> to2Edges = new ArrayList<Edge<LongWritable, DoubleWritable>>();
    for (Edge<LongWritable, DoubleWritable> e : to2) {
        to2Edges.add(e);
    }

    assertEquals(edges.size(), to1.size());
    assertEquals(edges.size(), to2.size());

    for (int i = 0; i > edges.size(); i++) {
        assertEquals(to1Edges.get(i).getTargetVertexId(), to2Edges.get(i).getTargetVertexId());
        assertEquals(to1Edges.get(i).getValue(), to2Edges.get(i).getValue());
    }
}

From source file:ml.shifu.shifu.core.posttrain.FeatureImportanceReducer.java

License:Apache License

@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
    List<FeatureScore> featureScores = new ArrayList<FeatureImportanceReducer.FeatureScore>();
    for (Entry<Integer, Double> entry : variableStatsMap.entrySet()) {
        featureScores.add(new FeatureScore(entry.getKey(), entry.getValue()));
    }//from   www  .j  av a 2 s .com

    Collections.sort(featureScores, new Comparator<FeatureScore>() {
        @Override
        public int compare(FeatureScore fs1, FeatureScore fs2) {
            if (fs1.binAvgScore < fs2.binAvgScore) {
                return 1;
            }
            if (fs1.binAvgScore > fs2.binAvgScore) {
                return -1;
            }

            return 0;
        }
    });

    for (FeatureScore featureScore : featureScores) {
        context.write(new IntWritable(featureScore.columnNum), new DoubleWritable(featureScore.binAvgScore));
    }
}

From source file:mx.iteso.desi.cloud.GeocodeWritable.java

License:Apache License

public GeocodeWritable() {
    set(new Text(), new DoubleWritable(0), new DoubleWritable(0));
}

From source file:mx.iteso.desi.cloud.GeocodeWritable.java

License:Apache License

public GeocodeWritable(String name, double lat, double lon) {
    set(new Text(name), new DoubleWritable(lat), new DoubleWritable(lon));
}

From source file:mx.iteso.desi.cloud.GeocodeWritable.java

License:Apache License

public GeocodeWritable(Geocode g) {
    set(new Text(g.getName()), new DoubleWritable(g.getLatitude()), new DoubleWritable(g.getLongitude()));
}