Add Laplacian and CrossLaplacian difference functions (#154)

* Add Laplacian and CrossLaplacian difference functions

* use usesOrigin
This commit is contained in:
Brendan Tracey
2017-08-03 21:29:12 -06:00
committed by GitHub
parent 4d30eb012e
commit 084f84ee0e
7 changed files with 560 additions and 57 deletions

View File

@@ -16,60 +16,62 @@ type HessianTester interface {
Hess(dst mat.MutableSymmetric, x []float64)
}
var hessianTestCases = []struct {
h HessianTester
x []float64
settings *Settings
tol float64
}{
{
h: Watson{},
x: []float64{0.2, 0.3, 0.1, 0.4},
tol: 1e-3,
},
{
h: Watson{},
x: []float64{2, 3, 1, 4},
tol: 1e-3,
settings: &Settings{
Step: 1e-5,
Formula: Central,
},
},
{
h: Watson{},
x: []float64{2, 3, 1},
tol: 1e-3,
settings: &Settings{
OriginKnown: true,
OriginValue: 7606.529501201192,
},
},
{
h: ConstFunc(5),
x: []float64{1, 9},
tol: 1e-16,
},
{
h: LinearFunc{w: []float64{10, 6, -1}, c: 5},
x: []float64{3, 1, 8},
tol: 1e-6,
},
{
h: QuadFunc{
a: mat.NewSymDense(3, []float64{
10, 2, 1,
2, 5, -3,
1, -3, 6,
}),
b: mat.NewVecDense(3, []float64{3, -2, -1}),
c: 5,
},
x: []float64{-1.6, -3, 2},
tol: 1e-6,
},
}
func TestHessian(t *testing.T) {
for cas, test := range []struct {
h HessianTester
x []float64
settings *Settings
tol float64
}{
{
h: Watson{},
x: []float64{0.2, 0.3, 0.1, 0.4},
tol: 1e-3,
},
{
h: Watson{},
x: []float64{2, 3, 1, 4},
tol: 1e-3,
settings: &Settings{
Step: 1e-5,
Formula: Central,
},
},
{
h: Watson{},
x: []float64{2, 3, 1},
tol: 1e-3,
settings: &Settings{
OriginKnown: true,
OriginValue: 7606.529501201192,
},
},
{
h: ConstFunc(5),
x: []float64{1, 9},
tol: 1e-16,
},
{
h: LinearFunc{w: []float64{10, 6, -1}, c: 5},
x: []float64{3, 1, 8},
tol: 1e-6,
},
{
h: QuadFunc{
a: mat.NewSymDense(3, []float64{
10, 2, 1,
2, 5, -3,
1, -3, 6,
}),
b: mat.NewVecDense(3, []float64{3, -2, -1}),
c: 5,
},
x: []float64{-1.6, -3, 2},
tol: 1e-6,
},
} {
for cas, test := range hessianTestCases {
n := len(test.x)
got := Hessian(nil, test.h.Func, test.x, test.settings)
want := mat.NewSymDense(n, nil)