[RBM]
- added DBN stack - concentrated RBM params into structure git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@295 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+131
-82
@@ -38,10 +38,9 @@ void mylog(const char* format, ...)
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
MainComponent::MainComponent ()
|
MainComponent::MainComponent ()
|
||||||
: Thread("RBM"),
|
: Thread("RBM"),
|
||||||
m_pRbmComponent(nullptr),
|
m_pRbmComponentCurr(nullptr),
|
||||||
m_layers(this)
|
m_weightsCurr(nullptr),
|
||||||
|
m_layers(this)
|
||||||
|
|
||||||
{
|
{
|
||||||
addAndMakeVisible (trainButton = new TextButton ("Train button"));
|
addAndMakeVisible (trainButton = new TextButton ("Train button"));
|
||||||
trainButton->setButtonText (TRANS("Train"));
|
trainButton->setButtonText (TRANS("Train"));
|
||||||
@@ -269,10 +268,20 @@ MainComponent::MainComponent ()
|
|||||||
rbmNormalizeDataToggleButton->setButtonText (TRANS("Normalize data"));
|
rbmNormalizeDataToggleButton->setButtonText (TRANS("Normalize data"));
|
||||||
rbmNormalizeDataToggleButton->addListener (this);
|
rbmNormalizeDataToggleButton->addListener (this);
|
||||||
|
|
||||||
|
addAndMakeVisible (m_rbmSelect = new ComboBox ("RBM Selector"));
|
||||||
|
m_rbmSelect->setEditableText (false);
|
||||||
|
m_rbmSelect->setJustificationType (Justification::centredLeft);
|
||||||
|
m_rbmSelect->setTextWhenNothingSelected (String::empty);
|
||||||
|
m_rbmSelect->setTextWhenNoChoicesAvailable (TRANS("(no choices)"));
|
||||||
|
m_rbmSelect->addListener (this);
|
||||||
|
|
||||||
|
|
||||||
//[UserPreSize]
|
//[UserPreSize]
|
||||||
|
memset(m_pRbmComponent, 0, sizeof(m_pRbmComponent));
|
||||||
|
memset(m_weights, 0, sizeof(m_weights));
|
||||||
|
m_rbmSelect->addItem(String(0), 1);
|
||||||
|
m_rbmSelect->setSelectedId(1, dontSendNotification);
|
||||||
m_progressBarSlider->setValue(100);
|
m_progressBarSlider->setValue(100);
|
||||||
create();
|
|
||||||
//[/UserPreSize]
|
//[/UserPreSize]
|
||||||
|
|
||||||
setSize (1000, 600);
|
setSize (1000, 600);
|
||||||
@@ -324,10 +333,10 @@ MainComponent::~MainComponent()
|
|||||||
weightInitLabel = nullptr;
|
weightInitLabel = nullptr;
|
||||||
rbmLearnVarianceButton = nullptr;
|
rbmLearnVarianceButton = nullptr;
|
||||||
rbmNormalizeDataToggleButton = nullptr;
|
rbmNormalizeDataToggleButton = nullptr;
|
||||||
|
m_rbmSelect = nullptr;
|
||||||
|
|
||||||
|
|
||||||
//[Destructor]. You can add your own custom destruction code here..
|
//[Destructor]. You can add your own custom destruction code here..
|
||||||
m_pRbmComponent = nullptr;
|
|
||||||
|
|
||||||
//[/Destructor]
|
//[/Destructor]
|
||||||
}
|
}
|
||||||
@@ -443,6 +452,7 @@ void MainComponent::resized()
|
|||||||
weightInitLabel->setBounds (888, 200, 72, 24);
|
weightInitLabel->setBounds (888, 200, 72, 24);
|
||||||
rbmLearnVarianceButton->setBounds (808, 60, 128, 24);
|
rbmLearnVarianceButton->setBounds (808, 60, 128, 24);
|
||||||
rbmNormalizeDataToggleButton->setBounds (808, 92, 160, 24);
|
rbmNormalizeDataToggleButton->setBounds (808, 92, 160, 24);
|
||||||
|
m_rbmSelect->setBounds (844, 404, 62, 24);
|
||||||
//[UserResized] Add your own custom resize handling here..
|
//[UserResized] Add your own custom resize handling here..
|
||||||
//[/UserResized]
|
//[/UserResized]
|
||||||
}
|
}
|
||||||
@@ -461,29 +471,30 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
else if (buttonThatWasClicked == addButton)
|
else if (buttonThatWasClicked == addButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_addButton] -- add your button handler code here..
|
//[UserButtonCode_addButton] -- add your button handler code here..
|
||||||
m_layers.add(m_pRbmComponent->getTrainingData(), m_weights->getNumVisible());
|
m_layers.add(m_pRbmComponent[0]->getTrainingData(), m_weights[0]->getNumVisible());
|
||||||
m_pRbmComponent->addFromTraining();
|
m_pRbmComponent[0]->batchchanged();
|
||||||
//[/UserButtonCode_addButton]
|
//[/UserButtonCode_addButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == reconstructButton)
|
else if (buttonThatWasClicked == reconstructButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_reconstructButton] -- add your button handler code here..
|
//[UserButtonCode_reconstructButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->redrawReconstruction();
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
//[/UserButtonCode_reconstructButton]
|
//[/UserButtonCode_reconstructButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == ShakeButton)
|
else if (buttonThatWasClicked == ShakeButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_ShakeButton] -- add your button handler code here..
|
//[UserButtonCode_ShakeButton] -- add your button handler code here..
|
||||||
m_weights->shuffle(weightInitLabel->getText().getFloatValue());
|
m_weightsCurr->shuffle(weightInitLabel->getText().getFloatValue());
|
||||||
m_pRbmComponent->redrawWeights();
|
m_pRbmComponentCurr->batchchanged();
|
||||||
m_pRbmComponent->redrawReconstruction();
|
m_pRbmComponentCurr->redrawWeights();
|
||||||
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
//[/UserButtonCode_ShakeButton]
|
//[/UserButtonCode_ShakeButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == testButton)
|
else if (buttonThatWasClicked == testButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_testButton] -- add your button handler code here..
|
//[UserButtonCode_testButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->copyReconstructionToTraining();
|
m_pRbmComponentCurr->copyReconstructionToTraining();
|
||||||
m_pRbmComponent->redrawReconstruction();
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
//[/UserButtonCode_testButton]
|
//[/UserButtonCode_testButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == createButton)
|
else if (buttonThatWasClicked == createButton)
|
||||||
@@ -495,7 +506,8 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
else if (buttonThatWasClicked == loadButton)
|
else if (buttonThatWasClicked == loadButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_loadButton] -- add your button handler code here..
|
//[UserButtonCode_loadButton] -- add your button handler code here..
|
||||||
load();
|
m_rbmSelect->setSelectedId(1, sendNotification);
|
||||||
|
create(getBaseDir());
|
||||||
//[/UserButtonCode_loadButton]
|
//[/UserButtonCode_loadButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == saveButton)
|
else if (buttonThatWasClicked == saveButton)
|
||||||
@@ -531,48 +543,48 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
else if (buttonThatWasClicked == reconstructEquButton)
|
else if (buttonThatWasClicked == reconstructEquButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_reconstructEquButton] -- add your button handler code here..
|
//[UserButtonCode_reconstructEquButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->redrawReconstruction();
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
//[/UserButtonCode_reconstructEquButton]
|
//[/UserButtonCode_reconstructEquButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton)
|
else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_rbmDoRaoBlackwellToggleButton] -- add your button handler code here..
|
//[UserButtonCode_rbmDoRaoBlackwellToggleButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->setDoRaoBlackwell(buttonThatWasClicked->getToggleState());
|
m_pRbmComponentCurr->setDoRaoBlackwell(buttonThatWasClicked->getToggleState());
|
||||||
//[/UserButtonCode_rbmDoRaoBlackwellToggleButton]
|
//[/UserButtonCode_rbmDoRaoBlackwellToggleButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == rbmReduceVarianceToggleButton)
|
else if (buttonThatWasClicked == rbmReduceVarianceToggleButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_rbmReduceVarianceToggleButton] -- add your button handler code here..
|
//[UserButtonCode_rbmReduceVarianceToggleButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->setUseProbsForHiddenReconstruction(buttonThatWasClicked->getToggleState());
|
m_pRbmComponentCurr->setUseProbsForHiddenReconstruction(buttonThatWasClicked->getToggleState());
|
||||||
//[/UserButtonCode_rbmReduceVarianceToggleButton]
|
//[/UserButtonCode_rbmReduceVarianceToggleButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == rbmUseVisibleGaussianToggleButton)
|
else if (buttonThatWasClicked == rbmUseVisibleGaussianToggleButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_rbmUseVisibleGaussianToggleButton] -- add your button handler code here..
|
//[UserButtonCode_rbmUseVisibleGaussianToggleButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->setUseVisibleGaussian(buttonThatWasClicked->getToggleState());
|
m_pRbmComponentCurr->setUseVisibleGaussian(buttonThatWasClicked->getToggleState());
|
||||||
m_pRbmComponent->redrawReconstruction();
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
//[/UserButtonCode_rbmUseVisibleGaussianToggleButton]
|
//[/UserButtonCode_rbmUseVisibleGaussianToggleButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == rbmDoSparseToggleButton)
|
else if (buttonThatWasClicked == rbmDoSparseToggleButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_rbmDoSparseToggleButton] -- add your button handler code here..
|
//[UserButtonCode_rbmDoSparseToggleButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->setDoSparse(buttonThatWasClicked->getToggleState());
|
m_pRbmComponentCurr->setDoSparse(buttonThatWasClicked->getToggleState());
|
||||||
//[/UserButtonCode_rbmDoSparseToggleButton]
|
//[/UserButtonCode_rbmDoSparseToggleButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == rbmLearnVarianceButton)
|
else if (buttonThatWasClicked == rbmLearnVarianceButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_rbmLearnVarianceButton] -- add your button handler code here..
|
//[UserButtonCode_rbmLearnVarianceButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->setDoLearnVariance(buttonThatWasClicked->getToggleState());
|
m_pRbmComponentCurr->setDoLearnVariance(buttonThatWasClicked->getToggleState());
|
||||||
if (!buttonThatWasClicked->getToggleState())
|
if (!buttonThatWasClicked->getToggleState())
|
||||||
{
|
{
|
||||||
m_pRbmComponent->setSigma(sigmaLabel->getText().getFloatValue());
|
m_pRbmComponentCurr->setSigma(sigmaLabel->getText().getFloatValue());
|
||||||
}
|
}
|
||||||
//[/UserButtonCode_rbmLearnVarianceButton]
|
//[/UserButtonCode_rbmLearnVarianceButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == rbmNormalizeDataToggleButton)
|
else if (buttonThatWasClicked == rbmNormalizeDataToggleButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_rbmNormalizeDataToggleButton] -- add your button handler code here..
|
//[UserButtonCode_rbmNormalizeDataToggleButton] -- add your button handler code here..
|
||||||
m_pRbmComponent->setNormalizeData(buttonThatWasClicked->getToggleState());
|
m_pRbmComponentCurr->setNormalizeData(buttonThatWasClicked->getToggleState());
|
||||||
//[/UserButtonCode_rbmNormalizeDataToggleButton]
|
//[/UserButtonCode_rbmNormalizeDataToggleButton]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,19 +600,19 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
|
|||||||
if (sliderThatWasMoved == patterSlider)
|
if (sliderThatWasMoved == patterSlider)
|
||||||
{
|
{
|
||||||
//[UserSliderCode_patterSlider] -- add your slider handling code here..
|
//[UserSliderCode_patterSlider] -- add your slider handling code here..
|
||||||
m_pRbmComponent->selectTraining((int)sliderThatWasMoved->getValue());
|
m_pRbmComponentCurr->setTrainingIndex((int)sliderThatWasMoved->getValue());
|
||||||
//[/UserSliderCode_patterSlider]
|
//[/UserSliderCode_patterSlider]
|
||||||
}
|
}
|
||||||
else if (sliderThatWasMoved == WeightsSlider)
|
else if (sliderThatWasMoved == WeightsSlider)
|
||||||
{
|
{
|
||||||
//[UserSliderCode_WeightsSlider] -- add your slider handling code here..
|
//[UserSliderCode_WeightsSlider] -- add your slider handling code here..
|
||||||
m_pRbmComponent->selectWeights((int)sliderThatWasMoved->getValue());
|
m_pRbmComponentCurr->setWeightsIndex((int)sliderThatWasMoved->getValue());
|
||||||
//[/UserSliderCode_WeightsSlider]
|
//[/UserSliderCode_WeightsSlider]
|
||||||
}
|
}
|
||||||
else if (sliderThatWasMoved == numGibbsSlider)
|
else if (sliderThatWasMoved == numGibbsSlider)
|
||||||
{
|
{
|
||||||
//[UserSliderCode_numGibbsSlider] -- add your slider handling code here..
|
//[UserSliderCode_numGibbsSlider] -- add your slider handling code here..
|
||||||
m_pRbmComponent->setNumGibbs((uint32_t)sliderThatWasMoved->getValue());
|
m_pRbmComponentCurr->setNumGibbs((uint32_t)sliderThatWasMoved->getValue());
|
||||||
//[/UserSliderCode_numGibbsSlider]
|
//[/UserSliderCode_numGibbsSlider]
|
||||||
}
|
}
|
||||||
else if (sliderThatWasMoved == m_progressBarSlider)
|
else if (sliderThatWasMoved == m_progressBarSlider)
|
||||||
@@ -626,7 +638,7 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
|||||||
else if (labelThatHasChanged == learningRateLabel)
|
else if (labelThatHasChanged == learningRateLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_learningRateLabel] -- add your label text handling code here..
|
//[UserLabelCode_learningRateLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setMuWeights(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setMuWeights(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_learningRateLabel]
|
//[/UserLabelCode_learningRateLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == numVisibleLabel)
|
else if (labelThatHasChanged == numVisibleLabel)
|
||||||
@@ -652,44 +664,44 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
|||||||
else if (labelThatHasChanged == lambdaLabel)
|
else if (labelThatHasChanged == lambdaLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_lambdaLabel] -- add your label text handling code here..
|
//[UserLabelCode_lambdaLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setLambda(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setLambda(labelThatHasChanged->getText().getFloatValue());
|
||||||
m_pRbmComponent->redrawReconstruction();
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
//[/UserLabelCode_lambdaLabel]
|
//[/UserLabelCode_lambdaLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == sigmaLabel)
|
else if (labelThatHasChanged == sigmaLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_sigmaLabel] -- add your label text handling code here..
|
//[UserLabelCode_sigmaLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setSigma(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setSigma(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_sigmaLabel]
|
//[/UserLabelCode_sigmaLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == sparsityLabel)
|
else if (labelThatHasChanged == sparsityLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_sparsityLabel] -- add your label text handling code here..
|
//[UserLabelCode_sparsityLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setSparsity(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setSparsity(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_sparsityLabel]
|
//[/UserLabelCode_sparsityLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == sigmaDecayLabel)
|
else if (labelThatHasChanged == sigmaDecayLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_sigmaDecayLabel] -- add your label text handling code here..
|
//[UserLabelCode_sigmaDecayLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setSigmaDecay(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setSigmaDecay(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_sigmaDecayLabel]
|
//[/UserLabelCode_sigmaDecayLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == weightDecayLabel)
|
else if (labelThatHasChanged == weightDecayLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_weightDecayLabel] -- add your label text handling code here..
|
//[UserLabelCode_weightDecayLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setWeightDecay(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setWeightDecay(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_weightDecayLabel]
|
//[/UserLabelCode_weightDecayLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == momentumLabel)
|
else if (labelThatHasChanged == momentumLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_momentumLabel] -- add your label text handling code here..
|
//[UserLabelCode_momentumLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setMomentum(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setMomentum(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_momentumLabel]
|
//[/UserLabelCode_momentumLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == sparsityLearningRateLabel)
|
else if (labelThatHasChanged == sparsityLearningRateLabel)
|
||||||
{
|
{
|
||||||
//[UserLabelCode_sparsityLearningRateLabel] -- add your label text handling code here..
|
//[UserLabelCode_sparsityLearningRateLabel] -- add your label text handling code here..
|
||||||
m_pRbmComponent->setMuSparsity(labelThatHasChanged->getText().getFloatValue());
|
m_pRbmComponentCurr->setMuSparsity(labelThatHasChanged->getText().getFloatValue());
|
||||||
//[/UserLabelCode_sparsityLearningRateLabel]
|
//[/UserLabelCode_sparsityLearningRateLabel]
|
||||||
}
|
}
|
||||||
else if (labelThatHasChanged == weightInitLabel)
|
else if (labelThatHasChanged == weightInitLabel)
|
||||||
@@ -702,6 +714,29 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
|||||||
//[/UserlabelTextChanged_Post]
|
//[/UserlabelTextChanged_Post]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
|
||||||
|
{
|
||||||
|
//[UsercomboBoxChanged_Pre]
|
||||||
|
//[/UsercomboBoxChanged_Pre]
|
||||||
|
|
||||||
|
if (comboBoxThatHasChanged == m_rbmSelect)
|
||||||
|
{
|
||||||
|
//[UserComboBoxCode_m_rbmSelect] -- add your combo box handling code here..
|
||||||
|
m_pRbmComponentCurr = m_pRbmComponent[m_rbmSelect->getSelectedId()-1];
|
||||||
|
m_weightsCurr = m_weights[m_rbmSelect->getSelectedId()-1];
|
||||||
|
|
||||||
|
if (m_pRbmComponentCurr == nullptr)
|
||||||
|
{
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
updateControls();
|
||||||
|
//[/UserComboBoxCode_m_rbmSelect]
|
||||||
|
}
|
||||||
|
|
||||||
|
//[UsercomboBoxChanged_Post]
|
||||||
|
//[/UsercomboBoxChanged_Post]
|
||||||
|
}
|
||||||
|
|
||||||
void MainComponent::mouseMove (const MouseEvent& e)
|
void MainComponent::mouseMove (const MouseEvent& e)
|
||||||
{
|
{
|
||||||
//[UserCode_mouseMove] -- Add your code here...
|
//[UserCode_mouseMove] -- Add your code here...
|
||||||
@@ -755,61 +790,44 @@ void MainComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails
|
|||||||
|
|
||||||
|
|
||||||
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
|
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
|
||||||
void MainComponent::load ()
|
|
||||||
{
|
|
||||||
create(getBaseDir());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainComponent::save ()
|
void MainComponent::save ()
|
||||||
{
|
{
|
||||||
m_weights->save((String(getBaseDir() + String(".weights.dat"))).toUTF8());
|
m_weights[0]->save((String(getBaseDir() + String(".weights.dat"))).toUTF8());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainComponent::create(juce::String const &projectName)
|
void MainComponent::create(juce::String const &projectName)
|
||||||
{
|
{
|
||||||
m_weights = nullptr;
|
size_t id = m_rbmSelect->getSelectedId()-1;
|
||||||
m_pRbmComponent = nullptr;
|
if ((m_pRbmComponent[id] == nullptr) and ((id+1) < DBN_SIZE))
|
||||||
|
m_rbmSelect->addItem(String(id+1), id+2);
|
||||||
|
|
||||||
if (!projectName.isEmpty())
|
m_weights[id] = nullptr;
|
||||||
|
m_pRbmComponent[id] = nullptr;
|
||||||
|
|
||||||
|
if (id == 0)
|
||||||
{
|
{
|
||||||
m_weights = new Weights((String(projectName + String(".weights.dat"))).toUTF8());
|
if (!projectName.isEmpty())
|
||||||
loadTraining((String(projectName + String(".trainingStates.dat"))).toUTF8());
|
{
|
||||||
|
m_weights[id] = new Weights((String(projectName + String(".weights.dat"))).toUTF8());
|
||||||
|
loadTraining((String(projectName + String(".trainingStates.dat"))).toUTF8());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_weights[id] = new Weights(numVisibleLabel->getText().getIntValue(), numVisibleYLabel->getText().getIntValue(), numHiddenLabel->getText().getIntValue());
|
||||||
|
}
|
||||||
|
addAndMakeVisible(m_pRbmComponent[id] = new RbmComponent(*m_weights[id], m_layers.data(), *this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_weights = new Weights(numVisibleLabel->getText().getIntValue(), numVisibleYLabel->getText().getIntValue(), numHiddenLabel->getText().getIntValue());
|
m_weights[id] = new Weights(m_weights[id-1]->getNumHidden(), 1, numHiddenLabel->getText().getIntValue());
|
||||||
|
addAndMakeVisible(m_pRbmComponent[id] = new RbmComponent(*m_weights[id], m_pRbmComponent[id-1]->getHiddenBatch(), *this));
|
||||||
}
|
}
|
||||||
size_t vNumX = m_weights->getNumVisibleX();
|
m_pRbmComponentCurr = m_pRbmComponent[id];
|
||||||
size_t vNumY = m_weights->getNumVisibleY();
|
m_weightsCurr = m_weights[id];
|
||||||
size_t hNum = m_weights->getNumHidden();
|
m_pRbmComponentCurr->setBounds (16, 140*id+16, 430, 130);
|
||||||
WeightsSlider->setRange(0, hNum-1, 1);
|
m_pRbmComponentCurr->batchchanged();
|
||||||
|
m_pRbmComponentCurr->redrawReconstruction();
|
||||||
numVisibleLabel->setText(String(vNumX), dontSendNotification );
|
updateControls();
|
||||||
numVisibleYLabel->setText(String(vNumY), dontSendNotification );
|
|
||||||
numHiddenLabel->setText(String(hNum), dontSendNotification );
|
|
||||||
|
|
||||||
addAndMakeVisible(m_pRbmComponent = new RbmComponent(*m_weights, m_layers.data(), *this));
|
|
||||||
m_pRbmComponent->setBounds (16, 16, 430, 130);
|
|
||||||
|
|
||||||
m_pRbmComponent->setDoRaoBlackwell(rbmDoRaoBlackwellToggleButton->getToggleState());
|
|
||||||
m_pRbmComponent->setUseProbsForHiddenReconstruction(rbmReduceVarianceToggleButton->getToggleState());
|
|
||||||
m_pRbmComponent->setUseVisibleGaussian(rbmUseVisibleGaussianToggleButton->getToggleState());
|
|
||||||
m_pRbmComponent->setDoSparse(rbmDoSparseToggleButton->getToggleState());
|
|
||||||
|
|
||||||
m_pRbmComponent->setLambda(lambdaLabel->getText().getFloatValue());
|
|
||||||
m_pRbmComponent->setSigmaDecay(sigmaDecayLabel->getText().getFloatValue());
|
|
||||||
m_pRbmComponent->setWeightDecay(weightDecayLabel->getText().getFloatValue());
|
|
||||||
m_pRbmComponent->setSparsity(sparsityLabel->getText().getFloatValue());
|
|
||||||
m_pRbmComponent->setNumGibbs((uint32_t)numGibbsSlider->getValue());
|
|
||||||
m_pRbmComponent->setDoLearnVariance(rbmLearnVarianceButton->getToggleState());
|
|
||||||
if (!rbmLearnVarianceButton->getToggleState())
|
|
||||||
{
|
|
||||||
m_pRbmComponent->setSigma(sigmaLabel->getText().getFloatValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pRbmComponent->redrawReconstruction();
|
|
||||||
m_pRbmComponent->selectWeights((int)WeightsSlider->getValue());
|
|
||||||
m_pRbmComponent->selectTraining((int)patterSlider->getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainComponent::destroy()
|
void MainComponent::destroy()
|
||||||
@@ -827,7 +845,7 @@ const juce::String& MainComponent::getBaseDir()
|
|||||||
void MainComponent::run()
|
void MainComponent::run()
|
||||||
{
|
{
|
||||||
// trainButton->setEnabled(false);
|
// trainButton->setEnabled(false);
|
||||||
m_pRbmComponent->train(numEpochslabel->getText().getIntValue());
|
m_pRbmComponentCurr->train(numEpochslabel->getText().getIntValue());
|
||||||
// trainButton->setEnabled(true);
|
// trainButton->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,6 +859,34 @@ void MainComponent::onRbmEpochTrained(size_t progressPercent)
|
|||||||
m_progressBarSlider->setValue(progressPercent);
|
m_progressBarSlider->setValue(progressPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainComponent::updateControls()
|
||||||
|
{
|
||||||
|
|
||||||
|
rbmDoRaoBlackwellToggleButton->setToggleState(m_pRbmComponentCurr->params().m_doRaoBlackwell, dontSendNotification);
|
||||||
|
rbmReduceVarianceToggleButton->setToggleState(m_pRbmComponentCurr->params().m_useProbsForHiddenReconstruction, dontSendNotification);
|
||||||
|
rbmUseVisibleGaussianToggleButton->setToggleState(m_pRbmComponentCurr->params().m_useVisibleGaussian, dontSendNotification);
|
||||||
|
rbmDoSparseToggleButton->setToggleState(m_pRbmComponentCurr->params().m_doSparse, dontSendNotification);
|
||||||
|
rbmLearnVarianceButton->setToggleState(m_pRbmComponentCurr->params().m_doLearnVariance, dontSendNotification);
|
||||||
|
|
||||||
|
lambdaLabel->setText(String(m_pRbmComponentCurr->params().m_lambda), dontSendNotification);
|
||||||
|
sigmaDecayLabel->setText(String(m_pRbmComponentCurr->params().m_sigmaDecay), dontSendNotification);
|
||||||
|
weightDecayLabel->setText(String(m_pRbmComponentCurr->params().m_weightDecay), dontSendNotification);
|
||||||
|
sparsityLabel->setText(String(m_pRbmComponentCurr->params().m_sparsity), dontSendNotification);
|
||||||
|
sigmaLabel->setText(String(m_pRbmComponentCurr->params().m_constantSigma), dontSendNotification);
|
||||||
|
sparsityLearningRateLabel->setText(String(m_pRbmComponentCurr->params().m_muSparsity), dontSendNotification);
|
||||||
|
learningRateLabel->setText(String(m_pRbmComponentCurr->params().m_muWeights), dontSendNotification);
|
||||||
|
momentumLabel->setText(String(m_pRbmComponentCurr->params().m_momentum), dontSendNotification);
|
||||||
|
numVisibleLabel->setText(String(m_weightsCurr->getNumVisibleX()), dontSendNotification );
|
||||||
|
numVisibleYLabel->setText(String(m_weightsCurr->getNumVisibleY()), dontSendNotification );
|
||||||
|
numHiddenLabel->setText(String(m_weightsCurr->getNumHidden()), dontSendNotification );
|
||||||
|
|
||||||
|
WeightsSlider->setRange(0, m_weightsCurr->getNumHidden()-1, 1);
|
||||||
|
numGibbsSlider->setValue(m_pRbmComponentCurr->params().m_numGibbs);
|
||||||
|
WeightsSlider->setValue(m_pRbmComponentCurr->getWeightsIndex());
|
||||||
|
patterSlider->setValue(m_pRbmComponentCurr->getTrainingIndex());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//[/MiscUserCode]
|
//[/MiscUserCode]
|
||||||
|
|
||||||
|
|
||||||
@@ -854,8 +900,8 @@ void MainComponent::onRbmEpochTrained(size_t progressPercent)
|
|||||||
BEGIN_JUCER_METADATA
|
BEGIN_JUCER_METADATA
|
||||||
|
|
||||||
<JUCER_COMPONENT documentType="Component" className="MainComponent" componentName=""
|
<JUCER_COMPONENT documentType="Component" className="MainComponent" componentName=""
|
||||||
parentClasses="public Component, public RbmComponentListener, public Thread"
|
parentClasses="public Component, public RbmComponentListener, public LayerArrayListener, public Thread"
|
||||||
constructorParams="" variableInitialisers="Thread("RBM"), m_pRbmComponent(nullptr)"
|
constructorParams="" variableInitialisers="Thread("RBM"), m_pRbmComponentCurr(nullptr), m_weightsCurr(nullptr), m_layers(this)"
|
||||||
snapPixels="4" snapActive="1" snapShown="1" overlayOpacity="0.330"
|
snapPixels="4" snapActive="1" snapShown="1" overlayOpacity="0.330"
|
||||||
fixedSize="1" initialWidth="1000" initialHeight="600">
|
fixedSize="1" initialWidth="1000" initialHeight="600">
|
||||||
<METHODS>
|
<METHODS>
|
||||||
@@ -1036,6 +1082,9 @@ BEGIN_JUCER_METADATA
|
|||||||
<TOGGLEBUTTON name="rbmNormalizeData toggle button" id="739772af1b096120" memberName="rbmNormalizeDataToggleButton"
|
<TOGGLEBUTTON name="rbmNormalizeData toggle button" id="739772af1b096120" memberName="rbmNormalizeDataToggleButton"
|
||||||
virtualName="" explicitFocusOrder="0" pos="808 92 160 24" buttonText="Normalize data"
|
virtualName="" explicitFocusOrder="0" pos="808 92 160 24" buttonText="Normalize data"
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
|
||||||
|
<COMBOBOX name="RBM Selector" id="71115a4f965bfd38" memberName="m_rbmSelect"
|
||||||
|
virtualName="" explicitFocusOrder="0" pos="844 404 62 24" editable="0"
|
||||||
|
layout="33" items="" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
|
||||||
</JUCER_COMPONENT>
|
</JUCER_COMPONENT>
|
||||||
|
|
||||||
END_JUCER_METADATA
|
END_JUCER_METADATA
|
||||||
|
|||||||
+12
-4
@@ -43,7 +43,8 @@ class MainComponent : public Component,
|
|||||||
public Thread,
|
public Thread,
|
||||||
public ButtonListener,
|
public ButtonListener,
|
||||||
public SliderListener,
|
public SliderListener,
|
||||||
public LabelListener
|
public LabelListener,
|
||||||
|
public ComboBoxListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@@ -61,6 +62,7 @@ public:
|
|||||||
void buttonClicked (Button* buttonThatWasClicked);
|
void buttonClicked (Button* buttonThatWasClicked);
|
||||||
void sliderValueChanged (Slider* sliderThatWasMoved);
|
void sliderValueChanged (Slider* sliderThatWasMoved);
|
||||||
void labelTextChanged (Label* labelThatHasChanged);
|
void labelTextChanged (Label* labelThatHasChanged);
|
||||||
|
void comboBoxChanged (ComboBox* comboBoxThatHasChanged);
|
||||||
void mouseMove (const MouseEvent& e);
|
void mouseMove (const MouseEvent& e);
|
||||||
void mouseEnter (const MouseEvent& e);
|
void mouseEnter (const MouseEvent& e);
|
||||||
void mouseExit (const MouseEvent& e);
|
void mouseExit (const MouseEvent& e);
|
||||||
@@ -74,10 +76,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//[UserVariables] -- You can add your own custom variables in this section.
|
//[UserVariables] -- You can add your own custom variables in this section.
|
||||||
ScopedPointer<Weights> m_weights;
|
static const size_t DBN_SIZE = 4;
|
||||||
ScopedPointer<RbmComponent> m_pRbmComponent;
|
ScopedPointer<Weights> m_weights[DBN_SIZE];
|
||||||
|
ScopedPointer<RbmComponent> m_pRbmComponent[DBN_SIZE];
|
||||||
|
Weights *m_weightsCurr;
|
||||||
|
RbmComponent *m_pRbmComponentCurr;
|
||||||
LayerArray m_layers;
|
LayerArray m_layers;
|
||||||
void load();
|
|
||||||
void save();
|
void save();
|
||||||
void create(juce::String const &projectName="");
|
void create(juce::String const &projectName="");
|
||||||
void destroy();
|
void destroy();
|
||||||
@@ -104,6 +108,9 @@ private:
|
|||||||
{
|
{
|
||||||
m_layers.removeAt(index);
|
m_layers.removeAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateControls();
|
||||||
|
|
||||||
//[/UserVariables]
|
//[/UserVariables]
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@@ -144,6 +151,7 @@ private:
|
|||||||
ScopedPointer<Label> weightInitLabel;
|
ScopedPointer<Label> weightInitLabel;
|
||||||
ScopedPointer<ToggleButton> rbmLearnVarianceButton;
|
ScopedPointer<ToggleButton> rbmLearnVarianceButton;
|
||||||
ScopedPointer<ToggleButton> rbmNormalizeDataToggleButton;
|
ScopedPointer<ToggleButton> rbmNormalizeDataToggleButton;
|
||||||
|
ScopedPointer<ComboBox> m_rbmSelect;
|
||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|||||||
+122
-92
@@ -38,27 +38,50 @@ public:
|
|||||||
class Rbm
|
class Rbm
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct Params
|
||||||
|
{
|
||||||
|
Params()
|
||||||
|
: m_constantSigma(1.0)
|
||||||
|
, m_sigmaDecay(1.0)
|
||||||
|
, m_weightDecay(0.0)
|
||||||
|
, m_lambda(1.0)
|
||||||
|
, m_sparsity(0.05)
|
||||||
|
, m_muWeights(0.01)
|
||||||
|
, m_muSparsity(0.01)
|
||||||
|
, m_momentum(0.5)
|
||||||
|
, m_useVisibleGaussian(false)
|
||||||
|
, m_doRaoBlackwell(false)
|
||||||
|
, m_useProbsForHiddenReconstruction(false)
|
||||||
|
, m_doSparse(false)
|
||||||
|
, m_doNormalizeData(false)
|
||||||
|
, m_doLearnVariance(false)
|
||||||
|
, m_numGibbs(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double m_constantSigma;
|
||||||
|
double m_sigmaDecay;
|
||||||
|
double m_weightDecay;
|
||||||
|
double m_lambda;
|
||||||
|
double m_sparsity;
|
||||||
|
double m_muWeights;
|
||||||
|
double m_muSparsity;
|
||||||
|
double m_momentum;
|
||||||
|
bool m_useVisibleGaussian;
|
||||||
|
bool m_doRaoBlackwell;
|
||||||
|
bool m_useProbsForHiddenReconstruction;
|
||||||
|
bool m_doSparse;
|
||||||
|
bool m_doNormalizeData;
|
||||||
|
bool m_doLearnVariance;
|
||||||
|
uint32_t m_numGibbs;
|
||||||
|
};
|
||||||
|
|
||||||
Rbm(Weights &weights, const MatrixXd &batch, RbmListener *pListener = nullptr)
|
Rbm(Weights &weights, const MatrixXd &batch, RbmListener *pListener = nullptr)
|
||||||
: m_w(weights)
|
: m_w(weights)
|
||||||
, m_batch(batch)
|
, m_batch(batch)
|
||||||
, m_variableSigma(weights.getNumVisible())
|
, m_variableSigma(weights.getNumVisible())
|
||||||
, m_constantSigma(1.0)
|
|
||||||
, m_pListener(pListener)
|
, m_pListener(pListener)
|
||||||
, m_progress(0)
|
, m_progress(0)
|
||||||
, m_sigmaDecay(1.0)
|
|
||||||
, m_weightDecay(0.0)
|
|
||||||
, m_lambda(1.0)
|
|
||||||
, m_sparsity(0)
|
|
||||||
, m_muWeights(0.01)
|
|
||||||
, m_muSparsity(0.01)
|
|
||||||
, m_momentum(0.5)
|
|
||||||
, m_useVisibleGaussian(false)
|
|
||||||
, m_doRaoBlackwell(false)
|
|
||||||
, m_useProbsForHiddenReconstruction(false)
|
|
||||||
, m_doSparse(false)
|
|
||||||
, m_doNormalizeData(false)
|
|
||||||
, m_doLearnVariance(false)
|
|
||||||
, m_numGibbs(1)
|
|
||||||
{
|
{
|
||||||
Noise_Init(&m_noise, 0x32727155);
|
Noise_Init(&m_noise, 0x32727155);
|
||||||
|
|
||||||
@@ -72,6 +95,8 @@ public:
|
|||||||
cout << b << endl;
|
cout << b << endl;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
m_variableSigma.fill(m_params.m_constantSigma);
|
||||||
|
updateHiddenBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Rbm()
|
~Rbm()
|
||||||
@@ -79,13 +104,18 @@ public:
|
|||||||
Noise_Free(&m_noise);
|
Noise_Free(&m_noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sample(MatrixXd &src)
|
void sample(MatrixXd &srcDst)
|
||||||
|
{
|
||||||
|
sample(srcDst, srcDst);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sample(MatrixXd &dst, MatrixXd const &src)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i=0; i < src.array().size(); i++)
|
for (i=0; i < src.array().size(); i++)
|
||||||
{
|
{
|
||||||
src.array()(i) = (double)(src.array()(i) > Noise_Uniform(&m_noise));
|
dst.array()(i) = (double)(src.array()(i) > Noise_Uniform(&m_noise));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +262,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
m_v.resize(batchSize, m_w.getNumVisible());
|
m_v.resize(batchSize, m_w.getNumVisible());
|
||||||
m_h.resize(batchSize, m_w.getNumHidden());
|
MatrixXd h(batchSize, m_w.getNumHidden());
|
||||||
|
|
||||||
MatrixXd sumBiasV(1, m_w.getNumVisible());
|
MatrixXd sumBiasV(1, m_w.getNumVisible());
|
||||||
MatrixXd sumBiasH(1, m_w.getNumHidden());
|
MatrixXd sumBiasH(1, m_w.getNumHidden());
|
||||||
@@ -248,7 +278,7 @@ public:
|
|||||||
|
|
||||||
MatrixXd batch = m_batch;
|
MatrixXd batch = m_batch;
|
||||||
|
|
||||||
if (m_doNormalizeData)
|
if (m_params.m_doNormalizeData)
|
||||||
{
|
{
|
||||||
RowVectorXd mean = calcMean(batch);
|
RowVectorXd mean = calcMean(batch);
|
||||||
for (i=0; i < batchSize; i++)
|
for (i=0; i < batchSize; i++)
|
||||||
@@ -258,37 +288,40 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_params.m_useProbsForHiddenReconstruction)
|
||||||
|
{
|
||||||
|
sample(batch);
|
||||||
|
}
|
||||||
|
|
||||||
for (epoch=0; epoch < numEpochs; epoch++)
|
for (epoch=0; epoch < numEpochs; epoch++)
|
||||||
{
|
{
|
||||||
double err;
|
double err;
|
||||||
|
|
||||||
// Create hidden layer base on training data
|
// Create hidden layer base on training data
|
||||||
toHiddenBatch(m_h, batch);
|
toHiddenBatch(h, batch);
|
||||||
probsLogistic(m_h);
|
if (!m_params.m_doRaoBlackwell)
|
||||||
|
|
||||||
if (!m_doRaoBlackwell)
|
|
||||||
{
|
{
|
||||||
sample(m_h);
|
sample(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update weights (positive phase)
|
// Update weights (positive phase)
|
||||||
sumBiasV = batch.colwise().sum();
|
sumBiasV = batch.colwise().sum();
|
||||||
if (!m_doSparse)
|
if (!m_params.m_doSparse)
|
||||||
{
|
{
|
||||||
sumBiasH = m_h.colwise().sum();
|
sumBiasH = h.colwise().sum();
|
||||||
}
|
}
|
||||||
sumWeights = batch.transpose() * m_h;
|
sumWeights = batch.transpose() * h;
|
||||||
diffErr = batch;
|
diffErr = batch;
|
||||||
|
|
||||||
for (gibbs=0; gibbs < m_numGibbs; gibbs++)
|
for (gibbs=0; gibbs < m_params.m_numGibbs; gibbs++)
|
||||||
{
|
{
|
||||||
sample(m_h);
|
sample(h);
|
||||||
|
|
||||||
// Create visible reconstruction (a fantasy...) given h
|
// Create visible reconstruction (a fantasy...) given h
|
||||||
toVisibleBatch(m_v, m_h);
|
toVisibleBatch(m_v, h);
|
||||||
if (m_useVisibleGaussian)
|
if (m_params.m_useVisibleGaussian)
|
||||||
{
|
{
|
||||||
if (!m_useProbsForHiddenReconstruction)
|
if (!m_params.m_useProbsForHiddenReconstruction)
|
||||||
{
|
{
|
||||||
sampleGaussian(m_v, m_variableSigma.replicate(batchSize, 1));
|
sampleGaussian(m_v, m_variableSigma.replicate(batchSize, 1));
|
||||||
}
|
}
|
||||||
@@ -296,59 +329,57 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
probsLogistic(m_v, m_variableSigma.replicate(batchSize, 1));
|
probsLogistic(m_v, m_variableSigma.replicate(batchSize, 1));
|
||||||
if (!m_useProbsForHiddenReconstruction)
|
if (!m_params.m_useProbsForHiddenReconstruction)
|
||||||
{
|
{
|
||||||
sample(m_v);
|
sample(m_v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create hidden representation given v
|
// Create hidden representation given v
|
||||||
toHiddenBatch(m_h, m_v);
|
toHiddenBatch(h, m_v);
|
||||||
probsLogistic(m_h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_doRaoBlackwell)
|
if (!m_params.m_doRaoBlackwell)
|
||||||
{
|
{
|
||||||
sample(m_h);
|
sample(h);
|
||||||
}
|
}
|
||||||
// Update weights (negative phase)
|
// Update weights (negative phase)
|
||||||
sumBiasV -= m_v.colwise().sum();
|
sumBiasV -= m_v.colwise().sum();
|
||||||
if (!m_doSparse)
|
if (!m_params.m_doSparse)
|
||||||
{
|
{
|
||||||
sumBiasH -= m_h.colwise().sum();
|
sumBiasH -= h.colwise().sum();
|
||||||
}
|
}
|
||||||
sumWeights -= m_v.transpose() * m_h;
|
sumWeights -= m_v.transpose() * h;
|
||||||
diffErr -= m_v;
|
diffErr -= m_v;
|
||||||
|
|
||||||
deltaWeights = m_momentum*deltaWeights + m_muWeights*(kTrain*sumWeights - m_weightDecay*m_w.weights());
|
deltaWeights = m_params.m_momentum*deltaWeights + m_params.m_muWeights*(kTrain*sumWeights - m_params.m_weightDecay*m_w.weights());
|
||||||
m_w.weights() += deltaWeights;
|
m_w.weights() += deltaWeights;
|
||||||
|
|
||||||
deltaBiasV = m_momentum*deltaBiasV + m_muWeights*kTrain*sumBiasV;
|
deltaBiasV = m_params.m_momentum*deltaBiasV + m_params.m_muWeights*kTrain*sumBiasV;
|
||||||
m_w.visibleBias() += deltaBiasV;
|
m_w.visibleBias() += deltaBiasV;
|
||||||
|
|
||||||
if (m_doSparse)
|
if (m_params.m_doSparse)
|
||||||
{
|
{
|
||||||
// Create hidden representation given v
|
// Create hidden representation given v
|
||||||
toHiddenBatch(m_h, m_v);
|
toHiddenBatch(h, m_v);
|
||||||
probsLogistic(m_h);
|
|
||||||
|
|
||||||
sumBiasH.fill(m_sparsity);
|
sumBiasH.fill(m_params.m_sparsity);
|
||||||
sumBiasH -= m_h.colwise().mean();
|
sumBiasH -= h.colwise().mean();
|
||||||
|
|
||||||
deltaBiasH = m_momentum*deltaBiasH + m_muSparsity*sumBiasH;
|
deltaBiasH = m_params.m_momentum*deltaBiasH + m_params.m_muSparsity*sumBiasH;
|
||||||
|
|
||||||
// cout << "Mean(" << m_sparsity << ") = " << (double)sumBiasH.array().mean() << endl;
|
// cout << "Mean(" << m_sparsity << ") = " << (double)sumBiasH.array().mean() << endl;
|
||||||
// cout << sumBiasH << endl;
|
// cout << sumBiasH << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
deltaBiasH = m_momentum*deltaBiasH + m_muWeights*kTrain*sumBiasH;
|
deltaBiasH = m_params.m_momentum*deltaBiasH + m_params.m_muWeights*kTrain*sumBiasH;
|
||||||
}
|
}
|
||||||
m_w.hiddenBias() += deltaBiasH;
|
m_w.hiddenBias() += deltaBiasH;
|
||||||
|
|
||||||
if (m_variableSigma[0] > sigmaMin)
|
if (m_variableSigma[0] > sigmaMin)
|
||||||
{
|
{
|
||||||
m_variableSigma.array() *= m_sigmaDecay;
|
m_variableSigma.array() *= m_params.m_sigmaDecay;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_progress += dProgress;
|
m_progress += dProgress;
|
||||||
@@ -364,6 +395,9 @@ public:
|
|||||||
cout << err << endl;
|
cout << err << endl;
|
||||||
|
|
||||||
} // Number of epochs
|
} // Number of epochs
|
||||||
|
|
||||||
|
updateHiddenBatch();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double getProgress() const
|
double getProgress() const
|
||||||
@@ -395,7 +429,7 @@ public:
|
|||||||
v = h * m_w.weights().transpose();
|
v = h * m_w.weights().transpose();
|
||||||
v += m_w.visibleBias();
|
v += m_w.visibleBias();
|
||||||
|
|
||||||
if (m_useVisibleGaussian)
|
if (m_params.m_useVisibleGaussian)
|
||||||
{
|
{
|
||||||
// probsGaussian(v, m_sigmas);
|
// probsGaussian(v, m_sigmas);
|
||||||
}
|
}
|
||||||
@@ -407,13 +441,13 @@ public:
|
|||||||
|
|
||||||
void setConstantSigma(double value)
|
void setConstantSigma(double value)
|
||||||
{
|
{
|
||||||
m_constantSigma = value;
|
m_params.m_constantSigma = value;
|
||||||
m_variableSigma.fill(m_constantSigma);
|
m_variableSigma.fill(m_params.m_constantSigma);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getConstantSigma()
|
double getConstantSigma()
|
||||||
{
|
{
|
||||||
return m_constantSigma;
|
return m_params.m_constantSigma;
|
||||||
}
|
}
|
||||||
|
|
||||||
RowVectorXd& getVariableSigma()
|
RowVectorXd& getVariableSigma()
|
||||||
@@ -423,85 +457,80 @@ public:
|
|||||||
|
|
||||||
void setSigmaDecay(double value)
|
void setSigmaDecay(double value)
|
||||||
{
|
{
|
||||||
m_sigmaDecay = value;
|
m_params.m_sigmaDecay = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWeightDecay(double value)
|
void setWeightDecay(double value)
|
||||||
{
|
{
|
||||||
m_weightDecay = value;
|
m_params.m_weightDecay = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLambda(double value)
|
void setLambda(double value)
|
||||||
{
|
{
|
||||||
m_lambda = value;
|
m_params.m_lambda = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSparsity(double value)
|
void setSparsity(double value)
|
||||||
{
|
{
|
||||||
m_sparsity = value;
|
m_params.m_sparsity = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUseVisibleGaussian(bool flag)
|
void setUseVisibleGaussian(bool flag)
|
||||||
{
|
{
|
||||||
m_useVisibleGaussian = flag;
|
m_params.m_useVisibleGaussian = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDoRaoBlackwell(bool flag)
|
void setDoRaoBlackwell(bool flag)
|
||||||
{
|
{
|
||||||
m_doRaoBlackwell = flag;
|
m_params.m_doRaoBlackwell = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUseProbsForHiddenReconstruction(bool flag)
|
void setUseProbsForHiddenReconstruction(bool flag)
|
||||||
{
|
{
|
||||||
m_useProbsForHiddenReconstruction = flag;
|
m_params.m_useProbsForHiddenReconstruction = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDoSparse(bool flag)
|
void setDoSparse(bool flag)
|
||||||
{
|
{
|
||||||
m_doSparse = flag;
|
m_params.m_doSparse = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNormalizeData(bool flag)
|
void setNormalizeData(bool flag)
|
||||||
{
|
{
|
||||||
m_doNormalizeData = flag;
|
m_params.m_doNormalizeData = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDoLearnVariance(bool flag)
|
void setDoLearnVariance(bool flag)
|
||||||
{
|
{
|
||||||
m_doLearnVariance = flag;
|
m_params.m_doLearnVariance = flag;
|
||||||
if (m_doLearnVariance && m_batch.rows())
|
if (m_params.m_doLearnVariance && m_batch.rows())
|
||||||
{
|
{
|
||||||
m_variableSigma = calcSigma(m_batch);
|
m_variableSigma = calcSigma(m_batch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_variableSigma.fill(m_constantSigma);
|
m_variableSigma.fill(m_params.m_constantSigma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNumGibbs(uint32_t value)
|
void setNumGibbs(uint32_t value)
|
||||||
{
|
{
|
||||||
m_numGibbs = value;
|
m_params.m_numGibbs = value;
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getNumGibbs()
|
|
||||||
{
|
|
||||||
return m_numGibbs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMuWeights(double value)
|
void setMuWeights(double value)
|
||||||
{
|
{
|
||||||
m_muWeights = value;
|
m_params.m_muWeights = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMuSparsity(double value)
|
void setMuSparsity(double value)
|
||||||
{
|
{
|
||||||
m_muSparsity = value;
|
m_params.m_muSparsity = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMomentum(double value)
|
void setMomentum(double value)
|
||||||
{
|
{
|
||||||
m_momentum = value;
|
m_params.m_momentum = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixXd const& getHiddenBatch()
|
MatrixXd const& getHiddenBatch()
|
||||||
@@ -519,35 +548,36 @@ public:
|
|||||||
return m_batch;
|
return m_batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateHiddenBatch()
|
||||||
|
{
|
||||||
|
m_h.resize(m_batch.rows(), m_w.getNumHidden());
|
||||||
|
toHiddenBatch(m_h, m_batch);
|
||||||
|
}
|
||||||
|
|
||||||
|
Params const& params()
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Weights &m_w;
|
Weights &m_w;
|
||||||
MatrixXd const &m_batch;
|
MatrixXd const &m_batch;
|
||||||
MatrixXd m_v;
|
MatrixXd m_v;
|
||||||
MatrixXd m_h;
|
MatrixXd m_h;
|
||||||
RowVectorXd m_variableSigma;
|
RowVectorXd m_variableSigma;
|
||||||
double m_constantSigma;
|
|
||||||
RbmListener *m_pListener;
|
RbmListener *m_pListener;
|
||||||
noise_gen_t m_noise;
|
noise_gen_t m_noise;
|
||||||
double m_progress;
|
double m_progress;
|
||||||
double m_sigmaDecay;
|
Params m_params;
|
||||||
double m_weightDecay;
|
|
||||||
double m_lambda;
|
|
||||||
double m_sparsity;
|
|
||||||
double m_muWeights;
|
|
||||||
double m_muSparsity;
|
|
||||||
double m_momentum;
|
|
||||||
bool m_useVisibleGaussian;
|
|
||||||
bool m_doRaoBlackwell;
|
|
||||||
bool m_useProbsForHiddenReconstruction;
|
|
||||||
bool m_doSparse;
|
|
||||||
bool m_doNormalizeData;
|
|
||||||
bool m_doLearnVariance;
|
|
||||||
uint32_t m_numGibbs;
|
|
||||||
|
|
||||||
void toHiddenBatch(MatrixXd &h, MatrixXd const &v)
|
void toHiddenBatch(MatrixXd &h, MatrixXd const &v)
|
||||||
{
|
{
|
||||||
h = v * m_w.weights();
|
if (v.cols() == m_w.weights().rows())
|
||||||
h += m_w.hiddenBias().replicate(m_batch.rows(), 1);
|
{
|
||||||
|
h = v * m_w.weights();
|
||||||
|
h += m_w.hiddenBias().replicate(m_batch.rows(), 1);
|
||||||
|
probsLogistic(h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toVisibleBatch(MatrixXd &v, MatrixXd const &h)
|
void toVisibleBatch(MatrixXd &v, MatrixXd const &h)
|
||||||
|
|||||||
+25
-11
@@ -48,6 +48,9 @@ RbmComponent::RbmComponent (Weights &weights, MatrixXd const &batch, RbmComponen
|
|||||||
addAndMakeVisible (DrawVars = new DrawComponent (vNumX, vNumY));
|
addAndMakeVisible (DrawVars = new DrawComponent (vNumX, vNumY));
|
||||||
addAndMakeVisible (DrawHidden = new DrawComponent (hNum, 1));
|
addAndMakeVisible (DrawHidden = new DrawComponent (hNum, 1));
|
||||||
DrawHidden->setListener(this);
|
DrawHidden->setListener(this);
|
||||||
|
redrawWeights();
|
||||||
|
redrawReconstruction();
|
||||||
|
redrawVariances();
|
||||||
//[/UserPreSize]
|
//[/UserPreSize]
|
||||||
|
|
||||||
setSize (430, 130);
|
setSize (430, 130);
|
||||||
@@ -229,7 +232,7 @@ void RbmComponent::redrawReconstruction()
|
|||||||
m_pRbm->toHidden(DrawHidden->getData(), DrawTraining->getData());
|
m_pRbm->toHidden(DrawHidden->getData(), DrawTraining->getData());
|
||||||
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
|
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
|
||||||
|
|
||||||
for (i=0; i < m_pRbm->getNumGibbs()-1; i++)
|
for (i=0; i < m_pRbm->params().m_numGibbs-1; i++)
|
||||||
{
|
{
|
||||||
m_pRbm->toHidden(DrawHidden->getData(), DrawReconstruction->getData());
|
m_pRbm->toHidden(DrawHidden->getData(), DrawReconstruction->getData());
|
||||||
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
|
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
|
||||||
@@ -244,12 +247,16 @@ void RbmComponent::redrawWeights()
|
|||||||
DrawWeights->DrawData();
|
DrawWeights->DrawData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RbmComponent::redrawVariances()
|
||||||
|
{
|
||||||
|
DrawVars->getData() = m_pRbm->getVariableSigma();
|
||||||
|
DrawVars->DrawData();
|
||||||
|
}
|
||||||
|
|
||||||
void RbmComponent::setDoLearnVariance(bool value)
|
void RbmComponent::setDoLearnVariance(bool value)
|
||||||
{
|
{
|
||||||
m_pRbm->setDoLearnVariance(value);
|
m_pRbm->setDoLearnVariance(value);
|
||||||
DrawVars->getData() = m_pRbm->getVariableSigma();
|
redrawVariances();
|
||||||
DrawVars->DrawData();
|
|
||||||
|
|
||||||
redrawReconstruction();
|
redrawReconstruction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,9 +310,7 @@ void RbmComponent::setNumGibbs(size_t value)
|
|||||||
void RbmComponent::setSigma(double value)
|
void RbmComponent::setSigma(double value)
|
||||||
{
|
{
|
||||||
m_pRbm->setConstantSigma(value);
|
m_pRbm->setConstantSigma(value);
|
||||||
DrawVars->getData() = m_pRbm->getVariableSigma();
|
redrawVariances();
|
||||||
DrawVars->DrawData();
|
|
||||||
|
|
||||||
redrawReconstruction();
|
redrawReconstruction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,11 +334,10 @@ void RbmComponent::setMomentum(double value)
|
|||||||
m_pRbm->setMomentum(value);
|
m_pRbm->setMomentum(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RbmComponent::addFromTraining()
|
void RbmComponent::batchchanged()
|
||||||
{
|
{
|
||||||
DrawReconstruction->getData() = DrawTraining->getData();
|
m_pRbm->updateHiddenBatch();
|
||||||
DrawReconstruction->DrawData();
|
redrawVariances();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RbmComponent::setWeightsIndex(size_t index)
|
void RbmComponent::setWeightsIndex(size_t index)
|
||||||
@@ -342,6 +346,11 @@ void RbmComponent::setWeightsIndex(size_t index)
|
|||||||
redrawWeights();
|
redrawWeights();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t RbmComponent::getWeightsIndex()
|
||||||
|
{
|
||||||
|
return m_currWeightIndexToDraw;
|
||||||
|
}
|
||||||
|
|
||||||
void RbmComponent::setTrainingIndex(size_t index)
|
void RbmComponent::setTrainingIndex(size_t index)
|
||||||
{
|
{
|
||||||
if (m_pRbm->getBatch().rows() > 0)
|
if (m_pRbm->getBatch().rows() > 0)
|
||||||
@@ -354,6 +363,11 @@ void RbmComponent::setTrainingIndex(size_t index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t RbmComponent::getTrainingIndex()
|
||||||
|
{
|
||||||
|
return m_currTrainingIndexToDraw;
|
||||||
|
}
|
||||||
|
|
||||||
void RbmComponent::copyReconstructionToTraining()
|
void RbmComponent::copyReconstructionToTraining()
|
||||||
{
|
{
|
||||||
DrawTraining->getData() = DrawReconstruction->getData();
|
DrawTraining->getData() = DrawReconstruction->getData();
|
||||||
|
|||||||
+22
-2
@@ -26,6 +26,16 @@
|
|||||||
#include "Rbm.hpp"
|
#include "Rbm.hpp"
|
||||||
//[/Headers]
|
//[/Headers]
|
||||||
|
|
||||||
|
|
||||||
|
class IRbm
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IRbm() {}
|
||||||
|
virtual ~IRbm()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class RbmComponentListener
|
class RbmComponentListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -84,19 +94,29 @@ public:
|
|||||||
void setMuWeights(double value);
|
void setMuWeights(double value);
|
||||||
void setMuSparsity(double value);
|
void setMuSparsity(double value);
|
||||||
void setMomentum(double value);
|
void setMomentum(double value);
|
||||||
void addFromTraining();
|
void batchchanged();
|
||||||
void setWeightsIndex(size_t index);
|
void setWeightsIndex(size_t index);
|
||||||
|
size_t getWeightsIndex();
|
||||||
|
|
||||||
void setTrainingIndex(size_t index);
|
void setTrainingIndex(size_t index);
|
||||||
|
size_t getTrainingIndex();
|
||||||
|
|
||||||
void copyReconstructionToTraining();
|
void copyReconstructionToTraining();
|
||||||
void redrawWeights();
|
void redrawWeights();
|
||||||
void redrawReconstruction();
|
void redrawReconstruction();
|
||||||
|
void redrawVariances();
|
||||||
void train(size_t numEpochs);
|
void train(size_t numEpochs);
|
||||||
RowVectorXd const& getTrainingData();
|
RowVectorXd const& getTrainingData();
|
||||||
MatrixXd getHiddenBatch()
|
MatrixXd const& getHiddenBatch()
|
||||||
{
|
{
|
||||||
return m_pRbm->getHiddenBatch();
|
return m_pRbm->getHiddenBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rbm::Params const& params()
|
||||||
|
{
|
||||||
|
return m_pRbm->params();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//[UserVariables] -- You can add your own custom variables in this section.
|
//[UserVariables] -- You can add your own custom variables in this section.
|
||||||
ScopedPointer<Rbm> m_pRbm;
|
ScopedPointer<Rbm> m_pRbm;
|
||||||
|
|||||||
Reference in New Issue
Block a user