Skip to main content

Summary

Version:

1.2.1

Author:

Keurfon Luu

Web site:

https://github.com/keurfonluu/stochopy

Copyright:

This document has been placed in the public domain.

License:

StochOPy is released under the MIT License.

NOTE: StochOPy has been implemented in the frame of my Ph. D. thesis. If you find any error or bug, or if you have any suggestion, please don’t hesitate to contact me.

Features

StochOPy provides routines for sampling of a model parameter space:

  • Pure Monte-Carlo

  • Metropolis-Hastings algorithm

  • Hamiltonian (Hybrid) Monte-Carlo [1,2]

or optimization of an objective function:

  • Differential Evolution [3]

  • Particle Swarm Optimization [4,5]

  • Competitive Particle Swarm Optimization [6]

  • Covariance Matrix Adaptation - Evolution Strategy [7]

Installation

The recommended way to install StochOPy is through pip (internet required):

pip install stochopy

Otherwise, download and extract the package, then run:

python setup.py install

Usage

First, import StochOPy and define an objective function (here Rosenbrock):

import numpy as np
from stochopy import MonteCarlo, Evolutionary

f = lambda x: 100*np.sum((x[1:]-x[:-1]**2)**2)+np.sum((1-x[:-1])**2)

You can define the search space boundaries if necessary:

n_dim = 2
lower = np.full(n_dim, -5.12)
upper = np.full(n_dim, 5.12)

Initialize the Monte-Carlo sampler:

max_iter = 1000
mc = MonteCarlo(f, lower = lower, upper = upper, max_iter = max_iter)

Now, you can start sampling with the simple method ‘sample’:

mc.sample(sampler = "hamiltonian", stepsize = 0.005, n_leap = 20, xstart = [ 2., 2. ])

Note that sampler can be set to “pure” or “hastings” too. The models sampled and their corresponding energies are stored in:

print(mc.models)
print(mc.energy)

Optimization is just as easy:

n_dim = 10
lower = np.full(n_dim, -5.12)
upper = np.full(n_dim, 5.12)
popsize = 4 + np.floor(3.*np.log(n_dim))
ea = Evolutionary(f, lower = lower, upper = upper, popsize = popsize, max_iter = max_iter)
xopt, gfit = ea.optimize(solver = "cmaes")
print(xopt)
print(gfit)

References

Release files for stochopy 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stochopy 1.2.1
File Size Uploaded
stochopy-1.2.1.tar.gz 29.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stochopy 1.2.1
File Interpreter ABI Platform
stochopy-1.2.1-py3.5.egg Legacy Egg format - - Details

Total release size: 64.9 kB

Release files / stochopy-1.2.1.tar.gz

Download URL stochopy-1.2.1.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8369a26895b82b4178fb96b11bd0d5af310e2d6e5e6d3668039b9463bbab3848
BLAKE2b-256 checksum
How to use checksums
143d65049336ec4d96d07cf4b5e86a6acfc7f28db40d0a7fe97af3d0976ab9e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / stochopy-1.2.1-py3.5.egg

Download URL stochopy-1.2.1-py3.5.egg
Size 35.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
8ac9cfdb2618d2965838bb835c4416cf3dbd4348fbf94858fd1e05b5abe6e51d
BLAKE2b-256 checksum
How to use checksums
7af82254a941630530ec9e41a5f7ace0815b0d2438b24a7023282c36b63b7abc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.7.3

1 release file

1.7.2

1 release file

1.7.1

1 release file

1.7.0

1 release file

1.6.0

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

2 release files

1.4.0

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

2 release files

1.2.3

1 release file

1.2.2

1 release file

This release

1.2.1 This release

2 release files

1.2.0

1 release file

1.1.2

2 release files

1.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page