sim-tools 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sim-tools
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Simulation Tools for Education and Practice
5
5
  Project-URL: Homepage, https://github.com/sim-tools/sim-tools
6
6
  Project-URL: Bug Tracker, https://github.com/sim-tools/sim-tools/issues
@@ -1,5 +1,5 @@
1
1
  """sim-tools"""
2
2
 
3
- __version__ = "1.1.0"
3
+ __version__ = "1.2.0"
4
4
 
5
5
  from . import datasets, distributions, time_dependent, ovs, output_analysis
@@ -601,7 +601,12 @@ class DistributionRegistry:
601
601
 
602
602
  # Copy params and inject the random seed.
603
603
  params = dist_config["params"].copy()
604
- params["random_seed"] = seed
604
+
605
+ # Only inject random seed if class constructor accepts it
606
+ distribution_class = cls.get(dist_config["class_name"])
607
+ sig = inspect.signature(distribution_class.__init__)
608
+ if "random_seed" in sig.parameters:
609
+ params["random_seed"] = seed
605
610
 
606
611
  # Instantiate and return the distribution object.
607
612
  return cls.create(dist_config["class_name"], **params)
@@ -1230,18 +1235,32 @@ class CombinationDistribution:
1230
1235
  sample a combination of values from multiple distributions.
1231
1236
  """
1232
1237
 
1233
- def __init__(self, *dists: Distribution):
1238
+ def __init__(self, *args: Distribution, dists=None):
1234
1239
  """
1235
- Initialize a combination distribution.
1240
+ Initialise a combination distribution.
1241
+
1242
+ Distributions can be passed either as positional arguments or via the
1243
+ `dists` keyword argument, but not both. The keyword form is required
1244
+ when creating instances through the `DistributionRegistry` class,
1245
+ which passes parameters by name.
1236
1246
 
1237
1247
  Parameters
1238
1248
  ----------
1239
- *dists : Sequence[Distribution]
1240
- Variable length sequence of Distribution objects to combine.
1241
- The sample method will return the sum of samples from all these
1242
- distributions.
1243
- """
1244
- self.dists = dists
1249
+ *args : Distribution
1250
+ Distribution objects to combine, passed as positional arguments.
1251
+ E.g. `CombinationDistribution(d1, d2)`.
1252
+ Cannot be used together with `dists`.
1253
+ dists : Sequence[Distribution], optional
1254
+ Distribution objects to combine, passed as a keyword argument.
1255
+ E.g. `CombinationDistribution(dists=[d1, d2])`.
1256
+ Cannot be used together with `*args`.
1257
+ """
1258
+ if args and dists is not None:
1259
+ raise ValueError(
1260
+ "Pass distributions either as positional arguments or as "
1261
+ "'dists', not both."
1262
+ )
1263
+ self.dists = dists if dists is not None else args
1245
1264
 
1246
1265
  def __repr__(self):
1247
1266
  dist_reprs = [repr(dist) for dist in self.dists]
@@ -2345,7 +2364,7 @@ class DiscreteEmpirical:
2345
2364
  """
2346
2365
 
2347
2366
  # convert to array first
2348
- self.values = np.asarray(values)
2367
+ self.values = np.asarray(list(values))
2349
2368
  self.freq = np.asarray(freq)
2350
2369
 
2351
2370
  validate(self.freq, "freq", is_positive_array)
@@ -2394,7 +2413,6 @@ class DiscreteEmpirical:
2394
2413
  - A numpy array of values with shape determined by size parameter
2395
2414
  """
2396
2415
  sample = self.rng.choice(self.values, p=self.probabilities, size=size)
2397
-
2398
2416
  if size is None:
2399
2417
  return sample.item()
2400
2418
  return sample
@@ -10,7 +10,11 @@ import pandas as pd
10
10
  import matplotlib.pyplot as plt
11
11
  import itertools
12
12
 
13
+ from sim_tools.distributions import DistributionRegistry
14
+
15
+
13
16
  # pylint: disable=too-few-public-methods
17
+ @DistributionRegistry.register()
14
18
  class NSPPThinning:
15
19
  """
16
20
  Non Stationary Poisson Process via Thinning.
File without changes
File without changes
File without changes
File without changes
File without changes