-
Notifications
You must be signed in to change notification settings - Fork 253
Improve Rule Generation #2277
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
Closed
Closed
Improve Rule Generation #2277
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e6110e9
add solute data to KineticsModel and Arrhenius
mjohnson541 a51925e
add ArrheniusChargeTransfer kinetics type
mjohnson541 aa39337
create ArrheniusChargeTransferBM type
mjohnson541 95db806
add ChargeTransfer types to kinetics/__init__.py
mjohnson541 25807c1
handle ChargeTransfer kinetics with in reaction.py
mjohnson541 908bad9
add handling ArrheniusChargeTransfer and fix handling SurfaceChargeTr…
mjohnson541 68d43d5
enable access to SoluteData object in kinetics database
mjohnson541 8d30987
when rule making is done on one processor don't use pool
mjohnson541 d81d824
add function for averaging kinetics
mjohnson541 1898402
update rule fitting
mjohnson541 5c727f1
enable use of non-surface charge transfer families
mjohnson541 321dbb8
add charge transfer types to database context
mjohnson541 1601dc8
standardize ascend option in cross validate
mjohnson541 58a9ef0
add comment to averaged kinetics
mjohnson541 ea72bf4
fix BM fitting
mjohnson541 4174c91
added Faraday's Constant `F`
davidfarinajr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3648,7 +3648,7 @@ def make_bm_rules_from_template_rxn_map(self, template_rxn_map, nprocs=1, Tref=1 | |
|
|
||
| index += 1 | ||
|
|
||
| def cross_validate(self, folds=5, template_rxn_map=None, test_rxn_inds=None, T=1000.0, iters=0, random_state=1, ascend=False): | ||
| def cross_validate(self, folds=5, template_rxn_map=None, test_rxn_inds=None, T=1000.0, iters=0, random_state=1): | ||
| """ | ||
| Perform K-fold cross validation on an automatically generated tree at temperature T | ||
| after finding an appropriate node for kinetics estimation it will move up the tree | ||
|
|
@@ -3704,47 +3704,43 @@ def cross_validate(self, folds=5, template_rxn_map=None, test_rxn_inds=None, T=1 | |
| if entry.parent: | ||
| entry = entry.parent | ||
|
|
||
| boo = True | ||
|
|
||
| while boo: | ||
| if entry.parent is None: | ||
| break | ||
| kin = self.rules.entries[entry.label][0].data | ||
| kinparent = self.rules.entries[entry.parent.label][0].data | ||
| err_parent = abs(kinparent.uncertainty.data_mean + kinparent.uncertainty.mu - kin.uncertainty.data_mean) + np.sqrt(2.0*kinparent.uncertainty.var/np.pi) | ||
| err_entry = abs(kin.uncertainty.mu) + np.sqrt(2.0*kin.uncertainty.var/np.pi) | ||
| if err_entry <= err_parent: | ||
| break | ||
| else: | ||
| entry = entry.parent | ||
|
|
||
| uncertainties[rxn] = self.rules.entries[entry.label][0].data.uncertainty | ||
|
|
||
| if not ascend: | ||
| L = list(set(template_rxn_map[entry.label]) - set(rxns_test)) | ||
|
|
||
| if L != []: | ||
| if isinstance(L[0].kinetics,Arrhenius): | ||
| kinetics = ArrheniusBM().fit_to_reactions(L, recipe=self.forward_recipe.actions) | ||
| kinetics = kinetics.to_arrhenius(rxn.get_enthalpy_of_reaction(T)) | ||
| L = list(set(template_rxn_map[entry.label]) - set(rxns_test)) | ||
|
|
||
| if L != []: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a more Pythonic way to check empty list is by |
||
| if isinstance(L[0].kinetics, Arrhenius): | ||
| kinetics = ArrheniusBM().fit_to_reactions(L, recipe=self.forward_recipe.actions) | ||
| if kinetics.E0.value_si < 0.0 or len(L) == 1: | ||
| kinetics = average_kinetics([r.kinetics for r in L]) | ||
| else: | ||
| kinetics = ArrheniusChargeTransferBM().fit_to_reactions(L, recipe=self.forward_recipe.actions) | ||
| kinetics = kinetics.to_arrhenius_charge_transfer(rxn.get_enthalpy_of_reaction(T)) | ||
| k = kinetics.get_rate_coefficient(T) | ||
| errors[rxn] = np.log(k / krxn) | ||
| kinetics = kinetics.to_arrhenius(rxn.get_enthalpy_of_reaction(298.0)) | ||
| else: | ||
| raise ValueError('only one piece of kinetics information in the tree?') | ||
| else: | ||
| boo = True | ||
| rlist = list(set(template_rxn_map[entry.label]) - set(rxns_test)) | ||
| kinetics = _make_rule((self.forward_recipe.actions,rlist,T,1.0e3,"",[rxn.rank for rxn in rlist])) | ||
| logging.error("determining fold rate") | ||
| c = 1 | ||
| while boo: | ||
| parent = entry.parent | ||
| if parent is None: | ||
| break | ||
| rlistparent = list(set(template_rxn_map[parent.label]) - set(rxns_test)) | ||
| kineticsparent = _make_rule((self.forward_recipe.actions,rlistparent,T,1.0e3,"",[rxn.rank for rxn in rlistparent])) | ||
| err_parent = abs(kineticsparent.uncertainty.data_mean + kineticsparent.uncertainty.mu - kinetics.uncertainty.data_mean) + np.sqrt(2.0*kineticsparent.uncertainty.var/np.pi) | ||
| err_entry = abs(kinetics.uncertainty.mu) + np.sqrt(2.0*kinetics.uncertainty.var/np.pi) | ||
| if err_entry > err_parent: | ||
| entry = entry.parent | ||
| kinetics = kineticsparent | ||
| logging.error("recursing {}".format(c)) | ||
| c += 1 | ||
| kinetics = ArrheniusChargeTransferBM().fit_to_reactions(L, recipe=self.forward_recipe.actions) | ||
| if kinetics.E0.value_si < 0.0 or len(L) == 1: | ||
| kinetics = average_kinetics([r.kinetics for r in L]) | ||
| else: | ||
| boo = False | ||
| kinetics = kinetics.to_arrhenius_charge_transfer(rxn.get_enthalpy_of_reaction(298.0)) | ||
|
|
||
| kinetics = kinetics.to_arrhenius(rxn.get_enthalpy_of_reaction(T)) | ||
| k = kinetics.get_rate_coefficient(T) | ||
| errors[rxn] = np.log(k / krxn) | ||
| else: | ||
| raise ValueError('only one piece of kinetics information in the tree?') | ||
|
|
||
| return errors, uncertainties | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
boo? A more informative name would help. ANd I don't see whereboois ever set to anything but True? So what's this infinite loop about?Does it mean
while entry.parent:?