package storm.ml;

import backtype.storm.Config;
import backtype.storm.drpc.LinearDRPCTopologyBuilder;
import backtype.storm.LocalCluster;
import backtype.storm.LocalDRPC;
import backtype.storm.StormSubmitter;

import java.util.ArrayList;
import java.util.List;

import storm.ml.bolt.EvaluationBolt;

public class PerceptronDRPCTopology {
    public static void main(String[] args) throws Exception {
        LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("evaluate");
        builder.addBolt(new EvaluationBolt(1.0, 0.5), 3);

        Config conf = new Config();

        if (args==null || args.length==0) {
            LocalDRPC drpc = new LocalDRPC();
            LocalCluster cluster = new LocalCluster();

            cluster.submitTopology("evaluation-demo", conf, builder.createLocalTopology(drpc));

            List<String> input_vectors = get_input_vectors();
            for (String input_vector : input_vectors) {
                System.out.println(String.format("%s -> %s", input_vector, drpc.execute("evaluate", input_vector)));
            }

            cluster.shutdown();
            drpc.shutdown();
        } else {
            conf.setNumWorkers(3);
            StormSubmitter.submitTopology(args[0], conf, builder.createRemoteTopology());
        }
    }

    public static List<String> get_input_vectors() {
        Double n=1.0;

        List<String> input_vectors = new ArrayList<String>();
        while (n<10) {
            List<Double> result_item = new ArrayList<Double>();
            result_item.add(n++);
            result_item.add(n*n);

            input_vectors.add(result_item.toString());
        }

        return input_vectors;
    }
}

@@ -1347,31 +1347,8 @@
 ) %7B%0A
-        Double n=1.0;%0A%0A
     
@@ -1417,19 +1417,90 @@
     
-while (n%3C10
+for (Double x=-10.0; x%3C=10.0; x++) %7B%0A            for (Double y=-10.0; y%3C=10.0; y++
 ) %7B%0A
@@ -1507,24 +1507,28 @@
             
+   
+ 
 List%3CDouble%3E
@@ -1571,32 +1571,36 @@
 ();%0A            
+    
 result_item.add(
@@ -1603,11 +1603,9 @@
 add(
-n++
+x
 );%0A 
@@ -1607,32 +1607,36 @@
 x);%0A            
+ 
+   
 result_item.add(
@@ -1639,11 +1639,9 @@
 add(
-n*n
+y
 );%0A%0A
@@ -1652,16 +1652,20 @@
         
+ 
+   
 input_ve
@@ -1695,24 +1695,38 @@
 oString());%0A
+            %7D%0A
         %7D%0A%0A 

generate more evaluation points