func (p *acenterProg) F2(x, z *matrix.FloatMatrix) (f, Df, H *matrix.FloatMatrix, err error) { f, Df, err = p.F1(x) u := matrix.Pow(x, 2.0).Scale(-1.0).Add(1.0) z0 := z.GetIndex(0) u2 := matrix.Pow(u, 2.0) hd := matrix.Div(matrix.Add(u2, 1.0), u2).Scale(2 * z0) H = matrix.FloatDiagonal(hd.NumElements(), hd.FloatArray()...) return }
func (p *floorPlan) F2(x, z *matrix.FloatMatrix) (f, Df, H *matrix.FloatMatrix, err error) { f, Df, err = p.F1(x) x17 := matrix.FloatVector(x.FloatArray()[17:]) tmp := matrix.Div(p.Amin, matrix.Pow(x17, 3.0)) tmp = matrix.Mul(z, tmp).Scale(2.0) diag := matrix.FloatDiagonal(5, tmp.FloatArray()...) H = matrix.FloatZeros(22, 22) H.SetSubMatrix(17, 17, diag) return }
func (p *acenterProg) F1(x *matrix.FloatMatrix) (f, Df *matrix.FloatMatrix, err error) { f = nil Df = nil err = nil max := matrix.Abs(x).Max() if max >= 1.0 { err = errors.New("max(abs(x)) >= 1.0") return } // u = 1 - x**2 u := matrix.Pow(x, 2.0).Scale(-1.0).Add(1.0) val := -matrix.Log(u).Sum() f = matrix.FloatValue(val) Df = matrix.Div(matrix.Scale(x, 2.0), u).Transpose() return }