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

fix optimization flag in ParameterHelper class #191

Merged
merged 16 commits into from
Jun 24, 2020

Conversation

nw13slx
Copy link
Collaborator

@nw13slx nw13slx commented Jun 23, 2020

ParameterHelper failed to apply the right constraints defined by set_constraints() functions, because the order was messed up...
If user use ParameterHelper to generate hyps_mask for constrained hyper-parameter optimization, it will optimized the wrong element of the hyper-parameters...

@nw13slx nw13slx requested a review from stevetorr June 23, 2020 16:19
self.logger.debug(f" using hyper-parameters of {sig:6.2g} "
f"{ls:6.2g}")
f"{ls:6.2g} {opt_sig} {opt_ls}")
self.hyps_opt[group_type] = all_opt_sig + all_opt_ls
Copy link
Contributor

Choose a reason for hiding this comment

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

So to confirm, it's okay that it's all signal hyps and then all length scale params within the hyps_opt indexes? If so, this looks good to me.

Copy link
Collaborator Author

@nw13slx nw13slx Jun 23, 2020

Choose a reason for hiding this comment

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

that's exactly where the bug was at. The hyper-parameter array is always ordered like "sig2-1 sig2-2 ls2-1 ls2-2 sig3-1 sig3-2 ..."

@stevetorr
Copy link
Contributor

At the risk of making a trite critique: Is it possible to unit test this logic (that constraints on optimization operate in the right way) slash were the previous unit tests not robust enough to catch this?

Comment on lines +114 to +128
species_labels = []
coded_species = []
for i, ele in enumerate(unique_species):
if isinstance(ele, str):
self.species_labels.append(ele)
self.coded_species.append(element_to_Z(ele))
species_labels.append(ele)
coded_species.append(element_to_Z(ele))
elif isinstance(ele, int):
self.coded_species.append(ele)
self.species_labels.append(Z_to_element(ele))
coded_species.append(ele)
species_labels.append(Z_to_element(ele))
else:
print("element type not accepted", ele, type(ele))
sort_id = np.argsort(coded_species)
for i in sort_id:
self.coded_species.append(coded_species[i])
self.species_labels.append(species_labels[i])
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

Choose a reason for hiding this comment

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

A quick question: Is there anything that we could do here to make this future-proofed for coarse graining? Maybe it's thinking too far ahead, but just so that if a user were to pass in a number outside of {1...118} or a species label outside of the periodic table that everything ends up working okay. I think that this might be too far in advance (and the logic here is easy enough that we could fix it later) but something to keep in mind. This could also matter sooner if someone wants to do FLARE with isotopes, to keep track of distinct species.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess we can change the element_to_Z part and allow hyps_mask to take any number beyond 118. I can change the ParameterHelper to accommodate that.

But we need to think a bit how to make it consistent. Maybe leave a dictionary in the element_coder module that allows users to injet str-integer pair. And the element_to_Z and Z_to_element function can read from that dictionary.

Copy link
Contributor

@stevetorr stevetorr left a comment

Choose a reason for hiding this comment

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

Pull looks good- I would just inquire how hard it would be to add more robust unit testing to ensure that when selective optimization is called for, the Hyp helper chooses the right ones to optimize, and to test a few different permutations. Otherwise LGTM

@stevetorr
Copy link
Contributor

stevetorr commented Jun 24, 2020

Thanks for adding those tests and for linting!! (a favor not only to the future version of you but also the future developers and contributors... :) )

@nw13slx nw13slx merged commit cd79a0f into development Jun 24, 2020
@nw13slx nw13slx deleted the bugfix/lixin/parameter_helper branch June 24, 2020 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants