@@ -716,8 +716,8 @@ def __init__(
716716 constraint : Constraint ,
717717 ssm : Any ,
718718 ):
719- self .ssm = ssm
720719 self .vector_field = vector_field
720+ self .ssm = ssm
721721 self .strategy = strategy
722722 self .prior = prior
723723 self .constraint = constraint
@@ -1499,12 +1499,34 @@ class solver_mle(ProbabilisticSolver):
14991499
15001500 """
15011501
1502+ def __init__ (
1503+ self ,
1504+ vector_field : VectorField ,
1505+ * ,
1506+ constraint : Constraint ,
1507+ prior : Callable ,
1508+ ssm : Any ,
1509+ strategy : MarkovStrategy ,
1510+ increase_init_damp_by_eps : bool = True ,
1511+ ):
1512+ super ().__init__ (
1513+ vector_field , strategy = strategy , ssm = ssm , prior = prior , constraint = constraint
1514+ )
1515+ self .increase_init_damp_by_eps = increase_init_damp_by_eps
1516+
15021517 def init (self , t , u : TaylorCoeffTarget , * , damp : float ) -> ProbabilisticSolution :
15031518 estimate , prediction = self .strategy .init_posterior (u = u )
15041519 correction_state = self .constraint .init_linearization ()
15051520
15061521 output_scale_prior = np .ones_like (self .ssm .prototypes .output_scale ())
15071522
1523+ # Increase the damping by machine epsilon because often,
1524+ # the initial taylor coefficients have zero standard deviation
1525+ # in which case the correction below would yield NaNs.
1526+ if self .increase_init_damp_by_eps :
1527+ damp = np .asarray (damp )
1528+ damp = damp + np .finfo_eps (damp )
1529+
15081530 # Update
15091531 f_wrapped = func .partial (self .vector_field , t = t )
15101532 fx , correction_state = self .constraint .linearize (
@@ -1617,20 +1639,27 @@ def __init__(
16171639 constraint : Constraint ,
16181640 ssm : Any ,
16191641 re_linearize_after_calibration = False ,
1642+ increase_init_damp_by_eps : bool = True ,
16201643 ):
1621- self .ssm = ssm
1622- self .vector_field = vector_field
1623- self .strategy = strategy
1624- self .prior = prior
1625- self .constraint = constraint
1644+ super ().__init__ (
1645+ vector_field , strategy = strategy , ssm = ssm , prior = prior , constraint = constraint
1646+ )
16261647 self .re_linearize_after_calibration = re_linearize_after_calibration
1648+ self .increase_init_damp_by_eps = increase_init_damp_by_eps
16271649
16281650 def init (self , t , u , * , damp ) -> ProbabilisticSolution :
16291651 u , prediction = self .strategy .init_posterior (u = u )
16301652 lin_state = self .constraint .init_linearization ()
16311653
16321654 output_scale = np .ones_like (self .ssm .prototypes .output_scale ())
16331655
1656+ # Increase the damping by machine epsilon because often,
1657+ # the initial taylor coefficients have zero standard deviation
1658+ # in which case the correction below would yield NaNs.
1659+ if self .increase_init_damp_by_eps :
1660+ damp = np .asarray (damp )
1661+ damp = damp + np .finfo_eps (damp )
1662+
16341663 f_wrapped = func .partial (self .vector_field , t = t )
16351664 fx , lin_state = self .constraint .linearize (
16361665 f_wrapped , u .marginals , lin_state , damp = damp
@@ -1741,13 +1770,35 @@ class solver(ProbabilisticSolver):
17411770
17421771 """
17431772
1773+ def __init__ (
1774+ self ,
1775+ vector_field : VectorField ,
1776+ * ,
1777+ constraint : Constraint ,
1778+ prior : Callable ,
1779+ ssm : Any ,
1780+ strategy : MarkovStrategy ,
1781+ increase_init_damp_by_eps : bool = True ,
1782+ ):
1783+ super ().__init__ (
1784+ vector_field , strategy = strategy , ssm = ssm , prior = prior , constraint = constraint
1785+ )
1786+ self .increase_init_damp_by_eps = increase_init_damp_by_eps
1787+
17441788 def init (
17451789 self , t : Array , u : TaylorCoeffTarget , * , damp : float
17461790 ) -> ProbabilisticSolution :
17471791 u , prediction = self .strategy .init_posterior (u = u )
17481792
17491793 correction_state = self .constraint .init_linearization ()
17501794
1795+ # Increase the damping by machine epsilon because often,
1796+ # the initial taylor coefficients have zero standard deviation
1797+ # in which case the correction below would yield NaNs.
1798+ if self .increase_init_damp_by_eps :
1799+ damp = np .asarray (damp )
1800+ damp = damp + np .finfo_eps (damp )
1801+
17511802 f_wrapped = func .partial (self .vector_field , t = t )
17521803 fx , correction_state = self .constraint .linearize (
17531804 f_wrapped , rv = u .marginals , state = correction_state , damp = damp
0 commit comments