diff --git a/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp b/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp index 20d79487ac..4f46782b59 100644 --- a/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp +++ b/src/mlpack/methods/ann/loss_functions/reconstruction_loss.hpp @@ -74,7 +74,7 @@ class ReconstructionLoss private: //! Locally-stored distribution object. - DistType* dist; + DistType dist; //! Locally-stored output parameter object. OutputDataType outputParameter; diff --git a/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp b/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp index aeb72df3e4..dc24ec30f5 100644 --- a/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/reconstruction_loss_impl.hpp @@ -33,8 +33,8 @@ template double ReconstructionLoss::Forward( const InputType&& input, const TargetType&& target) { - dist = new DistType(std::move(input)); - return dist->LogProbability(std::move(target)); + dist = DistType(std::move(input)); + return -dist.LogProbability(std::move(target)); } template @@ -44,7 +44,8 @@ void ReconstructionLoss::Backward( const TargetType&& target, OutputType&& output) { - dist->LogProbBackward(std::move(target), std::move(output)); + dist.LogProbBackward(std::move(target), std::move(output)); + output = -output; } template