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 they do 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 and installation

To install this python library you can just use the following command "pip install SimAnn" and you will get the lastest version of this package. 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!

Just as an example, you can set it up as follows:

temp = 1e4 alpha = 0.97 n = 1e4 final_params = SimAnn_fit(x,y,err,func,params,min,max,temp,alpha,n,'notchi',args)

Considerations

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

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

  • A good practice 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, giving to it the SimAnn 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.1.tar.gz (3.5 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.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simann-1.2.1.tar.gz
  • Upload date:
  • Size: 3.5 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.1.tar.gz
Algorithm Hash digest
SHA256 812129fb90d999e2a80c2f9883e7b759704f802470b2ed5dd0fde9a656c65c82
MD5 5b34bf8fbcb80e632123f74da2c8ccb3
BLAKE2b-256 f09cfcdd3252e2ac128d4da5ef4245dfae6e7f279bad9bc13947d8f619356f87

See more details on using hashes here.

File details

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

File metadata

  • Download URL: SimAnn-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c2c8e276992732de537aab41e97b20f5260c7766a9de3ec13df13d143ab5045
MD5 35af53b9aa0492c27aeb828e20db64d6
BLAKE2b-256 7f6325862b9e3017b3c5d8654a578cc7f093affbc6aecb32b5b6d832481994ae

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