Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b8dd8db
Make OrgByEnsStrat subclass of DefaultStrat
dwhswenson Jun 29, 2015
b1af386
Merge branch 'balance_and_choice_prob' into organize_by_ensemble_stra…
dwhswenson Jun 29, 2015
97abb06
Draft of OrgBeEns.make_chooser
dwhswenson Jun 30, 2015
3e4dba9
Tests for OrgByEns.make_chooser
dwhswenson Jul 1, 2015
52ef7e3
Merge remote-tracking branch 'upstream/master' into organize_by_ensem…
dwhswenson Jul 2, 2015
6517311
Starting skeleton of OrgByEns.make_movers
dwhswenson Jul 2, 2015
d07dba4
Merge branch 'move_scheme_cleanup' into organize_by_ensemble_strategy
dwhswenson Jul 6, 2015
29003eb
Fix for tests
dwhswenson Jul 6, 2015
fd8bda1
Early draft of EnsembleDictionaryMover
dwhswenson Jul 7, 2015
72e72b2
EnsDict runs, though tests don't check correctness
dwhswenson Jul 7, 2015
2821064
Working test for EnsDict with single replica
dwhswenson Jul 7, 2015
3db71f6
Tests for EnsDict with multiple replicas
dwhswenson Jul 7, 2015
77a6b87
Skeletons of OrgByEns and tests. Needs some redo.
dwhswenson Jul 7, 2015
0c47813
Cleaned up Default.make_chooser (now reusable?)
dwhswenson Jul 8, 2015
13a7849
Generalized choice_probability
dwhswenson Jul 8, 2015
57a3719
Reorg most of get_weights subsys to be general
dwhswenson Jul 8, 2015
122a9d4
I think that fully generalizes get_weight subsys
dwhswenson Jul 8, 2015
3eda6f0
Generalized mover keys. Ready to build new strat
dwhswenson Jul 8, 2015
960deb3
Draft of OrgByEns.make_movers
dwhswenson Jul 9, 2015
12cc5d2
first test of OrgByEns looks decent
dwhswenson Jul 9, 2015
5f20b9e
Upgraded EnsDictMover to support ensemble prob
dwhswenson Jul 9, 2015
6ab53ae
Test for weights in EnsDict
dwhswenson Jul 9, 2015
1eeca62
Test when we change the ensemble weight
dwhswenson Jul 10, 2015
8612f7e
Serious clean-up of mover weights normalization
dwhswenson Jul 10, 2015
77056fe
Added test for changing mover_weights in OrgByEns
dwhswenson Jul 10, 2015
2c81ab1
Various test fixes
dwhswenson Jul 10, 2015
fd58ca3
Committing screwy version before rewrite
dwhswenson Sep 30, 2015
604c8de
New version passes the first test....
dwhswenson Oct 1, 2015
34d4980
New version of choice_probability w/ tests
dwhswenson Oct 2, 2015
76a1a99
New make_movers in DefaultStrategy
dwhswenson Oct 2, 2015
6178d72
DefaultStrategy.weights_from_choice_prob & tests
dwhswenson Oct 2, 2015
2fb17b6
Fixed setting group weights when no shooting group
dwhswenson Oct 2, 2015
8e0bd42
Down to one test for DefaultStrategy
dwhswenson Oct 3, 2015
6a9d671
All tests for DefaultStrategy pass
dwhswenson Oct 3, 2015
2414a98
Looks like OrgByEns.choice_probability works
dwhswenson Oct 3, 2015
e55c7bf
More untested bits of code for OrgByEns
dwhswenson Oct 3, 2015
0d7c775
Fix for ensemble sig problems in test_choice_prob
dwhswenson Oct 4, 2015
0eca9cc
Test for OrgByEns.default_weights
dwhswenson Oct 4, 2015
cab0b2d
Test for chooser_movers
dwhswenson Oct 5, 2015
43302c4
Most of the OrgByEns.weights_from_choice_prob
dwhswenson Oct 5, 2015
67e861d
Separate out most_common calcs for renorming
dwhswenson Oct 6, 2015
4d97b55
OrgByEns.weights_from_choice_prob passes test
dwhswenson Oct 6, 2015
d9db71e
OrgByEns.make_movers (and test)
dwhswenson Oct 6, 2015
adc3e20
Fix bug in EnsDictMover test
dwhswenson Oct 6, 2015
180ba9c
Removed worthless old crap.
dwhswenson Oct 6, 2015
afa494c
DefaultStrategy => OrganizeByMoveGroupStrategy
dwhswenson Oct 6, 2015
daedfc0
Merge remote-tracking branch 'upstream/master' into organize_by_ensem…
dwhswenson Oct 7, 2015
c403c17
Partial fixes for unique ensemble stuff
dwhswenson Oct 7, 2015
a51df68
Fix the rest of stuff unique ensemble messed up
dwhswenson Oct 7, 2015
3f4676f
Removed EnsembleDictionaryMover
dwhswenson Oct 7, 2015
e75f393
testEnsDictMover => testRandomAllowedChoiceMover
dwhswenson Oct 7, 2015
ec36501
Outline of test for switching org strategies
dwhswenson Oct 8, 2015
75388d8
Can switch between global org strategies
dwhswenson Oct 8, 2015
e497fa9
Docstrings for MoveStrategies (part 1)
dwhswenson Oct 8, 2015
e12c0b9
No wonder it was failing. Too many RETIS steps!
dwhswenson Oct 8, 2015
2409601
Enough docstrings for now
dwhswenson Oct 8, 2015
ea1221d
Docstrings & some PEP8
dwhswenson Oct 12, 2015
d27ab0f
Merge remote-tracking branch 'upstream/master' into organize_by_ensem…
dwhswenson Oct 12, 2015
0cb98d9
Removed unused mover_key
dwhswenson Oct 12, 2015
5948097
First switch to using dict.get(key, default)
dwhswenson Oct 13, 2015
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
Prev Previous commit
Next Next commit
Docstrings & some PEP8
  • Loading branch information
