From 7a467207a40345a777935545d5315f31d3c6b7c8 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Fri, 29 Jun 2018 12:04:59 -0700 Subject: [PATCH] Initial commit; some base classes have been defined but no logic exists yet. --- .gitignore | 4 ++ src/ca/joeltherrien/randomforest/Main.java | 10 +++++ src/ca/joeltherrien/randomforest/Node.java | 5 +++ .../randomforest/NumericSplitRule.java | 44 +++++++++++++++++++ src/ca/joeltherrien/randomforest/Row.java | 33 ++++++++++++++ src/ca/joeltherrien/randomforest/Split.java | 20 +++++++++ .../joeltherrien/randomforest/SplitRule.java | 9 ++++ src/ca/joeltherrien/randomforest/Value.java | 7 +++ .../exceptions/MissingValueException.java | 17 +++++++ 9 files changed, 149 insertions(+) create mode 100644 .gitignore create mode 100644 src/ca/joeltherrien/randomforest/Main.java create mode 100644 src/ca/joeltherrien/randomforest/Node.java create mode 100644 src/ca/joeltherrien/randomforest/NumericSplitRule.java create mode 100644 src/ca/joeltherrien/randomforest/Row.java create mode 100644 src/ca/joeltherrien/randomforest/Split.java create mode 100644 src/ca/joeltherrien/randomforest/SplitRule.java create mode 100644 src/ca/joeltherrien/randomforest/Value.java create mode 100644 src/ca/joeltherrien/randomforest/exceptions/MissingValueException.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f61aa0d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.classpath +.settings +.project +target/ diff --git a/src/ca/joeltherrien/randomforest/Main.java b/src/ca/joeltherrien/randomforest/Main.java new file mode 100644 index 0000000..1ae6537 --- /dev/null +++ b/src/ca/joeltherrien/randomforest/Main.java @@ -0,0 +1,10 @@ +package ca.joeltherrien.randomforest; + +public class Main { + + public static void main(String[] args) { + System.out.println("Hello world!"); + + } + +} diff --git a/src/ca/joeltherrien/randomforest/Node.java b/src/ca/joeltherrien/randomforest/Node.java new file mode 100644 index 0000000..fa6efce --- /dev/null +++ b/src/ca/joeltherrien/randomforest/Node.java @@ -0,0 +1,5 @@ +package ca.joeltherrien.randomforest; + +public class Node { + +} diff --git a/src/ca/joeltherrien/randomforest/NumericSplitRule.java b/src/ca/joeltherrien/randomforest/NumericSplitRule.java new file mode 100644 index 0000000..d4e3fa9 --- /dev/null +++ b/src/ca/joeltherrien/randomforest/NumericSplitRule.java @@ -0,0 +1,44 @@ +package ca.joeltherrien.randomforest; + +import java.util.LinkedList; +import java.util.List; + +import ca.joeltherrien.randomforest.exceptions.MissingValueException; + +public class NumericSplitRule implements SplitRule{ + + public final String covariateName; + public final double threshold; + + public NumericSplitRule(String covariateName, double threshold) { + super(); + this.covariateName = covariateName; + this.threshold = threshold; + } + + @Override + public final String toString() { + return "NumericSplitRule on " + covariateName + " at " + threshold; + } + + @Override + public Split applyRule(List> rows) { + final List> leftHand = new LinkedList<>(); + final List> rightHand = new LinkedList<>(); + + for(final Row row : rows) { + final Value x = row.getCovariate(covariateName); + if(x == null) { + throw new MissingValueException(row, this); + } + + final NumericValue xNum = (NumericValue) x; + + } + + // TODO Auto-generated method stub + return null; + } + + +} diff --git a/src/ca/joeltherrien/randomforest/Row.java b/src/ca/joeltherrien/randomforest/Row.java new file mode 100644 index 0000000..ca379ae --- /dev/null +++ b/src/ca/joeltherrien/randomforest/Row.java @@ -0,0 +1,33 @@ +package ca.joeltherrien.randomforest; + +import java.util.Map; + +public class Row { + + private final Map covariates; + private final Y response; + private final int id; + + public Row(Map covariates, Y response, int id) { + super(); + this.covariates = covariates; + this.response = response; + this.id = id; + } + + public Value getCovariate(String name) { + return this.covariates.get(name); + } + + public Y getResponse() { + return this.response; + } + + @Override + public String toString() { + return "Row " + this.id; + } + + + +} diff --git a/src/ca/joeltherrien/randomforest/Split.java b/src/ca/joeltherrien/randomforest/Split.java new file mode 100644 index 0000000..741b608 --- /dev/null +++ b/src/ca/joeltherrien/randomforest/Split.java @@ -0,0 +1,20 @@ +package ca.joeltherrien.randomforest; + +import java.util.List; + +/** + * Very simple class that contains two lists; it's essentially a tuple. + * + * @author joel + * + */ +public class Split { + + public final List> leftHand; + public final List> rightHand; + + public Split(List> leftHand, List> rightHand){ + this.leftHand = leftHand; + this.rightHand = rightHand; + } +} diff --git a/src/ca/joeltherrien/randomforest/SplitRule.java b/src/ca/joeltherrien/randomforest/SplitRule.java new file mode 100644 index 0000000..d7efca6 --- /dev/null +++ b/src/ca/joeltherrien/randomforest/SplitRule.java @@ -0,0 +1,9 @@ +package ca.joeltherrien.randomforest; + +import java.util.List; + +public interface SplitRule { + + Split applyRule(List> rows); + +} diff --git a/src/ca/joeltherrien/randomforest/Value.java b/src/ca/joeltherrien/randomforest/Value.java new file mode 100644 index 0000000..f92affe --- /dev/null +++ b/src/ca/joeltherrien/randomforest/Value.java @@ -0,0 +1,7 @@ +package ca.joeltherrien.randomforest; + +public interface Value { + + // TODO + +} diff --git a/src/ca/joeltherrien/randomforest/exceptions/MissingValueException.java b/src/ca/joeltherrien/randomforest/exceptions/MissingValueException.java new file mode 100644 index 0000000..1de5e30 --- /dev/null +++ b/src/ca/joeltherrien/randomforest/exceptions/MissingValueException.java @@ -0,0 +1,17 @@ +package ca.joeltherrien.randomforest.exceptions; + +import ca.joeltherrien.randomforest.Row; +import ca.joeltherrien.randomforest.SplitRule; + +public class MissingValueException extends RuntimeException{ + + /** + * + */ + private static final long serialVersionUID = 6808060079431207726L; + + public MissingValueException(Row row, SplitRule rule) { + super("Missing value at row " + row + rule); + } + +}