func (f LinearFunction) Predict(x mat.MatrixRO) (float64, error) { if x.Cols() != f.InputDims() { return 0, fmt.Errorf("x has %d columns. Expected %d.", x.Cols(), f.InputDims()) } value, err := x.Times(&f.Weights) if f.AFunc != nil { return f.AFunc.Eval(value.Get(0, 0)), err } else { return value.Get(0, 0), err } }
func (f LinearFunction) PredictM(x mat.MatrixRO) (mat.MatrixRO, error) { if x.Cols() != f.InputDims() { return nil, fmt.Errorf("x has %d columns. Expected %d.", x.Cols(), f.InputDims()) } y, err := x.Times(&f.Weights) if err != nil { return nil, fmt.Errorf("Error predicting before applying activation function. %v", err) } var yprime mat.MatrixRO = nil if f.AFunc != nil { yprime = Apply(y, f.AFunc.Eval) } else { yprime = y } return yprime, nil }