largeRCRF-Java/src/main/java/ca/joeltherrien/randomforest/Bootstrapper.java

31 lines
608 B
Java
Raw Normal View History

package ca.joeltherrien.randomforest;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@RequiredArgsConstructor
public class Bootstrapper<T> {
final private List<T> originalData;
final private Random random = new Random();
public List<T> bootstrap(){
final int n = originalData.size();
final List<T> newList = new ArrayList<>(n);
for(int i=0; i<n; i++){
final int index = random.nextInt(n);
newList.add(originalData.get(index));
}
return newList;
}
}