Search in sources :

Example 1 with SquareCalculus

use of org.apache.apex.malhar.lib.math.SquareCalculus in project apex-malhar by apache.

the class Calculator method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    /* keep generating random values between 0 and 30000 */
    RandomEventGenerator xyGenerator = dag.addOperator("GenerateX", RandomEventGenerator.class);
    /* calculate square of each of the values it receives */
    SquareCalculus squareOperator = dag.addOperator("SquareX", SquareCalculus.class);
    /* pair the consecutive values */
    AbstractAggregator<Integer> pairOperator = dag.addOperator("PairXY", new ArrayListAggregator<Integer>());
    Sigma<Integer> sumOperator = dag.addOperator("SumXY", new Sigma<Integer>());
    LogicalCompareToConstant<Integer> comparator = dag.addOperator("AnalyzeLocation", new LogicalCompareToConstant<Integer>());
    comparator.setConstant(30000 * 30000);
    Counter inCircle = dag.addOperator("CountInCircle", Counter.class);
    Counter inSquare = dag.addOperator("CountInSquare", Counter.class);
    Division division = dag.addOperator("Ratio", Division.class);
    MultiplyByConstant multiplication = dag.addOperator("InstantPI", MultiplyByConstant.class);
    multiplication.setMultiplier(4);
    RunningAverage average = dag.addOperator("AveragePI", new RunningAverage());
    ConsoleOutputOperator oper = dag.addOperator("Console", new ConsoleOutputOperator());
    dag.addStream("x", xyGenerator.integer_data, squareOperator.input);
    dag.addStream("sqr", squareOperator.integerResult, pairOperator.input);
    dag.addStream("x2andy2", pairOperator.output, sumOperator.input);
    dag.addStream("x2plusy2", sumOperator.integerResult, comparator.input, inSquare.input);
    dag.addStream("inCirclePoints", comparator.greaterThan, inCircle.input);
    dag.addStream("numerator", inCircle.output, division.numerator);
    dag.addStream("denominator", inSquare.output, division.denominator);
    dag.addStream("ratio", division.doubleQuotient, multiplication.input);
    dag.addStream("instantPi", multiplication.doubleProduct, average.input);
    dag.addStream("averagePi", average.doubleAverage, oper.input);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) RunningAverage(org.apache.apex.malhar.lib.math.RunningAverage) Counter(org.apache.apex.malhar.lib.stream.Counter) MultiplyByConstant(org.apache.apex.malhar.lib.math.MultiplyByConstant) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator) Division(org.apache.apex.malhar.lib.math.Division) SquareCalculus(org.apache.apex.malhar.lib.math.SquareCalculus)

Aggregations

ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)1 Division (org.apache.apex.malhar.lib.math.Division)1 MultiplyByConstant (org.apache.apex.malhar.lib.math.MultiplyByConstant)1 RunningAverage (org.apache.apex.malhar.lib.math.RunningAverage)1 SquareCalculus (org.apache.apex.malhar.lib.math.SquareCalculus)1 Counter (org.apache.apex.malhar.lib.stream.Counter)1 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)1