Java Code Examples for org.apache.flink.types.DoubleValue#getValue()

The following examples show how to use org.apache.flink.types.DoubleValue#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoubleValueArray.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean add(DoubleValue value) {
	int newPosition = position + 1;

	if (newPosition > data.length) {
		if (isBounded) {
			return false;
		} else {
			ensureCapacity(newPosition);
		}
	}

	data[position] = value.getValue();
	position = newPosition;

	return true;
}
 
Example 2
Source File: DoubleValueArray.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean add(DoubleValue value) {
	int newPosition = position + 1;

	if (newPosition > data.length) {
		if (isBounded) {
			return false;
		} else {
			ensureCapacity(newPosition);
		}
	}

	data[position] = value.getValue();
	position = newPosition;

	return true;
}
 
Example 3
Source File: ParallelVB.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isConverged(int iteration, DoubleValue value) {


    if (iteration==1)
        return false;

    iteration--;

    if (Double.isNaN(value.getValue()))
        throw new IllegalStateException("A NaN elbo");

    if (value.getValue()==Double.NEGATIVE_INFINITY)
        value.setValue(-Double.MAX_VALUE);

    double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

    DecimalFormat df = new DecimalFormat("0.0000");

    if (iteration==1) {
        previousELBO=value.getValue();
        logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                df.format((System.nanoTime() - start) / 1000000000.0));
        System.out.println("Global bound at first iteration: 1," + df.format(value.getValue())+ "," +
                df.format((System.nanoTime() - start) / 1000000000.0) + " seconds");

        return false;
    }else if (percentage<0 && percentage < -threshold){
        logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                percentage), df.format(value.getValue()), df.format(previousELBO));
        //throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
        //        df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));
        //System.out.println("Global bound is not monotonically increasing: "+ iteration +", "+ percentage +
        // ", "+ (value.getValue() +">" + previousELBO));
        //this.previousELBO=value.getValue();
        return false;
    }else if (percentage>0 && percentage>threshold) {
        logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                df.format((System.nanoTime() - start) / 1000000000.0));
        System.out.println("Global bound is monotonically increasing: "+ iteration +","+df.format(percentage)+
                "," + (df.format(value.getValue()) +">" + df.format(previousELBO))+ ","+
                df.format((System.nanoTime() - start) / 1000000000.0) + " seconds");
        this.previousELBO=value.getValue();
        return false;
    }else {
        logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));
        System.out.println("Global bound Convergence: "+ iteration +"," + df.format(percentage) + "," +
                df.format(value.getValue())+ "," + df.format((System.nanoTime() - start) / 1000000000.0) +
                " seconds");
        return true;
    }
}
 
Example 4
Source File: dVMPv1.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
        public boolean isConverged(int iteration, DoubleValue value) {


/*
            if (iteration==1)
                return false;

            iteration--;

            if (iteration%epochs!=0)
                return false;

            iteration= iteration/epochs;
*/
            if (Double.isNaN(value.getValue()))
                throw new IllegalStateException("A NaN elbo");

            if (value.getValue()==Double.NEGATIVE_INFINITY)
                value.setValue(-Double.MAX_VALUE);

            double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

            double timeIteration = (System.nanoTime() - start) / 1000000000.0;

            DecimalFormat df = new DecimalFormat("0.0000");

            if (iteration==1) {
                previousELBO=value.getValue();
                logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                        df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound at first iteration: 1," + value.getValue()+ "," +
                        ((System.nanoTime() - start) / 1000000000.0) + " seconds");
                return false;
            }else if (percentage<-1){
                logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                        percentage), df.format(value.getValue()), df.format(previousELBO));
                //throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
                //        df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));

                System.out.println("Global bound is not monotonically increasing: "+ iteration +","+percentage+
                        "," + (value.getValue()) +">" + previousELBO+ ","+
                        (System.nanoTime() - start) / 1000000000.0 + " seconds");
                this.previousELBO=value.getValue();
                return false;
            }else if (percentage>-1 && timeIteration < timeLimit) {
                logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                        df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                        df.format((System.nanoTime() - start) / 1000000000.0));

                System.out.println("Global bound is monotonically increasing: "+ iteration +","+percentage+
                        "," + (value.getValue()) +">" + previousELBO+ ","+
                        (System.nanoTime() - start) / 1000000000.0 + " seconds");

                this.previousELBO=value.getValue();
                return false;
            }else {
                logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                        df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));

                System.out.println("Global bound Convergence: "+ iteration +"," + percentage + "," +
                        value.getValue()+ "," + (System.nanoTime() - start) / 1000000000.0 +
                        " seconds");
                return true;
            }
        }
 
