mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 15:16:59 +08:00
Add Laplacian and CrossLaplacian difference functions (#154)
* Add Laplacian and CrossLaplacian difference functions * use usesOrigin
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user