Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
4 storm-ml/src/main/java/com/twitter/storm/example/MainOnlineTopology.java
@@ -20,7 +20,7 @@
20 20
21 21 public static void main(String[] args) throws Exception {
22 22 MemcachedClient memcache = new MemcachedClient(AddrUtil.getAddresses(MEMCACHED_SERVERS));
23   - OperationFuture promise = memcache.set("model", 0, "[0.1, 0.1]");
  23 + OperationFuture promise = memcache.set("model", 0, "[0.1, -0.1]");
24 24 promise.get();
25 25
26 26 Config topology_conf = new Config();
@@ -30,7 +30,7 @@ public static void main(String[] args) throws Exception {
30 30 else
31 31 topology_name = args[0];
32 32
33   - MLTopologyBuilder ml_topology_builder = new MLTopologyBuilder(topology_name);
  33 + MLTopologyBuilder ml_topology_builder = new MLTopologyBuilder(topology_name, MEMCACHED_SERVERS);
34 34
35 35 ml_topology_builder.setTrainingSpout(new ExampleTrainingSpout());
36 36 ml_topology_builder.setTrainingBolt(new LocalLearner(2, MEMCACHED_SERVERS));
12 storm-ml/src/main/java/com/twitter/storm/primitives/MLTopologyBuilder.java
@@ -10,9 +10,8 @@
10 10
11 11 public class MLTopologyBuilder {
12 12
13   - public static final String MEMCACHED_SERVERS = "127.0.0.1:11211";
14   -
15 13 String topology_prefix;
  14 + String memcached_servers;
16 15
17 16 BaseTrainingSpout training_spout;
18 17 Number training_spout_parallelism;
@@ -25,12 +24,13 @@
25 24 IRichBolt rich_evaluation_bolt;
26 25 Number evaluation_bolt_parallelism;
27 26
28   - public MLTopologyBuilder(String topologyPrefix) {
  27 + public MLTopologyBuilder(String topologyPrefix, String memcached_servers) {
  28 + this.memcached_servers = memcached_servers;
29 29 this.topology_prefix = topologyPrefix;
30 30 }
31 31
32 32 public TopologyBuilder prepareTopology(String drpcFunctionName, ILocalDRPC drpc) {
33   - return prepareTopology(drpcFunctionName, drpc, 1.0, 0.0, 0.5, MEMCACHED_SERVERS);
  33 + return prepareTopology(drpcFunctionName, drpc, 1.0, 0.0, 0.5);
34 34 }
35 35
36 36 public void setTrainingSpout(BaseTrainingSpout exampleTrainingSpout, Number parallelism) {
@@ -83,7 +83,7 @@ public void setEvaluationBolt(IRichBolt evaluation_bolt) {
83 83 }
84 84
85 85 public TopologyBuilder prepareTopology(String drpcFunctionName, ILocalDRPC drpc, double bias, double threshold,
86   - double learning_rate, String memcached_servers) {
  86 + double learning_rate) {
87 87 TopologyBuilder topology_builder = new TopologyBuilder();
88 88
89 89 // training
@@ -97,7 +97,7 @@ public TopologyBuilder prepareTopology(String drpcFunctionName, ILocalDRPC drpc,
97 97 topology_builder.setBolt(this.topology_prefix + "-training-bolt", this.rich_training_bolt,
98 98 this.training_bolt_parallelism).shuffleGrouping(this.topology_prefix + "-training-spout");
99 99 }
100   - topology_builder.setBolt("aggregator", new Aggregator(MEMCACHED_SERVERS)).globalGrouping(
  100 + topology_builder.setBolt("aggregator", new Aggregator(this.memcached_servers)).globalGrouping(
101 101 this.topology_prefix + "-training-bolt");
102 102
103 103 // evaluation
4 storm-ml/src/main/java/com/twitter/storm/primitives/example/ExampleTrainingSpout.java
@@ -10,12 +10,12 @@
10 10
11 11 public static double get_label(Double x, Double y) {
12 12 // arbitrary expected output (for testing purposes)
13   - return (2 * x + -1 < y) ? 1.0 : -1.0;
  13 + return (2 * x + -1 > y) ? 1.0 : -1.0;
14 14 }
15 15
16 16 public void nextTuple() {
17 17 if (this.samples_count < this.max_samples) {
18   - Double x = 100 * Math.random();
  18 + Double x = 10 * Math.random();
19 19 Double y = 5.0;
20 20 double label = ExampleTrainingSpout.get_label(x, y);
21 21

No commit comments for this range

Something went wrong with that request. Please try again.