Now that we have a conceptual idea of how the neural network works, let's write the forward propagation function. We'll call it Predict because, well, to predict, you merely need to run the function forward:
func (nn *NN) Predict(a tensor.Tensor) (int, error) { if a.Dims() != 1 { return -1, errors.New("Expected a vector") } var m maybe hidden := m.do(func() (tensor.Tensor, error) { return nn.hidden.MatVecMul(a) }) act0 := m.do(func() (tensor.Tensor, error) { return hidden.Apply(sigmoid, tensor.UseUnsafe()) }) final := m.do(func() (tensor.Tensor, error) { return tensor.MatVecMul(nn.final, act0) }) pred := m.do(func() (tensor.Tensor, error) { return final.Apply(sigmoid, tensor.UseUnsafe()) }) if m.err != nil { return -1, m.err ...