- use Matrix, linear algebra library Eigen 3.2.2
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@23 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+21
-23
@@ -21,6 +21,8 @@
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <Eigen/Dense>
|
||||
//[/Headers]
|
||||
|
||||
#include "MainComponent.h"
|
||||
@@ -50,6 +52,8 @@ void mylog(const char* format, ...)
|
||||
|
||||
//[/MiscUserDefs]
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
//==============================================================================
|
||||
MainComponent::MainComponent ()
|
||||
: m_layers(this),
|
||||
@@ -220,12 +224,12 @@ MainComponent::MainComponent ()
|
||||
|
||||
projectNameLabel->setText(String("TestPrj"), dontSendNotification );
|
||||
numEpochslabel->setText(String(100), dontSendNotification );
|
||||
learningRateLabel->setText(String(0.2), dontSendNotification );
|
||||
learningRateLabel->setText(String(0.1), dontSendNotification );
|
||||
rbmUseExpectationsToggleButton->setToggleState(false, sendNotification);
|
||||
rbmDoRaoBlackwellToggleButton->setToggleState(false, sendNotification);
|
||||
rbmDoRobbinsMonroToggleButton->setToggleState(false, sendNotification);
|
||||
rbmReduceVarianceToggleButton->setToggleState(false, sendNotification);
|
||||
//[/Constructor]
|
||||
//[/Constructor]
|
||||
}
|
||||
|
||||
MainComponent::~MainComponent()
|
||||
@@ -334,7 +338,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
{
|
||||
//[UserButtonCode_addButton] -- add your button handler code here..
|
||||
Draw2->setData(Draw->getData());
|
||||
m_layers.add(Draw->getData(), m_vNumX*m_vNumY);
|
||||
m_layers.add(&Draw->getData(), m_vNumX*m_vNumY);
|
||||
patterSlider->setRange (0, m_layers.getSize()-1, 1);
|
||||
//[/UserButtonCode_addButton]
|
||||
}
|
||||
@@ -411,15 +415,15 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
{
|
||||
//[UserButtonCode_reconstructEquButton] -- add your button handler code here..
|
||||
uint32_t i;
|
||||
const double *pV, *pH;
|
||||
const VectorXd *pV, *pH;
|
||||
|
||||
pV = Draw->getData();
|
||||
pV = (const VectorXd*)&Draw->getData();
|
||||
for (i=0; i < 100; i++)
|
||||
{
|
||||
pH = m_pRbm->toHidden(pV);
|
||||
DrawHidden->setData(pH);
|
||||
pV = m_pRbm->toVisible(pH);
|
||||
Draw2->setData(pV);
|
||||
pH = (const VectorXd*)&m_pRbm->toHidden(*pV);
|
||||
DrawHidden->setData(*pH);
|
||||
pV = (const VectorXd*)&m_pRbm->toVisible(*pH);
|
||||
Draw2->setData(*pV);
|
||||
}
|
||||
//[/UserButtonCode_reconstructEquButton]
|
||||
}
|
||||
@@ -463,39 +467,33 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
|
||||
if (m_layers.getSize() > 0)
|
||||
{
|
||||
VisibleLayer &p = (VisibleLayer&)m_layers.getAt((int)sliderThatWasMoved->getValue());
|
||||
Draw2->setData(p.getStates());
|
||||
Draw2->setData(p.states());
|
||||
}
|
||||
//[/UserSliderCode_patterSlider]
|
||||
}
|
||||
else if (sliderThatWasMoved == WeightsSlider)
|
||||
{
|
||||
//[UserSliderCode_WeightsSlider] -- add your slider handling code here..
|
||||
double **ppW = m_weights.getWeights();
|
||||
if (!ppW)
|
||||
return;
|
||||
|
||||
double *pW = ppW[(int)sliderThatWasMoved->getValue()];
|
||||
double *pTemp = new double [m_vNumX*m_vNumY];
|
||||
VectorXd w = m_weights.weights().col((int)sliderThatWasMoved->getValue());
|
||||
VectorXd temp = w;
|
||||
double min = +1E12;
|
||||
double max = -1E12;
|
||||
|
||||
for (int i=0; i < m_vNumX*m_vNumY; i++)
|
||||
{
|
||||
pTemp[i] = pW[i];
|
||||
min = std::min<double>(min, pW[i]);
|
||||
max = std::max<double>(max, pW[i]);
|
||||
min = std::min<double>(min, (double)temp[i]);
|
||||
max = std::max<double>(max, (double)temp[i]);
|
||||
}
|
||||
for (int i=0; i < m_vNumX*m_vNumY; i++)
|
||||
{
|
||||
pTemp[i] -= min;
|
||||
temp[i] -= min;
|
||||
}
|
||||
for (int i=0; i < m_vNumX*m_vNumY; i++)
|
||||
{
|
||||
pTemp[i] /= (max-min);
|
||||
temp[i] /= (max-min);
|
||||
}
|
||||
|
||||
DrawWeights->setData(pTemp);
|
||||
delete pTemp;
|
||||
DrawWeights->setData(temp);
|
||||
//[/UserSliderCode_WeightsSlider]
|
||||
}
|
||||
else if (sliderThatWasMoved == numGibbsSlider)
|
||||
|
||||
Reference in New Issue
Block a user