|
51 | 51 |
|
52 | 52 | from pymc.aesaraf import (
|
53 | 53 | PointFunc,
|
| 54 | + SeedSequenceSeed, |
54 | 55 | compile_pymc,
|
55 | 56 | convert_observed_data,
|
56 | 57 | gradient,
|
@@ -986,43 +987,6 @@ def dim_lengths(self) -> Dict[str, Variable]:
|
986 | 987 | """
|
987 | 988 | return self._dim_lengths
|
988 | 989 |
|
989 |
| - @property |
990 |
| - def test_point(self) -> Dict[str, np.ndarray]: |
991 |
| - """Deprecated alias for `Model.initial_point(seed=None)`.""" |
992 |
| - warnings.warn( |
993 |
| - "`Model.test_point` has been deprecated. Use `Model.initial_point(seed=None)`.", |
994 |
| - FutureWarning, |
995 |
| - ) |
996 |
| - return self.initial_point() |
997 |
| - |
998 |
| - def initial_point(self, seed=None) -> Dict[str, np.ndarray]: |
999 |
| - """Computes the initial point of the model. |
1000 |
| -
|
1001 |
| - Returns |
1002 |
| - ------- |
1003 |
| - ip : dict |
1004 |
| - Maps names of transformed variables to numeric initial values in the transformed space. |
1005 |
| - """ |
1006 |
| - fn = make_initial_point_fn(model=self, return_transformed=True) |
1007 |
| - return Point(fn(seed), model=self) |
1008 |
| - |
1009 |
| - @property |
1010 |
| - def initial_values(self) -> Dict[TensorVariable, Optional[Union[np.ndarray, Variable, str]]]: |
1011 |
| - """Maps transformed variables to initial value placeholders. |
1012 |
| -
|
1013 |
| - Keys are the random variables (as returned by e.g. ``pm.Uniform()``) and |
1014 |
| - values are the numeric/symbolic initial values, strings denoting the strategy to get them, or None. |
1015 |
| - """ |
1016 |
| - return self._initial_values |
1017 |
| - |
1018 |
| - def set_initval(self, rv_var, initval): |
1019 |
| - """Sets an initial value (strategy) for a random variable.""" |
1020 |
| - if initval is not None and not isinstance(initval, (Variable, str)): |
1021 |
| - # Convert scalars or array-like inputs to ndarrays |
1022 |
| - initval = rv_var.type.filter(initval) |
1023 |
| - |
1024 |
| - self.initial_values[rv_var] = initval |
1025 |
| - |
1026 | 990 | def shape_from_dims(self, dims):
|
1027 | 991 | shape = []
|
1028 | 992 | if len(set(dims)) != len(dims):
|
@@ -1137,6 +1101,39 @@ def set_dim(self, name: str, new_length: int, coord_values: Optional[Sequence] =
|
1137 | 1101 | self.dim_lengths[name].set_value(new_length)
|
1138 | 1102 | return
|
1139 | 1103 |
|
| 1104 | + def initial_point(self, random_seed: SeedSequenceSeed = None) -> Dict[str, np.ndarray]: |
| 1105 | + """Computes the initial point of the model. |
| 1106 | +
|
| 1107 | + Parameters |
| 1108 | + ---------- |
| 1109 | + random_seed : SeedSequenceSeed, default None |
| 1110 | + Seed(s) for generating initial point from the model. Passed into :func:`pymc.aesaraf.reseed_rngs` |
| 1111 | +
|
| 1112 | + Returns |
| 1113 | + ------- |
| 1114 | + ip : dict of {str : array_like} |
| 1115 | + Maps names of transformed variables to numeric initial values in the transformed space. |
| 1116 | + """ |
| 1117 | + fn = make_initial_point_fn(model=self, return_transformed=True) |
| 1118 | + return Point(fn(random_seed), model=self) |
| 1119 | + |
| 1120 | + @property |
| 1121 | + def initial_values(self) -> Dict[TensorVariable, Optional[Union[np.ndarray, Variable, str]]]: |
| 1122 | + """Maps transformed variables to initial value placeholders. |
| 1123 | +
|
| 1124 | + Keys are the random variables (as returned by e.g. ``pm.Uniform()``) and |
| 1125 | + values are the numeric/symbolic initial values, strings denoting the strategy to get them, or None. |
| 1126 | + """ |
| 1127 | + return self._initial_values |
| 1128 | + |
| 1129 | + def set_initval(self, rv_var, initval): |
| 1130 | + """Sets an initial value (strategy) for a random variable.""" |
| 1131 | + if initval is not None and not isinstance(initval, (Variable, str)): |
| 1132 | + # Convert scalars or array-like inputs to ndarrays |
| 1133 | + initval = rv_var.type.filter(initval) |
| 1134 | + |
| 1135 | + self.initial_values[rv_var] = initval |
| 1136 | + |
1140 | 1137 | def set_data(
|
1141 | 1138 | self,
|
1142 | 1139 | name: str,
|
@@ -1259,34 +1256,6 @@ def set_data(
|
1259 | 1256 |
|
1260 | 1257 | shared_object.set_value(values)
|
1261 | 1258 |
|
1262 |
| - def initial_point(self, seed=None) -> Dict[str, np.ndarray]: |
1263 |
| - """Computes the initial point of the model. |
1264 |
| -
|
1265 |
| - Returns |
1266 |
| - ------- |
1267 |
| - ip : dict |
1268 |
| - Maps names of transformed variables to numeric initial values in the transformed space. |
1269 |
| - """ |
1270 |
| - fn = make_initial_point_fn(model=self, return_transformed=True) |
1271 |
| - return Point(fn(seed), model=self) |
1272 |
| - |
1273 |
| - @property |
1274 |
| - def initial_values(self) -> Dict[TensorVariable, Optional[Union[np.ndarray, Variable, str]]]: |
1275 |
| - """Maps transformed variables to initial value placeholders. |
1276 |
| -
|
1277 |
| - Keys are the random variables (as returned by e.g. ``pm.Uniform()``) and |
1278 |
| - values are the numeric/symbolic initial values, strings denoting the strategy to get them, or None. |
1279 |
| - """ |
1280 |
| - return self._initial_values |
1281 |
| - |
1282 |
| - def set_initval(self, rv_var, initval): |
1283 |
| - """Sets an initial value (strategy) for a random variable.""" |
1284 |
| - if initval is not None and not isinstance(initval, (Variable, str)): |
1285 |
| - # Convert scalars or array-like inputs to ndarrays |
1286 |
| - initval = rv_var.type.filter(initval) |
1287 |
| - |
1288 |
| - self.initial_values[rv_var] = initval |
1289 |
| - |
1290 | 1259 | def register_rv(
|
1291 | 1260 | self, rv_var, name, data=None, total_size=None, dims=None, transform=UNSET, initval=None
|
1292 | 1261 | ):
|
|
0 commit comments