Initial commit; some base classes have been defined

but no logic exists yet.
This commit is contained in:
Joel Therrien 2018-06-29 12:04:59 -07:00
commit 7a467207a4
9 changed files with 149 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.classpath
.settings
.project
target/

View file

@ -0,0 +1,10 @@
package ca.joeltherrien.randomforest;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View file

@ -0,0 +1,5 @@
package ca.joeltherrien.randomforest;
public class Node {
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View file

@ -0,0 +1,9 @@
package ca.joeltherrien.randomforest;
import java.util.List;
public interface SplitRule {
<Y> Split<Y> applyRule(List<Row<Y>> rows);
}

View file

@ -0,0 +1,7 @@
package ca.joeltherrien.randomforest;
public interface Value {
// TODO
}

View file

@ -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);
}
}