From 5cb7b16d962467009604441682885d4a7b8d8ebb Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 11 Jan 2022 19:13:30 +0000 Subject: [PATCH] - added rms_error function git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@786 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- source/Rbm.cpp | 8 ++------ source/Rbm.hpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/Rbm.cpp b/source/Rbm.cpp index 3af22aa..266c547 100644 --- a/source/Rbm.cpp +++ b/source/Rbm.cpp @@ -182,9 +182,7 @@ void Rbm::train(IListener* pListener) lastProgress = status.progress; // Calculate error - arma::mat diffErr = miniBatch - prob(h_to_v(prob(v_to_h(v_states)))); - arma::mat diffErr_squared = diffErr % diffErr; - status.err = accu(diffErr_squared)/diffErr_squared.n_elem; + status.err = rms_error_accu(miniBatch - prob(h_to_v(prob(v_to_h(v_states))))); if (pListener) { if(!pListener->onProgress(this, status)) @@ -200,9 +198,7 @@ void Rbm::train(IListener* pListener) } // number of mini batches // Update final status - arma::mat diffErr = batch - prob(h_to_v(prob(v_to_h(batch)))); - arma::mat diffErr_squared = diffErr % diffErr; - status.err_total = accu(diffErr_squared)/diffErr_squared.n_elem; + status.err_total = rms_error_accu(batch - prob(h_to_v(prob(v_to_h(batch))))); if (pListener) { diff --git a/source/Rbm.hpp b/source/Rbm.hpp index fb8390b..3a63200 100644 --- a/source/Rbm.hpp +++ b/source/Rbm.hpp @@ -170,6 +170,18 @@ public: arma::mat v_to_h(const arma::mat &visible) const; arma::mat h_to_v(const arma::mat &hidden) const; + static double rms_error_accu(arma::mat diffErr) + { + arma::mat diffErr_squared = diffErr % diffErr; + return arma::accu(diffErr_squared)/diffErr_squared.n_elem; + } + + static arma::mat rms_error(arma::mat diffErr) + { + arma::mat diffErr_squared = diffErr % diffErr; + return arma::sum(diffErr_squared, 1) * 1.0/diffErr_squared.n_cols; + } + private: Params m_params; arma::mat sample(arma::mat const &src);