Ejemplo n.º 1
0
func (BrownBadlyScaled) Hess(hess mat64.MutableSymmetric, x []float64) {
	if len(x) != 2 {
		panic("dimension of the problem must be 2")
	}
	if len(x) != hess.Symmetric() {
		panic("incorrect size of the Hessian")
	}

	h00 := 2 + 2*x[1]*x[1]
	h01 := 4*x[0]*x[1] - 4
	h11 := 2 + 2*x[0]*x[0]
	hess.SetSym(0, 0, h00)
	hess.SetSym(0, 1, h01)
	hess.SetSym(1, 1, h11)
}
Ejemplo n.º 2
0
func (Watson) Hess(hess mat64.MutableSymmetric, x []float64) {
	dim := len(x)
	if dim != hess.Symmetric() {
		panic("incorrect size of the Hessian")
	}

	for j := 0; j < dim; j++ {
		for k := j; k < dim; k++ {
			hess.SetSym(j, k, 0)
		}
	}
	for i := 1; i <= 29; i++ {
		d1 := float64(i) / 29
		d2 := 1.0
		var s1 float64
		for j := 1; j < dim; j++ {
			s1 += float64(j) * d2 * x[j]
			d2 *= d1
		}

		d2 = 1.0
		var s2 float64
		for _, v := range x {
			s2 += d2 * v
			d2 *= d1
		}

		t := s1 - s2*s2 - 1
		s3 := 2 * d1 * s2
		d2 = 2 / d1
		th := 2 * d1 * d1 * t
		for j := 0; j < dim; j++ {
			v := float64(j) - s3
			d3 := 1 / d1
			for k := 0; k <= j; k++ {
				hess.SetSym(k, j, hess.At(k, j)+d2*d3*(v*(float64(k)-s3)-th))
				d3 *= d1
			}
			d2 *= d1
		}
	}
	t1 := x[1] - x[0]*x[0] - 1
	hess.SetSym(0, 0, hess.At(0, 0)+8*x[0]*x[0]+2-4*t1)
	hess.SetSym(0, 1, hess.At(0, 1)-4*x[0])
	hess.SetSym(1, 1, hess.At(1, 1)+2)
}
Ejemplo n.º 3
0
func (Wood) Hess(hess mat64.MutableSymmetric, x []float64) {
	if len(x) != 4 {
		panic("dimension of the problem must be 4")
	}
	if len(x) != hess.Symmetric() {
		panic("incorrect size of the Hessian")
	}

	hess.SetSym(0, 0, 400*(3*x[0]*x[0]-x[1])+2)
	hess.SetSym(0, 1, -400*x[0])
	hess.SetSym(1, 1, 220.2)
	hess.SetSym(0, 2, 0)
	hess.SetSym(1, 2, 0)
	hess.SetSym(2, 2, 360*(3*x[2]*x[2]-x[3])+2)
	hess.SetSym(0, 3, 0)
	hess.SetSym(1, 3, 19.8)
	hess.SetSym(2, 3, -360*x[2])
	hess.SetSym(3, 3, 200.2)
}
Ejemplo n.º 4
0
func (PowellBadlyScaled) Hess(hess mat64.MutableSymmetric, x []float64) {
	if len(x) != 2 {
		panic("dimension of the problem must be 2")
	}
	if len(x) != hess.Symmetric() {
		panic("incorrect size of the Hessian")
	}

	t1 := 1e4*x[0]*x[1] - 1
	s1 := math.Exp(-x[0])
	s2 := math.Exp(-x[1])
	t2 := s1 + s2 - 1.0001

	h00 := 2 * (1e8*x[1]*x[1] + s1*(s1+t2))
	h01 := 2 * (1e4*(1+2*t1) + s1*s2)
	h11 := 2 * (1e8*x[0]*x[0] + s2*(s2+t2))
	hess.SetSym(0, 0, h00)
	hess.SetSym(0, 1, h01)
	hess.SetSym(1, 1, h11)
}
Ejemplo n.º 5
0
func (BrownAndDennis) Hess(hess mat64.MutableSymmetric, x []float64) {
	if len(x) != 4 {
		panic("dimension of the problem must be 4")
	}
	if len(x) != hess.Symmetric() {
		panic("incorrect size of the Hessian")
	}

	for i := 0; i < 4; i++ {
		for j := i; j < 4; j++ {
			hess.SetSym(i, j, 0)
		}
	}
	for i := 1; i <= 20; i++ {
		d1 := float64(i) / 5
		d2 := math.Sin(d1)
		t1 := x[0] + d1*x[1] - math.Exp(d1)
		t2 := x[2] + d2*x[3] - math.Cos(d1)
		t := t1*t1 + t2*t2
		s3 := 2 * t1 * t2
		r1 := t + 2*t1*t1
		r2 := t + 2*t2*t2
		hess.SetSym(0, 0, hess.At(0, 0)+r1)
		hess.SetSym(0, 1, hess.At(0, 1)+d1*r1)
		hess.SetSym(1, 1, hess.At(1, 1)+d1*d1*r1)
		hess.SetSym(0, 2, hess.At(0, 2)+s3)
		hess.SetSym(1, 2, hess.At(1, 2)+d1*s3)
		hess.SetSym(2, 2, hess.At(2, 2)+r2)
		hess.SetSym(0, 3, hess.At(0, 3)+d2*s3)
		hess.SetSym(1, 3, hess.At(1, 3)+d1*d2*s3)
		hess.SetSym(2, 3, hess.At(2, 3)+d2*r2)
		hess.SetSym(3, 3, hess.At(3, 3)+d2*d2*r2)
	}
	for i := 0; i < 4; i++ {
		for j := i; j < 4; j++ {
			hess.SetSym(i, j, 4*hess.At(i, j))
		}
	}
}
Ejemplo n.º 6
0
func (Beale) Hess(hess mat64.MutableSymmetric, x []float64) {
	if len(x) != 2 {
		panic("dimension of the problem must be 2")
	}
	if len(x) != hess.Symmetric() {
		panic("incorrect size of the Hessian")
	}

	t1 := 1 - x[1]
	t2 := 1 - x[1]*x[1]
	t3 := 1 - x[1]*x[1]*x[1]
	f1 := 1.5 - x[1]*t1
	f2 := 2.25 - x[1]*t2
	f3 := 2.625 - x[1]*t3

	h00 := 2 * (t1*t1 + t2*t2 + t3*t3)
	h01 := 2 * (f1 + x[1]*(2*f2+3*x[1]*f3) - x[0]*(t1+x[1]*(2*t2+3*x[1]*t3)))
	h11 := 2 * x[0] * (x[0] + 2*f2 + x[1]*(6*f3+x[0]*x[1]*(4+9*x[1]*x[1])))
	hess.SetSym(0, 0, h00)
	hess.SetSym(0, 1, h01)
	hess.SetSym(1, 1, h11)
}