/// <summary> /// Computes the BFGS correction formula for inverse hessiana approximation. /// </summary> /// <param name="func">Function to find it the hessiana approximation.</param> /// <param name="b">Current inverse approximation of the hessiana.</param> /// <param name="x">Current vector of the minimization Quasi-Newton algorithm.</param> /// <param name="x1">Next vector of the minimization Quasi-Newton algorithm.</param> /// <returns>Returns a matrix representing the next step in inverse hessiana approximation.s</returns> public static Matrix Bfgs(CompiledFunc func, Matrix b, Vector x, Vector x1) { var sk = new Matrix(x1 - x); var yk = new Matrix(func.Differentiate(x1) - func.Differentiate(x)); var t = b.Dot(sk.Transpose()).Dot(sk).Dot(b)/sk.Dot(b).Dot(sk.Transpose())[0,0]; var t1 = yk.Transpose().Dot(yk)/yk.Dot(sk.Transpose())[0,0]; return b - t + t1; }
public void DotValues() { var m1 = new Matrix(new[] {1, 2, 3}, new[] {1, 2, 3}); var m2 = new Matrix(new[] { 4, 5 }, new[] { 4, 5 }, new []{4, 5}); var res = m1.Dot(m2); Assert.AreEqual(2, res.Rows); Assert.AreEqual(2, res.Columns); Assert.AreEqual(24, res[0, 0]); Assert.AreEqual(30, res[0, 1]); Assert.AreEqual(24, res[1, 0]); Assert.AreEqual(30, res[1, 1]); }