2018-07-01 22:22:12 -07:00
|
|
|
package ca.joeltherrien.randomforest;
|
|
|
|
|
2018-07-05 12:59:29 -07:00
|
|
|
import ca.joeltherrien.randomforest.covariates.Covariate;
|
2018-07-01 22:22:12 -07:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
2018-09-14 14:53:01 -07:00
|
|
|
import java.io.Serializable;
|
2018-07-16 16:58:11 -07:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2018-07-01 22:22:12 -07:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@RequiredArgsConstructor
|
2018-09-14 14:53:01 -07:00
|
|
|
public class CovariateRow implements Serializable {
|
2018-07-01 22:22:12 -07:00
|
|
|
|
2018-07-03 17:00:02 -07:00
|
|
|
private final Map<String, Covariate.Value> valueMap;
|
2018-07-01 22:22:12 -07:00
|
|
|
|
|
|
|
@Getter
|
|
|
|
private final int id;
|
|
|
|
|
2018-07-03 17:00:02 -07:00
|
|
|
public Covariate.Value<?> getCovariateValue(String name){
|
2018-07-01 22:22:12 -07:00
|
|
|
return valueMap.get(name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString(){
|
|
|
|
return "CovariateRow " + this.id;
|
|
|
|
}
|
|
|
|
|
2018-07-16 16:58:11 -07:00
|
|
|
public static CovariateRow createSimple(Map<String, String> simpleMap, List<Covariate> covariateList, int id){
|
|
|
|
final Map<String, Covariate.Value> valueMap = new HashMap<>();
|
|
|
|
final Map<String, Covariate> covariateMap = new HashMap<>();
|
|
|
|
|
|
|
|
covariateList.forEach(covariate -> covariateMap.put(covariate.getName(), covariate));
|
|
|
|
|
|
|
|
simpleMap.forEach((name, valueStr) -> {
|
|
|
|
if(covariateMap.containsKey(name)){
|
|
|
|
valueMap.put(name, covariateMap.get(name).createValue(valueStr));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return new CovariateRow(valueMap, id);
|
|
|
|
}
|
|
|
|
|
2018-07-01 22:22:12 -07:00
|
|
|
}
|