- introduce RbmComponent git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@288 b431acfa-c32f-4a4a-93f1-934dc6c82436
316 lines
8.3 KiB
C++
316 lines
8.3 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, this);
|
|
m_vNumX = m_weights.getNumVisibleX();
|
|
m_vNumY = m_weights.getNumVisibleY();
|
|
m_hNum = m_weights.getNumHidden();
|
|
|
|
addAndMakeVisible (DrawTraining = new DrawComponent (m_vNumX, m_vNumY));
|
|
DrawTraining->setListener(this);
|
|
|
|
addAndMakeVisible (DrawReconstruction = new DrawComponent (m_vNumX, m_vNumY));
|
|
addAndMakeVisible (DrawWeights = new DrawComponent (m_vNumX, m_vNumY));
|
|
addAndMakeVisible (DrawVars = new DrawComponent (m_vNumX, m_vNumY));
|
|
addAndMakeVisible (DrawHidden = new DrawComponent (m_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)
|
|
{
|
|
DrawReconstruction->setData(m_pRbm->toVisible(obj.getData()));
|
|
}
|
|
if (&obj == DrawTraining)
|
|
{
|
|
redrawReconstruction();
|
|
}
|
|
}
|
|
|
|
void RbmComponent::redrawReconstruction()
|
|
{
|
|
uint32_t i;
|
|
VectorXd V, H;
|
|
|
|
V = DrawTraining->getData();
|
|
for (i=0; i < m_pRbm->getNumGibbs(); i++)
|
|
{
|
|
H = m_pRbm->toHidden(V);
|
|
DrawHidden->setData(H);
|
|
V = m_pRbm->toVisible(H);
|
|
DrawReconstruction->setData(V);
|
|
}
|
|
}
|
|
|
|
void RbmComponent::redrawWeights()
|
|
{
|
|
VectorXd w = m_weights.weights().col(m_currWeightIndexToDraw);
|
|
DrawWeights->setData(w);
|
|
DrawVars->setData(m_pRbm->getSigma());
|
|
|
|
}
|
|
|
|
void RbmComponent::setDoLearnVariance(bool value)
|
|
{
|
|
m_pRbm->setDoLearnVariance(value);
|
|
}
|
|
|
|
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->setSigma(value);
|
|
DrawVars->setData(m_pRbm->getSigma());
|
|
redrawReconstruction();
|
|
}
|
|
|
|
//[/MiscUserCode]
|
|
|
|
|
|
//==============================================================================
|