Socket
Book a DemoInstallSign in
Socket

simulated-annealing

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simulated-annealing

Simulated Annealing optimization algorithm for node.js

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Simulated Annealing for node.js

NPM version

Simulated Annealing optimization algorithm for node.js.

Simulated annealing searching for a maximum

Install

npm install --save simulated-annealing

Usage

var simulatedAnnealing = require('simulated-annealing');
var result = simulatedAnnealing(params);

Params

  • initialState - first state value
  • tempMax - initial temperature
  • tempMin - min temperature when algorithm will stop
  • newState - function for generating new state from current state newState(state)
  • getTemp - function for generating new temperature based on previous temperature getTemp(temperature)
  • getEnergy - function for calculating energy for state getEnergy(state) (less is better)

Example

Find solution for x^2=16

var simulatedAnnealing = require('simulated-annealing');

function getEnergy(v) {
    return Math.abs(v * v - 16);
}

function newState(x) {
    return x + (Math.random() - 0.5);
}

// linear temperature decreasing
function getTemp(prevTemperature) {
    return prevTemperature - 0.001;
}

var result = simulatedAnnealing({
    initialState: Math.random() * 16,
    tempMax: 15,
    tempMin: 0.001,
    newState: newState,
    getTemp: getTemp,
    getEnergy: getEnergy,
});

Testing

npm test

Keywords

optimization

FAQs

Package last updated on 27 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts