The triple-random constrainable curve generator for smooth function perturbation
Project description
Smurves
The triple-random constrainable curve generator for smooth function perturbation
Smurves is a tool for random smooth curve generation that allows for several constraints to be put on the generation process. If offers a more constrainable alternative to using, for example, Gaussian processes for that purpose. The method is based on Newtonian projectile motion and takes its inspiration from Brandon Sanderson's book series The Stormlight Archive and the books' magic system called "surgebinding". More specifically, this approach makes note of the parts that deal with the change in direction and magnitude of gravity for an in-flight object, which provided the initial concept.
With this idea in mind, Smurves generates smooth curves by randomly sampling the gravitational force, as well as locations and the number of gradient sign changes, for one projectile per curve path and making sure that all constraints are adhered to, with velocity and flight angle being retained after gravitational direction switches.
In essence, the code's inner workings can be imagined as firing a bullet at either zero angle or a random angle, from a specified or random point at either the left or the right side of the x-axis interval, depending on the user preferences. At a random number of random points, gravity gets turned upside down with a new random magnitude while the bullet continues its flight, all subject to the constraints set by the user for the properties of the required curves.
The motivation for this approach was to find a novel way* of generating utterly random curves with certain constraints to smoothly perturbate functions, for example the matter power spectrum in cosmology. A more detailed description of the methodology, as well as the first application of the tool to scientific inquiry, can be found in this paper on the viability of type SN Ia supernova data to test the standard model of cosmology.
* Because it's from a novel. This documentation comes fully equipped with bad jokes.
Installation
Smurves can be installed via PyPI, with a single command in the terminal:
pip install smurves
Alternatively, the file smurves.py
can be downloaded from the folder smurves
in this repository and used locally by placing the file into the working directory for a given project. An installation via the terminal is, however, highly recommended, as the installation process will check for the package requirements and automatically update or install any missing dependencies, thus sparing the user the effort of troubleshooting and installing them themselves.
Quickstart guide
The descriptions and example usage below provide a quick tutorial on Smurves. In addition, the examples.ipynb
Jupyter Notebook in the examples
folder in this repository show the use of the tool for various constraints and with explanations for each parameter set, and with the code necessary to plot the curves.
In addition to the number of curves and interval constraints for both x-axis and y-axis beyond which the curves shouldn't stray, the tool requires the number of measurement points amd the maximum number of directional changes per curve.
Six optional parameters include the placement of a point in which the curves should converge, the choice of a logarithmic scale for the x-axis, the choice to launch the curve trajectories at random instead of zero angles, the choice to let the curves converge on the right instead of the left side if a convergence point is provided, the percentiles along the x-axis before and which no directional gravity changes should be implemented, and the placing of a threshold point before which no deviation from the convergence point's x-axis value should take place. These parameters are described in the table below.
Variables | Explanations | Default |
---|---|---|
n_curves | The number of curves you want to generate | |
x_interval | The allowed x-axis interval for the curves | |
y_interval | The allowed y-axis interval for the curves | |
n_measure | The number of equally-spaced measurement points | |
direction_maximum | The maximum number of allowed gradient changes | |
convergence_point (optional) | The left-side point of convergence for curves | |
log_scale (optional) | Whether measurements should be on a log-scale | False |
random_launch (optional) | Whether the first launch angle should be random | False |
right_convergence (optional) | Whether convergence should be on the right side | False |
change_range (optional) | The x-axis percentiles before and after which no gradient changes should take place for curves |
[0.1, 0.9] |
change_spacing (optional) | The minimum space in measurement points between the different points of a gravitational force change |
None |
change_ratio (optional) | The multiplier for the last partial trajectory to get the upper limit for the next partial trajectory's force |
None |
start_force (optional) | The point of the first deviation from unity | None |
After the installation via PyPI, or using the smurves.py
file locally, an exemplary call without optional parameters looks like this:
from smurves import surgebinder
curves = surgebinder(n_curves = 10,
x_interval = [0.1, 10.0],
y_interval = [0.0, 1.0],
n_measure = 100,
direction_maximum = 1)
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
File details
Details for the file smurves-1.0.1.tar.gz
.
File metadata
- Download URL: smurves-1.0.1.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.14.2 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32afd7c4fc50d4a6d5f4206ca32b8c5e30cebd787455db9b84e84b08acf51ef8 |
|
MD5 | e0d477ac316d792878b41a023a1ba9a8 |
|
BLAKE2b-256 | 5327fd05bf475c7ec0475bf90ec3a2dba38c3ffc2fcc73cc404ebc2ff6b3f0f3 |
File details
Details for the file smurves-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: smurves-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.14.2 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b4c4471eea8f2ca112e1f78c18197ac238ded5e9c704f848c7cb28732695277 |
|
MD5 | f9414865af9e213c54b0a46b5e9e4862 |
|
BLAKE2b-256 | 0d4df7960e9dba908bb97bdc1c5b4c378591a46b6fb584429136005086da02d7 |