Initial commit; some base classes have been defined
but no logic exists yet.
This commit is contained in:
commit
7a467207a4
9 changed files with 149 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
|
.project
|
||||||
|
target/
|
10
src/ca/joeltherrien/randomforest/Main.java
Normal file
10
src/ca/joeltherrien/randomforest/Main.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package ca.joeltherrien.randomforest;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello world!");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
5
src/ca/joeltherrien/randomforest/Node.java
Normal file
5
src/ca/joeltherrien/randomforest/Node.java
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package ca.joeltherrien.randomforest;
|
||||||
|
|
||||||
|
public class Node {
|
||||||
|
|
||||||
|
}
|
44
src/ca/joeltherrien/randomforest/NumericSplitRule.java
Normal file
44
src/ca/joeltherrien/randomforest/NumericSplitRule.java
Normal file
|
@ -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 <Y> Split<Y> applyRule(List<Row<Y>> rows) {
|
||||||
|
final List<Row<Y>> leftHand = new LinkedList<>();
|
||||||
|
final List<Row<Y>> rightHand = new LinkedList<>();
|
||||||
|
|
||||||
|
for(final Row<Y> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
33
src/ca/joeltherrien/randomforest/Row.java
Normal file
33
src/ca/joeltherrien/randomforest/Row.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package ca.joeltherrien.randomforest;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Row<Y> {
|
||||||
|
|
||||||
|
private final Map<String, Value> covariates;
|
||||||
|
private final Y response;
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
public Row(Map<String, Value> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
20
src/ca/joeltherrien/randomforest/Split.java
Normal file
20
src/ca/joeltherrien/randomforest/Split.java
Normal file
|
@ -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<Y> {
|
||||||
|
|
||||||
|
public final List<Row<Y>> leftHand;
|
||||||
|
public final List<Row<Y>> rightHand;
|
||||||
|
|
||||||
|
public Split(List<Row<Y>> leftHand, List<Row<Y>> rightHand){
|
||||||
|
this.leftHand = leftHand;
|
||||||
|
this.rightHand = rightHand;
|
||||||
|
}
|
||||||
|
}
|
9
src/ca/joeltherrien/randomforest/SplitRule.java
Normal file
9
src/ca/joeltherrien/randomforest/SplitRule.java
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package ca.joeltherrien.randomforest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface SplitRule {
|
||||||
|
|
||||||
|
<Y> Split<Y> applyRule(List<Row<Y>> rows);
|
||||||
|
|
||||||
|
}
|
7
src/ca/joeltherrien/randomforest/Value.java
Normal file
7
src/ca/joeltherrien/randomforest/Value.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package ca.joeltherrien.randomforest;
|
||||||
|
|
||||||
|
public interface Value {
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue