Multiresolution Algorithm
This package is an implementation of the standard and hybrid multiresolution algorithm as proposed in Computation of the Distribution of the Absorption Time of the Drifted Diffusion with Stochastic Resetting and Mixed Boundary Conditions by Turin, Magalang, Aguilar, Colombani, Sanchez-Taltavull, and Gatto1
Installation
Install the package from PyPI:
pip install multires
Usage
To run a simulation, begin by first choosing the scheme that you want:
smrafor the standard MRAhmrafor the hybrid MRA
By default, either simulation scheme will produce a first passage time, rather than a full trajectory.
SMRA
The smra function has the following syntax:
smra(v, D, r, x0, eps, kmax = 30, kmin = 25, tmax_in = 10**5, trajectory = False)
Here is a description of each argument:
v: Float. Drift constant.D: Float. Diffusion constant. Must be positive.r: Float. Resetting constant. Must be non-negative.x0: Float. Initial position. Must be from $0 \leq x_0 < 1$eps: Float. Error threshold. Must be positive.kmax: Integer, optional. Simulation parameter to determine the maximum resolution $k$ considered before stopping the simulation. The default is 30.kmin: Integer, optional. Simulation parameter to determine the minimum resolution $k$ considered before computing the next resetting interval given that the stopping condition has not been reached prior. The default is 25.tmax_in: The time at the endpoint of the Brownian trajectory whenr = 0. The default is 10**5.trajectory: Boolean, optional. IfTrue, function returns the full arrays of position and time of the trajectory. IfFalse, function returns only the first passage time. The default isFalse.
Running the function will yield either three or four outputs, depending on the argument trajectory:
If trajectory is False (by default):
T: Float. First passage time.k: Integer. Resolution at end of simulationhas_reached_eps: Boolean. IfFalse, simulation has failed to reach the error threshold before reachingk = kmax
If trajectory is True:
x_arr: Array. Positions of the Brownian trajectory at the end of the simulation.t_arr: Array. Times of the Brownian trajectory at the end of the simulation.k: Integer. Resolution at end of simulationhas_reached_eps: Boolean. IfFalse, simulation has failed to reach the error threshold before reachingk = kmax
This is an example of the usage of the smra function:
For a single first passage time:
import multires as mra
T, k, has_reached_eps = mra.smra(-10**(-3), 10**(-4), (1/3)*(1/365), 0.8, 10**(-4))
Sample output:
>>> T
np.float64(370.1612953761)
>>> k
24
>>> has_reached_eps
True
For a trajectory:
import multires as mra
xvalues, tvalues, k, has_reached_eps = mra.smra(-10**(-3), 10**(-4), (1/3)*(1/365), 0.8, 10**(-4), trajectory = True)
Sample output:
>>> xvalues
array([ 0.8 , 0.80002268, 0.8000829 , ..., -0.03714226, -0.03716605, -0.03718239])
>>> tvalues
array([0.00000000e+00, 5.02717020e-05, 1.00543404e-04, ..., 8.43419103e+02, 8.43419153e+02, 8.43419204e+02]),
>>> k
24
>>> has_reached_eps
True
HMRA
The hmra function has the following syntax:
hmra(v, D, r, x0, eps, eul_dt, mul_thresh = 0.1, kmax = 30, tmax_in = 10**5, trajectory = False)
Here is a description of each argument:
v: Float. Drift constant.D: Float. Diffusion constant. Must be positive.r: Float. Resetting constant. Must be non-negative.x0: Float. Initial position. Must be from $0 \leq x_0 < 1$eps: Float. Error threshold. Must be positive.eul_dt: Float. Euler-Maruyama simulation timestep.mul_thresh: Float, optional. Position threshold, the multiresolution algorithm will begin to compute if the Euler trajectory is below this threshold. The default is 0.1.kmax: Integer, optional. Simulation parameter to determine the maximum resolution $k$ considered before stopping the simulation. The default is 30.tmax_in: The time at the endpoint of the Brownian trajectory whenr = 0. The default is 10**5.trajectory: Boolean, optional. IfTrue, function returns the full arrays of position and time of the trajectory. IfFalse, function returns only the first passage time. The default isFalse.
Running the function will yield either three or four outputs, depending on the argument trajectory:
If trajectory is False (by default):
T: Float. First passage time.k: Integer. Resolution at end of simulationhas_reached_eps: Boolean. IfFalse, simulation has failed to reach the error threshold before reachingk = kmax
If trajectory is True:
x_arr: Array. Positions of the Brownian trajectory at the end of the simulation.t_arr: Array. Times of the Brownian trajectory at the end of the simulation.k: Integer. Resolution at end of simulationhas_reached_eps: Boolean. IfFalse, simulation has failed to reach the error threshold before reachingk = kmax
This is an example of the usage of the smra function:
For a single first passage time:
import multires as mra
T, k, has_reached_eps = mra.hmra(-10**(-3), 10**(-4), (1/3)*(1/365), 0.8, 10**(-4), 0.1)
Sample output:
>>> T
np.float64(638.0523437500765)
>>> k
10
>>> has_reached_eps
True
For a trajectory:
import multires as mra
xvalues, tvalues, k, has_reached_eps = mra.hmra(-10**(-3), 10**(-4), (1/3)*(1/365), 0.8, 10**(-4), 0.1, trajectory = True)
Sample output:
>>> xvalues
array([ 0.8 , 0.79679549, 0.80113966, ..., -0.00413409, -0.0042602 , -0.00409163])
>>> tvalues
array([0.00000000e+00, 1.00000000e-01, 2.00000000e-01, ..., 7.48199805e+02, 7.48199902e+02, 7.48200000e+02]),
>>> k
10
>>> has_reached_eps
True
Auxiliary Functions
This package also contains auxiliary functions:
increase_resolutionincreases the resolution of a trajectory from level $k-1$ to $k$ given that the input array has length $2^{k-1}+1$.euleris an implementation of the Euler-Maruyama algorithm which outputs a full trajectory and is required for the HMRA.
Written with StackEdit.
-
Turin, R., Magalang, J., Aguilar, J., Colombani, L., Sanchez-Taltavull, D., & Gatto, R. (2024). Computation of the distribution of the absorption time of the drifted diffusion with stochastic resetting and mixed boundary conditions (arXiv:2311.03939). arXiv. https://doi.org/10.48550/arXiv.2311.03939 ↩
Metadata
Release files for multires 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| multires-0.1.3.tar.gz | 7.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multires-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.1 kB
Release files / multires-0.1.3.tar.gz
| Download URL | multires-0.1.3.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f806723123a2aae0c04c87e3e56779245f51533481c0fa5b8ec8899027169cd
|
|
BLAKE2b-256 checksum How to use checksums |
0e2b2bda4451f835e597f4d04a84406886e28e035484ebfc256633d133578273
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / multires-0.1.3-py3-none-any.whl
| Download URL | multires-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5094cb036f0fbe3d7bd67ad3d49c018e8a3a59b7eb73ac6341026cf4a49f203
|
|
BLAKE2b-256 checksum How to use checksums |
8c10d35ec54a499b7c18bccb66181ef2b84e44001535394f6a475476208b894f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|