- added grayscale display

- reconstruction and hidden probs can be displayed

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@15 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-09-26 05:30:16 +00:00
parent 470437eecb
commit b1a0c90ea0
10 changed files with 216 additions and 194 deletions
+68 -4
View File
@@ -34,12 +34,14 @@ MainComponent::MainComponent ()
//[UserPreSize]
addAndMakeVisible (Draw = new DrawComponent (4, 4, 32));
//[/UserPreSize]
setSize (600, 400);
//[Constructor] You can add your own custom stuff here..
m_pRbm = new Rbm(16, 4);
//[/Constructor]
}
@@ -52,6 +54,8 @@ MainComponent::~MainComponent()
//[Destructor]. You can add your own custom destruction code here..
Draw = nullptr;
m_pRbm = nullptr;
//[/Destructor]
}
@@ -69,20 +73,77 @@ void MainComponent::paint (Graphics& g)
void MainComponent::resized()
{
textButton->setBounds (88, 96, 150, 24);
textButton->setBounds (72, 312, 150, 24);
//[UserResized] Add your own custom resize handling here..
Draw->setBounds (16, 16, 336, 232);
//[/UserResized]
}
void MainComponent::buttonClicked (Button* buttonThatWasClicked)
{
//[UserbuttonClicked_Pre]
double trainingData[6][16] =
{
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1},
{1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0}
};
double hiddenTest[16][4] =
{
{0, 0, 0, 0},
{0, 0, 0, 1},
{0, 0, 1, 0},
{0, 0, 1, 1},
{0, 1, 0, 0},
{0, 1, 0, 1},
{0, 1, 1, 0},
{0, 1, 1, 1},
{1, 0, 0, 0},
{1, 0, 0, 1},
{1, 0, 1, 0},
{1, 0, 1, 1},
{1, 1, 0, 0},
{1, 1, 0, 1},
{1, 1, 1, 0},
{1, 1, 1, 1}
};
//[/UserbuttonClicked_Pre]
if (buttonThatWasClicked == textButton)
{
//[UserButtonCode_textButton] -- add your button handler code here..
//[/UserButtonCode_textButton]
m_pRbm->weightsShuffle(0.01);
m_pRbm->setNumTrainingPatterns(6);
for (uint32_t i=0; i < 6; i++)
{
m_pRbm->setTrainingInput(i, trainingData[i]);
}
m_pRbm->train(10000, 0.2);
m_pRbm->prob();
// Draw->drawGray(m_pRbm->toVisible(m_pRbm->toHidden(trainingData[rand()%6])));
Draw->drawGray(m_pRbm->toVisible(hiddenTest[rand()%16]));
#if 0
m_pRbm->weightsPrint();
// Test the network
for (uint32_t i=0; i < 6; i++)
{
m_pRbm->toHidden(trainingData[i]);
}
for (uint32_t i=0; i < 16; i++)
{
m_pRbm->toVisible(hiddenTest[i]);
}
#endif
//[/UserButtonCode_textButton]
}
//[UserbuttonClicked_Post]
@@ -107,11 +168,14 @@ BEGIN_JUCER_METADATA
<JUCER_COMPONENT documentType="Component" className="MainComponent" componentName=""
parentClasses="public Component" constructorParams="" variableInitialisers=""
snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
fixedSize="0" initialWidth="600" initialHeight="400">
fixedSize="1" initialWidth="600" initialHeight="400">
<BACKGROUND backgroundColour="ffffffff"/>
<TEXTBUTTON name="new button" id="7909d74b5522987c" memberName="textButton"
virtualName="" explicitFocusOrder="0" pos="88 96 150 24" buttonText="new button"
virtualName="" explicitFocusOrder="0" pos="72 312 150 24" buttonText="new button"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
<JUCERCOMP name="" id="5843cf32f5b9956c" memberName="Draw" virtualName=""
explicitFocusOrder="0" pos="16 16 336 232" sourceFile="DrawComponent.cpp"
constructorParams="200, 200, 2"/>
</JUCER_COMPONENT>
END_JUCER_METADATA