DOWNHILL
The downhill package provides algorithms for minimizing scalar loss functions that are defined using Theano.
Several optimization algorithms are included:
All algorithms permit the use of regular or Nesterov-style momentum as well.
Quick Start: Matrix Factorization
Let’s say you have 100 samples of 1000-dimensional data, and you want to represent your data as 100 coefficients in a 10-dimensional basis. This is pretty straightforward to model using Theano: you can use a matrix multiplication as the data model, a squared-error term for optimization, and a sparse regularizer to encourage small coefficient values.
Once you have constructed an expression for the loss, you can optimize it with a single call to downhill.minimize:
import downhill
import numpy as np
import theano
import theano.tensor as TT
FLOAT = 'df'[theano.config.floatX == 'float32']
def rand(a, b):
return np.random.randn(a, b).astype(FLOAT)
A, B, K = 20, 5, 3
# Set up a matrix factorization problem to optimize.
u = theano.shared(rand(A, K), name='u')
v = theano.shared(rand(K, B), name='v')
z = TT.matrix()
err = TT.sqr(z - TT.dot(u, v))
loss = err.mean() + abs(u).mean() + (v * v).mean()
# Minimize the regularized loss with respect to a data matrix.
y = np.dot(rand(A, K), rand(K, B)) + rand(A, B)
# Monitor during optimization.
monitors = (('err', err.mean()),
('|u|<0.1', (abs(u) < 0.1).mean()),
('|v|<0.1', (abs(v) < 0.1).mean()))
downhill.minimize(
loss=loss,
train=[y],
patience=0,
batch_size=A, # Process y as a single batch.
max_gradient_norm=1, # Prevent gradient explosion!
learning_rate=0.1,
monitors=monitors,
monitor_gradients=True)
# Print out the optimized coefficients u and basis v.
print('u =', u.get_value())
print('v =', v.get_value())
If you prefer to maintain more control over your model during optimization, downhill provides an iterative optimization interface:
opt = downhill.build(algo='rmsprop',
loss=loss,
monitors=monitors,
monitor_gradients=True)
for metrics, _ in opt.iterate(train=[[y]],
patience=0,
batch_size=A,
max_gradient_norm=1,
learning_rate=0.1):
print(metrics)
If that’s still not enough, you can just plain ask downhill for the updates to your model variables and do everything else yourself:
updates = downhill.build('rmsprop', loss).get_updates(
batch_size=A, max_gradient_norm=1, learning_rate=0.1)
func = theano.function([z], loss, updates=list(updates))
for _ in range(100):
print(func(y)) # Evaluate func and apply variable updates.
More Information
Source: http://github.com/lmjohns3/downhill
Documentation: http://downhill.readthedocs.org
Mailing list: https://groups.google.com/forum/#!forum/downhill-users
Release files for downhill 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| downhill-0.4.0.tar.gz | 20.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| downhill-0.4.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 44.7 kB
Release files / downhill-0.4.0.tar.gz
| Download URL | downhill-0.4.0.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
074ad91deb06c05108c67d982ef71ffffb6ede2c77201abc69e332649f823b42
|
|
BLAKE2b-256 checksum How to use checksums |
d50d7f07a67ee0f4890d8a924ee6e12a6eb8a445b4b55fc40fff48d8d9857dfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / downhill-0.4.0-py2.py3-none-any.whl
| Download URL | downhill-0.4.0-py2.py3-none-any.whl |
|---|---|
| Size | 24.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
29e3dbf4db13021734c5bbef0eef230a17c49dfd4155a41016b712f909868f1b
|
|
BLAKE2b-256 checksum How to use checksums |
3207fb2b465371d80d5686328640f31ad403193fe91d527cca538ff1834880b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |