[RBM]
- committed local changes git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@270 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+126
-65
@@ -280,9 +280,9 @@ MainComponent::MainComponent ()
|
||||
weightInitLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
|
||||
weightInitLabel->addListener (this);
|
||||
|
||||
addAndMakeVisible (rbmTrainV2ToggleButton = new ToggleButton ("rbmTrainV2ToggleButton toggle button"));
|
||||
rbmTrainV2ToggleButton->setButtonText (TRANS("Train Ver. 2"));
|
||||
rbmTrainV2ToggleButton->addListener (this);
|
||||
addAndMakeVisible (rbmLearnVarianceButton = new ToggleButton ("rbmLearnVariance button"));
|
||||
rbmLearnVarianceButton->setButtonText (TRANS("Learn Variance"));
|
||||
rbmLearnVarianceButton->addListener (this);
|
||||
|
||||
addAndMakeVisible (rbmNormalizeDataToggleButton = new ToggleButton ("rbmNormalizeData toggle button"));
|
||||
rbmNormalizeDataToggleButton->setButtonText (TRANS("Normalize data"));
|
||||
@@ -294,7 +294,7 @@ MainComponent::MainComponent ()
|
||||
m_vNumY = 16;
|
||||
m_hNum = 64;
|
||||
m_numGibbs = 1;
|
||||
m_weights.setUnits(m_vNumX*m_vNumY, m_hNum);
|
||||
m_weights.setUnits(m_vNumX, m_vNumY, m_hNum);
|
||||
m_pRbm = new Rbm(m_weights, this);
|
||||
create();
|
||||
|
||||
@@ -348,7 +348,7 @@ MainComponent::~MainComponent()
|
||||
momentumLabel = nullptr;
|
||||
sparsityLearningRateLabel = nullptr;
|
||||
weightInitLabel = nullptr;
|
||||
rbmTrainV2ToggleButton = nullptr;
|
||||
rbmLearnVarianceButton = nullptr;
|
||||
rbmNormalizeDataToggleButton = nullptr;
|
||||
|
||||
|
||||
@@ -356,6 +356,7 @@ MainComponent::~MainComponent()
|
||||
DrawTraining = nullptr;
|
||||
DrawReconstruction = nullptr;
|
||||
DrawWeights = nullptr;
|
||||
DrawVars = nullptr;
|
||||
DrawHidden = nullptr;
|
||||
m_pRbm = nullptr;
|
||||
|
||||
@@ -471,13 +472,14 @@ void MainComponent::resized()
|
||||
momentumLabel->setBounds (208, 368, 72, 24);
|
||||
sparsityLearningRateLabel->setBounds (416, 320, 72, 24);
|
||||
weightInitLabel->setBounds (416, 368, 72, 24);
|
||||
rbmTrainV2ToggleButton->setBounds (336, 200, 128, 24);
|
||||
rbmLearnVarianceButton->setBounds (336, 200, 128, 24);
|
||||
rbmNormalizeDataToggleButton->setBounds (336, 232, 160, 24);
|
||||
//[UserResized] Add your own custom resize handling here..
|
||||
DrawTraining->setBounds (16, 16, 100, 100);
|
||||
DrawReconstruction->setBounds (110+16, 16, 100, 100);
|
||||
DrawWeights->setBounds (220+16, 16, 100, 100);
|
||||
DrawHidden->setBounds (16, 16+110, 320, 20);
|
||||
DrawVars->setBounds (330+16, 16, 100, 100);
|
||||
DrawHidden->setBounds (16, 16+110, 430, 20);
|
||||
//[/UserResized]
|
||||
}
|
||||
|
||||
@@ -496,7 +498,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
{
|
||||
//[UserButtonCode_addButton] -- add your button handler code here..
|
||||
DrawReconstruction->setData(DrawTraining->getData());
|
||||
m_layers.add(&DrawTraining->getData(), m_vNumX*m_vNumY);
|
||||
m_layers.add(DrawTraining->getData(), m_vNumX*m_vNumY);
|
||||
patterSlider->setRange (0, m_layers.getSize()-1, 1);
|
||||
//[/UserButtonCode_addButton]
|
||||
}
|
||||
@@ -528,7 +530,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
m_vNumY = numVisibleYLabel->getText().getIntValue();
|
||||
m_hNum = numHiddenLabel->getText().getIntValue();
|
||||
|
||||
m_weights.setUnits(m_vNumX*m_vNumY, m_hNum);
|
||||
m_weights.setUnits(m_vNumX, m_vNumY, m_hNum);
|
||||
create();
|
||||
//[/UserButtonCode_createButton]
|
||||
}
|
||||
@@ -604,23 +606,6 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
{
|
||||
//[UserButtonCode_rbmUseVisibleGaussianToggleButton] -- add your button handler code here..
|
||||
m_pRbm->setUseVisibleGaussian(buttonThatWasClicked->getToggleState());
|
||||
rbmReduceVarianceToggleButton->setEnabled(!buttonThatWasClicked->getToggleState());
|
||||
|
||||
if (buttonThatWasClicked->getToggleState())
|
||||
{
|
||||
rbmReduceVarianceToggleButton_binary = rbmReduceVarianceToggleButton->getToggleState();
|
||||
rbmReduceVarianceToggleButton->setToggleState(false, sendNotification);
|
||||
sigmaLabel->setText(String(sigma_gauss, 2), sendNotification);
|
||||
sigmaDecayLabel->setText(String(sigmaDecay_gauss, 2), sendNotification);
|
||||
}
|
||||
else
|
||||
{
|
||||
sigma_gauss = sigmaLabel->getText().getFloatValue();
|
||||
sigmaDecay_gauss = sigmaDecayLabel->getText().getFloatValue();
|
||||
sigmaLabel->setText("1.0", sendNotification);
|
||||
sigmaDecayLabel->setText("1.0", sendNotification);
|
||||
rbmReduceVarianceToggleButton->setToggleState(rbmReduceVarianceToggleButton_binary, sendNotification);
|
||||
}
|
||||
redrawReconstruction();
|
||||
//[/UserButtonCode_rbmUseVisibleGaussianToggleButton]
|
||||
}
|
||||
@@ -630,10 +615,11 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
m_pRbm->setDoSparse(buttonThatWasClicked->getToggleState());
|
||||
//[/UserButtonCode_rbmDoSparseToggleButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == rbmTrainV2ToggleButton)
|
||||
else if (buttonThatWasClicked == rbmLearnVarianceButton)
|
||||
{
|
||||
//[UserButtonCode_rbmTrainV2ToggleButton] -- add your button handler code here..
|
||||
//[/UserButtonCode_rbmTrainV2ToggleButton]
|
||||
//[UserButtonCode_rbmLearnVarianceButton] -- add your button handler code here..
|
||||
m_pRbm->setDoLearnVariance(buttonThatWasClicked->getToggleState());
|
||||
//[/UserButtonCode_rbmLearnVarianceButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == rbmNormalizeDataToggleButton)
|
||||
{
|
||||
@@ -656,19 +642,10 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
|
||||
//[UserSliderCode_patterSlider] -- add your slider handling code here..
|
||||
if (m_layers.getSize() > 0)
|
||||
{
|
||||
VisibleLayer &p = (VisibleLayer&)m_layers.getAt((int)sliderThatWasMoved->getValue());
|
||||
VectorXd t = p.states();
|
||||
|
||||
DrawTraining->setData(p.states());
|
||||
cout << "mean = " << (double)p.states().array().mean() << endl;
|
||||
cout << "max = " << (double)p.states().array().maxCoeff() << endl;
|
||||
cout << "min = " << (double)p.states().array().minCoeff() << endl;
|
||||
t.array() -= t.array().mean();
|
||||
t.array() *= t.array();
|
||||
cout << "var = " << (double)t.mean() << endl;
|
||||
RowVectorXd t = m_layers.getAt((int)sliderThatWasMoved->getValue());
|
||||
|
||||
DrawTraining->setData(t);
|
||||
redrawReconstruction();
|
||||
|
||||
}
|
||||
//[/UserSliderCode_patterSlider]
|
||||
}
|
||||
@@ -784,6 +761,56 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
||||
//[/UserlabelTextChanged_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);
|
||||
cout << "Mouse = " << e.x << "," << e.y << 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...
|
||||
@@ -791,7 +818,8 @@ void MainComponent::load ()
|
||||
{
|
||||
m_weights.load((String(getBaseDir() + String(".weights.dat"))).toUTF8());
|
||||
|
||||
m_vNumX = m_vNumY = (int)sqrt((float)m_weights.getNumVisible());
|
||||
m_vNumX = m_weights.getNumVisibleX();
|
||||
m_vNumY = m_weights.getNumVisibleY();
|
||||
m_hNum = m_weights.getNumHidden();
|
||||
create();
|
||||
}
|
||||
@@ -806,6 +834,7 @@ void MainComponent::create()
|
||||
DrawTraining = nullptr;
|
||||
DrawReconstruction = nullptr;
|
||||
DrawWeights = nullptr;
|
||||
DrawVars = nullptr;
|
||||
DrawHidden = nullptr;
|
||||
|
||||
WeightsSlider->setRange(0, m_hNum-1, 1);
|
||||
@@ -814,14 +843,13 @@ void MainComponent::create()
|
||||
DrawTraining->setListener(this);
|
||||
addAndMakeVisible (DrawReconstruction = new DrawComponent (m_vNumX, m_vNumY));
|
||||
addAndMakeVisible (DrawWeights = new DrawComponent (m_vNumX, m_vNumY));
|
||||
addAndMakeVisible (DrawVars = new DrawComponent (m_vNumX, m_vNumY));
|
||||
addAndMakeVisible (DrawHidden = new DrawComponent (m_hNum, 1));
|
||||
DrawHidden->setListener(this);
|
||||
numVisibleLabel->setText(String(m_vNumX), dontSendNotification );
|
||||
numVisibleYLabel->setText(String(m_vNumY), dontSendNotification );
|
||||
numHiddenLabel->setText(String(m_hNum), dontSendNotification );
|
||||
|
||||
sigma_gauss = 0.5;
|
||||
sigmaDecay_gauss = 1.0;
|
||||
m_pRbm->setDoRaoBlackwell(rbmDoRaoBlackwellToggleButton->getToggleState());
|
||||
m_pRbm->setUseProbsForHiddenReconstruction(rbmReduceVarianceToggleButton->getToggleState());
|
||||
m_pRbm->setUseVisibleGaussian(rbmUseVisibleGaussianToggleButton->getToggleState());
|
||||
@@ -850,9 +878,9 @@ const juce::String& MainComponent::getBaseDir()
|
||||
|
||||
}
|
||||
|
||||
void MainComponent::onChanged(const LayerArray<VisibleLayer> &obj)
|
||||
void MainComponent::onChanged(const LayerArray &obj)
|
||||
{
|
||||
patterSlider->setRange(0, std::max(0,(int)m_layers.getSize()-1), 1);
|
||||
patterSlider->setRange(0, std::max(0,(int)obj.getSize()-1), 1);
|
||||
}
|
||||
|
||||
void MainComponent::onEpochTrained(const Rbm &obj)
|
||||
@@ -871,17 +899,46 @@ void MainComponent::onDraw(DrawComponent &obj)
|
||||
}
|
||||
if (&obj == DrawTraining)
|
||||
{
|
||||
DrawReconstruction->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData())));
|
||||
DrawHidden->setData(m_pRbm->toHidden(obj.getData()));
|
||||
// DrawReconstruction->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData())));
|
||||
// DrawHidden->setData(m_pRbm->toHidden(obj.getData()));
|
||||
redrawReconstruction();
|
||||
}
|
||||
}
|
||||
|
||||
void MainComponent::redrawReconstruction()
|
||||
{
|
||||
char table[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
VectorXd v;
|
||||
MatrixXd m;
|
||||
|
||||
DrawHidden->setData(m_pRbm->toHidden(DrawTraining->getData()));
|
||||
DrawReconstruction->setData(m_pRbm->toVisible(DrawHidden->getData()));
|
||||
// double energy = m_pRbm->getEnergy(DrawTraining->getData(), DrawHidden->getData());
|
||||
// cout << "Energy(" << 0 <<") = " << energy << endl;
|
||||
v = m_pRbm->toVisible(DrawHidden->getData());
|
||||
DrawReconstruction->setData(v);
|
||||
|
||||
if ((m_vNumX == 27) && (m_vNumY == 4))
|
||||
{
|
||||
m = v;
|
||||
m.resize(m_vNumX, m_vNumY);
|
||||
cout << "Reconstruction" << endl;
|
||||
cout << m << endl;
|
||||
|
||||
for (int y=0; y < m_vNumY; y++)
|
||||
{
|
||||
double maxV = -1000;
|
||||
int maxX = 0;
|
||||
for (int x=0; x < m_vNumX; x++)
|
||||
{
|
||||
if (m(x, y) > maxV)
|
||||
{
|
||||
maxV = m(x, y);
|
||||
maxX = x;
|
||||
}
|
||||
}
|
||||
cout << table[maxX];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -889,20 +946,15 @@ void MainComponent::redrawWeights(int index)
|
||||
{
|
||||
VectorXd w = m_weights.weights().col(index);
|
||||
DrawWeights->setData(w);
|
||||
DrawVars->setData(m_weights.sigma());
|
||||
|
||||
}
|
||||
|
||||
void MainComponent::run()
|
||||
{
|
||||
trainButton->setEnabled(false);
|
||||
if (rbmTrainV2ToggleButton->getToggleState())
|
||||
{
|
||||
m_pRbm->train2(m_layers, numEpochslabel->getText().getIntValue(), 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue());
|
||||
}
|
||||
trainButton->setEnabled(true);
|
||||
// trainButton->setEnabled(false);
|
||||
m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), 100);
|
||||
// trainButton->setEnabled(true);
|
||||
}
|
||||
|
||||
//[/MiscUserCode]
|
||||
@@ -918,10 +970,20 @@ void MainComponent::run()
|
||||
BEGIN_JUCER_METADATA
|
||||
|
||||
<JUCER_COMPONENT documentType="Component" className="MainComponent" componentName=""
|
||||
parentClasses="public Component, public LayerArrayListener<VisibleLayer>, public RbmListener, public DrawListener, public Thread"
|
||||
parentClasses="public Component, public LayerArrayListener, public RbmListener, public DrawListener, public Thread"
|
||||
constructorParams="" variableInitialisers="Thread("RBM"), m_layers(this), m_pRbm(nullptr) DrawTraining(nullptr), DrawReconstruction(nullptr), DrawWeights(nullptr), DrawHidden(nullptr)"
|
||||
snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
|
||||
fixedSize="1" initialWidth="800" initialHeight="600">
|
||||
<METHODS>
|
||||
<METHOD name="mouseMove (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseEnter (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseExit (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseDown (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseDrag (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseUp (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseDoubleClick (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)"/>
|
||||
</METHODS>
|
||||
<BACKGROUND backgroundColour="ffffffff">
|
||||
<TEXT pos="32 306 80 14" fill="solid: ff000000" hasStroke="0" text="Sigma"
|
||||
fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/>
|
||||
@@ -1084,10 +1146,9 @@ BEGIN_JUCER_METADATA
|
||||
edBkgCol="0" labelText="0.001" editableSingleClick="1" editableDoubleClick="1"
|
||||
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
||||
bold="0" italic="0" justification="36"/>
|
||||
<TOGGLEBUTTON name="rbmTrainV2ToggleButton toggle button" id="92c647c1f8b110a2"
|
||||
memberName="rbmTrainV2ToggleButton" virtualName="" explicitFocusOrder="0"
|
||||
pos="336 200 128 24" buttonText="Train Ver. 2" connectedEdges="0"
|
||||
needsCallback="1" radioGroupId="0" state="0"/>
|
||||
<TOGGLEBUTTON name="rbmLearnVariance button" id="92c647c1f8b110a2" memberName="rbmLearnVarianceButton"
|
||||
virtualName="" explicitFocusOrder="0" pos="336 200 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"
|
||||
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
|
||||
|
||||
Reference in New Issue
Block a user