Skip to main content

Neighbourhood Algorithm in Python

Project description

PyPI version Conda Version test docs

neighpy

neighphy is a Python implementation of the Neighbourhood Algorithm for the optimisation and appraisal of high-dimensional loss surfaces. First presented in two papers by M. Sambridge at the Australian National University in 1999, it has since been widely used, particularly in the geophysical community, for the optimisation of complex, high-dimensional functions.

This implementation hopes to replace the original Fortran code with a more modern, user-friendly and flexible Python package. It is a very simple implementation, with just two classes to implement the two phases of the algorithm: the neighpy.search.NASearcher class for the optimisation phase, and the neighpy.appraise.NAAppraiser class for the appraisal phase

Installation

pip install neighpy

Basic Usage

import numpy as np
from neighpy import NASearcher, NAAppraiser

def objective(x):
    # Objective function to be minimised
    return np.linalg.norm(data - predict_data(x))

# Bounds of the parameter space
bounds = ((-5, 5), (-5, 5))

# Initialise direct search phase
searcher = NASearcher(
    objective,
    ns=100, # number of samples per iteration
    nr=10, # number of cells to resample
    ni=100, # size of initial random search
    n=20, # number of iterations
    bounds=bounds
)

# Run the direct search phase
searcher.run() # results stored in searcher.samples and searcher.objectives

# Initialise the appraisal phase
appraiser = NAAppraiser(
    searcher.samples, # points of parameter space already sampled
    np.exp(-searcher.objectives), # objective function values (as a probability distribution)
    bounds=bounds,
    n_resample=500000, # number of desired new samples
    n_walkers=10 # number of parallel walkers
)

# Run the appraisal phase
appraiser.run()  # Results stored in appraiser.samples

Licence

This code is distributed under a GNU General Public License.

Contributing

If you have any questions, please to open an issue in this repository.

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

neighpy-0.1.8.1a2.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

neighpy-0.1.8.1a2-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file neighpy-0.1.8.1a2.tar.gz.

File metadata

  • Download URL: neighpy-0.1.8.1a2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for neighpy-0.1.8.1a2.tar.gz
Algorithm Hash digest
SHA256 4ba67d06487bdf8db79eb2e15776b969ef9fa2dc2b00a5d6d670f65ed599d7f2
MD5 e159f8db91002e5b2148e84d310d5e34
BLAKE2b-256 7400aec0ca461a3f4784555f34c7ce901a33c6312528cb35543a25c293a71d6a

See more details on using hashes here.

File details

Details for the file neighpy-0.1.8.1a2-py3-none-any.whl.

File metadata

  • Download URL: neighpy-0.1.8.1a2-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for neighpy-0.1.8.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 32c34eb1de1e2974bcf0d1e7357aa4f068cee89853288087b59a78ee4b22dff0
MD5 63eaa9b27b97bb0c4b20ecaf202fa777
BLAKE2b-256 7f8268710112239f67375f7bfec3666878545948927bdf484984659cd7da17fa

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