Skip to main content

Simple Simulated Annealing curve fit algorithm

Project description

Simple Simulated Annealing curve fit algorithm

Introduction

Simulated Annealing algorithm has been extensively used for many applications from computer science to biology. This algorithm is a random-search method in which the new solutions, generated according to a sequence of probability distributions (in this case the Boltzmann distribution), may be accepted even if theydo not lead to an improvement in the objective function. This algorithm can also be used to fit experimental data with complex theoretical models, where the need to escape from relative minima is a cricial part of the fitting process.

Usage

The principal function of this package is the following:

SimAnn_fit(x, y, e, func, params, min, max, temp, alpha, n, chi_or_y_th, args)

Where:

  • x: is the x values of your experimental data (numpy array);
  • y: is the y values of your experimental data (numpy array);
  • e: is the error values of your experimental data (numpy array);
  • func: is your theoretical model;
  • params: are the parameters for your theoretical model that you want to optimise;
  • min and max: are two different numpy arrays with the min and the max of your params array;
  • temp: is the temperature of the simulated annealing (for the Boltzmann distribution);
  • alpha: is a number between 0 and 1 expressing the decreasing of the temperature in each interation cycle;
  • n: is the number of iteration cycles;
  • chi_or_y_th: if your function returns a single value of chi square, you need to put 'chi' in this fiels, otherwise put 'not_chi';
  • args: numpy array tipe of anything else you need to pass to your theoretical function a part from the x, y, e, and params.

The function returns the optimised parameters!

Considerations

Not always it gives a good fit. Indeed, since it is a random based algorithm, higher iterations allow to explore more the parameters space.

  • If you have a very large range (min end max range) of many parameters, the algorithm might struggle to find the absolute minima. A suggestion would be to fit your function many times and reduce the range of your parameters to have a final better fit, changing also the temperature, alpha and iteration number.

  • A good thing would be to use other minimisation algorithms after the SimAnn in order to cool down a bit more the fit (using for instance a steepest descent method) to find a more minimised parameters.

Other functions in the library
  • residuals(y,y_th) It is a small function returning the difference between the the experimental and theoretical y

  • chi_calculation(y,e,y_th) It is a function calculating the chi square.

  • array_round(array) If it is useful, is a function rounding each element within an array to the second digit after the decimal point.

All these functions can be imported and called within your python script.

FOR ANY ISSUE OF DOUBTS, YOU CAN VISIT THE GITHUB PAGE AT: https://github.com/gcorucci/Simple_Simulated_Annealing_curve_fit OR DROP AN EMAIL AT: giacomocorucci@virgilio.it

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

simann-1.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

SimAnn-1.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file simann-1.2.tar.gz.

File metadata

  • Download URL: simann-1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for simann-1.2.tar.gz
Algorithm Hash digest
SHA256 223c842871afa2cba158343ba46d3604e15a14f2dceec16efb098639329c887d
MD5 b5d17c6d36382156424a4b06610e98c5
BLAKE2b-256 0c3188ad043d40fd32e78e2fd4e6a25ab442072daa14043d332eb79003d00bbf

See more details on using hashes here.

File details

Details for the file SimAnn-1.2-py3-none-any.whl.

File metadata

  • Download URL: SimAnn-1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for SimAnn-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 077eb9d9c28f615381de3be671cc09be1a250c2e2d4e4df3ad5f6215fac395ba
MD5 97cebaae1e4169c840b3deb3b6b4f9a7
BLAKE2b-256 763af6b1d2bd2ed804dc17dd3f2dbac4205fb29f141a1a862e12650931d05182

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