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

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


  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


    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.getRules().size(); index1++) {
      CDFitness eval1 = CDMapper.evaluate(mapper.getTarget(), mapper.getRules().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

    int tp = 0;
    int fp = 0;
    int tn = 0;
    int fn = 0;
    for (int index = 0; index < nbevals; 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<String> keys = collector.getKeys();
    assertEquals("nb keys", 1, keys.size());
    assertTrue("bad key", keys.contains(zero.toString()));

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

  }
View Full Code Here

    CDFitness[] expected = { TP, FP, TN, FN };
    for (String key : keys) {
      int index = Integer.parseInt(key);
      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

public class RandomRuleResults {

  private static final Map<Integer, CDFitness> results = new HashMap<Integer, CDFitness>();

  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

  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
    LongWritable 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.