|
Revision 640, 0.8 kB
(checked in by dmitrey.kroshko, 1 year ago)
|
init example of using d2f with scipy_ncg solver
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
this is an example of using d2f - Hesse matrix (2nd derivatives) |
|---|
| 3 |
d2c, d2h, d2l are intended to be implemented soon |
|---|
| 4 |
and to be connected to ALGENCAN and/or CVXOPT |
|---|
| 5 |
and/or other NLP solvers |
|---|
| 6 |
|
|---|
| 7 |
//Dmitrey |
|---|
| 8 |
""" |
|---|
| 9 |
from scikits.openopt import NLP |
|---|
| 10 |
from numpy import cos, arange, ones, asarray, abs, zeros, diag |
|---|
| 11 |
N = 300 |
|---|
| 12 |
M = 5 |
|---|
| 13 |
ff = lambda x: ((x-M)**4).sum() |
|---|
| 14 |
p = NLP(ff, cos(arange(N))) |
|---|
| 15 |
p.df = lambda x: 4*(x-M)**3 |
|---|
| 16 |
p.d2f = lambda x: diag(12*(x-M)**2) |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
r = p.solve('scipy_ncg') |
|---|
| 22 |
print 'objfunc val:', r.ff |
|---|