Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Delete trash directory

  • Loading branch information...
commit c57ad3b69bd47c585643fdbe88bcd8f27de1baa8 1 parent 63681e2
@fbrubacher authored
View
126 storm-ml/src/jvm/storm/ml/Main.java
@@ -1,126 +0,0 @@
-package storm.ml;
-
-import java.lang.Boolean;
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.ArrayList;
-
-import backtype.storm.Config;
-import backtype.storm.LocalCluster;
-import backtype.storm.StormSubmitter;
-import backtype.storm.task.OutputCollector;
-import backtype.storm.task.TopologyContext;
-import backtype.storm.testing.TestWordSpout;
-import backtype.storm.topology.OutputFieldsDeclarer;
-import backtype.storm.topology.TopologyBuilder;
-import backtype.storm.topology.base.BaseRichBolt;
-import backtype.storm.topology.base.BaseRichSpout;
-import backtype.storm.tuple.Fields;
-import backtype.storm.tuple.Tuple;
-import backtype.storm.tuple.Values;
-import backtype.storm.utils.Utils;
-import java.util.Map;
-
-import org.javatuples.Pair;
-
-import storm.ml.PerceptronTopologyBuilder;
-
-public class Main {
-
- public static class TrainingSpout extends BaseRichSpout {
- OutputCollector _collector;
-
- @Override
- public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
- _collector = collector;
- }
-
- @Override
- public void execute(Tuple tuple) {
- _t
- _collector.emit(tuple, new Values(tuple.getString(0) + "!!!"));
- _collector.ack(tuple);
- }
-
- @Override
- public void declareOutputFields(OutputFieldsDeclarer declarer) {
- declarer.declare(new Fields("word"));
- }
-
- }
-
- public static class TrainingBolt extends BaseRichBolt {
- OutputCollector _collector;
-
- @Override
- public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
- _collector = collector;
- }
-
- @Override
- public void execute(Tuple tuple) {
- _t
- _collector.emit(tuple, new Values(tuple.getString(0) + "!!!"));
- _collector.ack(tuple);
- }
-
- @Override
- public void declareOutputFields(OutputFieldsDeclarer declarer) {
- declarer.declare(new Fields("word"));
- }
-
- }
-
- public perceptronTopology() {
- TopologyBuilder builder = new TopologyBuilder();
-
- builder.setSpout("word", new TestWordSpout(), 10);
- builder.setBolt("exclaim1", new ExclamationBolt(), 3).shuffleGrouping("word");
- builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
-
- Config conf = new Config();
- conf.setDebug(true);
-
- if (args != null && args.length > 0) {
- conf.setNumWorkers(3);
-
- StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
- } else {
-
- LocalCluster cluster = new LocalCluster();
- cluster.submitTopology("test", conf, builder.createTopology());
- Utils.sleep(10000);
- cluster.killTopology("test");
- cluster.shutdown();
- }
- }
-
- public static void main(String[] keywords) {
- perceptronTopology();
-// List<Pair<List<BigDecimal>, Boolean>> training_set = new ArrayList<Pair<List<BigDecimal>, Boolean>>(4);
-// List<BigDecimal> input_vector = new ArrayList<BigDecimal>(3);
-//
-// input_vector.add(new BigDecimal(1));
-// input_vector.add(new BigDecimal(0));
-// input_vector.add(new BigDecimal(0));
-// training_set.add(new Pair<List<BigDecimal>, Boolean>(input_vector, true));
-//
-// input_vector.add(new BigDecimal(1));
-// input_vector.add(new BigDecimal(0));
-// input_vector.add(new BigDecimal(1));
-// training_set.add(new Pair<List<BigDecimal>, Boolean>(input_vector, true));
-//
-// input_vector.add(new BigDecimal(1));
-// input_vector.add(new BigDecimal(1));
-// input_vector.add(new BigDecimal(0));
-// training_set.add(new Pair<List<BigDecimal>, Boolean>(input_vector, true));
-//
-// input_vector.add(new BigDecimal(1));
-// input_vector.add(new BigDecimal(1));
-// input_vector.add(new BigDecimal(1));
-// training_set.add(new Pair<List<BigDecimal>, Boolean>(input_vector, false));
-//
-// PerceptronTopologyBuilder ptb = new PerceptronTopologyBuilder(3, 0.5, 0.1);
-// ptb.train(training_set);
- }
-}
View
59 storm-ml/src/jvm/storm/ml/PerceptronTopologyBuilder.java
@@ -1,59 +0,0 @@
-package storm.ml;
-
-import java.lang.Integer;
-import java.lang.Double;
-import java.lang.Boolean;
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.ArrayList;
-
-import org.javatuples.Pair;
-
-public class PerceptronTopologyBuilder {
- public final Integer size;
- public final Double threshold;
- public final Double learning_rate;
-
- privatez List<BigDecimal> weights;
-
- public PerceptronTopologyBuilder(Integer size, Double threshold, Double learning_rate) {
- this.size = size; // size of the weight array and input
- this.threshold = threshold; // margin to determine positive results
- this.learning_rate = learning_rate; // adaptation factor for the weights
-
- this.weights = new ArrayList<BigDecimal>(size);
- int i; for (i=0; i<size; i++)
- this.weights.add(new BigDecimal(0));
- }
-
- private BigDecimal dot_product(List<BigDecimal> vector1, List<BigDecimal> vector2) {
- BigDecimal result = new BigDecimal(0);
- int i; for (i=0; i<this.size; i++)
- result.add(vector1.get(i).multiply(vector2.get(i)));
-
- return result;
- }
-
- public void train(List<Pair<List<BigDecimal>, Boolean>> training_set) {
- while (true) {
- int error_count = 0;
- for (Pair<List<BigDecimal>, Boolean> training_pair : training_set) {
- List<BigDecimal> input_vector = training_pair.getValue0();
- Integer desired_output = training_pair.getValue1() ? 1 : 0;
- System.out.println(String.format("%s", this.weights));
-
- int result = dot_product(input_vector, this.weights).compareTo(new BigDecimal(threshold)) > 0 ? 1 : 0;
-
- int error = desired_output - result;
- if (error != 0) {
- error_count += 1;
- int i; for (i=0; i<this.size; i++)
- this.weights.set(i, this.weights.get(i).add(input_vector.get(i).multiply(new BigDecimal(this.learning_rate * error))));
- }
- }
- if (error_count == 0)
- break;
- System.out.println();
- }
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.