Skip to content

Commit

Permalink
Fixed the SquareError value calculation and the documentation formulas.
Browse files Browse the repository at this point in the history
The value was half of the expected result previously.
  • Loading branch information
Alexey Volkov authored and Ark-kun committed Mar 29, 2016
1 parent fdf1138 commit 34e3cc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Documentation/CNTK-TechReport/lyx/CNTKBook_CN_Chapter.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -8333,9 +8333,9 @@ SquareError
\begin_layout Standard
\begin_inset Formula
\begin{eqnarray}
v\left(\mathbf{X},\mathbf{\mathbf{Y}}\right) & \leftarrow & \frac{1}{2}\mathrm{Tr}\left(\left(\mathbf{X}-\mathbf{Y}\right)\left(\mathbf{X}-\mathbf{Y}\right)^{T}\right)\\
\nabla_{\mathbf{X}}^{J} & \leftarrow & \nabla_{\mathbf{X}}^{J}+\mathbf{\nabla_{n}^{\mathit{J}}}\left(\mathbf{X}-\mathbf{Y}\right)\\
\nabla_{\mathbf{\mathbf{Y}}}^{J} & \leftarrow & \nabla_{\mathbf{\mathbf{Y}}}^{J}-\mathbf{\nabla_{n}^{\mathit{J}}}\left(\mathbf{X}-\mathbf{Y}\right).
v\left(\mathbf{X},\mathbf{Y}\right) & \leftarrow & \mathrm{Tr}\left(\left(\mathbf{X}-\mathbf{Y}\right)\left(\mathbf{X}-\mathbf{Y}\right)^{T}\right)\\
\nabla_{\mathbf{X}}^{J} & \leftarrow & \nabla_{\mathbf{X}}^{J}+2\mathbf{\nabla_{n}^{\mathit{J}}}\left(\mathbf{X}-\mathbf{Y}\right)\\
\nabla_{\mathbf{Y}}^{J} & \leftarrow & \nabla_{\mathbf{Y}}^{J}-2\mathbf{\nabla_{n}^{\mathit{J}}}\left(\mathbf{X}-\mathbf{Y}\right).
\end{eqnarray}

\end_inset
Expand Down Expand Up @@ -8367,8 +8367,8 @@ Note that
\color none
\begin_inset Formula
\begin{eqnarray}
\frac{\partial v}{\partial\mathbf{X}} & = & \mathbf{X}-\mathbf{Y}\\
\frac{\partial v}{\partial\mathbf{Y}} & = & \mathbf{-\left(X-\mathbf{Y}\right)}.
\frac{\partial v}{\partial\mathbf{X}} & = & +2\left(\mathbf{X}-\mathbf{Y}\right)\\
\frac{\partial v}{\partial\mathbf{Y}} & = & -2\left(\mathbf{X}-\mathbf{Y}\right).
\end{eqnarray}

\end_inset
Expand Down
4 changes: 2 additions & 2 deletions Source/ComputationNetworkLib/TrainingNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SquareErrorNode : public ComputationNodeNonLooping /*ComputationNode*/<Ele
{
FrameRange fr(Input(0)->GetMBLayout());
auto gradient = Input(inputIndex)->GradientFor(fr);
Matrix<ElemType>::Multiply1x1AndWeightedAdd(inputIndex == 0 ? 1.0f : -1.0f, Gradient() /*1x1*/, *m_leftMinusRight, 1.0f, gradient);
Matrix<ElemType>::Multiply1x1AndWeightedAdd(inputIndex == 0 ? 2.0f : -2.0f, Gradient() /*1x1*/, *m_leftMinusRight, 1.0f, gradient);
}

virtual bool OutputUsedInComputingInputNodesGradients() const override
Expand All @@ -68,7 +68,7 @@ class SquareErrorNode : public ComputationNodeNonLooping /*ComputationNode*/<Ele
MaskMissingColumnsToZero(*m_leftMinusRight, Input(0)->GetMBLayout(), fr); // we are fine since it will only be called with full minibatch.
ElemType v = m_leftMinusRight->FrobeniusNorm();
Value().VerifySize(1, 1);
Value().SetValue(v * v / 2);
Value().SetValue(v * v);
#if NANCHECK
Value().HasNan("SquareError");
#endif
Expand Down

0 comments on commit 34e3cc9

Please sign in to comment.