Monte Carlo(random) Variable Object
Project description
MonteCarlo Variable object
This python object is a Monte Carlo variable.
- It is initialized with a central value, uncertainty and (optionnaly) distribution law
- It stores a value according to this probability distirbution
- The value is returned when converted to
floatorint - The MC value is renewed only when calling
mcvariable.refresh() - The module also includes a generator function to geneate multiple outcome of the random variable.
MCVariable usage:
The object is initialized with
MCVariable(parameters: Sequence[Number],
law: Callable[..., Number],
keep_positive: bool = True,
non_zero: bool = True,
replace_zero_with: float = 1e-20)
With the parameters:
parameters: parameters of the probability law.
As a tuple or list of numbers/law: Distribution law of the random variable
As a callable taking*parametersas arguments
and returning a number/keep_positive(bool) = True : keep the value >=0non_zero(bool) = True : prevent the value to be exactly 0.0000replace_zero_with(float) = 1e-20 : if the previous parameters is True,
replace all 0 by this value.
To be used, it is recommended to convert explicitely the variable
as int or float:
mcv = mcvariable.MCVariable((0., 1.))
print(f"{int(mcv)}")
Default probability laws
The module includes two probability law by default:
mcvariable.law_gaussianwhich takes two parameters:(mean,stddev)mcvariable.law_flatwhic takes to parameters:(central,delta)(and retruns a value within the (central - delta, central + delta) range.
Generator
To obtain a series of realization of the random variable,
use the mcvariable.MCGenerator function that returns a generator.
mcvariable.MCGenerator(mcv: MCVariable,
nmax: Number = math.inf,
variable_type: type = float)
The parameters are :
mcvthe MCVariable instance to use to generate the valuesnmaxnumber of elements to return (by defaultl infinite)variable_type: the type of value to return (floatby default, can be changed toint).
Testing
The module comes with a test script test_mcvariable.py.
Authors
- Greg Henning - ghenning.at.iphc․cnrs․fr
License
This project is licensed under the CeCILL FREE SOFTWARE LICENSE AGREEMENT.
See LICENSE for more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcvariable-0.1.0.tar.gz.
File metadata
- Download URL: mcvariable-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d85c7089ce34f1c1c5338ff832e75f8d55815d88a3d5e42f1729feac45dc941f
|
|
| MD5 |
c0ccc46961c5dad0c01eb1fcf50aaccd
|
|
| BLAKE2b-256 |
ec1efa6dcfa5e34c1d1c71169ea2815fe97fb9bb98bcf0d6e53a9437829aafbd
|
File details
Details for the file mcvariable-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcvariable-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13e58149abd303b70863f616c9f35e0897d4be8af3a828b0fceffd069c1f3a43
|
|
| MD5 |
7bde15d104b7381c4da1590ff1c2f35f
|
|
| BLAKE2b-256 |
b023894a1168ae68a15b7672304f8557aef8bac7ecbc1677ae32a716e5df8003
|