- added data normalization
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@45 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -284,6 +284,10 @@ MainComponent::MainComponent ()
|
|||||||
rbmTrainV2ToggleButton->setButtonText (TRANS("Train Ver. 2"));
|
rbmTrainV2ToggleButton->setButtonText (TRANS("Train Ver. 2"));
|
||||||
rbmTrainV2ToggleButton->addListener (this);
|
rbmTrainV2ToggleButton->addListener (this);
|
||||||
|
|
||||||
|
addAndMakeVisible (rbmNormalizeDataToggleButton = new ToggleButton ("rbmNormalizeData toggle button"));
|
||||||
|
rbmNormalizeDataToggleButton->setButtonText (TRANS("Normalize data"));
|
||||||
|
rbmNormalizeDataToggleButton->addListener (this);
|
||||||
|
|
||||||
|
|
||||||
//[UserPreSize]
|
//[UserPreSize]
|
||||||
m_vNumX = 16;
|
m_vNumX = 16;
|
||||||
@@ -345,6 +349,7 @@ MainComponent::~MainComponent()
|
|||||||
sparsityLearningRateLabel = nullptr;
|
sparsityLearningRateLabel = nullptr;
|
||||||
weightInitLabel = nullptr;
|
weightInitLabel = nullptr;
|
||||||
rbmTrainV2ToggleButton = nullptr;
|
rbmTrainV2ToggleButton = nullptr;
|
||||||
|
rbmNormalizeDataToggleButton = nullptr;
|
||||||
|
|
||||||
|
|
||||||
//[Destructor]. You can add your own custom destruction code here..
|
//[Destructor]. You can add your own custom destruction code here..
|
||||||
@@ -467,6 +472,7 @@ void MainComponent::resized()
|
|||||||
sparsityLearningRateLabel->setBounds (416, 320, 72, 24);
|
sparsityLearningRateLabel->setBounds (416, 320, 72, 24);
|
||||||
weightInitLabel->setBounds (416, 368, 72, 24);
|
weightInitLabel->setBounds (416, 368, 72, 24);
|
||||||
rbmTrainV2ToggleButton->setBounds (336, 200, 128, 24);
|
rbmTrainV2ToggleButton->setBounds (336, 200, 128, 24);
|
||||||
|
rbmNormalizeDataToggleButton->setBounds (336, 232, 160, 24);
|
||||||
//[UserResized] Add your own custom resize handling here..
|
//[UserResized] Add your own custom resize handling here..
|
||||||
DrawTraining->setBounds (16, 16, 100, 100);
|
DrawTraining->setBounds (16, 16, 100, 100);
|
||||||
DrawReconstruction->setBounds (110+16, 16, 100, 100);
|
DrawReconstruction->setBounds (110+16, 16, 100, 100);
|
||||||
@@ -629,6 +635,12 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
//[UserButtonCode_rbmTrainV2ToggleButton] -- add your button handler code here..
|
//[UserButtonCode_rbmTrainV2ToggleButton] -- add your button handler code here..
|
||||||
//[/UserButtonCode_rbmTrainV2ToggleButton]
|
//[/UserButtonCode_rbmTrainV2ToggleButton]
|
||||||
}
|
}
|
||||||
|
else if (buttonThatWasClicked == rbmNormalizeDataToggleButton)
|
||||||
|
{
|
||||||
|
//[UserButtonCode_rbmNormalizeDataToggleButton] -- add your button handler code here..
|
||||||
|
m_pRbm->setNormalizeData(buttonThatWasClicked->getToggleState());
|
||||||
|
//[/UserButtonCode_rbmNormalizeDataToggleButton]
|
||||||
|
}
|
||||||
|
|
||||||
//[UserbuttonClicked_Post]
|
//[UserbuttonClicked_Post]
|
||||||
//[/UserbuttonClicked_Post]
|
//[/UserbuttonClicked_Post]
|
||||||
@@ -645,7 +657,16 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
|
|||||||
if (m_layers.getSize() > 0)
|
if (m_layers.getSize() > 0)
|
||||||
{
|
{
|
||||||
VisibleLayer &p = (VisibleLayer&)m_layers.getAt((int)sliderThatWasMoved->getValue());
|
VisibleLayer &p = (VisibleLayer&)m_layers.getAt((int)sliderThatWasMoved->getValue());
|
||||||
|
VectorXd t = p.states();
|
||||||
|
|
||||||
DrawTraining->setData(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;
|
||||||
|
|
||||||
redrawReconstruction();
|
redrawReconstruction();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1067,6 +1088,9 @@ BEGIN_JUCER_METADATA
|
|||||||
memberName="rbmTrainV2ToggleButton" virtualName="" explicitFocusOrder="0"
|
memberName="rbmTrainV2ToggleButton" virtualName="" explicitFocusOrder="0"
|
||||||
pos="336 200 128 24" buttonText="Train Ver. 2" connectedEdges="0"
|
pos="336 200 128 24" buttonText="Train Ver. 2" connectedEdges="0"
|
||||||
needsCallback="1" radioGroupId="0" state="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"/>
|
||||||
</JUCER_COMPONENT>
|
</JUCER_COMPONENT>
|
||||||
|
|
||||||
END_JUCER_METADATA
|
END_JUCER_METADATA
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ private:
|
|||||||
ScopedPointer<Label> sparsityLearningRateLabel;
|
ScopedPointer<Label> sparsityLearningRateLabel;
|
||||||
ScopedPointer<Label> weightInitLabel;
|
ScopedPointer<Label> weightInitLabel;
|
||||||
ScopedPointer<ToggleButton> rbmTrainV2ToggleButton;
|
ScopedPointer<ToggleButton> rbmTrainV2ToggleButton;
|
||||||
|
ScopedPointer<ToggleButton> rbmNormalizeDataToggleButton;
|
||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
, m_doRaoBlackwell(false)
|
, m_doRaoBlackwell(false)
|
||||||
, m_useProbsForHiddenReconstruction(false)
|
, m_useProbsForHiddenReconstruction(false)
|
||||||
, m_doSparse(false)
|
, m_doSparse(false)
|
||||||
|
, m_doNormalizeData(false)
|
||||||
, m_numGibbs(1)
|
, m_numGibbs(1)
|
||||||
{
|
{
|
||||||
Noise_Init(&m_noise, 0x32727155);
|
Noise_Init(&m_noise, 0x32727155);
|
||||||
@@ -260,6 +261,31 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void normalizeData(MatrixXd &src, double mu, double sigma)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
uint32_t size = src.rows();
|
||||||
|
double mean;
|
||||||
|
double stdDev;
|
||||||
|
|
||||||
|
for (i=0; i < size; i++)
|
||||||
|
{
|
||||||
|
mean = src.row(i).array().mean();
|
||||||
|
src.row(i).array() -= mean;
|
||||||
|
src.row(i).array() += mu;
|
||||||
|
}
|
||||||
|
for (i=0; i < size; i++)
|
||||||
|
{
|
||||||
|
src.row(i).array() *= src.row(i).array();
|
||||||
|
}
|
||||||
|
for (i=0; i < size; i++)
|
||||||
|
{
|
||||||
|
stdDev = sqrt(src.row(i).array().mean());
|
||||||
|
src.row(i).array() /= stdDev;
|
||||||
|
src.row(i).array() *= sigma;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void train2(const LayerArray<VisibleLayer> &vt, uint32_t numEpochs, uint32_t batchSize, double sigmaMin = 0.05)
|
void train2(const LayerArray<VisibleLayer> &vt, uint32_t numEpochs, uint32_t batchSize, double sigmaMin = 0.05)
|
||||||
{
|
{
|
||||||
uint32_t t, i;
|
uint32_t t, i;
|
||||||
@@ -293,6 +319,11 @@ public:
|
|||||||
{
|
{
|
||||||
// t = (uint32_t)(0.5 + (vt.getSize()-1)*Noise_Uniform(&m_noise));
|
// t = (uint32_t)(0.5 + (vt.getSize()-1)*Noise_Uniform(&m_noise));
|
||||||
batch.row(i) = vt[i].states();
|
batch.row(i) = vt[i].states();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (m_doNormalizeData)
|
||||||
|
{
|
||||||
|
normalizeData(batch, 0.0, m_sigma);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (epoch=0; epoch < numEpochs; epoch++)
|
for (epoch=0; epoch < numEpochs; epoch++)
|
||||||
@@ -603,6 +634,11 @@ public:
|
|||||||
m_doSparse = flag;
|
m_doSparse = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setNormalizeData(bool flag)
|
||||||
|
{
|
||||||
|
m_doNormalizeData = flag;
|
||||||
|
}
|
||||||
|
|
||||||
void setNumGibbs(uint32_t value)
|
void setNumGibbs(uint32_t value)
|
||||||
{
|
{
|
||||||
m_numGibbs = value;
|
m_numGibbs = value;
|
||||||
@@ -646,6 +682,7 @@ private:
|
|||||||
bool m_doRaoBlackwell;
|
bool m_doRaoBlackwell;
|
||||||
bool m_useProbsForHiddenReconstruction;
|
bool m_useProbsForHiddenReconstruction;
|
||||||
bool m_doSparse;
|
bool m_doSparse;
|
||||||
|
bool m_doNormalizeData;
|
||||||
volatile bool m_doCancel;
|
volatile bool m_doCancel;
|
||||||
uint32_t m_numGibbs;
|
uint32_t m_numGibbs;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user