Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created March 10, 2018 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/ddc7df91561d76bc620f8f1f655f1dea to your computer and use it in GitHub Desktop.
Save NMZivkovic/ddc7df91561d76bc620f8f1f655f1dea to your computer and use it in GitHub Desktop.
public class RNN
{
private Matrix<double> _state;
private Matrix<double> _inputWeights;
private Matrix<double> _recurrentWeights;
private Matrix<double> _outputWeights;
public RNN(Matrix<double> initialInputWeights, Matrix<double> initialReccurentWeights, Matrix<double> initialOutputWeights)
{
_inputWeights = initialInputWeights;
_recurrentWeights = initialReccurentWeights;
_outputWeights = initialOutputWeights;
}
public Matrix<double> TimeStep(Matrix<double> input)
{
_state = Matrix<double>.Tanh(_state.Multiply(_recurrentWeights) + input.Multiply(_inputWeights));
return _state.Multiply(_outputWeights);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment