largeRCRF-Java/src/main/java/ca/joeltherrien/randomforest/Row.java
Joel Therrien a5fe856857 Massive refactor; Use Iterators/Updaters when calculating difference scores for faster calculations.
Changed the covariates to be more clever with how they produce the different splits. In the future (not yet implemented) a clever GroupDifferentiator
could update the current score calculation based just on how many rows moved from one hand to the other. There were a few other changes as well;
TreeTrainer#growTree now accepts a Random as a parameter which is used throughout the entire growing process. This means it's now theoretically
possible to grow trees using a seed, so that results can be fully reproducible.
2019-01-09 21:31:27 -08:00

47 lines
1.2 KiB
Java

package ca.joeltherrien.randomforest;
import ca.joeltherrien.randomforest.covariates.Covariate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Row<Y> extends CovariateRow {
private final Y response;
public Row(final Covariate.Value[] valueArray, final int id, final Y response){
super(valueArray, id);
this.response = response;
}
public Y getResponse() {
return this.response;
}
@Override
public String toString() {
return "Row " + this.getId();
}
public static <Y> Row<Y> createSimple(Map<String, String> simpleMap, List<Covariate> covariateList, int id, final Y response){
final Covariate.Value[] valueArray = new Covariate.Value[covariateList.size()];
final Map<String, Covariate> covariateMap = new HashMap<>();
covariateList.forEach(covariate -> covariateMap.put(covariate.getName(), covariate));
simpleMap.forEach((name, valueStr) -> {
final Covariate covariate = covariateMap.get(name);
if(covariate != null){ // happens often in tests where we experiment with adding / removing covariates
valueArray[covariate.getIndex()] = covariate.createValue(valueStr);
}
});
return new Row<Y>(valueArray, id, response);
}
}