Example 5
Source File: DoubleSumAggregator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void aggregate(DoubleValue element) {
	sum += element.getValue();
}
 
Example 6
Source File: dVMP.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
        public boolean isConverged(int iteration, DoubleValue value) {

/*
            if (iteration==1)
                return false;

            iteration--;
*/
            if (Double.isNaN(value.getValue()))
                throw new IllegalStateException("A NaN elbo");

            if (value.getValue()==Double.NEGATIVE_INFINITY)
                value.setValue(-Double.MAX_VALUE);

            double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

            DecimalFormat df = new DecimalFormat("0.0000");

            if (iteration==1) {
                previousELBO=value.getValue();
                logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                        df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound at first iteration: 1," + df.format(value.getValue())+ "," +
                        df.format((System.nanoTime() - start) / 1000000000.0) + " seconds");

                return false;
            }else if (percentage<0 && percentage < -threshold){
                logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                        percentage), df.format(value.getValue()), df.format(previousELBO));
//                throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
//                        df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));
                System.out.println("Global bound is not monotonically increasing: "+ iteration +", "+ percentage +
                 ", "+ (value.getValue() +">" + previousELBO));
                this.previousELBO=value.getValue();
                return false;
            }else if (percentage>0 && percentage>threshold) {
                logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                        df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                        df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound is monotonically increasing: "+ iteration +","+df.format(percentage)+
                        "," + (df.format(value.getValue()) +">" + df.format(previousELBO))+ ","+
                        df.format((System.nanoTime() - start) / 1000000000.0) + " seconds");
                this.previousELBO=value.getValue();
                return false;
            }else {
                logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                        df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound Convergence: "+ iteration +"," + df.format(percentage) + "," +
                        df.format(value.getValue())+ "," + df.format((System.nanoTime() - start) / 1000000000.0) +
                        " seconds");
                return true;
            }
        }
 
Example 7
Source File: ValueSummaryAggregator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected Double getValue(DoubleValue value) {
	return value.getValue();
}
 
Example 8
Source File: SumAggregationFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void aggregate(DoubleValue value) {
	agg += value.getValue();
}
 
Example 9
Source File: PageRank.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isConverged(int iteration, DoubleValue value) {
	double val = value.getValue();
	return (val <= convergenceThreshold);
}
 
Example 10
Source File: DistributedVI.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isConverged(int iteration, DoubleValue value) {


    if (iteration==1)
        return false;

    iteration--;

    if (Double.isNaN(value.getValue()))
        throw new IllegalStateException("A NaN elbo");

    if (value.getValue()==Double.NEGATIVE_INFINITY)
        value.setValue(-Double.MAX_VALUE);

    double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

    double timeIteration = (System.nanoTime() - start) / 1000000000.0;

    DecimalFormat df = new DecimalFormat("0.0000");

    if (iteration==1) {
        previousELBO=value.getValue();
        logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                df.format((System.nanoTime() - start) / 1000000000.0));
        System.out.println("Global bound at first iteration: 1," + value.getValue()+ "," +
                ((System.nanoTime() - start) / 1000000000.0) + " seconds");
        return false;
    }else if (percentage<-1){
        logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                percentage), df.format(value.getValue()), df.format(previousELBO));
        throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
                df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));
    }else if (percentage>-1 && timeIteration < timeLimit) {
        logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                df.format((System.nanoTime() - start) / 1000000000.0));

        System.out.println("Global bound is monotonically increasing: "+ iteration +","+percentage+
                "," + (value.getValue()) +">" + previousELBO+ ","+
                (System.nanoTime() - start) / 1000000000.0 + " seconds");

        this.previousELBO=value.getValue();
        return false;
    }else {
        logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));

        System.out.println("Global bound Convergence: "+ iteration +"," + percentage + "," +
                value.getValue()+ "," + (System.nanoTime() - start) / 1000000000.0 +
                " seconds");
        return true;
    }
}
 
