- refactored and cleaned up

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@290 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2016-06-15 20:32:28 +00:00
parent 3d56e4a163
commit 2de8e9ac48
7 changed files with 277 additions and 277 deletions
-6
View File
@@ -228,12 +228,6 @@ RowVectorXd& DrawComponent::getData ()
return m_data;
}
void DrawComponent::setData (const RowVectorXd& data)
{
m_data = data;
DrawData();
}
void DrawComponent::DrawData ()
{
+1 -2
View File
@@ -56,9 +56,9 @@ public:
//[UserMethods] -- You can add your own custom methods in this section.
void setListener(DrawListener *pListener);
void drawAt(int x, int y, bool setColor);
void setData(const RowVectorXd& data);
RowVectorXd& getData();
void clear();
void DrawData();
//[/UserMethods]
void paint (Graphics& g);
@@ -86,7 +86,6 @@ private:
Image m_image;
double m_currData;
Colour m_currColor;
void DrawData();
//[/UserVariables]
//==============================================================================
+114 -112
View File
@@ -268,14 +268,14 @@ MainComponent::MainComponent ()
//[UserPreSize]
m_progressBarSlider->setValue(100);
create();
//[/UserPreSize]
setSize (800, 600);
setSize (1000, 600);
//[Constructor] You can add your own custom stuff here..
m_progressBarSlider->setValue(100);
//[/Constructor]
}
@@ -340,61 +340,61 @@ void MainComponent::paint (Graphics& g)
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sigma"),
32, 306, 80, 14,
500, 138, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Lambda"),
120, 306, 80, 14,
588, 138, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Num. epochs"),
23, 354, 91, 14,
491, 186, 91, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Alpha"),
120, 354, 80, 14,
588, 186, 80, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sparsity"),
208, 306, 80, 14,
676, 138, 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,
764, 138, 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,
764, 186, 96, 14,
Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Momentum"),
208, 354, 80, 14,
676, 186, 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,
876, 138, 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,
876, 186, 96, 14,
Justification::centred, true);
//[UserPaint] Add your own custom painting code here..
@@ -403,43 +403,43 @@ void MainComponent::paint (Graphics& g)
void MainComponent::resized()
{
trainButton->setBounds (120, 408, 72, 24);
addButton->setBounds (24, 160, 72, 24);
patterSlider->setBounds (224, 448, 184, 24);
reconstructButton->setBounds (24, 408, 72, 24);
ShakeButton->setBounds (120, 448, 72, 24);
WeightsSlider->setBounds (224, 488, 184, 24);
numEpochslabel->setBounds (32, 368, 72, 24);
learningRateLabel->setBounds (120, 368, 72, 24);
testButton->setBounds (120, 160, 72, 24);
numVisibleLabel->setBounds (504, 224, 72, 24);
numHiddenLabel->setBounds (552, 256, 72, 24);
createButton->setBounds (552, 288, 72, 24);
projectNameLabel->setBounds (536, 192, 96, 24);
loadButton->setBounds (504, 160, 72, 24);
saveButton->setBounds (584, 160, 72, 24);
numVisibleYLabel->setBounds (576, 224, 72, 24);
loadTrainingButton->setBounds (504, 48, 72, 24);
saveTrainingButton->setBounds (584, 48, 72, 24);
clearTrainingButton->setBounds (584, 88, 72, 24);
removeTrainingButton->setBounds (504, 88, 72, 24);
numGibbsSlider->setBounds (224, 408, 184, 24);
reconstructEquButton->setBounds (24, 448, 72, 24);
rbmDoRaoBlackwellToggleButton->setBounds (24, 200, 112, 24);
rbmReduceVarianceToggleButton->setBounds (168, 200, 128, 24);
lambdaLabel->setBounds (120, 320, 72, 24);
sigmaLabel->setBounds (32, 320, 72, 24);
rbmUseVisibleGaussianToggleButton->setBounds (168, 232, 160, 24);
rbmDoSparseToggleButton->setBounds (24, 232, 128, 24);
sparsityLabel->setBounds (208, 320, 72, 24);
sigmaDecayLabel->setBounds (304, 320, 72, 24);
weightDecayLabel->setBounds (304, 368, 72, 24);
m_progressBarSlider->setBounds (216, 160, 184, 24);
momentumLabel->setBounds (208, 368, 72, 24);
sparsityLearningRateLabel->setBounds (416, 320, 72, 24);
weightInitLabel->setBounds (416, 368, 72, 24);
rbmLearnVarianceButton->setBounds (336, 200, 128, 24);
rbmNormalizeDataToggleButton->setBounds (336, 232, 160, 24);
trainButton->setBounds (592, 240, 72, 24);
addButton->setBounds (496, 20, 72, 24);
patterSlider->setBounds (696, 280, 184, 24);
reconstructButton->setBounds (496, 240, 72, 24);
ShakeButton->setBounds (592, 280, 72, 24);
WeightsSlider->setBounds (696, 320, 184, 24);
numEpochslabel->setBounds (504, 200, 72, 24);
learningRateLabel->setBounds (592, 200, 72, 24);
testButton->setBounds (592, 20, 72, 24);
numVisibleLabel->setBounds (736, 368, 48, 24);
numHiddenLabel->setBounds (840, 368, 48, 24);
createButton->setBounds (660, 368, 72, 24);
projectNameLabel->setBounds (892, 368, 96, 24);
loadButton->setBounds (496, 368, 72, 24);
saveButton->setBounds (576, 368, 72, 24);
numVisibleYLabel->setBounds (788, 368, 48, 24);
loadTrainingButton->setBounds (496, 404, 72, 24);
saveTrainingButton->setBounds (576, 404, 72, 24);
clearTrainingButton->setBounds (736, 404, 72, 24);
removeTrainingButton->setBounds (656, 404, 72, 24);
numGibbsSlider->setBounds (696, 240, 184, 24);
reconstructEquButton->setBounds (496, 280, 72, 24);
rbmDoRaoBlackwellToggleButton->setBounds (496, 60, 112, 24);
rbmReduceVarianceToggleButton->setBounds (640, 60, 128, 24);
lambdaLabel->setBounds (592, 152, 72, 24);
sigmaLabel->setBounds (504, 152, 72, 24);
rbmUseVisibleGaussianToggleButton->setBounds (640, 92, 160, 24);
rbmDoSparseToggleButton->setBounds (496, 92, 128, 24);
sparsityLabel->setBounds (680, 152, 72, 24);
sigmaDecayLabel->setBounds (776, 152, 72, 24);
weightDecayLabel->setBounds (776, 200, 72, 24);
m_progressBarSlider->setBounds (688, 20, 184, 24);
momentumLabel->setBounds (680, 200, 72, 24);
sparsityLearningRateLabel->setBounds (888, 152, 72, 24);
weightInitLabel->setBounds (888, 200, 72, 24);
rbmLearnVarianceButton->setBounds (808, 60, 128, 24);
rbmNormalizeDataToggleButton->setBounds (808, 92, 160, 24);
//[UserResized] Add your own custom resize handling here..
//[/UserResized]
}
@@ -580,7 +580,7 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
{
//[UsersliderValueChanged_Pre]
//[/UsersliderValueChanged_Pre]
if (sliderThatWasMoved == patterSlider)
{
//[UserSliderCode_patterSlider] -- add your slider handling code here..
@@ -753,7 +753,7 @@ void MainComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
void MainComponent::load ()
{
create((String(getBaseDir() + String(".weights.dat"))).toUTF8());
create(getBaseDir());
}
void MainComponent::save ()
@@ -761,29 +761,33 @@ void MainComponent::save ()
m_weights->save((String(getBaseDir() + String(".weights.dat"))).toUTF8());
}
void MainComponent::create(const char *pFilename)
void MainComponent::create(juce::String const &projectName)
{
m_weights = nullptr;
m_pRbmComponent = nullptr;
if (pFilename)
if (!projectName.isEmpty())
{
m_weights = new Weights(pFilename);
m_weights = new Weights((String(projectName + String(".weights.dat"))).toUTF8());
}
else
{
m_weights = new Weights(numVisibleLabel->getText().getIntValue(), numVisibleYLabel->getText().getIntValue(), numHiddenLabel->getText().getIntValue());
}
m_vNumX = m_weights->getNumVisibleX();
m_vNumY = m_weights->getNumVisibleY();
m_hNum = m_weights->getNumHidden();
WeightsSlider->setRange(0, m_hNum-1, 1);
size_t vNumX = m_weights->getNumVisibleX();
size_t vNumY = m_weights->getNumVisibleY();
size_t hNum = m_weights->getNumHidden();
WeightsSlider->setRange(0, hNum-1, 1);
numVisibleLabel->setText(String(m_vNumX), dontSendNotification );
numVisibleYLabel->setText(String(m_vNumY), dontSendNotification );
numHiddenLabel->setText(String(m_hNum), dontSendNotification );
numVisibleLabel->setText(String(vNumX), dontSendNotification );
numVisibleYLabel->setText(String(vNumY), dontSendNotification );
numHiddenLabel->setText(String(hNum), dontSendNotification );
addAndMakeVisible(m_pRbmComponent = new RbmComponent(*m_weights, *this));
if (!projectName.isEmpty())
{
m_pRbmComponent->loadTraining((String(projectName + String(".trainingStates.dat"))).toUTF8());
}
m_pRbmComponent->setBounds (16, 16, 430, 130);
m_pRbmComponent->setDoRaoBlackwell(rbmDoRaoBlackwellToggleButton->getToggleState());
@@ -802,11 +806,9 @@ void MainComponent::create(const char *pFilename)
m_pRbmComponent->setSigma(sigmaLabel->getText().getFloatValue());
}
resized();
m_pRbmComponent->loadTraining((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8());
m_pRbmComponent->redrawReconstruction();
m_pRbmComponent->selectWeights((int)WeightsSlider->getValue());
m_pRbmComponent->selectTraining((int)patterSlider->getValue());
}
void MainComponent::destroy()
@@ -854,7 +856,7 @@ BEGIN_JUCER_METADATA
parentClasses="public Component, public RbmComponentListener, public Thread"
constructorParams="" variableInitialisers="Thread("RBM"),
m_pRbmComponent(nullptr)"
snapPixels="4" snapActive="1" snapShown="1" overlayOpacity="0.330"
fixedSize="1" initialWidth="800" initialHeight="600">
fixedSize="1" initialWidth="1000" initialHeight="600">
<METHODS>
<METHOD name="mouseMove (const MouseEvent&amp; e)"/>
<METHOD name="mouseEnter (const MouseEvent&amp; e)"/>
@@ -866,172 +868,172 @@ BEGIN_JUCER_METADATA
<METHOD name="mouseWheelMove (const MouseEvent&amp; e, const MouseWheelDetails&amp; wheel)"/>
</METHODS>
<BACKGROUND backgroundColour="ffffffff">
<TEXT pos="32 306 80 14" fill="solid: ff000000" hasStroke="0" text="Sigma"
<TEXT pos="500 138 80 14" fill="solid: ff000000" hasStroke="0" text="Sigma"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="120 306 80 14" fill="solid: ff000000" hasStroke="0" text="Lambda"
<TEXT pos="588 138 80 14" fill="solid: ff000000" hasStroke="0" text="Lambda"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="23 354 91 14" fill="solid: ff000000" hasStroke="0" text="Num. epochs"
<TEXT pos="491 186 91 14" fill="solid: ff000000" hasStroke="0" text="Num. epochs"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="120 354 80 14" fill="solid: ff000000" hasStroke="0" text="Alpha"
<TEXT pos="588 186 80 14" fill="solid: ff000000" hasStroke="0" text="Alpha"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="208 306 80 14" fill="solid: ff000000" hasStroke="0" text="Sparsity"
<TEXT pos="676 138 80 14" fill="solid: ff000000" hasStroke="0" text="Sparsity"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="296 306 96 14" fill="solid: ff000000" hasStroke="0" text="Sigma decay"
<TEXT pos="764 138 96 14" fill="solid: ff000000" hasStroke="0" text="Sigma decay"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="296 354 96 14" fill="solid: ff000000" hasStroke="0" text="Weight decay"
<TEXT pos="764 186 96 14" fill="solid: ff000000" hasStroke="0" text="Weight decay"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="208 354 80 14" fill="solid: ff000000" hasStroke="0" text="Momentum"
<TEXT pos="676 186 80 14" fill="solid: ff000000" hasStroke="0" text="Momentum"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="408 306 96 14" fill="solid: ff000000" hasStroke="0" text="Sparsity Alpha"
<TEXT pos="876 138 96 14" fill="solid: ff000000" hasStroke="0" text="Sparsity Alpha"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
<TEXT pos="408 354 96 14" fill="solid: ff000000" hasStroke="0" text="Weight init"
<TEXT pos="876 186 96 14" fill="solid: ff000000" hasStroke="0" text="Weight init"
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
</BACKGROUND>
<TEXTBUTTON name="Train button" id="7909d74b5522987c" memberName="trainButton"
virtualName="" explicitFocusOrder="0" pos="120 408 72 24" buttonText="Train"
virtualName="" explicitFocusOrder="0" pos="592 240 72 24" buttonText="Train"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TEXTBUTTON name="Add button" id="4609f7b526ec1aef" memberName="addButton"
virtualName="" explicitFocusOrder="0" pos="24 160 72 24" buttonText="Add"
virtualName="" explicitFocusOrder="0" pos="496 20 72 24" buttonText="Add"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<SLIDER name="Pattern slider" id="c3e0a2c816db81d1" memberName="patterSlider"
virtualName="" explicitFocusOrder="0" pos="224 448 184 24" min="0"
virtualName="" explicitFocusOrder="0" pos="696 280 184 24" min="0"
max="0" int="1" style="LinearBar" textBoxPos="TextBoxLeft" textBoxEditable="1"
textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
<TEXTBUTTON name="Reconstruct button" id="c1901d121a5819d6" memberName="reconstructButton"
virtualName="" explicitFocusOrder="0" pos="24 408 72 24" buttonText="Reconstruct"
virtualName="" explicitFocusOrder="0" pos="496 240 72 24" buttonText="Reconstruct"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TEXTBUTTON name="Shake button" id="7fa4964a9a9ed199" memberName="ShakeButton"
virtualName="" explicitFocusOrder="0" pos="120 448 72 24" buttonText="Shake"
virtualName="" explicitFocusOrder="0" pos="592 280 72 24" buttonText="Shake"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<SLIDER name="Weights slider" id="699075a1fc01458a" memberName="WeightsSlider"
virtualName="" explicitFocusOrder="0" pos="224 488 184 24" min="0"
virtualName="" explicitFocusOrder="0" pos="696 320 184 24" min="0"
max="0" int="1" style="LinearBar" textBoxPos="TextBoxLeft" textBoxEditable="1"
textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
<LABEL name="Num Epochs label" id="b23ae372ee931474" memberName="numEpochslabel"
virtualName="" explicitFocusOrder="0" pos="32 368 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="504 200 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="1000" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="Learning Rate label" id="49611a27914e910d" memberName="learningRateLabel"
virtualName="" explicitFocusOrder="0" pos="120 368 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="592 200 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="0.01" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<TEXTBUTTON name="Test button" id="a1e6fed732ae7ee1" memberName="testButton"
virtualName="" explicitFocusOrder="0" pos="120 160 72 24" buttonText="Test"
virtualName="" explicitFocusOrder="0" pos="592 20 72 24" buttonText="Test"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<LABEL name="Num Visible label" id="60acd702770b77dd" memberName="numVisibleLabel"
virtualName="" explicitFocusOrder="0" pos="504 224 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="736 368 48 24" edTextCol="ff000000"
edBkgCol="0" labelText="16" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="Num Hidden label" id="8a56c0419bd3ce86" memberName="numHiddenLabel"
virtualName="" explicitFocusOrder="0" pos="552 256 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="840 368 48 24" edTextCol="ff000000"
edBkgCol="0" labelText="64" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<TEXTBUTTON name="Create button" id="6c71593a581844eb" memberName="createButton"
virtualName="" explicitFocusOrder="0" pos="552 288 72 24" buttonText="Create"
virtualName="" explicitFocusOrder="0" pos="660 368 72 24" buttonText="Create"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<LABEL name="Project Name label" id="b4e855167abdac6b" memberName="projectNameLabel"
virtualName="" explicitFocusOrder="0" pos="536 192 96 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="892 368 96 24" edTextCol="ff000000"
edBkgCol="0" labelText="test" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<TEXTBUTTON name="Load button" id="4e606c77b12e7d11" memberName="loadButton"
virtualName="" explicitFocusOrder="0" pos="504 160 72 24" buttonText="Load"
virtualName="" explicitFocusOrder="0" pos="496 368 72 24" buttonText="Load"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TEXTBUTTON name="Save button" id="c435e774a51e39bf" memberName="saveButton"
virtualName="" explicitFocusOrder="0" pos="584 160 72 24" buttonText="Save"
virtualName="" explicitFocusOrder="0" pos="576 368 72 24" buttonText="Save"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<LABEL name="Num Visible Y label" id="101a4f77ca2445ba" memberName="numVisibleYLabel"
virtualName="" explicitFocusOrder="0" pos="576 224 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="788 368 48 24" edTextCol="ff000000"
edBkgCol="0" labelText="16" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<TEXTBUTTON name="Load Training button" id="c603a32c128de05d" memberName="loadTrainingButton"
virtualName="" explicitFocusOrder="0" pos="504 48 72 24" buttonText="Load T"
virtualName="" explicitFocusOrder="0" pos="496 404 72 24" buttonText="Load T"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TEXTBUTTON name="Save Training button" id="8e665b97490357c4" memberName="saveTrainingButton"
virtualName="" explicitFocusOrder="0" pos="584 48 72 24" buttonText="Save T"
virtualName="" explicitFocusOrder="0" pos="576 404 72 24" buttonText="Save T"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TEXTBUTTON name="Clear Training button" id="b4c148828519c013" memberName="clearTrainingButton"
virtualName="" explicitFocusOrder="0" pos="584 88 72 24" buttonText="Clear T"
virtualName="" explicitFocusOrder="0" pos="736 404 72 24" buttonText="Clear T"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TEXTBUTTON name="Remove Training button" id="f0e1d068c39986f3" memberName="removeTrainingButton"
virtualName="" explicitFocusOrder="0" pos="504 88 72 24" buttonText="Remove T"
virtualName="" explicitFocusOrder="0" pos="656 404 72 24" buttonText="Remove T"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<SLIDER name="Num. Gibbs slider" id="fdd9d5ca4e05e18c" memberName="numGibbsSlider"
virtualName="" explicitFocusOrder="0" pos="224 408 184 24" min="1"
virtualName="" explicitFocusOrder="0" pos="696 240 184 24" min="1"
max="101" int="1" style="LinearBar" textBoxPos="TextBoxLeft"
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
<TEXTBUTTON name="Reconstruct Equilibrium button" id="208a587f5556207" memberName="reconstructEquButton"
virtualName="" explicitFocusOrder="0" pos="24 448 72 24" buttonText="Reconst Equ."
virtualName="" explicitFocusOrder="0" pos="496 280 72 24" buttonText="Reconst Equ."
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<TOGGLEBUTTON name="rbmDoRaoBlackwell toggle button" id="7f585de46e182418"
memberName="rbmDoRaoBlackwellToggleButton" virtualName="" explicitFocusOrder="0"
pos="24 200 112 24" buttonText="Rao-Blackwell" connectedEdges="0"
pos="496 60 112 24" buttonText="Rao-Blackwell" connectedEdges="0"
needsCallback="1" radioGroupId="0" state="0"/>
<TOGGLEBUTTON name="rbmReduceVariance toggle button" id="1636f6389abe9225"
memberName="rbmReduceVarianceToggleButton" virtualName="" explicitFocusOrder="0"
pos="168 200 128 24" buttonText="Reduce Variance" connectedEdges="0"
pos="640 60 128 24" buttonText="Reduce Variance" connectedEdges="0"
needsCallback="1" radioGroupId="0" state="0"/>
<LABEL name="Lambda label" id="c51a5dfb587390b4" memberName="lambdaLabel"
virtualName="" explicitFocusOrder="0" pos="120 320 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="592 152 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="1.0" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="Sigma label" id="68d7dad32ed357f8" memberName="sigmaLabel"
virtualName="" explicitFocusOrder="0" pos="32 320 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="504 152 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="1.0" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<TOGGLEBUTTON name="rbmUseVisibleGaussian toggle button" id="c89b32a4deaa7f19"
memberName="rbmUseVisibleGaussianToggleButton" virtualName=""
explicitFocusOrder="0" pos="168 232 160 24" buttonText="Use gaussian visible"
explicitFocusOrder="0" pos="640 92 160 24" buttonText="Use gaussian visible"
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
<TOGGLEBUTTON name="rbmDoSparse toggle button" id="ed3f2602ab35b5f2" memberName="rbmDoSparseToggleButton"
virtualName="" explicitFocusOrder="0" pos="24 232 128 24" buttonText="Do sparse"
virtualName="" explicitFocusOrder="0" pos="496 92 128 24" buttonText="Do sparse"
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
<LABEL name="Sparsity label" id="f4efe44dc0ca4894" memberName="sparsityLabel"
virtualName="" explicitFocusOrder="0" pos="208 320 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="680 152 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="0.05" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="SigmaDecay label" id="d5f2f5fffdafd926" memberName="sigmaDecayLabel"
virtualName="" explicitFocusOrder="0" pos="304 320 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="776 152 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="1.0" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="WeightDecay label" id="67bf3a0bec436468" memberName="weightDecayLabel"
virtualName="" explicitFocusOrder="0" pos="304 368 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="776 200 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="0.0" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<SLIDER name="progressBar slider" id="8c8748f39f6d0ec6" memberName="m_progressBarSlider"
virtualName="" explicitFocusOrder="0" pos="216 160 184 24" min="0"
virtualName="" explicitFocusOrder="0" pos="688 20 184 24" min="0"
max="100" int="1" style="LinearBar" textBoxPos="TextBoxLeft"
textBoxEditable="0" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
<LABEL name="Momentum label" id="570ca1355ccd4cdd" memberName="momentumLabel"
virtualName="" explicitFocusOrder="0" pos="208 368 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="680 200 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="0.5" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="SparsityLearn label" id="8e452129810c0ed3" memberName="sparsityLearningRateLabel"
virtualName="" explicitFocusOrder="0" pos="416 320 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="888 152 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="0.01" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<LABEL name="WeightInit label" id="c827025f2cc51ddf" memberName="weightInitLabel"
virtualName="" explicitFocusOrder="0" pos="416 368 72 24" edTextCol="ff000000"
virtualName="" explicitFocusOrder="0" pos="888 200 72 24" edTextCol="ff000000"
edBkgCol="0" labelText="0.001" editableSingleClick="1" editableDoubleClick="1"
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
bold="0" italic="0" justification="36"/>
<TOGGLEBUTTON name="rbmLearnVariance button" id="92c647c1f8b110a2" memberName="rbmLearnVarianceButton"
virtualName="" explicitFocusOrder="0" pos="336 200 128 24" buttonText="Learn Variance"
virtualName="" explicitFocusOrder="0" pos="808 60 128 24" buttonText="Learn Variance"
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
<TOGGLEBUTTON name="rbmNormalizeData toggle button" id="739772af1b096120" memberName="rbmNormalizeDataToggleButton"
virtualName="" explicitFocusOrder="0" pos="336 232 160 24" buttonText="Normalize data"
virtualName="" explicitFocusOrder="0" pos="808 92 160 24" buttonText="Normalize data"
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
</JUCER_COMPONENT>
+1 -4
View File
@@ -75,12 +75,9 @@ private:
//[UserVariables] -- You can add your own custom variables in this section.
ScopedPointer<Weights> m_weights;
ScopedPointer<RbmComponent> m_pRbmComponent;
uint32_t m_vNumX;
uint32_t m_vNumY;
uint32_t m_hNum;
void load();
void save();
void create(const char *pFilename=nullptr);
void create(juce::String const &projectName="");
void destroy();
const juce::String& getBaseDir();
void run();
+128 -135
View File
@@ -11,6 +11,7 @@
#include "VisibleLayer.hpp"
#include "HiddenLayer.hpp"
#include "Weights.hpp"
#include "LayerArray.hpp"
#include <cmath>
#include <Eigen/Dense>
@@ -37,11 +38,11 @@ public:
class Rbm
{
public:
Rbm(Weights &weights, RbmListener *pListener = nullptr)
Rbm(Weights &weights, const LayerArray &batch, RbmListener *pListener = nullptr)
: m_w(weights)
, m_v(weights.getNumVisible())
, m_h(weights.getNumHidden())
, m_sigmas(weights.getNumVisible())
, m_batch(batch)
, m_variableSigma(weights.getNumVisible())
, m_constantSigma(1.0)
, m_pListener(pListener)
, m_progress(0)
, m_sigmaDecay(1.0)
@@ -51,7 +52,6 @@ public:
, m_muWeights(0.01)
, m_muSparsity(0.01)
, m_momentum(0.5)
, m_doCancel(false)
, m_useVisibleGaussian(false)
, m_doRaoBlackwell(false)
, m_useProbsForHiddenReconstruction(false)
@@ -76,10 +76,7 @@ public:
~Rbm()
{
cancel();
Noise_Free(&m_noise);
m_v.resize(0);
m_h.resize(0);
}
void sample(MatrixXd &src)
@@ -222,20 +219,19 @@ public:
return t1;
}
void train(const LayerArray &vt, uint32_t numEpochs, double sigmaMin = 0.05)
void train(uint32_t numEpochs, double sigmaMin = 0.05)
{
uint32_t t, i;
uint32_t epoch;
uint32_t gibbs;
double dProgress = 1.0/numEpochs;
double kTrain = 1.0/vt.getSize();
double kTrain = 1.0/m_batch.getSize();
size_t batchSize = vt.getSize();
size_t batchSize = m_batch.getSize();
MatrixXd v(batchSize, m_w.getNumVisible());
MatrixXd h(batchSize, m_w.getNumHidden());
MatrixXd batch(batchSize, m_w.getNumVisible());
MatrixXd sumBiasV(1, m_w.getNumVisible());
MatrixXd sumBiasH(1, m_w.getNumHidden());
MatrixXd sumWeights(m_w.getNumVisible(), m_w.getNumHidden());
@@ -248,14 +244,8 @@ public:
MatrixXd diffErr(batchSize, m_w.getNumVisible());
m_progress = 0;
m_doCancel = false;
batch = vt.data();
if (m_doLearnVariance)
{
m_sigmas = calcSigma(batch);
}
MatrixXd batch = m_batch.data();
if (m_doNormalizeData)
{
@@ -263,7 +253,7 @@ public:
for (i=0; i < batchSize; i++)
{
RowVectorXd x = batch.row(i);
batch.row(i) = normalizeData(x, mean, m_sigmas);
batch.row(i) = normalizeData(x, mean, m_variableSigma);
}
}
@@ -271,16 +261,8 @@ public:
{
double err;
v = batch;
if (m_doCancel)
{
m_doCancel = false;
break;
}
// Create hidden layer base on training data
h = v * m_w.weights();
h += m_w.hiddenBias().replicate(batchSize, 1);
toHiddenBatch(h, batch);
probsLogistic(h);
if (!m_doRaoBlackwell)
@@ -289,41 +271,38 @@ public:
}
// Update weights (positive phase)
sumBiasV = v.colwise().sum();
sumBiasV = batch.colwise().sum();
if (!m_doSparse)
{
sumBiasH = h.colwise().sum();
}
sumWeights = v.transpose() * h;
diffErr = v;
sumWeights = batch.transpose() * h;
diffErr = batch;
for (gibbs=0; gibbs < m_numGibbs; gibbs++)
{
sample(h);
// Create visible reconstruction (a fantasy...)
v = h * m_w.weights().transpose();
v += m_w.visibleBias().replicate(batchSize, 1);
// Create visible reconstruction (a fantasy...) given h
toVisibleBatch(v, h);
if (m_useVisibleGaussian)
{
if (!m_useProbsForHiddenReconstruction)
{
sampleGaussian(v, m_sigmas.replicate(batchSize, 1));
sampleGaussian(v, m_variableSigma.replicate(batchSize, 1));
}
}
else
{
probsLogistic(v, m_sigmas.replicate(batchSize, 1));
probsLogistic(v, m_variableSigma.replicate(batchSize, 1));
if (!m_useProbsForHiddenReconstruction)
{
sample(v);
}
}
// Create hidden reconstruction
h = v * m_w.weights();
h += m_w.hiddenBias().replicate(batchSize, 1);
// Create hidden reconstruction given v
toHiddenBatch(h, v);
probsLogistic(h);
}
@@ -366,9 +345,9 @@ public:
}
m_w.hiddenBias() += deltaBiasH;
if (m_sigmas[0] > sigmaMin)
if (m_variableSigma[0] > sigmaMin)
{
m_sigmas.array() *= m_sigmaDecay;
m_variableSigma.array() *= m_sigmaDecay;
}
m_progress += dProgress;
@@ -394,7 +373,7 @@ public:
double getEnergy(const VectorXd& visible, const VectorXd& hidden)
{
double energy;
double sigma = m_sigmas.array().mean();
double sigma = m_variableSigma.array().mean();
energy = m_w.visibleBias() * visible;
energy += m_w.hiddenBias() * hidden;
@@ -403,19 +382,17 @@ public:
return -energy/(sigma*sigma);
}
RowVectorXd const & toHidden(const RowVectorXd& v)
void toHidden(RowVectorXd &h, RowVectorXd const &v)
{
m_h = v * m_w.weights();
m_h += m_w.hiddenBias();
probsLogistic(m_h);
return m_h;
h = v * m_w.weights();
h += m_w.hiddenBias();
probsLogistic(h);
}
RowVectorXd const & toVisible(const RowVectorXd& h)
void toVisible(RowVectorXd &v, RowVectorXd const &h)
{
m_v = h * m_w.weights().transpose();
m_v += m_w.visibleBias();
v = h * m_w.weights().transpose();
v += m_w.visibleBias();
if (m_useVisibleGaussian)
{
@@ -423,108 +400,114 @@ public:
}
else
{
probsLogistic(m_v, m_sigmas);
probsLogistic(v, m_variableSigma);
}
return m_v;
}
void setSigma(double value)
{
m_sigmas.fill(value);
}
void setConstantSigma(double value)
{
m_constantSigma = value;
m_variableSigma.fill(m_constantSigma);
}
RowVectorXd& getSigma()
{
return m_sigmas;
}
double getConstantSigma()
{
return m_constantSigma;
}
void setSigmaDecay(double value)
{
m_sigmaDecay = value;
}
RowVectorXd& getVariableSigma()
{
return m_variableSigma;
}
void setWeightDecay(double value)
{
m_weightDecay = value;
}
void setSigmaDecay(double value)
{
m_sigmaDecay = value;
}
void setLambda(double value)
{
m_lambda = value;
}
void setWeightDecay(double value)
{
m_weightDecay = value;
}
void setSparsity(double value)
{
m_sparsity = value;
}
void setLambda(double value)
{
m_lambda = value;
}
void setUseVisibleGaussian(bool flag)
{
m_useVisibleGaussian = flag;
}
void setSparsity(double value)
{
m_sparsity = value;
}
void setDoRaoBlackwell(bool flag)
{
m_doRaoBlackwell = flag;
}
void setUseVisibleGaussian(bool flag)
{
m_useVisibleGaussian = flag;
}
void setUseProbsForHiddenReconstruction(bool flag)
{
m_useProbsForHiddenReconstruction = flag;
}
void setDoRaoBlackwell(bool flag)
{
m_doRaoBlackwell = flag;
}
void setDoSparse(bool flag)
{
m_doSparse = flag;
}
void setUseProbsForHiddenReconstruction(bool flag)
{
m_useProbsForHiddenReconstruction = flag;
}
void setNormalizeData(bool flag)
{
m_doNormalizeData = flag;
}
void setDoSparse(bool flag)
{
m_doSparse = flag;
}
void setDoLearnVariance(bool flag)
{
m_doLearnVariance = flag;
}
void setNormalizeData(bool flag)
{
m_doNormalizeData = flag;
}
void setNumGibbs(uint32_t value)
{
m_numGibbs = value;
}
void setDoLearnVariance(bool flag)
{
m_doLearnVariance = flag;
if (m_doLearnVariance)
{
m_variableSigma = calcSigma(m_batch.data());
}
else
{
m_variableSigma.fill(m_constantSigma);
}
}
uint32_t getNumGibbs()
{
return m_numGibbs;
}
void setMuWeights(double value)
{
m_muWeights = value;
}
void setNumGibbs(uint32_t value)
{
m_numGibbs = value;
}
void setMuSparsity(double value)
{
m_muSparsity = value;
}
uint32_t getNumGibbs()
{
return m_numGibbs;
}
void setMomentum(double value)
{
m_momentum = value;
}
void setMuWeights(double value)
{
m_muWeights = value;
}
void cancel()
{
m_doCancel = true;
// while(m_doCancel);
}
void setMuSparsity(double value)
{
m_muSparsity = value;
}
void setMomentum(double value)
{
m_momentum = value;
}
private:
Weights &m_w;
RowVectorXd m_h;
RowVectorXd m_v;
RowVectorXd m_sigmas;
LayerArray const &m_batch;
RowVectorXd m_variableSigma;
double m_constantSigma;
RbmListener *m_pListener;
noise_gen_t m_noise;
double m_progress;
@@ -541,9 +524,19 @@ private:
bool m_doSparse;
bool m_doNormalizeData;
bool m_doLearnVariance;
volatile bool m_doCancel;
uint32_t m_numGibbs;
void toHiddenBatch(MatrixXd &h, MatrixXd const &v)
{
h = v * m_w.weights();
h += m_w.hiddenBias().replicate(m_batch.getSize(), 1);
}
void toVisibleBatch(MatrixXd &v, MatrixXd const &h)
{
v = h * m_w.weights().transpose();
v += m_w.visibleBias().replicate(m_batch.getSize(), 1);
}
};
+24 -14
View File
@@ -36,7 +36,7 @@ RbmComponent::RbmComponent (Weights &weights, RbmComponentListener &listener)
{
//[UserPreSize]
m_pRbm = new Rbm(m_weights, this);
m_pRbm = new Rbm(m_weights, m_layers, this);
m_vNumX = m_weights.getNumVisibleX();
m_vNumY = m_weights.getNumVisibleY();
m_hNum = m_weights.getNumHidden();
@@ -219,7 +219,8 @@ void RbmComponent::onDraw(DrawComponent &obj)
{
if (&obj == DrawHidden)
{
DrawReconstruction->setData(m_pRbm->toVisible(obj.getData()));
m_pRbm->toVisible(DrawReconstruction->getData(), obj.getData());
DrawReconstruction->DrawData();
}
if (&obj == DrawTraining)
{
@@ -230,29 +231,36 @@ void RbmComponent::onDraw(DrawComponent &obj)
void RbmComponent::redrawReconstruction()
{
uint32_t i;
VectorXd V, H;
V = DrawTraining->getData();
for (i=0; i < m_pRbm->getNumGibbs(); i++)
m_pRbm->toHidden(DrawHidden->getData(), DrawTraining->getData());
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
for (i=0; i < m_pRbm->getNumGibbs()-1; i++)
{
H = m_pRbm->toHidden(V);
DrawHidden->setData(H);
V = m_pRbm->toVisible(H);
DrawReconstruction->setData(V);
m_pRbm->toHidden(DrawHidden->getData(), DrawReconstruction->getData());
m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
}
DrawHidden->DrawData();
DrawReconstruction->DrawData();
}
void RbmComponent::redrawWeights()
{
VectorXd w = m_weights.weights().col(m_currWeightIndexToDraw);
DrawWeights->setData(w);
DrawVars->setData(m_pRbm->getSigma());
DrawWeights->getData() = w;
DrawWeights->DrawData();
DrawVars->getData() = m_pRbm->getVariableSigma();
DrawVars->DrawData();
}
void RbmComponent::setDoLearnVariance(bool value)
{
m_pRbm->setDoLearnVariance(value);
DrawVars->getData() = m_pRbm->getVariableSigma();
DrawVars->DrawData();
redrawReconstruction();
}
void RbmComponent::setDoRaoBlackwell(bool enable)
@@ -304,9 +312,11 @@ void RbmComponent::setNumGibbs(size_t value)
void RbmComponent::setSigma(double value)
{
m_pRbm->setSigma(value);
DrawVars->setData(m_pRbm->getSigma());
redrawReconstruction();
m_pRbm->setConstantSigma(value);
DrawVars->getData() = m_pRbm->getVariableSigma();
DrawVars->DrawData();
redrawReconstruction();
}
//[/MiscUserCode]
+9 -4
View File
@@ -106,7 +106,9 @@ public:
void addFromTraining()
{
DrawReconstruction->setData(DrawTraining->getData());
DrawReconstruction->getData() = DrawTraining->getData();
DrawReconstruction->DrawData();
m_layers.add(DrawTraining->getData(), m_vNumX*m_vNumY);
m_listener.onLayerSizeChanged(m_layers.getSize());
}
@@ -124,14 +126,17 @@ public:
m_currTrainingIndexToDraw = index;
RowVectorXd t = m_layers.getAt(index);
DrawTraining->setData(t);
DrawTraining->getData() = t;
DrawTraining->DrawData();
redrawReconstruction();
}
}
void copyReconstructionToTraining()
{
DrawTraining->setData(DrawReconstruction->getData());
DrawTraining->getData() = DrawReconstruction->getData();
DrawTraining->DrawData();
}
void clearTraining()
@@ -159,7 +164,7 @@ public:
void redrawReconstruction();
void train(size_t numEpochs)
{
m_pRbm->train(m_layers, numEpochs);
m_pRbm->train(numEpochs);
}
private: