Particle Swarm Optimization Constraint Optimization Solver
Arguments
| Name | Type | Default Value |
|---|---|---|
| particle_size | int | 2000 |
| max_iter | int | 1000 |
| sol_size | int | 7 |
| fitness | function | null |
| constraints | a list of functions | null |
Usage
Transform constraints, it becomes:
Note: In order to faster search optimal solutions, please initialize solutions with specific low and high.
import psoco
import math
def objective(x):
'''create objectives based on inputs x as 2D array'''
return (x[:, 0] - 2) ** 2 + (x[:, 1] - 1) ** 2
def constraints1(x):
'''create constraint1 based on inputs x as 2D array'''
return x[:, 0] - 2 * x[:, 1] + 1
def constraints2(x):
'''create constraint2 based on inputs x as 2D array'''
return - (x[:, 0] - 2 * x[:, 1] + 1)
def constraints3(x):
'''create constraint3 based on inputs x as 2D array'''
return x[:, 0] ** 2 / 4. + x[:, 1] ** 2 - 1
def new_penalty_func(k):
'''Easy Problem can use \sqrt{k}'''
return math.sqrt(k)
constraints = [constraints1, constraints2, constraints3]
num_runs = 10
# random parameters lead to variations, so run several time to get mean
for _ in range(num_runs):
pso = psoco.PSOCO(sol_size=2, fitness=objective, constraints=constraints)
pso.h = new_penalty_func
pso.init_Population(low=0, high=1) # x并集的上下限,默认为0和1
pso.solve()
# best solutions
x = pso.gbest.reshape((1, -1))
Reference
Metadata
Release files for psoco 0.0.8
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 |
|---|---|---|---|---|
| psoco-0.0.8.tar.gz | 3.9 kB | Without provenance | Details for psoco-0.0.8.tar.gz |
Release files / psoco-0.0.8.tar.gz
| Download URL | psoco-0.0.8.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a18bd142a46e314172a4a878d3c596ef58205a43b6ac1415484913327cafc0a9
|
|
BLAKE2b-256 checksum How to use checksums |
964a63d4367dca59e1f86b6131cbde5990d0f9c7b5e2ff45a5e98877d2cfbb26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.4
|
Security for psoco 0.0.8
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.