Algosto : May randomness be with you
Algosto, from the concatenation of french words Algorithmes Stochastiques (/al.ɡo.ʁitm stɔ.kas.tik/), is a Python package built on top of NumPy that provides implementations of various stochastic algorithms.
The full documentation is available here.
Installation
You can install Algosto with:
pip install algosto
Usage
This section shows an example on how Algosto works by applying the stochastic gradient descent algorithm (SGD) to a quadratic function.
Workflow
The basic workflow needs four elements :
An objective function : This is the function we want to minimize.
It is a Python function that takes a numpy matrix (n, d),
where n is the number of points to handle and d is the dimension of points,
and returns a result vector of length n.
A constraint : It is an object that defines the space in which the solver will optimize the function. Obviously, the objective function needs to be defined on this space.
A solver : In Algosto, solvers are always classes that need an objective function and a constraint to be instanciated.
Simply call the fit method to minimize the objective on the constraint.
A plot : Algosto provides some functions to plot most used graph. You can build your own graph using Matplotlib or Plotly.
Objective function
Based on the workflow given just before, we start by defining the quadratic objective function and its gradient in order to use the SGD.
import numpy as np
def objective(x: np.array) -> float :
return np.sum(x**2, axis=1)
def grad(x: np.array) -> float :
return 2*x
Algosto provides some toy objective functions, of which the quadratic function is a part, that you can import like this :
from algosto.utils.functions import quadratic
objective, grad = quadratic()
Constraints
Now, we need to specify the definition space.
To do that, Algosto provides object called constraints that you can import from the module algosto.constraints as follow :
import numpy as np
from algosto.constraints import RdBallConstraint
ct = RdBallConstraint(2, np.zeros(2), 5)
We define a two-dimensional ball in $\mathbb{R}^d$, centered at the origin. Constraints provide the solver with information about the space within which it can optimize the objective function.
Solver
It's time to speak about the solver itself.
Solvers are avaible from the algosto.solvers module where you can find all the solvers implemented in Algosto.
In this example, we are going to use the stochastic gradient descent (SGD) to minimize the objective.
from algosto.solvers import SGDSolver
solver = SGDSolver(ct, objective)
Finally, we can minimize the objective function with the help of the fit method :
from algosto.utils import plot
solver.fit()
plot(solver)
Full workflow code
The full Python code is avaible just below
import numpy as np
from algosto.functions import quadratic
from algosto.constraints import RdBallConstraint
from algosto.solvers import SGDSolver
from algosto.evaluate import trajectory
objective, grad = quadratic()
ct = RdBallConstraint(2, np.zeros(2), 5)
solver = SGDSolver(ct, objective, grad)
solver.fit()
plot(solver)
Metadata
Release files for algosto 0.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| algosto-0.0.18.tar.gz | 10.2 kB | Without provenance | Details for algosto-0.0.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| algosto-0.0.18-py3-none-any.whl | Python 3 | none | any | Details for algosto-0.0.18-py3-none-any.whl |
Total release size: 23.5 kB
Release files / algosto-0.0.18.tar.gz
| Download URL | algosto-0.0.18.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f5fa5b35aa1c9c43cd1b61ed1e5da01ba8a85ed0dca18381a64d7108605b3cb
|
|
BLAKE2b-256 checksum How to use checksums |
7504dc00762d2250e1e2b8cb6ef96d5dcba506b67c55a6bb789e844c797518ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Release files / algosto-0.0.18-py3-none-any.whl
| Download URL | algosto-0.0.18-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ec5b1817a3316475e90d4b35be76e443ed18f6cfe27a841726cc81841dcb3fc
|
|
BLAKE2b-256 checksum How to use checksums |
adc76adaa3a47bacfcf514ec776a6bbb7e85a6d34196ba8b5f2bf47a9cbb76bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for algosto 0.0.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.