// i(t) = sigmoid(W(i)*x(t) + U(i)*h(t-1)) input gate // f(t) = sigmoid(W(f)*x(t) + U(f)*h(t-1)) forget gate // o(t) = sigmoid(W(o)*x(t) + U(o)*h(t-1)) output exposure gate // c tilde(t) = tanh(W(c)*x(t) + U(c)*h(t-1)) new memory cell // c(t) = f(t).*c tilde(t-1) + i(t).*c tilde(t) final memory cell // h(t) = o(t).*tanh(c(t)) public Tensor Step(Graph.Graph f, Tensor x, Tensor h) { // input gate var inputGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wix), f.Multiply(h, _wih)), _bi)); // forget gate var forgetGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wfx), f.Multiply(h, _wfh)), _bf)); var newInput = f.Tanh(f.Multiply(x, _wcx)); return(f.Add(f.ElementwiseMultiply(inputGate, newInput), f.ElementwiseMultiply(forgetGate, f.Tanh(h)))); }
// i(t) = sigmoid(W(i)*x(t) + U(i)*h(t-1)) input gate // f(t) = sigmoid(W(f)*x(t) + U(f)*h(t-1)) forget gate // o(t) = sigmoid(W(o)*x(t) + U(o)*h(t-1)) output exposure gate // c tilde(t) = tanh(W(c)*x(t) + U(c)*h(t-1)) new memory cell // c(t) = f(t).*c tilde(t-1) + i(t).*c tilde(t) final memory cell // h(t) = o(t).*tanh(c(t)) public Tensor Step(Graph.Graph f, Tensor x, Tensor c, Tensor h, out Tensor nc) { // input gate var inputGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wix), f.Multiply(h, _wih)), _bi)); // forget gate var forgetGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wfx), f.Multiply(h, _wfh)), _bf)); // output gate var outputGate = f.Sigmoid(f.AddBias(f.Add(f.Multiply(x, _wox), f.Multiply(h, _woh)), _bo)); // new cell var newInfo = f.Tanh(f.AddBias(f.Add(f.Multiply(x, _wcx), f.Multiply(h, _wch)), _bc)); // final cell var retainCell = f.ElementwiseMultiply(forgetGate, c); var writeCell = f.ElementwiseMultiply(inputGate, newInfo); var finalCell = f.Add(retainCell, writeCell); // hidden unit nc = finalCell; return(f.ElementwiseMultiply(outputGate, f.Tanh(finalCell))); }