Giter VIP home page Giter VIP logo

sabs-bfgs's Introduction

Run unit tests Run on multiple OS

SABS-BFGS

Description

This package is an implementation of the BFGS algorithm.

BFGS is an efficient way to find the maximum/minimum of a function.

This project is a practical session of Modelling and Scientific Computing Module in the SABS programme.

Installation

System: Windows 11, MacOS 13.1, Ubuntu20.04 LTS

git clone https://github.com/weiym97/SABS-BFGS
cd SABS-BFGS

# Create and activate a new virtual environment. you have many options: 
# For those with anaconda
conda create -n SABS-BFGS
conda activate SABS-BFGS
# For those without anaconda (uncomment the following two lines)
#python -m venv venv
#source venv/bin/activate

# Install dependencies
pip install -r requirements.txt
# Install the package
pip install .

Usage

Example 1: find the global minimum of $f(x)=x^2$

from SABS_BFGS.bfgs import BFGS
bfgs = BFGS()
x0 = 1.0
x_argmin, f_min = bfgs.minimize(lambda x: x**2, x0)
print('Global minimum: ',x_argmin)
print('Minimal Value: ',format(float(f_min),".2f"))

Example 2: find the global minimum of Rosenbrock function $f(x,y)=(1-x)^2+(y-x^2)^2$.

import numpy as np
from SABS_BFGS.bfgs import BFGS
def func(x):
    return (1 - x[0]) ** 2 + (x[1] - x[0] ** 2) ** 2
bfgs = BFGS()
x0 = np.array([1.2,1.2])
x_argmin,fmin = bfgs.minimize(func,x0)
print('Global minimum: ',np.round(x_argmin,decimals=2))
print('Minimal Value: ',format(float(f_min),".2f"))

See below an visualisation of how it works Visualisation of BFGS on Rosenbrock function

Details

Read introduction.ipynb for more information, which includes a detailed description of how BFGS works.

Credits

Thank Martin Robinson for introducing us to this great module during the last two weeks. Also, I have received much help from all the demonstrators. I would like to express my gratitude to Nele Quast for helping us on the visualisation of this project.

sabs-bfgs's People

Contributors

weiym97 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.