/* ============================================================================== 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, MatrixXd const &batch, RbmComponentListener &listener) : m_weights(weights) , m_listener(listener) , m_currWeightIndexToDraw(0) , m_currTrainingIndexToDraw(0) , DrawTraining(nullptr) , DrawReconstruction(nullptr) , DrawWeights(nullptr) , DrawHidden(nullptr) { //[UserPreSize] m_pRbm = new Rbm(m_weights, batch, 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); redrawWeights(); redrawReconstruction(); redrawVariances(); //[/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::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->params().m_numGibbs-1; i++) { m_pRbm->toHidden(DrawHidden->getData(), DrawReconstruction->getData()); m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData()); } DrawHidden->DrawData(); DrawReconstruction->DrawData(); } void RbmComponent::redrawWeights() { DrawWeights->getData() = m_weights.weights().col(m_currWeightIndexToDraw); DrawWeights->DrawData(); } void RbmComponent::redrawVariances() { DrawVars->getData() = m_pRbm->getVariableSigma(); DrawVars->DrawData(); } void RbmComponent::setDoLearnVariance(bool value) { m_pRbm->setDoLearnVariance(value); redrawVariances(); 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); redrawVariances(); redrawReconstruction(); } void RbmComponent::setNormalizeData(bool enable) { m_pRbm->setNormalizeData(enable); } void RbmComponent::setMuWeights(double value) { m_pRbm->setMuWeights(value); } void RbmComponent::setMuSparsity(double value) { m_pRbm->setMuSparsity(value); } void RbmComponent::setMomentum(double value) { m_pRbm->setMomentum(value); } void RbmComponent::batchchanged() { m_pRbm->updateHiddenBatch(); redrawVariances(); } void RbmComponent::setWeightsIndex(size_t index) { m_currWeightIndexToDraw = index; redrawWeights(); } size_t RbmComponent::getWeightsIndex() { return m_currWeightIndexToDraw; } void RbmComponent::setTrainingIndex(size_t index) { if (m_pRbm->getBatch().rows() > 0) { m_currTrainingIndexToDraw = index; DrawTraining->getData() = m_pRbm->getBatch().row(index); DrawTraining->DrawData(); redrawReconstruction(); } } size_t RbmComponent::getTrainingIndex() { return m_currTrainingIndexToDraw; } void RbmComponent::copyReconstructionToTraining() { DrawTraining->getData() = DrawReconstruction->getData(); DrawTraining->DrawData(); } void RbmComponent::train(size_t numEpochs) { m_pRbm->train(numEpochs); } RowVectorXd const& RbmComponent::getTrainingData() { return DrawTraining->getData(); } //[/MiscUserCode] //==============================================================================