Files
Rbm-legacy/Source/RbmComponent.h
T
jens 1705287e37 [RBM]
- DBN fixes
- batch sample inside training loop
- implemented RbmComponent stacking

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@296 b431acfa-c32f-4a4a-93f1-934dc6c82436
2016-06-18 17:57:32 +00:00

202 lines
5.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.
==============================================================================
*/
#ifndef __RBM_COMPONENT__
#define __RBM_COMPONENT__
//[Headers] -- You can add your own extra header files here --
#include "JuceHeader.h"
#include "DrawComponent.h"
#include "Rbm.hpp"
//[/Headers]
class IRbmComponent
{
public:
IRbmComponent *upper;
IRbmComponent *lower;
IRbmComponent()
: upper(nullptr)
, lower(nullptr)
{}
virtual ~IRbmComponent()
{
}
virtual void batchchanged() = 0;
virtual void toHidden(RowVectorXd &h, RowVectorXd const &v) = 0;
virtual void toVisible(RowVectorXd &v, RowVectorXd const &h) = 0;
virtual void downPass(RowVectorXd &h) = 0;
virtual void upPass(RowVectorXd const &v) = 0;
void registerRbm(IRbmComponent *pObj)
{
lower = pObj;
pObj->upper = this;
}
};
class RbmComponentListener
{
public:
RbmComponentListener() {}
virtual ~RbmComponentListener()
{
}
virtual void onProgressChanged(size_t progressPercent) = 0;
};
//==============================================================================
/**
//[Comments]
An auto-generated component, created by the Introjucer.
Describe your class and how it works here!
//[/Comments]
*/
class RbmComponent : public Component,
public RbmListener,
public DrawListener,
public IRbmComponent
{
public:
//==============================================================================
RbmComponent (Weights &weights, MatrixXd const &batch, RbmComponentListener &listener);
~RbmComponent();
//==============================================================================
//[UserMethods] -- You can add your own custom methods in this section.
//[/UserMethods]
void paint (Graphics& g);
void resized() override;
void mouseMove (const MouseEvent& e) override;
void mouseEnter (const MouseEvent& e) override;
void mouseExit (const MouseEvent& e) override;
void mouseDown (const MouseEvent& e) override;
void mouseDrag (const MouseEvent& e) override;
void mouseUp (const MouseEvent& e) override;
void mouseDoubleClick (const MouseEvent& e) override;
void mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel) override;
void setDoLearnVariance(bool value);
void setDoRaoBlackwell(bool enable);
void setUseProbsForHiddenReconstruction(bool enable);
void setUseVisibleGaussian(bool enable);
void setDoSparse(bool enable);
void setNormalizeData(bool enable);
void setLambda(double value);
void setSigmaDecay(double value);
void setWeightDecay(double value);
void setSparsity(double value);
void setNumGibbs(size_t value);
void setSigma(double value);
void setMuWeights(double value);
void setMuSparsity(double value);
void setMomentum(double value);
void batchchanged() override;
void setWeightsIndex(size_t index);
size_t getWeightsIndex();
void setTrainingIndex(size_t index);
size_t getTrainingIndex();
void copyReconstructionToTraining();
void redrawWeights();
void redrawReconstruction();
void redrawVariances();
void train(size_t numEpochs);
RowVectorXd const& getTrainingData();
MatrixXd const& getHiddenBatch()
{
return m_pRbm->getHiddenBatch();
}
Rbm::Params const& params()
{
return m_pRbm->params();
}
void reconstructVisible(RowVectorXd& dst, const RowVectorXd& src)
{
toHidden(DrawHidden->getData(), src);
toVisible(dst, DrawHidden->getData());
DrawHidden->DrawData();
}
void toVisible(RowVectorXd &v, RowVectorXd const &h) override
{
m_pRbm->toVisible(v, h);
}
void toHidden(RowVectorXd &h, RowVectorXd const &v) override
{
m_pRbm->toHidden(h, v);
if (lower)
{
lower->downPass(h);
}
}
void downPass(RowVectorXd& h) override
{
toHidden(DrawHidden->getData(), h);
m_pRbm->toVisible(h, DrawHidden->getData());
DrawHidden->DrawData();
}
void upPass(RowVectorXd const &h) override
{
toVisible(DrawReconstruction->getData(), h);
DrawReconstruction->DrawData();
if (upper)
{
upper->upPass(DrawReconstruction->getData());
}
}
private:
//[UserVariables] -- You can add your own custom variables in this section.
ScopedPointer<Rbm> m_pRbm;
Weights &m_weights;
RbmComponentListener &m_listener;
ScopedPointer<DrawComponent> DrawTraining;
ScopedPointer<DrawComponent> DrawReconstruction;
ScopedPointer<DrawComponent> DrawWeights;
ScopedPointer<DrawComponent> DrawVars;
ScopedPointer<DrawComponent> DrawHidden;
size_t m_currWeightIndexToDraw;
size_t m_currTrainingIndexToDraw;
void onProgressChanged(const Rbm &obj) override;
void onDraw(DrawComponent &obj) override;
//[/UserVariables]
//==============================================================================
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RbmComponent)
};
//[EndFile] You can add extra defines here...
//[/EndFile]
#endif // __RBM_COMPONENT__