Search in sources :

Example 1 with DoublesUnion

use of com.yahoo.sketches.quantiles.DoublesUnion in project Gaffer by gchq.

the class DoublesUnionAggregatorTest method testEquals.

@Test
public void testEquals() {
    final DoublesUnion sketch1 = DoublesUnion.builder().build();
    sketch1.update(1.0D);
    final DoublesUnionAggregator sketchAggregator1 = new DoublesUnionAggregator();
    sketchAggregator1.aggregate(new DoublesUnion[] { sketch1 });
    final DoublesUnion sketch2 = DoublesUnion.builder().build();
    sketch2.update(1.0D);
    final DoublesUnionAggregator sketchAggregator2 = new DoublesUnionAggregator();
    sketchAggregator2.aggregate(new DoublesUnion[] { sketch2 });
    assertEquals(sketchAggregator1, sketchAggregator2);
    sketch2.update(2.0D);
    sketchAggregator2.aggregate(new DoublesUnion[] { sketch2 });
    assertNotEquals(sketchAggregator1, sketchAggregator2);
}
Also used : DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Example 2 with DoublesUnion

use of com.yahoo.sketches.quantiles.DoublesUnion in project Gaffer by gchq.

the class DoublesUnionSerialiserTest method testSerialiseAndDeserialise.

@Test
public void testSerialiseAndDeserialise() {
    final DoublesUnion union = DoublesUnion.builder().build();
    union.update(1.0D);
    union.update(2.0D);
    union.update(3.0D);
    testSerialiser(union);
    final DoublesUnion emptyUnion = DoublesUnion.builder().build();
    testSerialiser(emptyUnion);
}
Also used : DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) Test(org.junit.Test)

Example 3 with DoublesUnion

use of com.yahoo.sketches.quantiles.DoublesUnion in project Gaffer by gchq.

the class LoadAndQuery11 method run.

public Iterable<Entity> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] add the edges to the graph
    // ---------------------------------------------------------
    final Set<String> dummyData = Collections.singleton("");
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator11()).objects(dummyData).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    log("Added an edge A-B 1000 times, each time with a DoublesUnion containing a normally distributed" + " (mean 0, standard deviation 1) random double.");
    // [get] Get all edges
    // ---------------------------------------------------------
    Iterable<Edge> allEdges = graph.execute(new GetAllEdges(), user);
    // ---------------------------------------------------------
    log("\nAll edges:");
    for (final Edge edge : allEdges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get 0.25, 0.5, 0.75 percentiles] Get the edge A-B and print an estimate of the 0.25, 0.5 and 0.75 quantiles, i.e. the 25th, 50th and 75th percentiles
    // ---------------------------------------------------------
    final GetEdges<EdgeSeed> query = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
    final Iterable<Edge> edges = graph.execute(query, user);
    final Edge edge = edges.iterator().next();
    final DoublesUnion doublesUnion = (DoublesUnion) edge.getProperty("doublesUnion");
    final double[] quantiles = doublesUnion.getResult().getQuantiles(new double[] { 0.25D, 0.5D, 0.75D });
    final String quantilesEstimate = "Edge A-B with percentiles of double property - 25th percentile: " + quantiles[0] + ", 50th percentile: " + quantiles[1] + ", 75th percentile: " + quantiles[2];
    // ---------------------------------------------------------
    log("\nEdge A-B with an estimate of the median value");
    log("GET_0.25,0.5,0.75_PERCENTILES_FOR_EDGE_A_B", quantilesEstimate);
    // [get cdf] Get the edge A-B and print some values from the cumulative density function
    // ---------------------------------------------------------
    final GetEdges<EdgeSeed> query2 = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
    final Iterable<Edge> edges2 = graph.execute(query2, user);
    final Edge edge2 = edges2.iterator().next();
    final DoublesSketch doublesSketch2 = ((DoublesUnion) edge2.getProperty("doublesUnion")).getResult();
    final double[] cdf = doublesSketch2.getCDF(new double[] { 0.0D, 1.0D, 2.0D });
    final String cdfEstimate = "Edge A-B with CDF values at 0: " + cdf[0] + ", at 1: " + cdf[1] + ", at 2: " + cdf[2];
    // ---------------------------------------------------------
    log("\nEdge A-B with the cumulative density function values at 0, 1, 2");
    log("GET_CDF_FOR_EDGE_A_B_RESULT", cdfEstimate);
    return null;
}
Also used : DataGenerator11(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator11) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 4 with DoublesUnion

use of com.yahoo.sketches.quantiles.DoublesUnion in project Gaffer by gchq.

the class DataGenerator11 method getElements.

@Override
public Iterable<Element> getElements(final String line) {
    final Set<Element> elements = new HashSet<>();
    for (int i = 0; i < 1000; i++) {
        final DoublesUnion doublesUnion = DoublesUnion.builder().build();
        doublesUnion.update(RANDOM.nextGaussian());
        final Edge edge = new Edge.Builder().group("red").source("A").dest("B").property("doublesUnion", doublesUnion).build();
        elements.add(edge);
    }
    return elements;
}
Also used : DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) Element(uk.gov.gchq.gaffer.data.element.Element) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 5 with DoublesUnion

use of com.yahoo.sketches.quantiles.DoublesUnion in project Gaffer by gchq.

the class DoublesUnionSerialiser method deserialise.

@Override
public DoublesUnion deserialise(final byte[] bytes) throws SerialisationException {
    final DoublesUnion union = DoublesUnion.builder().build();
    union.update(new NativeMemory(bytes));
    return union;
}
Also used : NativeMemory(com.yahoo.memory.NativeMemory) DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion)

Aggregations

DoublesUnion (com.yahoo.sketches.quantiles.DoublesUnion)7 Test (org.junit.Test)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)2 NativeMemory (com.yahoo.memory.NativeMemory)1 DoublesSketch (com.yahoo.sketches.quantiles.DoublesSketch)1 HashSet (java.util.HashSet)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 DataGenerator11 (uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator11)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)1 User (uk.gov.gchq.gaffer.user.User)1