Files
Rbm-legacy/Source/RbmComponent.cpp
T
jens 4dccddd50f [RBM]
- added getHiddenBatch() and getVisibleBatch()
- cleaned up

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@292 b431acfa-c32f-4a4a-93f1-934dc6c82436
2016-06-15 21:30:28 +00:00

326 lines
8.8 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.h"
//==============================================================================
RbmComponent::RbmComponent (Weights &weights, RbmComponentListener &listener)
: m_weights(weights)
, m_listener(listener)
, m_layers(this)
, m_currWeightIndexToDraw(0)
, m_currTrainingIndexToDraw(0)
, DrawTraining(nullptr)
, DrawReconstruction(nullptr)
, DrawWeights(nullptr)
, DrawHidden(nullptr)
{
//[UserPreSize]
m_pRbm = new Rbm(m_weights, m_layers.data(), this);
size_t vNumX = m_weights.getNumVisibleX();
size_t vNumY = m_weights.getNumVisibleY();
size_t hNum = m_weights.getNumHidden();
addAndMakeVisible (DrawTraining = new DrawComponent (vNumX, vNumY));
DrawTraining->setListener(this);
addAndMakeVisible (DrawReconstruction = new DrawComponent (vNumX, vNumY));
addAndMakeVisible (DrawWeights = new DrawComponent (vNumX, vNumY));
addAndMakeVisible (DrawVars = new DrawComponent (vNumX, vNumY));
addAndMakeVisible (DrawHidden = new DrawComponent (hNum, 1));
DrawHidden->setListener(this);
//[/UserPreSize]
setSize (430, 130);
resized();
}
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;
DrawVars = nullptr;
DrawHidden = nullptr;
m_pRbm = 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);
DrawVars->setBoundsRelative (330./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);
cout << "Mouse = " << e.x << "," << e.y << 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]
}
void RbmComponent::onChanged(const LayerArray &obj)
{
m_listener.onLayerSizeChanged((size_t)obj.getSize());
}
void RbmComponent::onEpochTrained(const Rbm &obj)
{
// mylog("Training %f %%\n", obj.getProgress()*100);
redrawReconstruction();
redrawWeights();
m_listener.onRbmEpochTrained((size_t)(100*obj.getProgress()));
}
void RbmComponent::onDraw(DrawComponent &obj)
{
if (&obj == DrawHidden)
{
m_pRbm->toVisible(DrawReconstruction->getData(), obj.getData());
DrawReconstruction->DrawData();
}
if (&obj == DrawTraining)
{
redrawReconstruction();
}
}
void RbmComponent::redrawReconstruction()
{
uint32_t i;
m_pRbm->toHidden(DrawHidden->getData(), DrawTraining->getData());
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
for (i=0; i < m_pRbm->getNumGibbs()-1; i++)
{
m_pRbm->toHidden(DrawHidden->getData(), DrawReconstruction->getData());
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
}
DrawHidden->DrawData();
DrawReconstruction->DrawData();
}
void RbmComponent::redrawWeights()
{
VectorXd w = m_weights.weights().col(m_currWeightIndexToDraw);
DrawWeights->getData() = w;
DrawWeights->DrawData();
DrawVars->getData() = m_pRbm->getVariableSigma();
DrawVars->DrawData();
}
void RbmComponent::setDoLearnVariance(bool value)
{
m_pRbm->setDoLearnVariance(value);
DrawVars->getData() = m_pRbm->getVariableSigma();
DrawVars->DrawData();
redrawReconstruction();
}
void RbmComponent::setDoRaoBlackwell(bool enable)
{
m_pRbm->setDoRaoBlackwell(enable);
}
void RbmComponent::setUseProbsForHiddenReconstruction(bool enable)
{
m_pRbm->setUseProbsForHiddenReconstruction(enable);
}
void RbmComponent::setUseVisibleGaussian(bool enable)
{
m_pRbm->setUseVisibleGaussian(enable);
}
void RbmComponent::setDoSparse(bool enable)
{
m_pRbm->setDoSparse(enable);
}
void RbmComponent::setLambda(double value)
{
m_pRbm->setLambda(value);
}
void RbmComponent::setSigmaDecay(double value)
{
m_pRbm->setSigmaDecay(value);
}
void RbmComponent::setWeightDecay(double value)
{
m_pRbm->setWeightDecay(value);
}
void RbmComponent::setSparsity(double value)
{
m_pRbm->setSparsity(value);
}
void RbmComponent::setNumGibbs(size_t value)
{
m_pRbm->setNumGibbs(value);
redrawReconstruction();
}
void RbmComponent::setSigma(double value)
{
m_pRbm->setConstantSigma(value);
DrawVars->getData() = m_pRbm->getVariableSigma();
DrawVars->DrawData();
redrawReconstruction();
}
//[/MiscUserCode]
//==============================================================================