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

feat(python): best sol candidate in phenotype space #221

Merged
merged 1 commit into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/lcmaes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ boost::python::list get_candidate_x(const Candidate &c)
return x;
}

boost::python::list get_best_candidate_pheno(const CMASolutions &s,
const GenoPheno<pwqBoundStrategy> &gp)
{
boost::python::list gpx;
dVec d = gp.pheno(s.best_candidate().get_x_dvec());
for (int i=0;i<d.rows();++i)
gpx.append(d[i]);
return gpx;
}

PyObject* get_solution_cov_py(const CMASolutions &s)
{
npy_intp shape[2] = {s.dim(),s.dim()};
Expand Down Expand Up @@ -443,6 +453,7 @@ BOOST_PYTHON_MODULE(lcmaes)
.def("set_fvalue",&Candidate::set_fvalue,"sets candidate's objective function value")
;
def("get_candidate_x",get_candidate_x,args("cand"),"returns candidate's parameter vector");
def("get_best_candidate_pheno",get_best_candidate_pheno,args("cmasol","gp"),"returns candidate's parameter vector in phenotype space");

/*- genopheno object -*/
class_<GenoPheno<NoBoundStrategy>>("GenoPhenoNB","genotype/phenotype transformation object for problem with unbounded parameters")
Expand Down
2 changes: 2 additions & 0 deletions python/ptest_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def nfitfunc(x,n):

# collect and inspect results
bcand = cmasols.best_candidate()
bcand_pheno = lcmaes.get_best_candidate_pheno(cmasols,gp)
bx = lcmaes.get_candidate_x(bcand)
print("best x=",bx)
print('best x in phenotype space=',bcand_pheno)
print("distribution mean=",lcmaes.get_solution_xmean(cmasols))
cov = lcmaes.get_solution_cov(cmasols) # numpy array
print("cov=",cov)
Expand Down