2018-07-02 17:58:53 -07:00
|
|
|
package ca.joeltherrien.randomforest;
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-07-16 16:58:11 -07:00
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
2018-07-02 17:58:53 -07:00
|
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class Bootstrapper<T> {
|
|
|
|
|
|
|
|
final private List<T> originalData;
|
|
|
|
|
|
|
|
public List<T> bootstrap(){
|
|
|
|
final int n = originalData.size();
|
|
|
|
|
|
|
|
final List<T> newList = new ArrayList<>(n);
|
|
|
|
|
|
|
|
for(int i=0; i<n; i++){
|
2018-07-16 16:58:11 -07:00
|
|
|
final int index = ThreadLocalRandom.current().nextInt(n);
|
2018-07-02 17:58:53 -07:00
|
|
|
|
|
|
|
newList.add(originalData.get(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
return newList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|