Introduce Support for Factors #7

Merged
joel merged 7 commits from 01-factors into master 2018-07-04 20:27:42 +00:00
Showing only changes of commit c7298f7da6 - Show all commits

View file

@ -17,18 +17,20 @@ public class NumericCovariate implements Covariate<Double>{
@Override @Override
public Collection<NumericSplitRule> generateSplitRules(List<Value<Double>> data, int number) { public Collection<NumericSplitRule> generateSplitRules(List<Value<Double>> data, int number) {
final Random random = ThreadLocalRandom.current();
// for this implementation we need to shuffle the data // for this implementation we need to shuffle the data
final List<Value<Double>> shuffledData; final List<Value<Double>> shuffledData;
if(number > data.size()){ if(number > data.size()){
shuffledData = new ArrayList<>(data); shuffledData = new ArrayList<>(data);
Collections.shuffle(shuffledData); Collections.shuffle(shuffledData, random);
} }
else{ // only need the top number entries else{ // only need the top number entries
shuffledData = new ArrayList<>(number); shuffledData = new ArrayList<>(number);
final Set<Integer> indexesToUse = new HashSet<>(); final Set<Integer> indexesToUse = new HashSet<>();
while(indexesToUse.size() < number){ while(indexesToUse.size() < number){
final int index = ThreadLocalRandom.current().nextInt(data.size()); final int index = random.nextInt(data.size());
if(indexesToUse.add(index)){ if(indexesToUse.add(index)){
shuffledData.add(data.get(index)); shuffledData.add(data.get(index));