From ff1cf6020112c6691df09092de0ca0be26b39a76 Mon Sep 17 00:00:00 2001 From: Larry Dong Date: Thu, 8 Apr 2021 08:18:57 -0400 Subject: [PATCH 1/3] :turtle: Fixed documentation --- docs/source/Gaussian_Processes.rst | 2 +- docs/source/PyMC3_and_Aesara.rst | 6 +- docs/source/api/math.rst | 2 +- docs/source/developer_guide.rst | 10 ++-- pymc3/aesaraf.py | 20 +++---- pymc3/data.py | 2 +- pymc3/distributions/continuous.py | 92 ++++++++++++++--------------- pymc3/distributions/discrete.py | 40 ++++++------- pymc3/distributions/dist_math.py | 6 +- pymc3/distributions/distribution.py | 2 +- pymc3/distributions/mixture.py | 4 +- pymc3/glm/utils.py | 2 +- pymc3/model.py | 28 ++++----- pymc3/step_methods/arraystep.py | 6 +- pymc3/step_methods/hmc/base_hmc.py | 4 +- pymc3/step_methods/hmc/hmc.py | 2 +- pymc3/step_methods/mlda.py | 8 +-- pymc3/step_methods/sgmcmc.py | 2 +- pymc3/tests/test_aesaraf.py | 2 +- pymc3/tests/test_ode.py | 2 +- pymc3/tests/test_types.py | 2 +- pymc3/variational/inference.py | 2 +- 22 files changed, 123 insertions(+), 123 deletions(-) diff --git a/docs/source/Gaussian_Processes.rst b/docs/source/Gaussian_Processes.rst index 40c987acd7..d357cea0e3 100644 --- a/docs/source/Gaussian_Processes.rst +++ b/docs/source/Gaussian_Processes.rst @@ -158,7 +158,7 @@ other type of random variable. The first argument is the name of the random variable representing the function we are placing the prior over. The second argument is the inputs to the function that the prior is over, :code:`X`. The inputs are usually known and present in the data, but they can -also be PyMC3 random variables. If the inputs are a Aesara tensor or a +also be PyMC3 random variables. If the inputs are an Aesara tensor or a PyMC3 random variable, the :code:`shape` needs to be given. Usually at this point, inference is performed on the model. The diff --git a/docs/source/PyMC3_and_Aesara.rst b/docs/source/PyMC3_and_Aesara.rst index cfa9f8470a..fe6006a67a 100644 --- a/docs/source/PyMC3_and_Aesara.rst +++ b/docs/source/PyMC3_and_Aesara.rst @@ -12,7 +12,7 @@ What is Aesara Aesara is a package that allows us to define functions involving array operations and linear algebra. When we define a PyMC3 model, we implicitly -build up a Aesara function from the space of our parameters to +build up an Aesara function from the space of our parameters to their posterior probability density up to a constant factor. We then use symbolic manipulations of this function to also get access to its gradient. @@ -159,7 +159,7 @@ where with the normal likelihood :math:`N(x|μ,σ^2)` To build that function we need to keep track of two things: The parameter space (the *free variables*) and the logp function. For each free variable -we generate a Aesara variable. And for each variable (observed or otherwise) +we generate an Aesara variable. And for each variable (observed or otherwise) we add a term to the global logp. In the background something similar to this is happening:: @@ -177,7 +177,7 @@ So calling `pm.Normal()` modifies the model: It changes the logp function of the model. If the `observed` keyword isn't set it also creates a new free variable. In contrast, `pm.Normal.dist()` doesn't care about the model, it just creates an object that represents the normal distribution. Calling -`logp` on this object creates a Aesara variable for the logp probability +`logp` on this object creates an Aesara variable for the logp probability or log probability density of the distribution, but again without changing the model in any way. diff --git a/docs/source/api/math.rst b/docs/source/api/math.rst index 8842a77c33..b3721afbf3 100644 --- a/docs/source/api/math.rst +++ b/docs/source/api/math.rst @@ -4,7 +4,7 @@ Math This submodule contains various mathematical functions. Most of them are imported directly from aesara.tensor (see there for more details). Doing any kind of math with PyMC3 random -variables, or defining custom likelihoods or priors requires you to use these aesara +variables, or defining custom likelihoods or priors requires you to use these Aesara expressions rather than NumPy or Python code. .. currentmodule:: pymc3.math diff --git a/docs/source/developer_guide.rst b/docs/source/developer_guide.rst index 6073bb08b4..25d4d8db39 100644 --- a/docs/source/developer_guide.rst +++ b/docs/source/developer_guide.rst @@ -193,7 +193,7 @@ explicit about the conversion. For example: ``logp`` method, very different behind the curtain ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The ``logp`` method is straightforward - it is a Aesara function within each +The ``logp`` method is straightforward - it is an Aesara function within each distribution. It has the following signature: .. code:: python @@ -201,7 +201,7 @@ distribution. It has the following signature: def logp(self, value): # GET PARAMETERS param1, param2, ... = self.params1, self.params2, ... - # EVALUATE LOG-LIKELIHOOD FUNCTION, all inputs are (or array that could be convert to) aesara tensor + # EVALUATE LOG-LIKELIHOOD FUNCTION, all inputs are (or array that could be convert to) Aesara tensor total_log_prob = f(param1, param2, ..., value) return total_log_prob @@ -360,7 +360,7 @@ cannot be transformed. ``Factor`` basically `enable and assign the logp `__ - (representated as a tensor also) property to a Aesara tensor (thus + (representated as a tensor also) property to an Aesara tensor (thus making it a random variable). For a ``TransformedRV``, it transforms the distribution into a ``TransformedDistribution``, and then ``model.Var`` is called again to added the RV associated with the @@ -474,7 +474,7 @@ sum them together to get the model logp: ... return logp -which returns a Aesara tensor that its value depends on the free +which returns an Aesara tensor that its value depends on the free parameters in the model (i.e., its parent nodes from the Aesara graph).You can evaluate or compile into a python callable (that you can pass numpy as input args). Note that the logp tensor depends on its @@ -751,7 +751,7 @@ We love NUTS, or to be more precise Dynamic HMC with complex stopping rules. This part is actually all done outside of Aesara, for NUTS, it includes: the leapfrog, dual averaging, tunning of mass matrix and step size, the tree building, sampler related statistics like divergence and -energy checking. We actually have a Aesara version of HMC, but it has never +energy checking. We actually have an Aesara version of HMC, but it has never been used, and has been removed from the main repository. It can still be found in the `git history `__, diff --git a/pymc3/aesaraf.py b/pymc3/aesaraf.py index c0fc4a93e1..c9041e8462 100644 --- a/pymc3/aesaraf.py +++ b/pymc3/aesaraf.py @@ -78,7 +78,7 @@ def pandas_to_array(data): """Convert a pandas object to a NumPy array. - XXX: When `data` is a generator, this will return a Aesara tensor! + XXX: When `data` is a generator, this will return an Aesara tensor! """ if hasattr(data, "to_numpy") and hasattr(data, "isnull"): @@ -349,11 +349,11 @@ def transform_replacements(var, replacements): def inputvars(a): """ - Get the inputs into a aesara variables + Get the inputs into Aesara variables Parameters ---------- - a: aesara variable + a: Aesara variable Returns ------- @@ -362,24 +362,24 @@ def inputvars(a): return [v for v in graph_inputs(makeiter(a)) if isinstance(v, TensorVariable)] -def cont_inputs(f): +def cont_inputs(a): """ - Get the continuous inputs into a aesara variables + Get the continuous inputs into Aesara variables Parameters ---------- - a: aesara variable + a: Aesara variable Returns ------- r: list of tensor variables that are continuous inputs """ - return typefilter(inputvars(f), continuous_types) + return typefilter(inputvars(a), continuous_types) def floatX(X): """ - Convert a aesara tensor or numpy array to aesara.config.floatX type. + Convert an Aesara tensor or numpy array to aesara.config.floatX type. """ try: return X.astype(aesara.config.floatX) @@ -554,12 +554,12 @@ def join_nonshared_inputs( make_shared: bool = False, ): """ - Takes a list of aesara Variables and joins their non shared inputs into a single input. + Takes a list of Aesara Variables and joins their non shared inputs into a single input. Parameters ---------- point: a sample point - xs: list of aesara tensors + xs: list of Aesara tensors vars: list of variables to join Returns diff --git a/pymc3/data.py b/pymc3/data.py index 0bdc7c6fc0..846e8272b7 100644 --- a/pymc3/data.py +++ b/pymc3/data.py @@ -464,7 +464,7 @@ def align_minibatches(batches=None): class Data: - """Data container class that wraps the aesara ``SharedVariable`` class + """Data container class that wraps the Aesara ``SharedVariable`` class and lets the model be aware of its inputs and outputs. Parameters diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index d06400679c..db4a191967 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -304,7 +304,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -321,7 +321,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -361,7 +361,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -378,7 +378,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -681,7 +681,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -808,7 +808,7 @@ def logp(value, loc, sigma): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -832,7 +832,7 @@ def logcdf(value, loc, sigma): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1006,7 +1006,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1039,7 +1039,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1187,7 +1187,7 @@ def logp(value, alpha, beta): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1327,7 +1327,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1398,7 +1398,7 @@ def logp(value, mu): value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple values are desired the values must be - provided in a numpy array or aesara tensor + provided in a numpy array or Aesara tensor Returns ------- @@ -1421,7 +1421,7 @@ def logcdf(value, mu): value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple values are desired the values must be provided in a numpy - array or aesara tensor. + array or Aesara tensor. Returns ------- @@ -1515,7 +1515,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1535,7 +1535,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1643,7 +1643,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1772,7 +1772,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1799,7 +1799,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1925,7 +1925,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -2080,7 +2080,7 @@ def logp( ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -2109,7 +2109,7 @@ def logcdf( ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -2194,7 +2194,7 @@ def logp(value, alpha, beta): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -2213,7 +2213,7 @@ def logcdf(value, alpha, beta): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -2279,7 +2279,7 @@ def logp(value, loc, beta): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -2300,7 +2300,7 @@ def logcdf(value, loc, beta): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -2566,7 +2566,7 @@ def logp(value, alpha, beta): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -2588,7 +2588,7 @@ def logcdf(value, alpha, beta): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -2742,7 +2742,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -2769,7 +2769,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -2890,7 +2890,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3031,7 +3031,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3072,7 +3072,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -3188,7 +3188,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3317,7 +3317,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3439,7 +3439,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3467,7 +3467,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -3572,7 +3572,7 @@ def logp( ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3597,7 +3597,7 @@ def logcdf( ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -3750,7 +3750,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3855,7 +3855,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -3878,7 +3878,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -3981,7 +3981,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -4112,7 +4112,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -4215,7 +4215,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -4238,7 +4238,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -4251,4 +4251,4 @@ def logcdf(self, value): return bound( at.log(at.erfc(at.exp(-scaled / 2) * (2 ** -0.5))), 0 < sigma, - ) + ) \ No newline at end of file diff --git a/pymc3/distributions/discrete.py b/pymc3/distributions/discrete.py index 31cf813a5d..3672da8c83 100644 --- a/pymc3/distributions/discrete.py +++ b/pymc3/distributions/discrete.py @@ -113,7 +113,7 @@ def logp(value, n, p): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -277,7 +277,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -385,7 +385,7 @@ def logp(value, p): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -412,7 +412,7 @@ def logcdf(value, p): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -525,7 +525,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -550,7 +550,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -628,7 +628,7 @@ def logp(value, mu): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -647,7 +647,7 @@ def logcdf(value, mu): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -765,7 +765,7 @@ def logp(value, n, p): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -885,7 +885,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -903,7 +903,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1010,7 +1010,7 @@ def logp(self, value): ---------- value : numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1155,7 +1155,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1178,7 +1178,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1333,7 +1333,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1434,7 +1434,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1460,7 +1460,7 @@ def logcdf(self, value): ---------- value: numeric or np.ndarray or aesara.tensor Value(s) for which log CDF is calculated. If the log CDF for multiple - values are desired the values must be provided in a numpy array or aesara tensor. + values are desired the values must be provided in a numpy array or Aesara tensor. Returns ------- @@ -1566,7 +1566,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1734,7 +1734,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -1966,7 +1966,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- diff --git a/pymc3/distributions/dist_math.py b/pymc3/distributions/dist_math.py index 3626e1b80f..8fe3ce74e8 100644 --- a/pymc3/distributions/dist_math.py +++ b/pymc3/distributions/dist_math.py @@ -189,14 +189,14 @@ def log_diff_normal_cdf(mu, sigma, x, y): def sigma2rho(sigma): """ - `sigma -> rho` aesara converter + `sigma -> rho` Aesara converter :math:`mu + sigma*e = mu + log(1+exp(rho))*e`""" return at.log(at.exp(at.abs_(sigma)) - 1.0) def rho2sigma(rho): """ - `rho -> sigma` aesara converter + `rho -> sigma` Aesara converter :math:`mu + sigma*e = mu + log(1+exp(rho))*e`""" return at.nnet.softplus(rho) @@ -317,7 +317,7 @@ def dlogp(inputs, gradients): class SplineWrapper(Op): """ - Creates a aesara operation from scipy.interpolate.UnivariateSpline + Creates an Aesara operation from scipy.interpolate.UnivariateSpline """ __props__ = ("spline",) diff --git a/pymc3/distributions/distribution.py b/pymc3/distributions/distribution.py index e3f5893718..4960592c8c 100644 --- a/pymc3/distributions/distribution.py +++ b/pymc3/distributions/distribution.py @@ -331,7 +331,7 @@ def __init__( logp: callable A callable that has the following signature ``logp(value)`` and - returns a aesara tensor that represents the distribution's log + returns an Aesara tensor that represents the distribution's log probability density. shape: tuple (Optional): defaults to `()` The shape of the distribution. The default value indicates a scalar. diff --git a/pymc3/distributions/mixture.py b/pymc3/distributions/mixture.py index 4410292429..3d82436f7d 100644 --- a/pymc3/distributions/mixture.py +++ b/pymc3/distributions/mixture.py @@ -408,7 +408,7 @@ def logp(self, value): ---------- value: numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- @@ -715,7 +715,7 @@ def logp(self, value): ---------- value : numeric Value(s) for which log-probability is calculated. If the log probabilities for multiple - values are desired the values must be provided in a numpy array or aesara tensor + values are desired the values must be provided in a numpy array or Aesara tensor Returns ------- diff --git a/pymc3/glm/utils.py b/pymc3/glm/utils.py index ce5efe90af..7fee1cd1e6 100644 --- a/pymc3/glm/utils.py +++ b/pymc3/glm/utils.py @@ -104,7 +104,7 @@ def any_to_tensor_and_labels(x, labels=None): # we should check that we can extract labels if labels is None and not isinstance(x, Variable): labels = ["x%d" % i for i in range(x.shape[1])] - # for aesara variables we should have labels from user + # for Aesara variables we should have labels from user elif labels is None: raise ValueError("Please provide labels as " "we cannot infer shape of input") else: # trust labels, user knows what he is doing diff --git a/pymc3/model.py b/pymc3/model.py index 9cccde8b30..0b5c6993d7 100644 --- a/pymc3/model.py +++ b/pymc3/model.py @@ -336,11 +336,11 @@ def logp_nojact(self): class ValueGradFunction: - """Create a Aesara function that computes a value and its gradient. + """Create an Aesara function that computes a value and its gradient. Parameters ---------- - costs: list of aesara variables + costs: list of Aesara variables We compute the weighted sum of the specified Aesara values, and the gradient of that sum. The weights can be specified with `ValueGradFunction.set_weights`. grad_vars: list of named Aesara variables or None @@ -484,7 +484,7 @@ def __call__(self, grad_vars, grad_out=None, extra_vars=None): @property def profile(self): - """Profiling information of the underlying aesara function.""" + """Profiling information of the underlying Aesara function.""" return self._aesara_function.profile @@ -508,9 +508,9 @@ class Model(Factor, WithMemoization, metaclass=ContextMeta): So that 'nested' model contributes to the variables and likelihood factors of parent model. aesara_config: dict - A dictionary of aesara config values that should be set + A dictionary of Aesara config values that should be set temporarily in the model context. See the documentation - of aesara for a complete list. + of Aesara for a complete list. check_bounds: bool Ensure that input parameters to distributions are in a valid range. If your model is built in a way where you know your @@ -652,7 +652,7 @@ def ndim(self): return sum(var.ndim for var in self.value_vars) def logp_dlogp_function(self, grad_vars=None, tempered=False, **kwargs): - """Compile a aesara function that computes logp and gradient. + """Compile an Aesara function that computes logp and gradient. Parameters ---------- @@ -1036,7 +1036,7 @@ def __getitem__(self, key): raise e def makefn(self, outs, mode=None, *args, **kwargs): - """Compiles a Aesara function which returns ``outs`` and takes the variable + """Compiles an Aesara function which returns ``outs`` and takes the variable ancestors of ``outs`` as inputs. Parameters @@ -1061,7 +1061,7 @@ def makefn(self, outs, mode=None, *args, **kwargs): ) def fn(self, outs, mode=None, *args, **kwargs): - """Compiles a Aesara function which returns the values of ``outs`` + """Compiles an Aesara function which returns the values of ``outs`` and takes values of model vars as arguments. Parameters @@ -1076,7 +1076,7 @@ def fn(self, outs, mode=None, *args, **kwargs): return LoosePointFunc(self.makefn(outs, mode, *args, **kwargs), self) def fastfn(self, outs, mode=None, *args, **kwargs): - """Compiles a Aesara function which returns ``outs`` and takes values + """Compiles an Aesara function which returns ``outs`` and takes values of model vars as a dict as an argument. Parameters @@ -1092,7 +1092,7 @@ def fastfn(self, outs, mode=None, *args, **kwargs): return FastPointFunc(f) def profile(self, outs, n=1000, point=None, profile=True, *args, **kwargs): - """Compiles and profiles a Aesara function which returns ``outs`` and + """Compiles and profiles an Aesara function which returns ``outs`` and takes values of model vars as a dict as an argument. Parameters @@ -1371,7 +1371,7 @@ def set_data(new_data, model=None): def fn(outs, mode=None, model=None, *args, **kwargs): - """Compiles a Aesara function which returns the values of ``outs`` and + """Compiles an Aesara function which returns the values of ``outs`` and takes values of model vars as arguments. Parameters @@ -1388,7 +1388,7 @@ def fn(outs, mode=None, model=None, *args, **kwargs): def fastfn(outs, mode=None, model=None): - """Compiles a Aesara function which returns ``outs`` and takes values of model + """Compiles an Aesara function which returns ``outs`` and takes values of model vars as a dict as an argument. Parameters @@ -1532,7 +1532,7 @@ def Deterministic(name, var, model=None, dims=None): Parameters ---------- name: str - var: aesara variables + var: Aesara variables Returns ------- @@ -1552,7 +1552,7 @@ def Potential(name, var, model=None): Parameters ---------- name: str - var: aesara variables + var: Aesara variables Returns ------- diff --git a/pymc3/step_methods/arraystep.py b/pymc3/step_methods/arraystep.py index bd02887cd8..1329c640f2 100644 --- a/pymc3/step_methods/arraystep.py +++ b/pymc3/step_methods/arraystep.py @@ -128,7 +128,7 @@ class ArrayStep(BlockedStep): ---------- vars: list List of variables for sampler. - fs: list of logp aesara functions + fs: list of logp Aesara functions allvars: Boolean (default False) blocked: Boolean (default True) """ @@ -181,7 +181,7 @@ def __init__(self, vars, shared, blocked=True): Parameters ---------- vars: list of sampling variables - shared: dict of aesara variable -> shared variable + shared: dict of Aesara variable -> shared variable blocked: Boolean (default True) """ self.vars = vars @@ -241,7 +241,7 @@ def __init__(self, vars, shared, blocked=True): Parameters ---------- vars: list of sampling variables - shared: dict of aesara variable -> shared variable + shared: dict of Aesara variable -> shared variable blocked: Boolean (default True) """ self.population = None diff --git a/pymc3/step_methods/hmc/base_hmc.py b/pymc3/step_methods/hmc/base_hmc.py index 89f74ad07e..a3d368eec3 100644 --- a/pymc3/step_methods/hmc/base_hmc.py +++ b/pymc3/step_methods/hmc/base_hmc.py @@ -64,7 +64,7 @@ def __init__( Parameters ---------- - vars: list of aesara variables + vars: list of Aesara variables scaling: array_like, ndim = {1,2} Scaling for momentum distribution. 1d arrays interpreted matrix diagonal. @@ -78,7 +78,7 @@ def __init__( potential: Potential, optional An object that represents the Hamiltonian with methods `velocity`, `energy`, and `random` methods. - **aesara_kwargs: passed to aesara functions + **aesara_kwargs: passed to Aesara functions """ self._model = modelcontext(model) diff --git a/pymc3/step_methods/hmc/hmc.py b/pymc3/step_methods/hmc/hmc.py index 522a40d94f..fa06a932db 100644 --- a/pymc3/step_methods/hmc/hmc.py +++ b/pymc3/step_methods/hmc/hmc.py @@ -59,7 +59,7 @@ def __init__(self, vars=None, path_length=2.0, max_steps=1024, **kwargs): Parameters ---------- - vars: list of aesara variables + vars: list of Aesara variables path_length: float, default=2 total length to travel step_rand: function float -> float, default=unif diff --git a/pymc3/step_methods/mlda.py b/pymc3/step_methods/mlda.py index a155993fef..9621c79961 100644 --- a/pymc3/step_methods/mlda.py +++ b/pymc3/step_methods/mlda.py @@ -280,7 +280,7 @@ class MLDA(ArrayStepShared): the PyMC3 model (also demonstrated in the example notebook): - Include a `pm.Data()` variable with the name `Q` in the model description of all levels. - - Use a Aesara Op to calculate the forward model (or the + - Use an Aesara Op to calculate the forward model (or the combination of a forward model and a likelihood). This Op should have a `perform()` method which (in addition to all the other calculations), calculates the quantity of interest @@ -305,7 +305,7 @@ class MLDA(ArrayStepShared): extra variables mu_B and Sigma_B, which will capture the bias between different levels. All these variables should be instantiated using the pm.Data method. - - Use a Aesara Op to define the forward model (and + - Use an Aesara Op to define the forward model (and optionally the likelihood) for all levels. The Op needs to store the result of each forward model calculation to the variable model_output of the PyMC3 model, @@ -555,12 +555,12 @@ def __init__( self.accepted = 0 - # Construct aesara function for current-level model likelihood + # Construct Aesara function for current-level model likelihood # (for use in acceptance) shared = pm.make_shared_replacements(initial_values, value_vars, model) self.delta_logp = delta_logp_inverse(initial_values, model.logpt, value_vars, shared) - # Construct aesara function for below-level model likelihood + # Construct Aesara function for below-level model likelihood # (for use in acceptance) model_below = pm.modelcontext(self.model_below) vars_below = [var for var in model_below.value_vars if var.name in self.var_names] diff --git a/pymc3/step_methods/sgmcmc.py b/pymc3/step_methods/sgmcmc.py index 9fabf9cf62..800c2da540 100644 --- a/pymc3/step_methods/sgmcmc.py +++ b/pymc3/step_methods/sgmcmc.py @@ -109,7 +109,7 @@ class BaseStochasticGradient(ArrayStepShared): Defining a BaseStochasticGradient needs custom implementation of the following methods: - :code: `.mk_training_fn()` - Returns a aesara function which is called for each sampling step + Returns an Aesara function which is called for each sampling step - :code: `._initialize_values()` Returns None it creates class variables which are required for the training fn """ diff --git a/pymc3/tests/test_aesaraf.py b/pymc3/tests/test_aesaraf.py index 87d9af4a5a..4e923212a7 100644 --- a/pymc3/tests/test_aesaraf.py +++ b/pymc3/tests/test_aesaraf.py @@ -417,7 +417,7 @@ def test_pandas_to_array(input_dtype): # Make sure the returned object has .set_gen and .set_default methods assert hasattr(wrapped, "set_gen") assert hasattr(wrapped, "set_default") - # Make sure the returned object is a Aesara TensorVariable + # Make sure the returned object is an Aesara TensorVariable assert isinstance(wrapped, TensorVariable) diff --git a/pymc3/tests/test_ode.py b/pymc3/tests/test_ode.py index e7ca50013a..94dfb0dd6f 100644 --- a/pymc3/tests/test_ode.py +++ b/pymc3/tests/test_ode.py @@ -26,7 +26,7 @@ def test_gradients(): - """Tests the computation of the sensitivities from the aesara computation graph""" + """Tests the computation of the sensitivities from the Aesara computation graph""" # ODE system for which to compute gradients def ode_func(y, t, p): diff --git a/pymc3/tests/test_types.py b/pymc3/tests/test_types.py index 4adf8a6218..c38c04edf8 100644 --- a/pymc3/tests/test_types.py +++ b/pymc3/tests/test_types.py @@ -27,7 +27,7 @@ class TestType: samplers = (Metropolis, Slice, HamiltonianMC, NUTS) def setup_method(self): - # save aesara config object + # save Aesara config object self.aesara_config = copy(aesara.config) def teardown_method(self): diff --git a/pymc3/variational/inference.py b/pymc3/variational/inference.py index 63a8bb2a72..c8b02e7a1c 100644 --- a/pymc3/variational/inference.py +++ b/pymc3/variational/inference.py @@ -425,7 +425,7 @@ class ADVI(KLqp): The tensors to which mini-bathced samples are supplied are handled separately by using callbacks in :func:`Inference.fit` method - that change storage of shared aesara variable or by :func:`pymc3.generator` + that change storage of shared Aesara variable or by :func:`pymc3.generator` that automatically iterates over minibatches and defined beforehand. - (optional) Parameters of deterministic mappings From 903eaa2ea5981940922c41f87613ddb52f412840 Mon Sep 17 00:00:00 2001 From: Larry Dong Date: Thu, 8 Apr 2021 08:51:31 -0400 Subject: [PATCH 2/3] :turtle: Minor fix on top of grammar fixed in docs --- pymc3/distributions/continuous.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index db4a191967..d91fa762ad 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -4251,4 +4251,4 @@ def logcdf(self, value): return bound( at.log(at.erfc(at.exp(-scaled / 2) * (2 ** -0.5))), 0 < sigma, - ) \ No newline at end of file + ) From 685a06554195eeb73b07fceea90fb783187990cb Mon Sep 17 00:00:00 2001 From: Larry Dong Date: Sun, 25 Apr 2021 18:14:45 -0400 Subject: [PATCH 3/3] Weibull RandomVariable refactoring: an example --- pymc3/distributions/continuous.py | 58 ++++++++++--------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index 3ffa68df93..9bad238f00 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -36,6 +36,7 @@ normal, pareto, uniform, + weibull, ) from aesara.tensor.random.op import RandomVariable from aesara.tensor.var import TensorVariable @@ -2690,46 +2691,23 @@ class Weibull(PositiveContinuous): beta: float Scale parameter (beta > 0). """ + rv_op = weibull - def __init__(self, alpha, beta, *args, **kwargs): - super().__init__(*args, **kwargs) - self.alpha = alpha = at.as_tensor_variable(floatX(alpha)) - self.beta = beta = at.as_tensor_variable(floatX(beta)) - self.mean = beta * at.exp(gammaln(1 + 1.0 / alpha)) - self.median = beta * at.exp(gammaln(at.log(2))) ** (1.0 / alpha) - self.variance = beta ** 2 * at.exp(gammaln(1 + 2.0 / alpha)) - self.mean ** 2 - self.mode = at.switch( - alpha >= 1, beta * ((alpha - 1) / alpha) ** (1 / alpha), 0 - ) # Reference: https://en.wikipedia.org/wiki/Weibull_distribution + @classmethod + def dist(cls, alpha, beta, *args, **kwargs): + alpha = at.as_tensor_variable(floatX(alpha)) + beta = at.as_tensor_variable(floatX(beta)) assert_negative_support(alpha, "alpha", "Weibull") assert_negative_support(beta, "beta", "Weibull") - def random(self, point=None, size=None): - """ - Draw random values from Weibull distribution. - - Parameters - ---------- - point: dict, optional - Dict of variable values on which random values are to be - conditioned (uses default point if not specified). - size: int, optional - Desired size of random sample (returns one sample if not - specified). - - Returns - ------- - array - """ - # alpha, beta = draw_values([self.alpha, self.beta], point=point, size=size) - # - # def _random(a, b, size=None): - # return b * (-np.log(np.random.uniform(size=size))) ** (1 / a) - # - # return generate_samples(_random, alpha, beta, dist_shape=self.shape, size=size) + return super().dist([alpha, beta], **kwargs) - def logp(self, value): + def logp( + value: Union[float, np.ndarray, TensorVariable], + alpha: Union[float, np.ndarray, TensorVariable], + beta: Union[float, np.ndarray, TensorVariable], + ) -> RandomVariable: """ Calculate log-probability of Weibull distribution at specified value. @@ -2743,8 +2721,7 @@ def logp(self, value): ------- TensorVariable """ - alpha = self.alpha - beta = self.beta + return bound( at.log(alpha) - at.log(beta) @@ -2755,7 +2732,11 @@ def logp(self, value): beta > 0, ) - def logcdf(self, value): + def logcdf( + value: Union[float, np.ndarray, TensorVariable], + alpha: Union[float, np.ndarray, TensorVariable], + beta: Union[float, np.ndarray, TensorVariable], + ): r""" Compute the log of the cumulative distribution function for Weibull distribution at the specified value. @@ -2770,8 +2751,7 @@ def logcdf(self, value): ------- TensorVariable """ - alpha = self.alpha - beta = self.beta + a = (value / beta) ** alpha return bound( log1mexp(a),