tgboost
tgboost copied to clipboard
Try to fix some code in AttributeList.java
The original code is:
private void initialize_cutting_inds_thresholds(){
cutting_inds = new int[feature_dim][][];
cutting_thresholds = new float[feature_dim][];
for(int i=0;i<feature_dim;i++){
//for this feature, get its cutting index
ArrayList<Integer> list = new ArrayList<>();
int last_index = 0;
for(int j=0;j<attribute_list[i].length;j++){
if(attribute_list[i][j][0]==attribute_list[i][last_index][0]){
last_index = j;
}else {
list.add(last_index);
last_index = j;
}
}
//for this feature,store its cutting threshold
cutting_thresholds[i] = new float[list.size()+1];
for(int t=0;t<cutting_thresholds[i].length-1;t++){
cutting_thresholds[i][t] = attribute_list[i][list.get(t)][0];
}
cutting_thresholds[i][list.size()] = attribute_list[i][list.get(list.size()-1)+1][0];
//for this feature,store inds of each interval
cutting_inds[i] = new int[list.size()+1][]; //list.size()+1 interval
list.add(0,-1);
list.add(attribute_list[i].length-1);
for(int k=0;k<cutting_inds[i].length;k++){
int start_ind = list.get(k)+1;
int end_ind = list.get(k+1);
cutting_inds[i][k] = new int[end_ind-start_ind+1];
for(int m=0;m<cutting_inds[i][k].length;m++){
cutting_inds[i][k][m] = (int) attribute_list[i][start_ind+m][1];
}
}
}
}
Edited code is:
private void initialize_cutting_idx_thresholds() {
cutting_idx = new int[feature_dim][][];
cutting_thresholds = new double[feature_dim][];
for (int i = 0; i < feature_dim; ++i) {
List<Integer> list = new ArrayList<>();
int last_index = -1;
for (int j = 0; j < attribute_list[i].length; ++j) {
if (last_index == -1 || attribute_list[i][j][0] == attribute_list[i][last_index][0]) {
last_index = j;
}
else {
list.add(last_index);
last_index = j;
}
}
cutting_thresholds[i] = new double[list.size()];
for (int t = 0; t < cutting_thresholds[i].length; ++t) {
cutting_thresholds[i][t] = attribute_list[i][list.get(t)][0];
}
cutting_idx[i] = new int[list.size()][];
list.add(attribute_list[i].length);
for (int k = 0; k < cutting_idx[i].length; ++k) {
int s_idx = list.get(k);
int e_idx = list.get(k + 1);
cutting_idx[i][k] = new int[e_idx - s_idx];
for (int m = 0; m < cutting_idx[i][k].length; ++m) {
cutting_idx[i][k][m] = (int)attribute_list[i][s_idx + m][1];
}
}
}
}
It work for me