Package org.apache.mahout.ga.watchmaker.cd

Examples of org.apache.mahout.ga.watchmaker.cd.CDFitness


  @Override
  protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    DataLine dl = new DataLine(value.toString());

    for (int index = 0; index < rules.size(); index++) {
      CDFitness eval = evaluate(target, rules.get(index).classify(dl), dl.getLabel());
      context.write(new LongWritable(index), eval);
    }
  }
View Full Code Here


    boolean labelIsTarget = label == target;
    int tp = labelIsTarget && prediction == 1 ? 1 : 0;
    int fp = !labelIsTarget && prediction == 1 ? 1 : 0;
    int tn = !labelIsTarget && prediction == 0 ? 1 : 0;
    int fn = labelIsTarget && prediction == 0 ? 1 : 0;
    return new CDFitness(tp, fp, tn, fn);
  }
View Full Code Here

  @Override
  protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    DataLine dl = new DataLine(value.toString());

    for (int index = 0; index < rules.size(); index++) {
      CDFitness eval = evaluate(target, rules.get(index).classify(dl), dl.getLabel());
      context.write(new LongWritable(index), eval);
    }
  }
View Full Code Here

    boolean labelIsTarget = label == target;
    int tp = labelIsTarget && prediction == 1 ? 1 : 0;
    int fp = !labelIsTarget && prediction == 1 ? 1 : 0;
    int tn = !labelIsTarget && prediction == 0 ? 1 : 0;
    int fn = labelIsTarget && prediction == 0 ? 1 : 0;
    return new CDFitness(tp, fp, tn, fn);
  }
View Full Code Here

    int tp = 0;
    int fp = 0;
    int tn = 0;
    int fn = 0;
    for (int index = 0; index < NUM_EVALS; index++) {
      CDFitness fitness = new CDFitness(rng.nextInt(100), rng.nextInt(100), rng.nextInt(100), rng.nextInt(100));
      tp += fitness.getTp();
      fp += fitness.getFp();
      tn += fitness.getTn();
      fn += fitness.getFn();

      evaluations.add(fitness);
    }
    expected = new CDFitness(tp, fp, tn, fn);
  }
View Full Code Here

    Set<LongWritable> keys = reduceWriter.getKeys();
    assertEquals("nb keys", 1, keys.size());
    assertTrue("bad key", keys.contains(zero));

    assertEquals("nb values", 1, reduceWriter.getValue(zero).size());
    CDFitness fitness = reduceWriter.getValue(zero).get(0);
    assertEquals(expected, fitness);

  }
View Full Code Here

    mapper.configure(rules, 1);

    // test the mapper
    DummyOutputCollector<LongWritable, CDFitness> collector = new DummyOutputCollector<LongWritable, CDFitness>();
    for (int index1 = 0; index1 < mapper.rules.size(); index1++) {
      CDFitness eval1 = CDMapper.evaluate(mapper.target, mapper.rules.get(index1).classify(dl), dl.getLabel());
      collector.collect(new LongWritable(index1), eval1);
    }

    // check the evaluations
    Set<LongWritable> keys = collector.getKeys();
    assertEquals("Number of evaluations", rules.size(), keys.size());

    CDFitness[] expected = {TP, FP, TN, FN};
    for (LongWritable key : keys) {
      int index = (int) key.get();
      assertEquals("Values for key " + key, 1, collector.getValue(key).size());
      CDFitness eval = collector.getValue(key).get(0);

      assertEquals("Evaluation of the rule " + key, expected[index], eval);
    }

    EasyMock.verify(rule);
View Full Code Here

  private RandomRuleResults() {
  }

  public static synchronized void addResult(int ruleid, CDFitness fit) {
    CDFitness f = results.get(ruleid);
    if (f == null) {
      f = new CDFitness(fit);
    } else {
      f.add(fit);
    }
   
    results.put(ruleid, f);
  }
View Full Code Here

  @Override
  public int classify(DataLine dl) {
    int label = dl.getLabel();
    int prediction = rng.nextInt(2);

    CDFitness fitness = CDMapper.evaluate(target, prediction, label);
    RandomRuleResults.addResult(ruleid, fitness);

    return prediction;
  }
View Full Code Here

    Path output = new Path(outpath, "output.sorted");
    sorter.merge(outfiles, output);

    // import the evaluations
    Writable key = new LongWritable();
    CDFitness value = new CDFitness();
    Reader reader = new Reader(fs, output, conf);

    while (reader.next(key, value)) {
      evaluations.add(new CDFitness(value));
    }

    reader.close();
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.ga.watchmaker.cd.CDFitness

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.