Ejemplo n.º 1
0
func (lr *LROWLQN) getScore(model *core.Vector, sample *core.Sample) float64 {
	var score float64 = 0
	for _, fea := range sample.Features {
		score += model.GetValue(fea.Id) * fea.Value
	}
	return score
}
Ejemplo n.º 2
0
func (m *OWLQNMinimizer) fixDirSign(dir *core.Vector, steepestDescDir *core.Vector) {
	if m.l1reg == 0 {
		return
	}
	for key, val := range dir.Data {
		if val*steepestDescDir.GetValue(key) <= 0 {
			dir.SetValue(key, 0)
		}
	}
}
Ejemplo n.º 3
0
func (cov_func *CovSEARD) Cov(x1 *core.Vector, x2 *core.Vector) float64 {
	ret := 0.0
	tmp := 0.0
	for key, r := range cov_func.Radiuses.Data {
		v1 := x1.GetValue(key)
		v2 := x2.GetValue(key)
		tmp = (v1 - v2) / r
		ret += tmp * tmp
	}
	ret = cov_func.Amp * math.Exp(-ret)
	return ret
}
Ejemplo n.º 4
0
func (lr *LROWLQN) Equals(x *core.Vector, y *core.Vector) bool {
	if y == nil && x == nil {
		return true
	}
	if y == nil || x == nil {
		return false
	}
	for key, val := range x.Data {
		if y.GetValue(key) != val {
			return false
		}
	}
	for key, val := range y.Data {
		if x.GetValue(key) != val {
			return false
		}
	}
	return true
}
Ejemplo n.º 5
0
// Description: assume all the features in x also appears in grad
func (m *OWLQNMinimizer) updateGrad(x *core.Vector, grad *core.Vector) {
	if m.l1reg == 0 {
		return
	}
	for key, val := range grad.Data {
		xval := x.GetValue(key)
		if xval < 0 {
			grad.SetValue(key, val-m.l1reg)
		} else if xval > 0 {
			grad.SetValue(key, val+m.l1reg)
		} else {
			if val < -m.l1reg {
				grad.SetValue(key, val+m.l1reg)
			} else if val > m.l1reg {
				grad.SetValue(key, val-m.l1reg)
			}
		}
	}
	return
}
Ejemplo n.º 6
0
// Description: assume all the features in x also appears in grad
//              all the features in dir must be in grad
func (m *OWLQNMinimizer) updateGradForNewPos(x *core.Vector, grad *core.Vector, dir *core.Vector) {
	if m.l1reg == 0 {
		return
	}
	for key, val := range grad.Data {
		xval := x.GetValue(key)
		if xval < 0 {
			grad.SetValue(key, val-m.l1reg)
		} else if xval > 0 {
			grad.SetValue(key, val+m.l1reg)
		} else {
			dirval := dir.GetValue(key)
			if dirval < 0 {
				grad.SetValue(key, val-m.l1reg)
			} else if dirval > 0 {
				grad.SetValue(key, val+m.l1reg)
			}
		}
	}
	return
}