Example 11
Source File: ParallelVB.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isConverged(int iteration, DoubleValue value) {


    if (iteration==1)
        return false;

    iteration--;

    if (Double.isNaN(value.getValue()))
        throw new IllegalStateException("A NaN elbo");

    if (value.getValue()==Double.NEGATIVE_INFINITY)
        value.setValue(-Double.MAX_VALUE);

    double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

    double timeIteration = (System.nanoTime() - start) / 1000000000.0;

    DecimalFormat df = new DecimalFormat("0.0000");

    if (iteration==1) {
        previousELBO=value.getValue();
        logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                df.format((System.nanoTime() - start) / 1000000000.0));
        System.out.println("Global bound at first iteration: 1," + value.getValue()+ "," +
                ((System.nanoTime() - start) / 1000000000.0) + " seconds");
        return false;
    }else if (percentage<-1){
        logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                percentage), df.format(value.getValue()), df.format(previousELBO));
        System.out.println("Global bound is not monotonically increasing: "+ iteration +","+percentage+
                "," + (value.getValue()) +">" + previousELBO+ ","+
                (System.nanoTime() - start) / 1000000000.0 + " seconds");
        //throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
        //        df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));
        return false;
    }else if (percentage>-1 && timeIteration < timeLimit) {
        logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                df.format((System.nanoTime() - start) / 1000000000.0));

        System.out.println("Global bound is monotonically increasing: "+ iteration +","+percentage+
                "," + (value.getValue()) +">" + previousELBO+ ","+
                (System.nanoTime() - start) / 1000000000.0 + " seconds");

        this.previousELBO=value.getValue();
        return false;
    }else {
        logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));

        System.out.println("Global bound Convergence: "+ iteration +"," + percentage + "," +
                value.getValue()+ "," + (System.nanoTime() - start) / 1000000000.0 +
                " seconds");
        return true;
    }
}
 
Example 12
Source File: ValueSummaryAggregator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected Double getValue(DoubleValue value) {
	return value.getValue();
}
 
Example 13
Source File: SumAggregationFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void aggregate(DoubleValue value) {
	agg += value.getValue();
}
 
Example 14
Source File: dVMPv1.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
        public boolean isConverged(int iteration, DoubleValue value) {

/*
            if (iteration==1)
                return false;

            iteration--;
*/
            if (Double.isNaN(value.getValue()))
                throw new IllegalStateException("A NaN elbo");

            if (value.getValue()==Double.NEGATIVE_INFINITY)
                value.setValue(-Double.MAX_VALUE);

            double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

            DecimalFormat df = new DecimalFormat("0.0000");

            if (iteration==1) {
                previousELBO=value.getValue();
                logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                        df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound at first iteration: 1," + df.format(value.getValue())+ "," +
                        df.format((System.nanoTime() - start) / 1000000000.0) + " seconds");

                return false;
            }else if (percentage<0 && percentage < -threshold){
                logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                        percentage), df.format(value.getValue()), df.format(previousELBO));
                throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
                        df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));
                //System.out.println("Global bound is not monotonically increasing: "+ iteration +", "+ percentage +
                // ", "+ (value.getValue() +">" + previousELBO));
                //this.previousELBO=value.getValue();
                //return false;
            }else if (percentage>0 && percentage>threshold) {
                logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                        df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                        df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound is monotonically increasing: "+ iteration +","+df.format(percentage)+
                        "," + (df.format(value.getValue()) +">" + df.format(previousELBO))+ ","+
                        df.format((System.nanoTime() - start) / 1000000000.0) + " seconds");
                this.previousELBO=value.getValue();
                return false;
            }else {
                logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                        df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound Convergence: "+ iteration +"," + df.format(percentage) + "," +
                        df.format(value.getValue())+ "," + df.format((System.nanoTime() - start) / 1000000000.0) +
                        " seconds");
                return true;
            }
        }
 
