From 376f2dfa356ec90cf30141de805d8a2354a44101 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 25 Oct 2014 21:08:57 +0000 Subject: [PATCH] -autoscale of data during draw. data remains unchanged git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@41 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- Source/DrawComponent.cpp | 32 ++++++++++++++++++++++++++++---- Source/DrawComponent.h | 1 + Source/MainComponent.cpp | 20 +------------------- Source/Rbm.hpp | 1 + 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Source/DrawComponent.cpp b/Source/DrawComponent.cpp index dc7a3e0..b31fa0c 100644 --- a/Source/DrawComponent.cpp +++ b/Source/DrawComponent.cpp @@ -229,21 +229,45 @@ const VectorXd& DrawComponent::getData () void DrawComponent::setData (const VectorXd& data) { - double a; - m_data = data; + DrawData(data); +} - for (int i=0; i < m_height; i++) +void DrawComponent::DrawData (const VectorXd& data) +{ + + double a; + VectorXd temp = data; + double min = +1E12; + double max = -1E12; + + for (int i=0; i < m_width*m_height; i++) + { + min = std::min(min, (double)temp[i]); + max = std::max(max, (double)temp[i]); + } + for (int i=0; i < m_width*m_height; i++) + { + temp[i] -= min; + } + for (int i=0; i < m_width*m_height; i++) + { + temp[i] /= (max-min); + } + + for (int i=0; i < m_height; i++) { for (int j=0; j < m_width; j++) { - a = std::min(std::max((double)m_data[i*m_width + j], 0), 1); + a = std::min(std::max((double)temp[i*m_width + j], 0), 1); m_pG->setColour(Colour(Colours::white).greyLevel(a)); m_pG->fillRect(m_scaleX*j, m_scaleY*i, m_scaleX, m_scaleY); } } repaint(); + } + //[/MiscUserCode] diff --git a/Source/DrawComponent.h b/Source/DrawComponent.h index b23ac98..ab0ceb2 100644 --- a/Source/DrawComponent.h +++ b/Source/DrawComponent.h @@ -57,6 +57,7 @@ public: void setListener(DrawListener *pListener); void drawAt(int x, int y, bool setColor); void setData(const VectorXd& data); + void DrawData(const VectorXd& data); const VectorXd& getData(); void clear(); //[/UserMethods] diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index 1aa3491..2b8f828 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -859,25 +859,7 @@ void MainComponent::redrawReconstruction() void MainComponent::redrawWeights(int index) { VectorXd w = m_weights.weights().col(index); - VectorXd temp = w; - double min = +1E12; - double max = -1E12; - - for (int i=0; i < m_vNumX*m_vNumY; i++) - { - min = std::min(min, (double)temp[i]); - max = std::max(max, (double)temp[i]); - } - for (int i=0; i < m_vNumX*m_vNumY; i++) - { - temp[i] -= min; - } - for (int i=0; i < m_vNumX*m_vNumY; i++) - { - temp[i] /= (max-min); - } - - DrawWeights->setData(temp); + DrawWeights->setData(w); } void MainComponent::run() diff --git a/Source/Rbm.hpp b/Source/Rbm.hpp index 46cea9b..8d94873 100644 --- a/Source/Rbm.hpp +++ b/Source/Rbm.hpp @@ -117,6 +117,7 @@ public: { h.statesUpdateStochastic(); } + // Update weights (positive phase) sumWeights += vt[t].states() * h.states().transpose(); sumBiasV += vt[t].states();