Search in sources :

Example 6 with DoublesUnion

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

the class DoublesUnionAggregatorTest method testCloneOfBusySketch.

@Test
public void testCloneOfBusySketch() {
    final DoublesUnionAggregator unionAggregator = new DoublesUnionAggregator();
    unionAggregator.init();
    for (int i = 0; i < 100; i++) {
        final DoublesUnion union = DoublesUnion.builder().build();
        for (int j = 0; j < 100; j++) {
            union.update(Math.random());
        }
        unionAggregator._aggregate(union);
    }
    final DoublesUnionAggregator clone = unionAggregator.statelessClone();
    assertNotSame(unionAggregator, clone);
    clone._aggregate(union1);
    assertEquals(union1.getResult().getQuantile(0.5D), ((DoublesUnion) clone.state()[0]).getResult().getQuantile(0.5D), DELTA);
}
Also used : DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Example 7 with DoublesUnion

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

the class DoublesUnionSerialiserTest method testSerialiser.

private void testSerialiser(final DoublesUnion union) {
    final double quantile1 = union.getResult().getQuantile(0.5D);
    final byte[] unionSerialised;
    try {
        unionSerialised = SERIALISER.serialise(union);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    final DoublesUnion unionDeserialised;
    try {
        unionDeserialised = SERIALISER.deserialise(unionSerialised);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    assertEquals(quantile1, unionDeserialised.getResult().getQuantile(0.5D), DELTA);
}
Also used : DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException)

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