Files
Rbm-legacy/Source/MainComponent.cpp
T
jens b1a0c90ea0 - 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
2014-09-26 05:30:16 +00:00

188 lines
5.2 KiB
C++

/*
==============================================================================
This is an automatically generated GUI class created by the Introjucer!
Be careful when adding custom code to these files, as only the code within
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved.
Created with Introjucer version: 3.1.0
------------------------------------------------------------------------------
The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-13 by Raw Material Software Ltd.
==============================================================================
*/
//[Headers] You can add your own extra header files here...
//[/Headers]
#include "MainComponent.h"
//[MiscUserDefs] You can add your own user definitions and misc code here...
//[/MiscUserDefs]
//==============================================================================
MainComponent::MainComponent ()
{
addAndMakeVisible (textButton = new TextButton ("new button"));
textButton->addListener (this);
//[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]
}
MainComponent::~MainComponent()
{
//[Destructor_pre]. You can add your own custom destruction code here..
//[/Destructor_pre]
textButton = nullptr;
//[Destructor]. You can add your own custom destruction code here..
Draw = nullptr;
m_pRbm = nullptr;
//[/Destructor]
}
//==============================================================================
void MainComponent::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here..
//[/UserPrePaint]
g.fillAll (Colours::white);
//[UserPaint] Add your own custom painting code here..
//[/UserPaint]
}
void MainComponent::resized()
{
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..
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]
//[/UserbuttonClicked_Post]
}
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
//[/MiscUserCode]
//==============================================================================
#if 0
/* -- Introjucer information section --
This is where the Introjucer stores the metadata that describe this GUI layout, so
make changes in here at your peril!
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="1" initialWidth="600" initialHeight="400">
<BACKGROUND backgroundColour="ffffffff"/>
<TEXTBUTTON name="new button" id="7909d74b5522987c" memberName="textButton"
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
*/
#endif
//[EndFile] You can add extra defines here...
//[/EndFile]