dwhswenson committed Oct 12, 2015
commit ea1221de692310f0f6dde8a5654881395a81dc6c
79 changes: 48 additions & 31 deletions openpathsampling/analysis/move_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def __init__(self, ensembles, group, replace):
@property
def level(self):
"""
The level of this strategy.
The level of this strategy.

Levels are numeric, but roughly correspond to levels in the default
move tree. This way, we build the tree from bottom up.
"""
Expand Down Expand Up @@ -178,19 +178,19 @@ def make_movers(self, scheme):

For example, `GLOBAL`-level strategies must set
`scheme.choice_probability`.

Parameters
----------
scheme : paths.MoveScheme
the move scheme that this strategy will be used for

Returns
-------
paths.PathMover or list of paths.PathMover
the movers created by this part of the strategy
"""
raise NotImplementedError #TODO: use JHP's ABCError when 302 is merged

class OneWayShootingStrategy(MoveStrategy):
"""
Strategy for OneWayShooting. Allows choice of shooting point selector.
Expand Down Expand Up @@ -376,8 +376,8 @@ class SingleReplicaMinusMoveStrategy(MinusMoveStrategy):

class OrganizeByMoveGroupStrategy(MoveStrategy):
"""
Default global strategy.
Default global strategy.

First choose move type, then choose specific instance of the mover.

Attributes
Expand All @@ -398,6 +398,8 @@ class OrganizeByMoveGroupStrategy(MoveStrategy):
'minus' : 0.2
}
def __init__(self, ensembles=None, group=None, replace=True):
super(OrganizeByMoveGroupStrategy, self).__init__(ensembles,
group, replace)
self.group_weights = {}
self.mover_weights = {}
self.group = group
Expand Down Expand Up @@ -475,7 +477,7 @@ def get_weights(self, scheme, sorted_movers, sort_weights_override={},
scheme : paths.MoveScheme
the scheme to which this strategy is being applied
sorted_movers : unneeded?
sort_weights_override : dict
sort_weights_override : dict
Overrides for sort weights. Format {sort_key : weight}; see
class definition for sort_key format
mover_weights_override : dict
Expand All @@ -488,7 +490,7 @@ class definition for mover_key format
Canonical weights for this strategy. sortkey_w is a dictionary
of sort keys to weights; movers_w is a dictionary of mover keys
to weights. See class definition for the specific formats of the
keys.
keys.
"""
(sorted_w, mover_w) = self.default_weights(scheme)
sorted_weights = self.override_weights(sorted_w, sort_weights_override)
Expand All @@ -514,7 +516,7 @@ def weights_from_choice_probability(self, scheme, choice_probability):
scheme and choice_probability. sortkey_w is a dictionary of
sort keys to weights; movers_w is a dictionary of mover keys to
weights. See class definition for the specific formats of the
keys.
keys.
"""

# first get the norm-based probabilities, then reset them.
Expand All @@ -524,8 +526,8 @@ def weights_from_choice_probability(self, scheme, choice_probability):
# most_most_common tracks which group has the largest count of
# common values (used as backup if there is no shooting group)
for group in scheme.movers:
group_probs = {m : choice_probability[m]
for m in choice_probability
group_probs = {m : choice_probability[m]
for m in choice_probability
if m in scheme.movers[group]}

# normalize here based on making the most common within the
Expand All @@ -540,7 +542,7 @@ def weights_from_choice_probability(self, scheme, choice_probability):
for group in scheme.movers:
m0 = scheme.movers[group][0]
mover_w0 = mover_weights[(group, m0.ensemble_signature)]
group_unscaled[group] = choice_probability[m0] / mover_w0
group_unscaled[group] = choice_probability[m0] / mover_w0

try:
scaling = most_common['shooting'][0]
Expand All @@ -553,7 +555,7 @@ def weights_from_choice_probability(self, scheme, choice_probability):
most_most_common = g
scaling = most_common[most_most_common][0]

group_weights = {g : group_unscaled[g] / scaling
group_weights = {g : group_unscaled[g] / scaling
for g in group_unscaled}

return (group_weights, mover_weights)
Expand All @@ -568,7 +570,7 @@ def choice_probability(self, scheme, group_weights, mover_weights):
are obtained from the strategy.get_weights function.
"""
unnormed = {}
for g_name in scheme.movers.keys():
for g_name in scheme.movers.keys():
for mover in scheme.movers[g_name]:
m_sig = (g_name, mover.ensemble_signature)
unnormed[mover] = group_weights[g_name]*mover_weights[m_sig]
Expand All @@ -582,8 +584,8 @@ def chooser_root_weights(self, scheme, group_weights, mover_weights):
"""
weights = {}
for g in scheme.movers.keys():
weights[g] = sum([mover_weights[m] for m in mover_weights
if m[0]==g]) * group_weights[g]
weights[g] = sum([mover_weights[m] for m in mover_weights
if m[0] == g]) * group_weights[g]
return weights

def chooser_mover_weights(self, scheme, group, mover_weights):
Expand All @@ -597,8 +599,8 @@ def chooser_mover_weights(self, scheme, group, mover_weights):

def make_movers(self, scheme):
(group_weights, mover_weights) = self.get_weights(
scheme=scheme,
sorted_movers=scheme.movers,
scheme=scheme,
sorted_movers=scheme.movers,
sort_weights_override=self.group_weights,
mover_weights_override=self.mover_weights
)
Expand All @@ -615,10 +617,10 @@ def make_movers(self, scheme):
weight_dict = self.chooser_mover_weights(scheme, group,
mover_weights)
choosername = group.capitalize()+"Chooser"
chooser_dict[group] = self.make_chooser(scheme, weight_dict,
chooser_dict[group] = self.make_chooser(scheme, weight_dict,
choosername)

root_couples = [(root_info[g], chooser_dict[g])
root_couples = [(root_info[g], chooser_dict[g])
for g in root_info.keys()]
(root_weights, choosers) = zip(*root_couples)
root_chooser = paths.RandomChoiceMover(movers=choosers,
Expand All @@ -636,6 +638,21 @@ class SingleReplicaStrategy(MoveStrategy):
pass

class OrganizeByEnsembleStrategy(OrganizeByMoveGroupStrategy):
"""
Global strategy to organize by ensemble first. Needed for SRTIS.