Example 15
Source File: HITS.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isConverged(int iteration, DoubleValue value) {
	double val = value.getValue();
	return (0 <= val && val <= convergenceThreshold);
}
 
Example 16
Source File: dVMP.java    From toolbox with Apache License 2.0 4 votes vote down vote up
@Override
        public boolean isConverged(int iteration, DoubleValue value) {

/*
            if (iteration==1)
                return false;

            iteration--;
*/
            if (Double.isNaN(value.getValue()))
                throw new IllegalStateException("A NaN elbo");

            if (value.getValue()==Double.NEGATIVE_INFINITY)
                value.setValue(-Double.MAX_VALUE);

            double percentage = 100*(value.getValue() - previousELBO)/Math.abs(previousELBO);

            double timeIteration = (System.nanoTime() - start) / 1000000000.0;

            DecimalFormat df = new DecimalFormat("0.0000");

            if (iteration==1) {
                previousELBO=value.getValue();
                logger.info("Global bound at first iteration: 1,{},{} seconds",df.format(value.getValue()),
                        df.format((System.nanoTime() - start) / 1000000000.0));
                System.out.println("Global bound at first iteration: 1," + value.getValue()+ "," +
                        ((System.nanoTime() - start) / 1000000000.0) + " seconds");
                return false;
            }else if (percentage<-1){
                logger.info("Global bound is not monotonically increasing: {},{},{}<{}",iteration, df.format(
                        percentage), df.format(value.getValue()), df.format(previousELBO));
                //throw new IllegalStateException("Global bound is not monotonically increasing: "+ iteration +","+
                //        df.format(percentage) +"," + df.format(value.getValue()) +" < " + df.format(previousELBO));

                System.out.println("Global bound is not monotonically increasing: "+ iteration +","+percentage+
                        "," + (value.getValue()) +">" + previousELBO+ ","+
                        (System.nanoTime() - start) / 1000000000.0 + " seconds");
                this.previousELBO=value.getValue();
                return false;
            }else if (percentage>-1 && timeIteration < timeLimit) {
                logger.info("Global bound is monotonically increasing: {},{},{}>{},{} seconds",iteration,
                        df.format(percentage), df.format(value.getValue()), df.format(previousELBO),
                        df.format((System.nanoTime() - start) / 1000000000.0));

                System.out.println("Global bound is monotonically increasing: "+ iteration +","+percentage+
                        "," + (value.getValue()) +">" + previousELBO+ ","+
                        (System.nanoTime() - start) / 1000000000.0 + " seconds");

                this.previousELBO=value.getValue();
                return false;
            }else {
                logger.info("Global bound Convergence: {},{},{},{} seconds",iteration,df.format(percentage),
                        df.format(value.getValue()), df.format((System.nanoTime() - start) / 1000000000.0));

                System.out.println("Global bound Convergence: "+ iteration +"," + percentage + "," +
                        value.getValue()+ "," + (System.nanoTime() - start) / 1000000000.0 +
                        " seconds");
                return true;
            }
        }
 
Example 17
Source File: DoubleSumAggregator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void aggregate(DoubleValue element) {
	sum += element.getValue();
}
 
Example 18
Source File: ValueSummaryAggregator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected Double getValue(DoubleValue value) {
	return value.getValue();
}
 
Example 19
Source File: DoubleZeroConvergence.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true, if the aggregator value is zero, false otherwise.
 * 
 * @param iteration The number of the iteration superstep. Ignored in this case.
 * @param value The aggregator value, which is compared to zero.
 * @return True, if the aggregator value is zero, false otherwise.
 */
@Override
public boolean isConverged(int iteration, DoubleValue value) {
	return value.getValue() == 0;
}
 
Example 20
Source File: DoubleZeroConvergence.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true, if the aggregator value is zero, false otherwise.
 * 
 * @param iteration The number of the iteration superstep. Ignored in this case.
 * @param value The aggregator value, which is compared to zero.
 * @return True, if the aggregator value is zero, false otherwise.
 */
@Override
public boolean isConverged(int iteration, DoubleValue value) {
	return value.getValue() == 0;
}