45
45
else :
46
46
_has_dill = True
47
47
48
- __version__ = '0.2 .0'
48
+ __version__ = '0.3 .0'
49
49
version = __version__
50
50
51
51
_math_symbols = {'__mul__' : '*' , '__add__' : '+' , '__sub__' : '-' ,
@@ -3255,7 +3255,8 @@ def uncertainties(self, sigma=1, tex=False, dimension=None, samples=None):
3255
3255
else :
3256
3256
return qs_per_dim
3257
3257
3258
- def sample (self , size = None , dimension = None , seed = None , cache_sample = True ):
3258
+ def sample (self , size = None , dimension = None , seed = None , cache_sample = True ,
3259
+ unit = None , as_quantity = False ):
3259
3260
"""
3260
3261
Sample from the distribution.
3261
3262
@@ -3270,13 +3271,18 @@ def sample(self, size=None, dimension=None, seed=None, cache_sample=True):
3270
3271
prior to sampling.
3271
3272
* `cache_sample` (bool, optional, default=True): whether to override the
3272
3273
existing <<class>.cached_sample>.
3274
+ * `unit` (None): NOT YET IMPLEMENTED will raise error if not None
3275
+ * `as_quantity` (False): NOT YET IMPLEMENTED will raise error if not False
3273
3276
3274
3277
Returns
3275
3278
---------
3276
3279
* float or array: float if `size=None`, otherwise a numpy array with
3277
3280
shape defined by `size`.
3278
3281
"""
3279
3282
3283
+ if unit is not None or as_quantity :
3284
+ raise NotImplementedError ("unit and quantities not yet supported for multivariate distributions" )
3285
+
3280
3286
# TODO: add support for per-dimension unit, wrap_at, as_quantity (and pass in to_mvhistogram)
3281
3287
# TODO: add support for seed
3282
3288
if isinstance (seed , dict ):
@@ -3714,14 +3720,16 @@ def uncertainties(self, sigma=1, tex=False):
3714
3720
3715
3721
### SAMPLING & PLOTTING
3716
3722
3717
- def sample (self , size = None , wrap_at = None , seed = None , cache_sample = True ):
3723
+ def sample (self , size = None , wrap_at = None , seed = None , cache_sample = True ,
3724
+ unit = None , as_quantity = False ):
3718
3725
"""
3719
3726
Sample the underlying <<class>.multivariate> distribution in the dimension
3720
3727
defined in <<class>.dimension>.
3721
3728
"""
3722
3729
3723
3730
# TODO: support unit, wrap_at, as_quantity
3724
- return self .multivariate .sample (size = size , seed = seed , dimension = self .dimension , cache_sample = cache_sample )
3731
+ return self .multivariate .sample (size = size , seed = seed , dimension = self .dimension , cache_sample = cache_sample ,
3732
+ unit = unit , as_quantity = as_quantity )
3725
3733
3726
3734
def plot_sample (self , * args , ** kwargs ):
3727
3735
if hasattr (self , 'bins' ):
@@ -3958,7 +3966,7 @@ def get_distributions_with_values(self, values=None, as_univariates=False):
3958
3966
if not as_univariates and isinstance (dist_orig , BaseMultivariateSliceDistribution ):
3959
3967
d = dist_orig .multivariate
3960
3968
else :
3961
- d = dist_orig
3969
+ d = dist_orig #.to_univariate()?
3962
3970
3963
3971
# if as_univariates then we want MVSlices with the same parent MV to be treated separately
3964
3972
take_dimensions = not as_univariates and isinstance (dist_orig , BaseMultivariateSliceDistribution )
@@ -4044,7 +4052,7 @@ def logpdf(self, values=None, as_univariates=False):
4044
4052
samples are available, a ValueError will be raised.
4045
4053
* `as_univariates` (bool, optional, default=False): whether `values` corresponds
4046
4054
to the passed distributions (<DistributionCollection.distributions>)
4047
- or the underlying unpacked distributions (<DistributionCollection.distributions_unpacked >).
4055
+ or the underlying unpacked distributions (<DistributionCollection.dists_unpacked >).
4048
4056
If the former (`as_univariates=False`), covariances will be respected
4049
4057
from any underlying multivariate distributions. If the latter
4050
4058
(`as_univariates=True`) covariances will be ignored.
@@ -7245,7 +7253,8 @@ def take_dimensions(self, dimensions):
7245
7253
labels = [self .labels [d ] for d in dimensions ] if self .labels is not None else None ,
7246
7254
wrap_ats = [self .wrap_ats [d ] for d in dimensions ] if self .wrap_ats is not None else None )
7247
7255
7248
- def sample (self , size = None , dimension = None , seed = None , cache_sample = True ):
7256
+ def sample (self , size = None , dimension = None , seed = None , cache_sample = True ,
7257
+ unit = None , as_quantity = False ):
7249
7258
"""
7250
7259
7251
7260
Arguments
@@ -7256,6 +7265,8 @@ def sample(self, size=None, dimension=None, seed=None, cache_sample=True):
7256
7265
prior to sampling.
7257
7266
* `cache_sample` (bool, optional, default=True): whether to override the
7258
7267
existing <<class>.cached_sample>.
7268
+ * `unit` (None): NOT YET IMPLEMENTED will raise error if not None
7269
+ * `as_quantity` (False): NOT YET IMPLEMENTED will raise error if not False
7259
7270
7260
7271
"""
7261
7272
# if dimension is not None:
@@ -7266,6 +7277,10 @@ def sample(self, size=None, dimension=None, seed=None, cache_sample=True):
7266
7277
# bins = self.bins
7267
7278
# density = self.density
7268
7279
7280
+ if unit is not None or as_quantity :
7281
+ raise NotImplementedError ("unit and quantities not yet supported for multivariate distributions" )
7282
+
7283
+
7269
7284
if isinstance (seed , dict ):
7270
7285
seed = seed .get (self .uniqueid , None )
7271
7286
@@ -7535,7 +7550,7 @@ def __init__(self, samples, weights=None, bw_method=None, units=None,
7535
7550
7536
7551
Arguments
7537
7552
--------------
7538
- * `samples` (np.array object with shape (nsamples, <MVSamples.ndimensions>)):
7553
+ * `samples` (np.array object with shape (<MVSamples. nsamples> , <MVSamples.ndimensions>)):
7539
7554
the samples.
7540
7555
* `weights` (np.array object with shape (nsamples) or None, optional, default=None):
7541
7556
weights for each entry in `samples`. NOTE: only supported with scipy
@@ -7560,6 +7575,8 @@ def __init__(self, samples, weights=None, bw_method=None, units=None,
7560
7575
--------
7561
7576
* an <MVSamples> object
7562
7577
"""
7578
+ # NOTE: the passed samples need to be transposed, so see the override
7579
+ # in dist_constructor_args
7563
7580
super (MVSamples , self ).__init__ (units , labels , labels_latex , wrap_ats ,
7564
7581
_stats .gaussian_kde , ('samples' , 'bw_method' ) if StrictVersion (_scipy_version ) < StrictVersion ("1.2.0" ) else ('samples' , 'bw_method' , 'weights' ),
7565
7582
samples = samples , weights = weights , bw_method = bw_method ,
@@ -7580,7 +7597,7 @@ def samples(self, value):
7580
7597
@property
7581
7598
def weights (self ):
7582
7599
"""
7583
- weights for each entry in <Samples.samples>
7600
+ weights for each sample in <Samples.samples> (nsamples)
7584
7601
"""
7585
7602
return self ._weights
7586
7603
@@ -7608,6 +7625,25 @@ def bw_method(self, value):
7608
7625
self ._bw_method = is_float (value )
7609
7626
self ._dist_constructor_object_clear_cache ()
7610
7627
7628
+ @property
7629
+ def dist_constructor_args (self ):
7630
+ """
7631
+ Return the arguments to pass to the the underlying distribution
7632
+ constructor (often the scipy.stats random variable generator function)
7633
+
7634
+ <MVSamples.samples> is transposed before passing on to gaussian_kde
7635
+
7636
+ See also:
7637
+
7638
+ * <<class>.dist_constructor_func>
7639
+ * <<class>.dist_constructor_object>
7640
+
7641
+ Returns
7642
+ -------
7643
+ * tuple
7644
+ """
7645
+ return [getattr (self , a ).T if a == 'samples' else getattr (self ,a ) for a in self .dist_constructor_argnames ]
7646
+
7611
7647
@property
7612
7648
def ndimensions (self ):
7613
7649
"""
@@ -7733,7 +7769,8 @@ def interval(self, *args, **kwargs):
7733
7769
# TODO: manual implementation
7734
7770
raise NotImplementedError ()
7735
7771
7736
- def sample (self , size = None , dimension = None , seed = None , cache_sample = True ):
7772
+ def sample (self , size = None , dimension = None , seed = None , cache_sample = True ,
7773
+ unit = None , as_quantity = False ):
7737
7774
"""
7738
7775
Sample from the samples (<MVSamples.samples> if <MVSamples.weights>
7739
7776
is not provided, otherwise <MVSamples.samples_weighted>)
@@ -7746,9 +7783,16 @@ def sample(self, size=None, dimension=None, seed=None, cache_sample=True):
7746
7783
prior to sampling.
7747
7784
* `cache_sample` (bool, optional, default=True): whether to override the
7748
7785
existing <<class>.cached_sample>.
7786
+ * `unit` (None): NOT YET IMPLEMENTED will raise error if not None
7787
+ * `as_quantity` (False): NOT YET IMPLEMENTED will raise error if not False
7788
+
7749
7789
7750
7790
"""
7751
7791
7792
+ if unit is not None or as_quantity :
7793
+ raise NotImplementedError ("unit and quantities not yet supported for multivariate distributions" )
7794
+
7795
+
7752
7796
if isinstance (seed , dict ):
7753
7797
seed = seed .get (self .uniqueid , None )
7754
7798
@@ -7928,7 +7972,8 @@ def to_mvhistogram(self, N=1e6, bins=15, range=None):
7928
7972
Arguments
7929
7973
-----------
7930
7974
* `N` (int, optional, default=1e6): number of samples to use for
7931
- the histogram.
7975
+ the histogram. If N>=<MVSamples.nsamples>, <MVSamples.samples>
7976
+ will be passed directly.
7932
7977
* `bins` (int, optional, default=15): number of bins to use for the
7933
7978
histogram.
7934
7979
* `range` (tuple or None): range to use for the histogram.
@@ -7938,7 +7983,7 @@ def to_mvhistogram(self, N=1e6, bins=15, range=None):
7938
7983
* an <MVHistogram> object
7939
7984
"""
7940
7985
# TODO: if sample is updated to take wrap_at/wrap_ats... pass wrap_at=False here
7941
- return MVHistogram .from_data (self .sample (size = int (N ), cache_sample = False ),
7986
+ return MVHistogram .from_data (self .samples if N >= self . nsamples else self . sample (size = int (N ), cache_sample = False ),
7942
7987
bins = bins , range = range ,
7943
7988
units = self .units ,
7944
7989
labels = self .labels , labels_latex = self ._labels_latex ,
@@ -8015,6 +8060,18 @@ def ppf(self, q, unit=None, as_quantity=False, wrap_at=None):
8015
8060
"""
8016
8061
return Samples (samples = self .samples , weights = self .weights , bw_method = self .bw_method , unit = self .unit ).ppf (q , unit = unit , as_quantity = as_quantity , wrap_at = wrap_at )
8017
8062
8063
+ # def pdf(self, x, unit=None, as_quantity=False, wrap_at=None):
8064
+ # """
8065
+ # See <Samples.pdf>
8066
+ # """
8067
+ # return Samples(samples=self.samples, weights=self.weights, bw_method=self.bw_method, unit=self.unit).pdf(x, unit=unit, as_quantity=as_quantity, wrap_at=wrap_at)
8068
+ #
8069
+ # def logpdf(self, x, unit=None, as_quantity=False, wrap_at=None):
8070
+ # """
8071
+ # See <Samples.logpdf>
8072
+ # """
8073
+ # return Samples(samples=self.samples, weights=self.weights, bw_method=self.bw_method, unit=self.unit).logpdf(x, unit=unit, as_quantity=as_quantity, wrap_at=wrap_at)
8074
+
8018
8075
def interval (self , alpha , unit = None , as_quantity = False , wrap_at = None ):
8019
8076
"""
8020
8077
See <Samples.interval>
0 commit comments