Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexicase survival #23

Merged
merged 9 commits into from Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 4 additions & 32 deletions few/lib/epsilon_lexicase.h
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];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get rid of this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. removed message array declaration

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
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