First we choose an ensemble, then we choose the specific mover within
that ensemble.

Attributes
----------
ensemble_weights : dict
The sortkey weights. In the format {paths.Ensemble : float(weight)}
mover_weights : dict
The mover weights. In the fromat {(str(groupname),
PathMover.ensemble_signature, paths.Ensemble) : float(weight)}

"""
def __init__(self, ensembles=None, group=None, replace=True):
super(OrganizeByEnsembleStrategy, self).__init__(
ensembles=ensembles, group=group, replace=replace
Expand All @@ -662,7 +679,7 @@ def weights_from_choice_probability(self, scheme, choice_probability):
ensemble_list.extend([e for e in m.ensemble_signature[0]])
ensembles = set(ensemble_list)
for ens in ensembles:
ens_movers = [m for m in choice_probability
ens_movers = [m for m in choice_probability
if ens in m.ensemble_signature[0]]
for m in ens_movers:
ens_sig = m.ensemble_signature
Expand All @@ -671,10 +688,10 @@ def weights_from_choice_probability(self, scheme, choice_probability):
mover_weights[(group, ens_sig, ens)] = weight

local_movers = {s : mover_weights[s] for s in mover_weights
if s[2]==ens}
if s[2] == ens}
ensemble_weights[ens] = sum(local_movers.values())

shooters = [s for s in local_movers if s[0]=='shooting']
shooters = [s for s in local_movers if s[0] == 'shooting']
if len(shooters) > 0:
renorm = local_movers[shooters[0]]
else:
Expand Down Expand Up @@ -741,11 +758,11 @@ def choice_probability(self, scheme, ensemble_weights, mover_weights):
scheme and choice_probability. sortkey_w is a dictionary of
sort keys to weights; movers_w is a dictionary of mover keys to
weights. See class definition for the specific formats of the
keys.
keys.
"""
choice_probability = {}
ens_prob_norm = sum(ensemble_weights.values())
ens_prob = {e : ensemble_weights[e] / ens_prob_norm
ens_prob = {e : ensemble_weights[e] / ens_prob_norm
for e in ensemble_weights}

mover_norm = {e : sum([mover_weights[s] for s in mover_weights
Expand Down Expand Up @@ -780,10 +797,10 @@ def chooser_mover_weights(self, scheme, ensemble, mover_weights):
the sorting depends on the class definition.
"""
weights = {}
for sig in [s for s in mover_weights if s[2]==ensemble]:
for sig in [s for s in mover_weights if s[2] == ensemble]:
group = sig[0]
ens_sig = sig[1]
ens = sig[2]
#ens = sig[2]
# there can be only one
mover = [m for m in scheme.movers[group]
if m.ensemble_signature == ens_sig][0]
Expand All @@ -792,8 +809,8 @@ def chooser_mover_weights(self, scheme, ensemble, mover_weights):

def make_movers(self, scheme):
(ensemble_weights, mover_weights) = self.get_weights(
scheme=scheme,
sorted_movers=scheme.movers,
scheme=scheme,
sorted_movers=scheme.movers,
sort_weights_override=self.ensemble_weights,
mover_weights_override=self.mover_weights
)
Expand All @@ -814,7 +831,7 @@ def make_movers(self, scheme):
choosername)


root_couples = [(root_info[g], chooser_dict[g])
root_couples = [(root_info[g], chooser_dict[g])
for g in root_info.keys()]
(root_weights, choosers) = zip(*root_couples)
root_chooser = paths.RandomChoiceMover(movers=choosers,
Expand Down