// NewEngine allocates and initializes a learning engine for the given corpus // size. By default, users consider all elements equally. func NewEngine(users, choices int) *Engine { return &Engine{ X: gauss.Zero(users, choices), Xp: gauss.Zero(users, choices), Z: gauss.Zero(users, choices), History: make([]Query, 0), Nu: 1, Lambda: 0.04, Alpha: 1, T: 1, } }
func (p *Engine) gradientLoss(samps []Query) gauss.Array { result := gauss.Zero(p.X.Shape...) before := p.hingeLoss(samps) for i := range result.Data { p.X.Data[i] += 0.0001 result.Data[i] = (p.hingeLoss(samps) - before) / 0.0001 p.X.Data[i] -= 0.0001 } return result }