@@ -102,7 +102,7 @@ <h1 class="title">Module <code>mici.adapters</code></h1>
102102< details class ="source ">
103103< summary >
104104< span > Expand source code</ span >
105- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L0-L475 " class ="git-link "> Browse git</ a >
105+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L0-L478 " class ="git-link "> Browse git</ a >
106106</ summary >
107107< pre > < code class ="python "> """Methods for adaptively setting algorithmic parameters of transitions."""
108108
@@ -276,7 +276,7 @@ <h1 class="title">Module <code>mici.adapters</code></h1>
276276 }
277277 init_step_size = (
278278 self._find_and_set_init_step_size(chain_state, system, integrator)
279- if integrator.step_size is None else integrator.step_size )
279+ )
280280 if self.log_step_size_reg_target is None:
281281 adapt_state['log_step_size_reg_target'] = log(10 * init_step_size)
282282 else:
@@ -317,14 +317,17 @@ <h1 class="title">Module <code>mici.adapters</code></h1>
317317 """
318318 init_state = state.copy()
319319 h_init = system.h(init_state)
320+ if np.isnan(h_init):
321+ raise AdaptationError('Hamiltonian evaluating to NaN at initial state.')
320322 integrator.step_size = 1
321323 delta_h_threshold = log(2)
322324 for s in range(self.max_init_step_size_iters):
323325 try:
324326 state = integrator.step(init_state)
325327 delta_h = abs(h_init - system.h(state))
326- if s == 0:
327- step_size_too_big = delta_h > delta_h_threshold
328+ if s == 0 or np.isnan(delta_h):
329+ step_size_too_big = (
330+ np.isnan(delta_h) or delta_h > delta_h_threshold)
328331 if (step_size_too_big and delta_h <= delta_h_threshold) or (
329332 not step_size_too_big and delta_h > delta_h_threshold):
330333 return integrator.step_size
@@ -606,7 +609,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
606609< details class ="source ">
607610< summary >
608611< span > Expand source code</ span >
609- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L11-L85 " class ="git-link "> Browse git</ a >
612+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L11-L85 " class ="git-link "> Browse git</ a >
610613</ summary >
611614< pre > < code class ="python "> class Adapter(ABC):
612615 """Abstract adapter for implementing schemes to adapt transition parameters.
@@ -706,7 +709,7 @@ <h3>Instance variables</h3>
706709< details class ="source ">
707710< summary >
708711< span > Expand source code</ span >
709- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L76-L85 " class ="git-link "> Browse git</ a >
712+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L76-L85 " class ="git-link "> Browse git</ a >
710713</ summary >
711714< pre > < code class ="python "> @property
712715@abstractmethod
@@ -747,7 +750,7 @@ <h2 id="returns">Returns</h2>
747750< details class ="source ">
748751< summary >
749752< span > Expand source code</ span >
750- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L22-L36 " class ="git-link "> Browse git</ a >
753+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L22-L36 " class ="git-link "> Browse git</ a >
751754</ summary >
752755< pre > < code class ="python "> @abstractmethod
753756def initialize(self, chain_state, transition):
@@ -793,7 +796,7 @@ <h2 id="args">Args</h2>
793796< details class ="source ">
794797< summary >
795798< span > Expand source code</ span >
796- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L38-L55 " class ="git-link "> Browse git</ a >
799+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L38-L55 " class ="git-link "> Browse git</ a >
797800</ summary >
798801< pre > < code class ="python "> @abstractmethod
799802def update(self, adapt_state, chain_state, trans_stats, transition):
@@ -839,7 +842,7 @@ <h2 id="args">Args</h2>
839842< details class ="source ">
840843< summary >
841844< span > Expand source code</ span >
842- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L57-L74 " class ="git-link "> Browse git</ a >
845+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L57-L74 " class ="git-link "> Browse git</ a >
843846</ summary >
844847< pre > < code class ="python "> @abstractmethod
845848def finalize(self, adapt_state, transition):
@@ -932,7 +935,7 @@ <h2 id="args">Args</h2>
932935< details class ="source ">
933936< summary >
934937< span > Expand source code</ span >
935- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L88-L263 " class ="git-link "> Browse git</ a >
938+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L88-L266 " class ="git-link "> Browse git</ a >
936939</ summary >
937940< pre > < code class ="python "> class DualAveragingStepSizeAdapter(Adapter):
938941 """Dual averaging integrator step size adapter.
@@ -1019,7 +1022,7 @@ <h2 id="args">Args</h2>
10191022 }
10201023 init_step_size = (
10211024 self._find_and_set_init_step_size(chain_state, system, integrator)
1022- if integrator.step_size is None else integrator.step_size )
1025+ )
10231026 if self.log_step_size_reg_target is None:
10241027 adapt_state['log_step_size_reg_target'] = log(10 * init_step_size)
10251028 else:
@@ -1060,14 +1063,17 @@ <h2 id="args">Args</h2>
10601063 """
10611064 init_state = state.copy()
10621065 h_init = system.h(init_state)
1066+ if np.isnan(h_init):
1067+ raise AdaptationError('Hamiltonian evaluating to NaN at initial state.')
10631068 integrator.step_size = 1
10641069 delta_h_threshold = log(2)
10651070 for s in range(self.max_init_step_size_iters):
10661071 try:
10671072 state = integrator.step(init_state)
10681073 delta_h = abs(h_init - system.h(state))
1069- if s == 0:
1070- step_size_too_big = delta_h > delta_h_threshold
1074+ if s == 0 or np.isnan(delta_h):
1075+ step_size_too_big = (
1076+ np.isnan(delta_h) or delta_h > delta_h_threshold)
10711077 if (step_size_too_big and delta_h <= delta_h_threshold) or (
10721078 not step_size_too_big and delta_h > delta_h_threshold):
10731079 return integrator.step_size
@@ -1152,7 +1158,7 @@ <h2 id="returns">Returns</h2>
11521158< details class ="source ">
11531159< summary >
11541160< span > Expand source code</ span >
1155- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L163-L179 " class ="git-link "> Browse git</ a >
1161+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L163-L179 " class ="git-link "> Browse git</ a >
11561162</ summary >
11571163< pre > < code class ="python "> def initialize(self, chain_state, transition):
11581164 integrator = transition.integrator
@@ -1164,7 +1170,7 @@ <h2 id="returns">Returns</h2>
11641170 }
11651171 init_step_size = (
11661172 self._find_and_set_init_step_size(chain_state, system, integrator)
1167- if integrator.step_size is None else integrator.step_size )
1173+ )
11681174 if self.log_step_size_reg_target is None:
11691175 adapt_state['log_step_size_reg_target'] = log(10 * init_step_size)
11701176 else:
@@ -1200,7 +1206,7 @@ <h2 id="args">Args</h2>
12001206< details class ="source ">
12011207< summary >
12021208< span > Expand source code</ span >
1203- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L241-L254 " class ="git-link "> Browse git</ a >
1209+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L244-L257 " class ="git-link "> Browse git</ a >
12041210</ summary >
12051211< pre > < code class ="python "> def update(self, adapt_state, chain_state, trans_stats, transition):
12061212 adapt_state['iter'] += 1
@@ -1242,7 +1248,7 @@ <h2 id="args">Args</h2>
12421248< details class ="source ">
12431249< summary >
12441250< span > Expand source code</ span >
1245- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L256-L263 " class ="git-link "> Browse git</ a >
1251+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L259-L266 " class ="git-link "> Browse git</ a >
12461252</ summary >
12471253< pre > < code class ="python "> def finalize(self, adapt_state, transition):
12481254 if isinstance(adapt_state, dict):
@@ -1301,7 +1307,7 @@ <h2 id="args">Args</h2>
13011307< details class ="source ">
13021308< summary >
13031309< span > Expand source code</ span >
1304- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L266-L368 " class ="git-link "> Browse git</ a >
1310+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L269-L371 " class ="git-link "> Browse git</ a >
13051311</ summary >
13061312< pre > < code class ="python "> class OnlineVarianceMetricAdapter(Adapter):
13071313 """Diagonal metric adapter using online variance estimates.
@@ -1448,7 +1454,7 @@ <h2 id="returns">Returns</h2>
14481454< details class ="source ">
14491455< summary >
14501456< span > Expand source code</ span >
1451- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L311-L316 " class ="git-link "> Browse git</ a >
1457+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L314-L319 " class ="git-link "> Browse git</ a >
14521458</ summary >
14531459< pre > < code class ="python "> def initialize(self, chain_state, transition):
14541460 return {
@@ -1485,7 +1491,7 @@ <h2 id="args">Args</h2>
14851491< details class ="source ">
14861492< summary >
14871493< span > Expand source code</ span >
1488- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L318-L327 " class ="git-link "> Browse git</ a >
1494+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L321-L330 " class ="git-link "> Browse git</ a >
14891495</ summary >
14901496< pre > < code class ="python "> def update(self, adapt_state, chain_state, trans_stats, transition):
14911497 # Use Welford (1962) incremental algorithm to update statistics to
@@ -1523,7 +1529,7 @@ <h2 id="args">Args</h2>
15231529< details class ="source ">
15241530< summary >
15251531< span > Expand source code</ span >
1526- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L339-L368 " class ="git-link "> Browse git</ a >
1532+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L342-L371 " class ="git-link "> Browse git</ a >
15271533</ summary >
15281534< pre > < code class ="python "> def finalize(self, adapt_state, transition):
15291535 if isinstance(adapt_state, dict):
@@ -1605,7 +1611,7 @@ <h2 id="args">Args</h2>
16051611< details class ="source ">
16061612< summary >
16071613< span > Expand source code</ span >
1608- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L371-L476 " class ="git-link "> Browse git</ a >
1614+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L374-L479 " class ="git-link "> Browse git</ a >
16091615</ summary >
16101616< pre > < code class ="python "> class OnlineCovarianceMetricAdapter(Adapter):
16111617 """Dense metric adapter using online covariance estimates.
@@ -1755,7 +1761,7 @@ <h2 id="returns">Returns</h2>
17551761< details class ="source ">
17561762< summary >
17571763< span > Expand source code</ span >
1758- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L418-L425 " class ="git-link "> Browse git</ a >
1764+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L421-L428 " class ="git-link "> Browse git</ a >
17591765</ summary >
17601766< pre > < code class ="python "> def initialize(self, chain_state, transition):
17611767 dim_pos = chain_state.pos.shape[0]
@@ -1794,7 +1800,7 @@ <h2 id="args">Args</h2>
17941800< details class ="source ">
17951801< summary >
17961802< span > Expand source code</ span >
1797- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L427-L436 " class ="git-link "> Browse git</ a >
1803+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L430-L439 " class ="git-link "> Browse git</ a >
17981804</ summary >
17991805< pre > < code class ="python "> def update(self, adapt_state, chain_state, trans_stats, transition):
18001806 # Use Welford (1962) incremental algorithm to update statistics to
@@ -1832,7 +1838,7 @@ <h2 id="args">Args</h2>
18321838< details class ="source ">
18331839< summary >
18341840< span > Expand source code</ span >
1835- < a href ="https://github.com/matt-graham/mici/blob/056095624298b0e017652794677e9ba43f7f5ed8 /mici/adapters.py#L448-L476 " class ="git-link "> Browse git</ a >
1841+ < a href ="https://github.com/matt-graham/mici/blob/aaaad1aae5ce2d12baf95e59bc5ade40149c397b /mici/adapters.py#L451-L479 " class ="git-link "> Browse git</ a >
18361842</ summary >
18371843< pre > < code class ="python "> def finalize(self, adapt_state, transition):
18381844 if isinstance(adapt_state, dict):
0 commit comments