Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joshdk/pygradesc

A simple to use gradient descent library written in python
https://github.com/joshdk/pygradesc

Last synced: about 5 hours ago
JSON representation

A simple to use gradient descent library written in python

Awesome Lists containing this project

README

        

pygradesc
=========

An n-dimensional gradient descent algorithm

Example
-------

![Example output from demo.py](https://raw.github.com/joshdk/pygradesc/master/img/graph1.png "Example output from demo.py")

Usage
-----

### Importing

```python
import pygradesc as gd
````

### Creating functions

```python
# Functions (or lambdas) take the form f(a1, a2, ..., an) -> an+1

# Constructor a 2D function f(x) -> y
fx = lambda x: x*x

# Constructor a 3D function f(x,y) -> z
fxy = lambda x, y: (x-1)**2+(y-2)**2

# Constructor a 4D function f(x,y,z) -> d
fxyz = lambda x, y, z: x**2+5*y+z
```

### Running

```python
# Starting point
start = [-2, -6]

# Delta size (how far should we move towards our goal)
delta = 0.25

# Number of steps
steps = 1000

# Get a list of points for each step in the algorithm
points = gd.minimize(fxy, start, delta, steps)
```

### Printing

```python
print(points)
# points[0] -> [-2.0, -6.0, 73.0 ]
# points[1] -> [-1.83.., -5.82.., 69.21.. ]
# ..
# points[999] -> [ 0.99.., 1.99.., 2.47..e-31]
```

### Plotting

![f(x,y)=(x-1)^2+(y-2)^2](https://raw.github.com/joshdk/pygradesc/master/img/graph2.png "f(x,y)=(x-1)^2+(y-2)^2")

Dependencies
------------

* [Python2](http://www.python.org/download/releases/2.7.3/)
* [NumPy](http://numpy.scipy.org/)