// Description: Update the dir from -grad to optimal direction // Dir will be modified directly func (h *QuasiNewtonHelper) ApplyQuasiInverseHession(dir *core.Vector) { count := len(h.sList) if count == 0 { return } alphas := make([]float64, count, count) for n := count - 1; n >= 0; n-- { alphas[n] = -dir.Dot(h.sList[n]) / h.roList[n] dir.ApplyElemWiseMultiplyAccumulation(h.yList[n], alphas[n]) } lastY := h.yList[count-1] yDotY := lastY.Dot(lastY) scalar := h.roList[count-1] / yDotY dir.ApplyScale(scalar) for n := 0; n < count; n++ { beta := dir.Dot(h.yList[n]) / h.roList[n] dir.ApplyElemWiseMultiplyAccumulation(h.sList[n], -alphas[n]-beta) } return }