示例#1
0
func (m *OWLQNMinimizer) NextPoint(curPos *core.Vector, dir *core.Vector, alpha float64) *core.Vector {
	if owlqn_output_switch {
		fmt.Printf(".")
	}
	newPos := curPos.ElemWiseMultiplyAdd(dir, alpha)
	if m.l1reg > 0 {
		for key, val := range curPos.Data {
			if val*newPos.GetValue(key) < 0 {
				newPos.SetValue(key, 0)
			}
		}
	}
	return newPos
}
// Description: the pos and gradient arguments should NOT be modified outside
func (h *QuasiNewtonHelper) UpdateState(nextPos *core.Vector, nextGrad *core.Vector) (isOptimal bool) {
	if int64(len(h.sList)) >= h.numHist {
		h.sList = h.sList[1:]
		h.yList = h.yList[1:]
		h.roList = h.roList[1:]
	}
	newS := nextPos.ElemWiseMultiplyAdd(h.curPos, -1)
	newY := nextGrad.ElemWiseMultiplyAdd(h.curGrad, -1)
	ro := newS.Dot(newY)
	h.sList = append(h.sList, newS)
	h.yList = append(h.yList, newY)
	h.roList = append(h.roList, ro)
	h.curPos = nextPos
	h.curGrad = nextGrad
	return ro == 0
}
示例#3
0
func (m *LBFGSMinimizer) NextPoint(curPos *core.Vector, dir *core.Vector, alpha float64) *core.Vector {
	if lbfgs_output_switch {
		fmt.Printf(".")
	}
	return curPos.ElemWiseMultiplyAdd(dir, alpha)
}