Package com.inadco.hbl.math.aggregators

Examples of com.inadco.hbl.math.aggregators.OnlineCannyAvgSummarizer


    }

    static OnlineCannyAvgSummarizer createCannyAvgSum(Properties props, boolean bareInstance) {
        if (bareInstance)
            return new OnlineCannyAvgSummarizer();

        double dt;
        double m = OnlineCannyAvgSummarizer.DEFAULT_MARGIN;
        double k = OnlineCannyAvgSummarizer.DEFAULT_K;

        if (props.containsKey("m"))
            m = Double.parseDouble(props.getProperty("m"));
        if (props.containsKey("k"))
            k = Double.parseDouble(props.getProperty("k"));

        Validate.isTrue(props.containsKey("dt"), "dt parameter is required for exp avg summarizer");
        dt = Double.parseDouble(props.getProperty("dt"));

        return new OnlineCannyAvgSummarizer(dt, m, k);

    }
View Full Code Here


    private final double PREC = 1E-10;

    @Test
    public void testCannyAvg1() {
        OnlineCannyAvgSummarizer sum = new OnlineCannyAvgSummarizer(5d), sum1 = new OnlineCannyAvgSummarizer(5d), sum2 =
            new OnlineCannyAvgSummarizer(5d);

        sum.update(1, 1);
        sum1.update(1, 1);

        Assert.assertTrue(Math.abs(sum.getValue() - 1d) < PREC);
        Assert.assertTrue(Math.abs(sum.getValueNow(5d) - 1d) < PREC);

        sum.update(4, 2);
        sum2.update(4, 2);

        Assert.assertTrue(Math.abs(sum.getValue() - sum.getValueNow(5d)) < PREC);

        OnlineCannyAvgSummarizer combined = IOUtil.tryClone(sum1);
        combined.combine(sum2);
        OnlineCannyAvgSummarizer compl1 = IOUtil.tryClone(sum);
        compl1.complement(sum1, false);
        OnlineCannyAvgSummarizer compl2 = IOUtil.tryClone(sum);
        compl2.complement(sum2, false);

        Assert.assertTrue(Math.abs(sum.getValue() - combined.getValue()) < PREC);
        Assert.assertTrue(Math.abs(sum1.getValue() - compl2.getValue()) < PREC);
        Assert.assertTrue(Math.abs(sum2.getValue() - compl1.getValue()) < PREC);
    }
View Full Code Here

     * @param dt
     */
    public FCannyAvgSum(String name, int ordinal, double dt) {
        super(name, ordinal);
        // this.dt = dt;
        sumBuf = new OnlineCannyAvgSummarizer(dt);
        sumBuf1 = new OnlineCannyAvgSummarizer(dt);
    }
View Full Code Here

        double x = ((Number) fact).doubleValue();

        try {

            OnlineCannyAvgSummarizer s = super.extractState(result, sumBuf);
            if (s == null) {
                sumBuf.reset();
                s = sumBuf;
            }
            s.update(x, sample.getTime());

            super.saveState(result, sumBuf);
        } catch (IOException exc) {
            // should not happen .
            // otherwise, probably a bad practice.
View Full Code Here

    }

    @Override
    public void merge(Builder accumulator, Aggregation source, SliceOperation operation) {
        try {
            OnlineCannyAvgSummarizer s1 = super.extractState(accumulator, sumBuf);
            OnlineCannyAvgSummarizer s2 = super.extractState(source, sumBuf1);

            switch (operation) {
            case ADD:
                if (s1 != null && s2 != null)
                    s1.combine(s2);
View Full Code Here

            /*
             * since we don't have control over result object lifecycle in this
             * case, we'd rather create a new summarizer for each incoming
             * request.
             */
            return extractState(source, new OnlineCannyAvgSummarizer());
        } catch (IOException exc) {
            throw new RuntimeException(exc);
        }

    }
View Full Code Here

                closeables.addFirst(rs);
                while (rs.hasNext()) {
                    rs.next();
                    PreparedAggregateResult ar = (PreparedAggregateResult) rs.current();

                    OnlineCannyAvgSummarizer ctrSum = (OnlineCannyAvgSummarizer) ar.getObject("ctr");
                    double wctr = ctrSum == null ? 0 : ctrSum.getValue();

                    Double impSum = (Double) ar.getObject("impSum");
                    if (impSum == null)
                        impSum = new Double(0);
                    Double clickSum = (Double) ar.getObject("clickSum");
View Full Code Here

                    closeables.addFirst(rs);
                    while (rs.hasNext()) {
                        rs.next();
                        PreparedAggregateResult ar = (PreparedAggregateResult) rs.current();

                        OnlineCannyAvgSummarizer ctrSum = (OnlineCannyAvgSummarizer) ar.getObject("ctr");
                        Double wctr = ctrSum == null ? null : ctrSum.getValue();

                        Double impSum = (Double) ar.getObject("impSum");
                        if (impSum == null)
                            impSum = new Double(0);
                        Double clickSum = (Double) ar.getObject("clickSum");
View Full Code Here

                closeables.addFirst(rs);
                while (rs.hasNext()) {
                    rs.next();
                    PreparedAggregateResult ar = (PreparedAggregateResult) rs.current();

                    OnlineCannyAvgSummarizer ctrSum = (OnlineCannyAvgSummarizer) ar.getObject("ctr");
                    Double wctr = ctrSum == null ? null : ctrSum.getValue();

                    // sum has semantics of being NULL for sum of all NULLs
                    Double impSum = (Double) ar.getObject("impSum");
                    if (impSum == null)
                        impSum = new Double(0);
View Full Code Here

TOP

Related Classes of com.inadco.hbl.math.aggregators.OnlineCannyAvgSummarizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.