git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@625 b431acfa-c32f-4a4a-93f1-934dc6c82436
285 lines
7.7 KiB
C++
285 lines
7.7 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
This is an automatically generated GUI class created by the Introjucer!
|
|
|
|
Be careful when adding custom code to these files, as only the code within
|
|
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
|
|
and re-saved.
|
|
|
|
Created with Introjucer version: 3.1.0
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
|
|
Copyright 2004-13 by Raw Material Software Ltd.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
|
|
#include "RbmComponent.hpp"
|
|
|
|
|
|
|
|
//==============================================================================
|
|
RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden, RbmComponentListener *pListener)
|
|
: Layer(name, id, numVisibleX, numVisibleY, numHidden)
|
|
, m_currWeightIndexToDraw(0)
|
|
, DrawTraining(nullptr)
|
|
, DrawReconstruction(nullptr)
|
|
, DrawWeights(nullptr)
|
|
, DrawHidden(nullptr)
|
|
, m_listener(pListener)
|
|
{
|
|
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
|
|
DrawTraining->setListener(this);
|
|
|
|
addAndMakeVisible (DrawReconstruction = new DrawComponent (numVisibleX, numVisibleY));
|
|
|
|
|
|
addAndMakeVisible (DrawWeights = new DrawComponent (numVisibleX, numVisibleY, 0.5, 0.5));
|
|
addAndMakeVisible (DrawHidden = new DrawComponent (numHidden, 1));
|
|
DrawHidden->setListener(this);
|
|
redrawWeights();
|
|
redrawReconstruction();
|
|
|
|
setSize (430, 130);
|
|
resized();
|
|
setBounds (16, 140*id+16, 430, 130);
|
|
}
|
|
|
|
RbmComponent::~RbmComponent()
|
|
{
|
|
//[Destructor_pre]. You can add your own custom destruction code here..
|
|
//[/Destructor_pre]
|
|
|
|
//[Destructor]. You can add your own custom destruction code here..
|
|
DrawTraining = nullptr;
|
|
DrawReconstruction = nullptr;
|
|
DrawWeights = nullptr;
|
|
DrawHidden = nullptr;
|
|
//[/Destructor]
|
|
}
|
|
|
|
//==============================================================================
|
|
void RbmComponent::paint (Graphics& g)
|
|
{
|
|
//[UserPrePaint] Add your own custom painting code here..
|
|
//[/UserPrePaint]
|
|
|
|
g.fillAll (Colours::white);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Sigma"),
|
|
32, 306, 80, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Lambda"),
|
|
120, 306, 80, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Num. epochs"),
|
|
32, 354, 80, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Alpha"),
|
|
120, 354, 80, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Sparsity"),
|
|
208, 306, 80, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Sigma decay"),
|
|
296, 306, 96, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Weight decay"),
|
|
296, 354, 96, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Momentum"),
|
|
208, 354, 80, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Sparsity Alpha"),
|
|
408, 306, 96, 14,
|
|
Justification::centred, true);
|
|
|
|
g.setColour (Colours::black);
|
|
g.setFont (Font (15.00f, Font::plain));
|
|
g.drawText (TRANS("Weight init"),
|
|
408, 354, 96, 14,
|
|
Justification::centred, true);
|
|
|
|
//[UserPaint] Add your own custom painting code here..
|
|
//[/UserPaint]
|
|
}
|
|
|
|
void RbmComponent::resized()
|
|
{
|
|
DrawTraining->setBoundsRelative(0, 0, 100./430, 100./130);
|
|
DrawReconstruction->setBoundsRelative(110./430, 0, 100./430, 100./130);
|
|
DrawWeights->setBoundsRelative (220./430, 0, 100./430, 100./130);
|
|
DrawHidden->setBoundsRelative (0, 110./130, 430./430, 20./130);
|
|
}
|
|
|
|
void RbmComponent::mouseMove (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseMove] -- Add your code here...
|
|
//[/UserCode_mouseMove]
|
|
}
|
|
|
|
void RbmComponent::mouseEnter (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseEnter] -- Add your code here...
|
|
//[/UserCode_mouseEnter]
|
|
}
|
|
|
|
void RbmComponent::mouseExit (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseExit] -- Add your code here...
|
|
//[/UserCode_mouseExit]
|
|
}
|
|
|
|
void RbmComponent::mouseDown (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseDown] -- Add your code here...
|
|
//[/UserCode_mouseDown]
|
|
}
|
|
|
|
void RbmComponent::mouseDrag (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseDrag] -- Add your code here...
|
|
// e.eventComponent->setCentrePosition(e.getPosition().x, e.getPosition().y);
|
|
std::cout << "Mouse = " << e.x << "," << e.y << std::endl;
|
|
//[/UserCode_mouseDrag]
|
|
}
|
|
|
|
void RbmComponent::mouseUp (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseUp] -- Add your code here...
|
|
//[/UserCode_mouseUp]
|
|
}
|
|
|
|
void RbmComponent::mouseDoubleClick (const MouseEvent& e)
|
|
{
|
|
//[UserCode_mouseDoubleClick] -- Add your code here...
|
|
//[/UserCode_mouseDoubleClick]
|
|
}
|
|
|
|
void RbmComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
|
|
{
|
|
//[UserCode_mouseWheelMove] -- Add your code here...
|
|
//[/UserCode_mouseWheelMove]
|
|
}
|
|
|
|
bool RbmComponent::onProgress(const Rbm::Status &status)
|
|
{
|
|
upPass(DrawHidden->getData());
|
|
redrawReconstruction();
|
|
redrawWeights();
|
|
if (m_listener)
|
|
{
|
|
return m_listener->onProgressChanged((size_t)(100*status.progress + 0.5));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void RbmComponent::onDraw(DrawComponent &obj)
|
|
{
|
|
if (&obj == DrawHidden)
|
|
{
|
|
upPass(obj.getData());
|
|
}
|
|
if (&obj == DrawTraining)
|
|
{
|
|
redrawReconstruction();
|
|
}
|
|
}
|
|
|
|
void RbmComponent::redrawReconstruction()
|
|
{
|
|
uint32_t i;
|
|
|
|
downPass(DrawReconstruction->getData(), DrawTraining->getData());
|
|
|
|
for (i=0; i < params().numGibbs-1; i++)
|
|
{
|
|
downPass(DrawReconstruction->getData(), DrawReconstruction->getData());
|
|
}
|
|
DrawReconstruction->DrawData();
|
|
}
|
|
|
|
arma::mat RbmComponent::getConvolutedWeight(arma::mat const &w)
|
|
{
|
|
if (upper)
|
|
{
|
|
arma::mat wc = w * upper->getWeights().t(); // * 1.0/sqrt((double)w.cols());
|
|
return upper->getConvolutedWeight(wc);
|
|
}
|
|
else
|
|
{
|
|
return w;
|
|
}
|
|
|
|
}
|
|
void RbmComponent::redrawWeights()
|
|
{
|
|
DrawWeights->getData() = getConvolutedWeight(w().col(m_currWeightIndexToDraw));
|
|
DrawWeights->DrawData();
|
|
}
|
|
|
|
void RbmComponent::redrawWeights(size_t index)
|
|
{
|
|
m_currWeightIndexToDraw = index;
|
|
}
|
|
|
|
void RbmComponent::setTrainingData(arma::mat const& batch)
|
|
{
|
|
DrawTraining->getData() = batch;
|
|
DrawTraining->DrawData();
|
|
|
|
redrawReconstruction();
|
|
upPass(DrawHidden->getData());
|
|
}
|
|
|
|
arma::mat const& RbmComponent::getTopWeights()
|
|
{
|
|
if (upper)
|
|
{
|
|
return upper->getTopWeights();
|
|
}
|
|
else
|
|
{
|
|
return w();
|
|
}
|
|
}
|
|
|
|
arma::mat const& RbmComponent::getWeights()
|
|
{
|
|
return w();
|
|
}
|
|
//[/MiscUserCode]
|
|
|
|
|
|
//==============================================================================
|