Skip to main content

A wrapper around some of scipy's optimization functions to allow for a more convenient use of parameters and constants.

Project description

Wrapped-Optimizations

Description

wrapped_optimizations is a Python wrapper around some of SciPy's optimization functions. Instead of having one 1D array which contains all parameters to be optimized, the wrapped functions allow the parameters to be defined locally in the functions to be optimized.

Installation

To install this package, use pip:

pip install wrapped_optimizations

Usage

Here is a simple example of how to use Wrapped-Optimizations:

from wrapped_optimizations import differential_evolution, eval_function

def func(use_param, use_const, use_print=False):
    # define a named parameter
    x = use_param((2), 'x', bounds=(-5, 5))
    # define an unnamed parameter
    y = use_param((2,2), bounds=(-5, 5))

    # define a (named) constant
    # equals `N = 3`, but with the advantage that the value also gets saved to result.x
    N = use_const(3, name='N')

    V = use_param((N), bounds=(0, 20))
    if use_print:
        print(f'V: {V}')
    return np.linalg.norm(x - 1)**2 + np.linalg.norm(y - 3)**2

result = differential_evolution(func)
# result.x now contains all the parameters and constants
# {
#   'x': array([1., 1.]),
#   'param_1': array([[3., 3.], [3., 3.]]),
#   'param_2': array([ 9.49532267, 16.89317493,  9.37888973]),
#   'N': 3
# }

# `func` can now be called, also with additional parameters being forwarded to `func`:
# eval_function(func, result.x, True)

Requirements

Wrapped-Optimizations requires the following Python libraries:

  • NumPy
  • SciPy

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wrapped_optimizations-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrapped_optimizations-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file wrapped_optimizations-0.1.1.tar.gz.

File metadata

  • Download URL: wrapped_optimizations-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for wrapped_optimizations-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f180dc7180748e1790c118d44643cd2a942602a6a2253ef4eb52f907c01469c2
MD5 660e6ccc478f26bd54d70c6e7cbd4d5b
BLAKE2b-256 6c00c5229e8e5fffaa03f8065d4f57092b94e0dfc2d7263cdff14c3be23f477b

See more details on using hashes here.

File details

Details for the file wrapped_optimizations-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wrapped_optimizations-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 720186702565cf991b13a8761d5a88ec8230ec77bade7eea4ceb7bf7c52c8d8b
MD5 38a5be85917748f86ed8b9ac0a39cf59
BLAKE2b-256 1996b4711b092b5a0e491986bcb7fcb50e068673609f63f6fc86b2cc87e59cae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page