Skip to content

Commit

Permalink
seg fault fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh Gupta committed Jul 31, 2017
1 parent f42d00a commit f6af3ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
36 changes: 4 additions & 32 deletions few/lib/epsilon_lexicase.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,56 +96,28 @@ void epsilon_lexicase(const ExtMat & F, int n, int d,
for (int i = 0; i<epsilon.size(); ++i)
epsilon(i) = mad(F.col(i));

/*vector<int> ind_locs;
if(lex_size){
//randomly select a size from sizes
int max_index = sizes.size();
int random_index = rand() % max_index;
// individual locations
vector<int> ind_locs_temp(sizes[random_index]);
ind_locs = ind_locs_temp;
//ind_locs.reserve(sizes[random_index]);
}
else{
// individual locations
vector<int> ind_locs_temp(n);
ind_locs = ind_locs_temp;
//ind_locs.reserve(n);
}*/

vector<int> ind_locs;
if(lex_size){
vector<int> ind_locs(n);
if(lex_size){
char message[200];
PyOS_snprintf(message, sizeof(message),"lex_size");
//randomly select a size from sizes
int max_index = sizes.size();
int random_index = rand() % max_index;
vector<int> ind_locs_temp(n);

// individual locations
int j=0;
for(int i=0;i<max_index;i++){
if(sizes[i]==random_index)
ind_locs_temp[j++] = i;
}
ind_locs.reserve(j);
for(int k=0;k<j;k++){
ind_locs[k] = ind_locs_temp[k];
if(sizes[i]<=sizes[random_index])
ind_locs.push_back(i);
}

}
else{
// individual locations
ind_locs.reserve(n);
iota(ind_locs.begin(),ind_locs.end(),0);
}


// temporary winner pool
vector<int> winner;

for (int i = 0; i<num_selections; ++i){
//cout << "selection " << i << "\n";
// perform selection
Expand Down
5 changes: 0 additions & 5 deletions few/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ def survival(self,parents,offspring,elite=None,elite_index=None,X=None,F=None,F_
elif self.sel == 'epsilon_lexicase':
# survivors, survivor_index = self.epsilon_lexicase(parents + offspring, num_selections = len(parents), survival = True)
if self.lex_size:
print(parents + offspring)
sizes = [len(i.stack) for i in (parents + offspring)]
print(sizes)
print("--")
survivor_index = self.epsilon_lexicase(np.vstack((F,F_offspring)), sizes, num_selections = F.shape[0], survival = True)
print(survivor_index)
survivors = [(parents+ offspring)[s] for s in survivor_index]
else:
survivor_index = self.epsilon_lexicase(np.vstack((F,F_offspring)), [], num_selections = F.shape[0], survival = True)
print(survivor_index)
survivors = [(parents+ offspring)[s] for s in survivor_index]
elif self.sel == 'deterministic_crowding':
survivors, survivor_index = self.deterministic_crowding(parents,offspring,X,X_offspring)
Expand Down

0 comments on commit f6af3ae

Please sign in to comment.