Files
Rbm/source/MainComponent.cpp
T
jensandClaude Sonnet 5 0149cdf7ce Rename weightDecay to l2Lambda
Rbm::Params::weightDecay is now applied directly to the weights outside
the momentum recursion (previous commit), exactly like the newly-added
l1Lambda and matching pyRBM's l2_lambda -- same lambda*W gradient form,
same decoupled-from-momentum treatment. The two are functionally the
same mechanism in this codebase, so name it accordingly. Renamed the
Params field, its JSON key, and the two GUI references in
MainComponent.cpp that read/write it (the "weightDecayLabel" widget
identifier and its JUCE-generated marker comment are left as-is --
cosmetic, not part of the actual API).

Existing .prj files still have a "weightDecay" JSON key; fromJson()
no longer reads it, so it's silently ignored on load. Harmless today
since every current project has it set to 0.0 (confirmed: unchanged
poet.elf output, unchanged test-suite results). Not migrating the .prj
files themselves in this change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016K8Gu7Qejd11JbdiHZqYAs
2026-07-27 15:41:01 +02:00

967 lines
40 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.
==============================================================================
*/
//[Headers] You can add your own extra header files here...
//[/Headers]
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include "MainComponent.hpp"
#include "StackCreator.hpp"
//[MiscUserDefs] You can add your own user definitions and misc code here...
void mylog(const char* format, ...)
{
char log_buf[257];
va_list argptr;
va_start(argptr, format);
vprintf(format, argptr);
va_end(argptr);
}
//[/MiscUserDefs]
//==============================================================================
MainComponent::MainComponent (const String prjname)
: Thread("RBM")
, m_stack(nullptr)
, m_pLayer(nullptr)
, m_trainingIndex(0)
, m_weightIndex(0)
, m_toolTipWindow(this)
, m_file(prjname)
, m_dir(".")
{
addAndMakeVisible (trainButton = new TextButton ("Train button"));
trainButton->setTooltip (TRANS("Start/Stop training"));
trainButton->setButtonText (TRANS("Train"));
trainButton->addListener (this);
addAndMakeVisible (addButton = new TextButton ("Add button"));
addButton->setTooltip (TRANS("Add training pattern"));
addButton->setButtonText (TRANS("Add"));
addButton->addListener (this);
addAndMakeVisible (patterSlider = new Slider ("Pattern slider"));
patterSlider->setTooltip (TRANS("Browse training patterns"));
patterSlider->setRange (0, 0, 1);
patterSlider->setSliderStyle (Slider::LinearBar);
patterSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
patterSlider->addListener (this);
addAndMakeVisible (ShakeButton = new TextButton ("Shake button"));
ShakeButton->setTooltip (TRANS("Shake weights"));
ShakeButton->setButtonText (TRANS("Shake"));
ShakeButton->addListener (this);
addAndMakeVisible (WeightsSlider = new Slider ("Weights slider"));
WeightsSlider->setTooltip (TRANS("Browse weights"));
WeightsSlider->setRange (0, 0, 1);
WeightsSlider->setSliderStyle (Slider::LinearBar);
WeightsSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
WeightsSlider->addListener (this);
addAndMakeVisible (numEpochslabel = new Label ("Num Epochs label",
TRANS("1000")));
numEpochslabel->setTooltip (TRANS("Number of epochs to run on a mini batch"));
numEpochslabel->setFont (Font (15.00f, Font::plain));
numEpochslabel->setJustificationType (Justification::centred);
numEpochslabel->setEditable (true, true, false);
numEpochslabel->setColour (TextEditor::textColourId, Colours::black);
numEpochslabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
numEpochslabel->addListener (this);
addAndMakeVisible (learningRateLabel = new Label ("Learning Rate label",
TRANS("0.01")));
learningRateLabel->setTooltip (TRANS("Learning rate for updating of weights and biases"));
learningRateLabel->setFont (Font (15.00f, Font::plain));
learningRateLabel->setJustificationType (Justification::centred);
learningRateLabel->setEditable (true, true, false);
learningRateLabel->setColour (TextEditor::textColourId, Colours::black);
learningRateLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
learningRateLabel->addListener (this);
addAndMakeVisible (numVisibleLabel = new Label ("Num Visible label",
TRANS("16")));
numVisibleLabel->setTooltip (TRANS("Number of visible units X"));
numVisibleLabel->setFont (Font (15.00f, Font::plain));
numVisibleLabel->setJustificationType (Justification::centred);
numVisibleLabel->setEditable (true, true, false);
numVisibleLabel->setColour (TextEditor::textColourId, Colours::black);
numVisibleLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
numVisibleLabel->addListener (this);
addAndMakeVisible (numHiddenLabel = new Label ("Num Hidden label",
TRANS("64")));
numHiddenLabel->setTooltip (TRANS("Number of hidden units"));
numHiddenLabel->setFont (Font (15.00f, Font::plain));
numHiddenLabel->setJustificationType (Justification::centred);
numHiddenLabel->setEditable (true, true, false);
numHiddenLabel->setColour (TextEditor::textColourId, Colours::black);
numHiddenLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
numHiddenLabel->addListener (this);
addAndMakeVisible (createButton = new TextButton ("Create button"));
createButton->setTooltip (TRANS("Create new layer"));
createButton->setButtonText (TRANS("Create"));
createButton->addListener (this);
addAndMakeVisible (clearButton = new TextButton ("Clear button"));
clearButton->setTooltip (TRANS("Delete all layers"));
clearButton->setButtonText (TRANS("Clear"));
clearButton->addListener (this);
addAndMakeVisible (projectNameLabel = new Label ("Project Name label",
m_file.getFileNameWithoutExtension()));
projectNameLabel->setTooltip (TRANS("Name of project"));
projectNameLabel->setFont (Font (15.00f, Font::plain));
projectNameLabel->setJustificationType (Justification::centred);
projectNameLabel->setEditable (true, true, false);
projectNameLabel->setColour (TextEditor::textColourId, Colours::black);
projectNameLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
projectNameLabel->addListener (this);
addAndMakeVisible (loadButton = new TextButton ("Load button"));
loadButton->setTooltip (TRANS("Load project from disk"));
loadButton->setButtonText (TRANS("Load"));
loadButton->addListener (this);
addAndMakeVisible (saveButton = new TextButton ("Save button"));
saveButton->setTooltip (TRANS("Save project to disk"));
saveButton->setButtonText (TRANS("Save"));
saveButton->addListener (this);
addAndMakeVisible (numVisibleYLabel = new Label ("Num Visible Y label",
TRANS("16")));
numVisibleYLabel->setTooltip (TRANS("Number of visible units Y"));
numVisibleYLabel->setFont (Font (15.00f, Font::plain));
numVisibleYLabel->setJustificationType (Justification::centred);
numVisibleYLabel->setEditable (true, true, false);
numVisibleYLabel->setColour (TextEditor::textColourId, Colours::black);
numVisibleYLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
numVisibleYLabel->addListener (this);
addAndMakeVisible (loadTrainingButton = new TextButton ("Load Training button"));
loadTrainingButton->setTooltip (TRANS("Load training patterns from disk"));
loadTrainingButton->setButtonText (TRANS("Load T"));
loadTrainingButton->addListener (this);
addAndMakeVisible (saveTrainingButton = new TextButton ("Save Training button"));
saveTrainingButton->setTooltip (TRANS("Save training patterns to disk"));
saveTrainingButton->setButtonText (TRANS("Save T"));
saveTrainingButton->addListener (this);
addAndMakeVisible (clearTrainingButton = new TextButton ("Clear Training button"));
clearTrainingButton->setTooltip (TRANS("Clear all training patterns"));
clearTrainingButton->setButtonText (TRANS("Clear T"));
clearTrainingButton->addListener (this);
addAndMakeVisible (removeTrainingButton = new TextButton ("Remove Training button"));
removeTrainingButton->setTooltip (TRANS("Remove current training pattern"));
removeTrainingButton->setButtonText (TRANS("Remove T"));
removeTrainingButton->addListener (this);
addAndMakeVisible (numGibbsSlider = new Slider ("Num. Gibbs slider"));
numGibbsSlider->setTooltip (TRANS("Number of gibbs samples"));
numGibbsSlider->setRange (1, 101, 1);
numGibbsSlider->setSliderStyle (Slider::LinearBar);
numGibbsSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
numGibbsSlider->addListener (this);
addAndMakeVisible (rbmDoRaoBlackwellToggleButton = new ToggleButton ("rbmDoRaoBlackwell toggle button"));
rbmDoRaoBlackwellToggleButton->setTooltip (TRANS("Don\'t sample hidden during learning"));
rbmDoRaoBlackwellToggleButton->setButtonText (TRANS("Rao-Blackwell"));
rbmDoRaoBlackwellToggleButton->addListener (this);
addAndMakeVisible (rbmDoSampleVisibleToggleButton = new ToggleButton ("rbmDoSampleVisible toggle button"));
rbmDoSampleVisibleToggleButton->setTooltip (TRANS("Sample visible during learning\n"));
rbmDoSampleVisibleToggleButton->setButtonText (TRANS("Sample Visible"));
rbmDoSampleVisibleToggleButton->addListener (this);
addAndMakeVisible (lambdaLabel = new Label ("Lambda label",
TRANS("1.0")));
lambdaLabel->setTooltip (TRANS("Unused"));
lambdaLabel->setFont (Font (15.00f, Font::plain));
lambdaLabel->setJustificationType (Justification::centred);
lambdaLabel->setEditable (true, true, false);
lambdaLabel->setColour (TextEditor::textColourId, Colours::black);
lambdaLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
lambdaLabel->addListener (this);
addAndMakeVisible (sigmaLabel = new Label ("Sigma label",
TRANS("1.0")));
sigmaLabel->setTooltip (TRANS("Unused"));
sigmaLabel->setFont (Font (15.00f, Font::plain));
sigmaLabel->setJustificationType (Justification::centred);
sigmaLabel->setEditable (true, true, false);
sigmaLabel->setColour (TextEditor::textColourId, Colours::black);
sigmaLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
sigmaLabel->addListener (this);
addAndMakeVisible (rbmUseVisibleGaussianToggleButton = new ToggleButton ("rbmUseVisibleGaussian toggle button"));
rbmUseVisibleGaussianToggleButton->setTooltip (TRANS("Use gaussian visible units"));
rbmUseVisibleGaussianToggleButton->setButtonText (TRANS("Use gaussian visible"));
rbmUseVisibleGaussianToggleButton->addListener (this);
addAndMakeVisible (rbmDoSparseToggleButton = new ToggleButton ("rbmDoSparse toggle button"));
rbmDoSparseToggleButton->setTooltip (TRANS("Unused"));
rbmDoSparseToggleButton->setButtonText (TRANS("Do sparse"));
rbmDoSparseToggleButton->addListener (this);
addAndMakeVisible (sparsityLabel = new Label ("Sparsity label",
TRANS("0.05")));
sparsityLabel->setTooltip (TRANS("Unused"));
sparsityLabel->setFont (Font (15.00f, Font::plain));
sparsityLabel->setJustificationType (Justification::centred);
sparsityLabel->setEditable (true, true, false);
sparsityLabel->setColour (TextEditor::textColourId, Colours::black);
sparsityLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
sparsityLabel->addListener (this);
addAndMakeVisible (sigmaDecayLabel = new Label ("SigmaDecay label",
TRANS("1.0")));
sigmaDecayLabel->setTooltip (TRANS("Unused"));
sigmaDecayLabel->setFont (Font (15.00f, Font::plain));
sigmaDecayLabel->setJustificationType (Justification::centred);
sigmaDecayLabel->setEditable (true, true, false);
sigmaDecayLabel->setColour (TextEditor::textColourId, Colours::black);
sigmaDecayLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
sigmaDecayLabel->addListener (this);
addAndMakeVisible (weightDecayLabel = new Label ("WeightDecay label",
TRANS("0")));
weightDecayLabel->setTooltip (TRANS("Penalize large weights during training"));
weightDecayLabel->setFont (Font (15.00f, Font::plain));
weightDecayLabel->setJustificationType (Justification::centred);
weightDecayLabel->setEditable (true, true, false);
weightDecayLabel->setColour (TextEditor::textColourId, Colours::black);
weightDecayLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
weightDecayLabel->addListener (this);
addAndMakeVisible (m_progressBarSlider = new Slider ("progressBar slider"));
m_progressBarSlider->setTooltip (TRANS("Progress"));
m_progressBarSlider->setRange (0, 100, 1);
m_progressBarSlider->setSliderStyle (Slider::LinearBar);
m_progressBarSlider->setTextBoxStyle (Slider::TextBoxLeft, true, 80, 20);
m_progressBarSlider->addListener (this);
addAndMakeVisible (momentumLabel = new Label ("Momentum label",
TRANS("0.5")));
momentumLabel->setTooltip (TRANS("Momentum during training"));
momentumLabel->setFont (Font (15.00f, Font::plain));
momentumLabel->setJustificationType (Justification::centred);
momentumLabel->setEditable (true, true, false);
momentumLabel->setColour (TextEditor::textColourId, Colours::black);
momentumLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
momentumLabel->addListener (this);
addAndMakeVisible (sparsityLearningRateLabel = new Label ("SparsityLearn label",
TRANS("0.01")));
sparsityLearningRateLabel->setTooltip (TRANS("Ununsed"));
sparsityLearningRateLabel->setFont (Font (15.00f, Font::plain));
sparsityLearningRateLabel->setJustificationType (Justification::centred);
sparsityLearningRateLabel->setEditable (true, true, false);
sparsityLearningRateLabel->setColour (TextEditor::textColourId, Colours::black);
sparsityLearningRateLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
sparsityLearningRateLabel->addListener (this);
addAndMakeVisible (weightInitLabel = new Label ("WeightInit label",
TRANS("0.01")));
weightInitLabel->setTooltip (TRANS("Std. deviation for weight shaking"));
weightInitLabel->setFont (Font (15.00f, Font::plain));
weightInitLabel->setJustificationType (Justification::centred);
weightInitLabel->setEditable (true, true, false);
weightInitLabel->setColour (TextEditor::textColourId, Colours::black);
weightInitLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
weightInitLabel->addListener (this);
addAndMakeVisible (rbmLearnVarianceButton = new ToggleButton ("rbmLearnVariance button"));
rbmLearnVarianceButton->setTooltip (TRANS("Unused"));
rbmLearnVarianceButton->setButtonText (TRANS("Learn Variance"));
rbmLearnVarianceButton->addListener (this);
addAndMakeVisible (rbmNormalizeDataToggleButton = new ToggleButton ("rbmNormalizeData toggle button"));
rbmNormalizeDataToggleButton->setTooltip (TRANS("Remove mean from training data and normalize to variance=1"));
rbmNormalizeDataToggleButton->setButtonText (TRANS("Normalize data"));
rbmNormalizeDataToggleButton->addListener (this);
addAndMakeVisible (m_rbmSelect = new ComboBox ("RBM Selector"));
m_rbmSelect->setTooltip (TRANS("Select RBM from stack"));
m_rbmSelect->setEditableText (false);
m_rbmSelect->setJustificationType (Justification::centredLeft);
m_rbmSelect->setTextWhenNothingSelected (String::empty);
m_rbmSelect->setTextWhenNoChoicesAvailable (TRANS("(no choices)"));
m_rbmSelect->addListener (this);
addAndMakeVisible (rbmDoSampleHidden = new ToggleButton ("rbmDoSampleHidden button"));
rbmDoSampleHidden->setTooltip (TRANS("Do stochastic sampling from hidden state during gibbs sampling"));
rbmDoSampleHidden->setTooltip (TRANS("Sample hidden state during learning\n"));
rbmDoSampleHidden->setButtonText (TRANS("Sample hidden"));
rbmDoSampleHidden->addListener (this);
addAndMakeVisible (sizeMiniBatch = new Label ("sizeMiniBatch",
TRANS("100")));
sizeMiniBatch->setTooltip (TRANS("Mini batch size"));
sizeMiniBatch->setFont (Font (15.00f, Font::plain));
sizeMiniBatch->setJustificationType (Justification::centred);
sizeMiniBatch->setEditable (true, true, false);
sizeMiniBatch->setColour (TextEditor::textColourId, Colours::black);
sizeMiniBatch->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
sizeMiniBatch->addListener (this);
addAndMakeVisible (rbmUseHiddenGaussianToggleButton = new ToggleButton ("rbmUseHiddenGaussian toggle button"));
rbmUseHiddenGaussianToggleButton->setTooltip (TRANS("Use gaussian hidden units"));
rbmUseHiddenGaussianToggleButton->setButtonText (TRANS("Use gaussian hidden"));
rbmUseHiddenGaussianToggleButton->addListener (this);
//[UserPreSize]
m_progressBarSlider->setValue(100);
//[/UserPreSize]
setSize (1200, 600);
//[Constructor] You can add your own custom stuff here..
//[/Constructor]
}
MainComponent::~MainComponent()
{
//[Destructor_pre]. You can add your own custom destruction code here..
//[/Destructor_pre]
trainButton = nullptr;
addButton = nullptr;
patterSlider = nullptr;
ShakeButton = nullptr;
WeightsSlider = nullptr;
numEpochslabel = nullptr;
learningRateLabel = nullptr;
numVisibleLabel = nullptr;
numHiddenLabel = nullptr;
createButton = nullptr;
clearButton = nullptr;
projectNameLabel = nullptr;
loadButton = nullptr;
saveButton = nullptr;
numVisibleYLabel = nullptr;
loadTrainingButton = nullptr;
saveTrainingButton = nullptr;
clearTrainingButton = nullptr;
removeTrainingButton = nullptr;
numGibbsSlider = nullptr;
rbmDoRaoBlackwellToggleButton = nullptr;
rbmDoSampleVisibleToggleButton = nullptr;
lambdaLabel = nullptr;
sigmaLabel = nullptr;
rbmUseVisibleGaussianToggleButton = nullptr;
rbmDoSparseToggleButton = nullptr;
sparsityLabel = nullptr;
sigmaDecayLabel = nullptr;
weightDecayLabel = nullptr;
m_progressBarSlider = nullptr;
momentumLabel = nullptr;
sparsityLearningRateLabel = nullptr;
weightInitLabel = nullptr;
rbmLearnVarianceButton = nullptr;
rbmNormalizeDataToggleButton = nullptr;
m_rbmSelect = nullptr;
rbmDoSampleHidden = nullptr;
sizeMiniBatch = nullptr;
rbmUseHiddenGaussianToggleButton = nullptr;
//[Destructor]. You can add your own custom destruction code here..
//[/Destructor]
}
//==============================================================================
void MainComponent::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"),
560, 138, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Lambda"),
648, 138, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Num. epochs"),
551, 186, 91, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Alpha"),
648, 186, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sparsity"),
736, 138, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sigma decay"),
824, 138, 96, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Weight decay"),
824, 186, 96, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Momentum"),
736, 186, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sparsity Alpha"),
936, 138, 96, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Weight init"),
936, 186, 96, 14,
Justification::centred, true);
//[UserPaint] Add your own custom painting code here..
//[/UserPaint]
}
void MainComponent::resized()
{
trainButton->setBounds (648, 20, 72, 24);
addButton->setBounds (556, 20, 72, 24);
patterSlider->setBounds (896, 280, 220, 24);
ShakeButton->setBounds (740, 20, 72, 24);
WeightsSlider->setBounds (896, 320, 220, 24);
numEpochslabel->setBounds (564, 200, 72, 24);
learningRateLabel->setBounds (652, 200, 72, 24);
projectNameLabel->setBounds (552, 248, 96, 24);
numVisibleLabel->setBounds (648, 248, 48, 24);
numVisibleYLabel->setBounds (700, 248, 48, 24);
numHiddenLabel->setBounds (748, 248, 48, 24);
m_rbmSelect->setBounds (810, 248, 62, 24);
loadButton->setBounds (564, 280, 72, 24);
saveButton->setBounds (644, 280, 72, 24);
createButton->setBounds (724, 280, 72, 24);
clearButton->setBounds (804, 280, 72, 24);
loadTrainingButton->setBounds (564, 316, 72, 24);
saveTrainingButton->setBounds (644, 316, 72, 24);
removeTrainingButton->setBounds (724, 316, 72, 24);
clearTrainingButton->setBounds (804, 316, 72, 24);
numGibbsSlider->setBounds (896, 240, 220, 24);
rbmDoRaoBlackwellToggleButton->setBounds (556, 60, 112, 24);
rbmDoSampleVisibleToggleButton->setBounds (680, 60, 128, 24);
lambdaLabel->setBounds (652, 152, 72, 24);
sigmaLabel->setBounds (564, 152, 72, 24);
rbmUseVisibleGaussianToggleButton->setBounds (680, 92, 156, 24);
rbmDoSparseToggleButton->setBounds (556, 92, 96, 24);
sparsityLabel->setBounds (740, 152, 72, 24);
sigmaDecayLabel->setBounds (836, 152, 72, 24);
weightDecayLabel->setBounds (836, 200, 72, 24);
m_progressBarSlider->setBounds (828, 20, 220, 24);
momentumLabel->setBounds (740, 200, 72, 24);
sparsityLearningRateLabel->setBounds (948, 152, 72, 24);
weightInitLabel->setBounds (948, 200, 72, 24);
rbmLearnVarianceButton->setBounds (1004, 92, 128, 24);
rbmNormalizeDataToggleButton->setBounds (1004, 60, 124, 24);
rbmDoSampleHidden->setBounds (844, 60, 128, 24);
sizeMiniBatch->setBounds (1064, 20, 48, 24);
rbmUseHiddenGaussianToggleButton->setBounds (840, 92, 156, 24);
//[UserResized] Add your own custom resize handling here..
//[/UserResized]
}
void MainComponent::buttonClicked (Button* buttonThatWasClicked)
{
//[UserbuttonClicked_Pre]
//[/UserbuttonClicked_Pre]
if (buttonThatWasClicked == trainButton)
{
//[UserButtonCode_trainButton] -- add your button handler code here..
if (isThreadRunning())
{
m_doStop = true;
}
else
{
m_doStop = false;
startThread();
}
//[/UserButtonCode_trainButton]
}
else if (buttonThatWasClicked == addButton)
{
//[UserButtonCode_addButton] -- add your button handler code here..
Layer *layer = m_stack->getLayer(0);
RbmComponent *pComp = static_cast<RbmComponent*>(m_stack->getLayer(0));
addTraining(arma::join_rows(pComp->DrawVisibleTrain->getData(), pComp->DrawContextTrain->getData()));
//[/UserButtonCode_addButton]
}
else if (buttonThatWasClicked == ShakeButton)
{
//[UserButtonCode_ShakeButton] -- add your button handler code here..
m_pLayer->weightsInit(weightInitLabel->getText().getFloatValue());
m_pLayer->redrawWeights();
m_pLayer->redrawReconstruction();
//[/UserButtonCode_ShakeButton]
}
else if (buttonThatWasClicked == createButton)
{
//[UserButtonCode_createButton] -- add your button handler code here..
int next_index = m_rbmSelect->getNumItems();
int numVisX = numVisibleLabel->getText().getIntValue();
int numVisY = numVisibleYLabel->getText().getIntValue();
int numHid = numHiddenLabel->getText().getIntValue();
int numCtx = 0;
if (!m_stack)
{
m_stack = new DeepStack(std::string(projectNameLabel->getText().getCharPointer()));
}
Layer *pPrev = m_stack->getLayer(next_index-1);
if (pPrev)
{
numVisX = pPrev->bh().n_elem;
numVisY = 1;
}
m_stack->addLayer(onConstruct(m_stack, "Layer", next_index, numVisX, numVisY, numHid, numCtx));
m_rbmSelect->addItem(String(next_index), next_index+1);
m_rbmSelect->setSelectedId(next_index+1, sendNotification);
//[/UserButtonCode_createButton]
}
else if (buttonThatWasClicked == clearButton)
{
m_stack = nullptr;
m_rbmSelect->clear(NotificationType::dontSendNotification);
}
else if (buttonThatWasClicked == loadButton)
{
//[UserButtonCode_loadButton] -- add your button handler code here..
ScopedPointer<FileChooser>fc = new FileChooser("Open project", m_file.getParentDirectory().getFullPathName(), "*.prj");
if (fc->browseForFileToOpen())
{
m_file = fc->getResult();
projectNameLabel->setText(m_file.getFileNameWithoutExtension(), NotificationType::dontSendNotification);
AStack *pStack = StackCreator::fromFile(m_file.getParentDirectory().getFullPathName().toStdString(), std::string(projectNameLabel->getText().getCharPointer()), this);
m_stack = reinterpret_cast<DeepStack*>(pStack);
m_stack->loadWeights(m_dir);
m_rbmSelect->clear(dontSendNotification);
for (int id=0; id < m_stack->numLayers(); id++)
{
m_rbmSelect->addItem(String(id), id+1);
}
loadTraining();
m_rbmSelect->setSelectedId(1, sendNotification);
}
//[/UserButtonCode_loadButton]
}
else if (buttonThatWasClicked == saveButton)
{
//[UserButtonCode_saveButton] -- add your button handler code here..
save();
//[/UserButtonCode_saveButton]
}
else if (buttonThatWasClicked == loadTrainingButton)
{
//[UserButtonCode_loadTrainingButton] -- add your button handler code here..
loadTraining();
//[/UserButtonCode_loadTrainingButton]
}
else if (buttonThatWasClicked == saveTrainingButton)
{
//[UserButtonCode_saveTrainingButton] -- add your button handler code here..
saveTraining();
//[/UserButtonCode_saveTrainingButton]
}
else if (buttonThatWasClicked == clearTrainingButton)
{
//[UserButtonCode_clearTrainingButton] -- add your button handler code here..
clearTraining();
//[/UserButtonCode_clearTrainingButton]
}
else if (buttonThatWasClicked == removeTrainingButton)
{
//[UserButtonCode_removeTrainingButton] -- add your button handler code here..
removeTrainingAt((int)patterSlider->getValue());
//[/UserButtonCode_removeTrainingButton]
}
else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton)
{
//[UserButtonCode_rbmDoRaoBlackwellToggleButton] -- add your button handler code here..
m_pLayer->params().doRaoBlackwell = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoRaoBlackwellToggleButton]
}
else if (buttonThatWasClicked == rbmDoSampleVisibleToggleButton)
{
//[UserButtonCode_rbmDoSampleVisibleToggleButton] -- add your button handler code here..
m_pLayer->params().gibbsDoSampleVisible = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoSampleVisibleToggleButton]
}
else if (buttonThatWasClicked == rbmUseVisibleGaussianToggleButton)
{
//[UserButtonCode_rbmUseVisibleGaussianToggleButton] -- add your button handler code here..
m_pLayer->params().doGaussianVisible = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmUseVisibleGaussianToggleButton]
}
else if (buttonThatWasClicked == rbmDoSparseToggleButton)
{
//[UserButtonCode_rbmDoSparseToggleButton] -- add your button handler code here..
//[/UserButtonCode_rbmDoSparseToggleButton]
}
else if (buttonThatWasClicked == rbmLearnVarianceButton)
{
//[UserButtonCode_rbmLearnVarianceButton] -- add your button handler code here..
//[/UserButtonCode_rbmLearnVarianceButton]
}
else if (buttonThatWasClicked == rbmNormalizeDataToggleButton)
{
//[UserButtonCode_rbmNormalizeDataToggleButton] -- add your button handler code here..
//[/UserButtonCode_rbmNormalizeDataToggleButton]
}
else if (buttonThatWasClicked == rbmDoSampleHidden)
{
//[UserButtonCode_rbmDoSampleBatch] -- add your button handler code here..
m_pLayer->params().gibbsDoSampleHidden = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoSampleBatch]
}
else if (buttonThatWasClicked == rbmUseHiddenGaussianToggleButton)
{
//[UserButtonCode_rbmUseHiddenGaussianToggleButton] -- add your button handler code here..
m_pLayer->params().doGaussianHidden = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmUseHiddenGaussianToggleButton]
}
//[UserbuttonClicked_Post]
//[/UserbuttonClicked_Post]
}
void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
{
//[UsersliderValueChanged_Pre]
//[/UsersliderValueChanged_Pre]
if (sliderThatWasMoved == patterSlider)
{
//[UserSliderCode_patterSlider] -- add your slider handling code here..
size_t trainingIndex = (size_t)sliderThatWasMoved->getValue();
if (trainingIndex < m_stack->numTraining())
{
m_trainingIndex = trainingIndex;
m_stack->upDownPass(m_pLayer, m_stack->trainingBatchFrom(m_pLayer, trainingAt(m_trainingIndex)));
}
//[/UserSliderCode_patterSlider]
}
else if (sliderThatWasMoved == WeightsSlider)
{
//[UserSliderCode_WeightsSlider] -- add your slider handling code here..
m_weightIndex = (int)sliderThatWasMoved->getValue();
m_pLayer->redrawWeights(m_weightIndex);
//[/UserSliderCode_WeightsSlider]
}
else if (sliderThatWasMoved == numGibbsSlider)
{
//[UserSliderCode_numGibbsSlider] -- add your slider handling code here..
m_pLayer->params().numGibbs = sliderThatWasMoved->getValue();
m_pLayer->redrawReconstruction();
//[/UserSliderCode_numGibbsSlider]
}
else if (sliderThatWasMoved == m_progressBarSlider)
{
//[UserSliderCode_m_progressBarSlider] -- add your slider handling code here..
//[/UserSliderCode_m_progressBarSlider]
}
//[UsersliderValueChanged_Post]
//[/UsersliderValueChanged_Post]
}
void MainComponent::labelTextChanged (Label* labelThatHasChanged)
{
//[UserlabelTextChanged_Pre]
//[/UserlabelTextChanged_Pre]
if (labelThatHasChanged == numEpochslabel)
{
//[UserLabelCode_numEpochslabel] -- add your label text handling code here..
m_pLayer->params().numEpochs = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_numEpochslabel]
}
else if (labelThatHasChanged == learningRateLabel)
{
//[UserLabelCode_learningRateLabel] -- add your label text handling code here..
m_pLayer->params().learningRate = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_learningRateLabel]
}
else if (labelThatHasChanged == numVisibleLabel)
{
//[UserLabelCode_numVisibleLabel] -- add your label text handling code here..
//[/UserLabelCode_numVisibleLabel]
}
else if (labelThatHasChanged == numHiddenLabel)
{
//[UserLabelCode_numHiddenLabel] -- add your label text handling code here..
//[/UserLabelCode_numHiddenLabel]
}
else if (labelThatHasChanged == projectNameLabel)
{
//[UserLabelCode_projectNameLabel] -- add your label text handling code here..
if (m_stack)
{
m_stack->setName(labelThatHasChanged->getText().toStdString());
}
//[/UserLabelCode_projectNameLabel]
}
else if (labelThatHasChanged == numVisibleYLabel)
{
//[UserLabelCode_numVisibleYLabel] -- add your label text handling code here..
//[/UserLabelCode_numVisibleYLabel]
}
else if (labelThatHasChanged == lambdaLabel)
{
//[UserLabelCode_lambdaLabel] -- add your label text handling code here..
//[/UserLabelCode_lambdaLabel]
}
else if (labelThatHasChanged == sigmaLabel)
{
//[UserLabelCode_sigmaLabel] -- add your label text handling code here..
//[/UserLabelCode_sigmaLabel]
}
else if (labelThatHasChanged == sparsityLabel)
{
//[UserLabelCode_sparsityLabel] -- add your label text handling code here..
//[/UserLabelCode_sparsityLabel]
}
else if (labelThatHasChanged == sigmaDecayLabel)
{
//[UserLabelCode_sigmaDecayLabel] -- add your label text handling code here..
//[/UserLabelCode_sigmaDecayLabel]
}
else if (labelThatHasChanged == weightDecayLabel)
{
//[UserLabelCode_weightDecayLabel] -- add your label text handling code here..
m_pLayer->params().l2Lambda = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_weightDecayLabel]
}
else if (labelThatHasChanged == momentumLabel)
{
//[UserLabelCode_momentumLabel] -- add your label text handling code here..
m_pLayer->params().momentum = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_momentumLabel]
}
else if (labelThatHasChanged == sparsityLearningRateLabel)
{
//[UserLabelCode_sparsityLearningRateLabel] -- add your label text handling code here..
//[/UserLabelCode_sparsityLearningRateLabel]
}
else if (labelThatHasChanged == weightInitLabel)
{
//[UserLabelCode_weightInitLabel] -- add your label text handling code here..
//[/UserLabelCode_weightInitLabel]
}
else if (labelThatHasChanged == sizeMiniBatch)
{
//[UserLabelCode_sizeMiniBatch] -- add your label text handling code here..
m_pLayer->params().miniBatchSize = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_sizeMiniBatch]
}
//[UserlabelTextChanged_Post]
//[/UserlabelTextChanged_Post]
}
void MainComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
{
//[UsercomboBoxChanged_Pre]
//[/UsercomboBoxChanged_Pre]
if (comboBoxThatHasChanged == m_rbmSelect)
{
int index = m_rbmSelect->getSelectedItemIndex();
m_pLayer = static_cast<RbmComponent*>(m_stack->getLayer(index));
m_weightIndex = 0;
m_trainingIndex = 0;
updateControls();
m_pLayer->redrawWeights(m_weightIndex);
if (m_stack->trainingBatch().n_rows > 0)
{
m_stack->upDownPass(m_pLayer, m_stack->trainingBatchFrom(m_pLayer, trainingAt(m_trainingIndex)));
}
//[/UserComboBoxCode_m_rbmSelect]
}
//[UsercomboBoxChanged_Post]
//[/UsercomboBoxChanged_Post]
}
void MainComponent::mouseMove (const MouseEvent& e)
{
//[UserCode_mouseMove] -- Add your code here...
//[/UserCode_mouseMove]
}
void MainComponent::mouseEnter (const MouseEvent& e)
{
//[UserCode_mouseEnter] -- Add your code here...
//[/UserCode_mouseEnter]
}
void MainComponent::mouseExit (const MouseEvent& e)
{
//[UserCode_mouseExit] -- Add your code here...
//[/UserCode_mouseExit]
}
void MainComponent::mouseDown (const MouseEvent& e)
{
//[UserCode_mouseDown] -- Add your code here...
//[/UserCode_mouseDown]
}
void MainComponent::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 MainComponent::mouseUp (const MouseEvent& e)
{
//[UserCode_mouseUp] -- Add your code here...
//[/UserCode_mouseUp]
}
void MainComponent::mouseDoubleClick (const MouseEvent& e)
{
//[UserCode_mouseDoubleClick] -- Add your code here...
//[/UserCode_mouseDoubleClick]
}
void MainComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
{
//[UserCode_mouseWheelMove] -- Add your code here...
//[/UserCode_mouseWheelMove]
}
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
void MainComponent::save ()
{
m_stack->saveTrainingBatch(m_dir);
m_stack->saveWeights(m_dir);
m_stack->save(m_dir);
}
const juce::String& MainComponent::getBaseDir()
{
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
m_baseDir = String(homedir) + String("/.rbm/") + projectNameLabel->getText();
return m_baseDir;
}
void MainComponent::run()
{
trainButton->setButtonText (TRANS("Stop"));
m_pLayer->calcContextBatch(m_stack->trainingBatch());
m_stack->train(m_pLayer, m_stack->trainingBatch(), this);
trainButton->setButtonText (TRANS("Train"));
}
bool MainComponent::onProgress(Rbm *pRbm, const Rbm::Status &status)
{
if (status.err_total >= 0)
{
printf("[%3u] : Error total: %f\n", status.progress, status.err_total);
}
else
{
printf("[%3u] : Error: %f\n", status.progress, status.err);
}
RbmComponent *pComp = static_cast<RbmComponent*>(pRbm);
m_stack->upPass(pComp, pComp->getTraining());
// pComp->upPass(pComp->getTraining());
pComp->redrawReconstruction();
pComp->redrawWeights();
m_progressBarSlider->setValue(status.progress);
return !m_doStop;
}
void MainComponent::updateControls()
{
rbmDoRaoBlackwellToggleButton->setToggleState(m_pLayer->params().doRaoBlackwell, dontSendNotification);
rbmUseVisibleGaussianToggleButton->setToggleState(m_pLayer->params().doGaussianVisible, dontSendNotification);
rbmUseHiddenGaussianToggleButton->setToggleState(m_pLayer->params().doGaussianHidden, dontSendNotification);
rbmDoSampleVisibleToggleButton->setToggleState(m_pLayer->params().gibbsDoSampleVisible, dontSendNotification);
rbmDoSampleHidden->setToggleState(m_pLayer->params().gibbsDoSampleHidden, dontSendNotification);
weightDecayLabel->setText(String(m_pLayer->params().l2Lambda), dontSendNotification);
learningRateLabel->setText(String(m_pLayer->params().learningRate), dontSendNotification);
momentumLabel->setText(String(m_pLayer->params().momentum), dontSendNotification);
numVisibleLabel->setText(String(m_pLayer->numVisibleX()), dontSendNotification );
numVisibleYLabel->setText(String(m_pLayer->numVisibleY()), dontSendNotification );
numHiddenLabel->setText(String((int)m_pLayer->numHidden()), dontSendNotification );
numEpochslabel->setText(String((int)m_pLayer->params().numEpochs), dontSendNotification);
sizeMiniBatch->setText(String((int)m_pLayer->params().miniBatchSize), dontSendNotification);
numGibbsSlider->setValue(m_pLayer->params().numGibbs, dontSendNotification);
WeightsSlider->setRange(0, m_pLayer->numHidden()-1, 1);
numGibbsSlider->setValue(m_pLayer->params().numGibbs);
WeightsSlider->setValue(m_weightIndex);
patterSlider->setValue(m_trainingIndex);
}