- fixed load and save
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@628 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -530,6 +530,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
//[UserButtonCode_loadButton] -- add your button handler code here..
|
//[UserButtonCode_loadButton] -- add your button handler code here..
|
||||||
m_stack = new Stack(std::string(projectNameLabel->getText().getCharPointer()));
|
m_stack = new Stack(std::string(projectNameLabel->getText().getCharPointer()));
|
||||||
m_stack->load(this);
|
m_stack->load(this);
|
||||||
|
m_stack->loadWeights();
|
||||||
m_rbmSelect->clear(dontSendNotification);
|
m_rbmSelect->clear(dontSendNotification);
|
||||||
|
|
||||||
for (int id=0; id < m_stack->numLayers(); id++)
|
for (int id=0; id < m_stack->numLayers(); id++)
|
||||||
@@ -810,69 +811,14 @@ void MainComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails
|
|||||||
//[/UserCode_mouseWheelMove]
|
//[/UserCode_mouseWheelMove]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
|
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
|
||||||
void MainComponent::save ()
|
void MainComponent::save ()
|
||||||
{
|
{
|
||||||
|
m_stack->saveTraining(m_trainingData);
|
||||||
m_stack->saveWeights();
|
m_stack->saveWeights();
|
||||||
m_stack->save();
|
m_stack->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainComponent::create(juce::String const &projectName)
|
|
||||||
{
|
|
||||||
m_stack = new Stack(std::string(projectName.getCharPointer()));
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
int id = m_rbmSelect->getSelectedId()-1;
|
|
||||||
bool shouldAddItem = true;
|
|
||||||
if (id == 0)
|
|
||||||
{
|
|
||||||
m_rbmSelect->clear(dontSendNotification);
|
|
||||||
m_rbmSelect->addItem(String(id), id+1);
|
|
||||||
m_rbmSelect->setSelectedId(id+1, dontSendNotification);
|
|
||||||
|
|
||||||
for (size_t i=0; i < DBN_SIZE; i++)
|
|
||||||
{
|
|
||||||
m_weights[i] = nullptr;
|
|
||||||
m_pRbmComponent[i] = nullptr;
|
|
||||||
}
|
|
||||||
if (!projectName.isEmpty())
|
|
||||||
{
|
|
||||||
m_weights[id] = new Weights((String(projectName + String(".weights.dat"))).toUTF8());
|
|
||||||
loadTraining((String(projectName + String(".trainingStates.dat"))).toUTF8());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_weights[id] = new Weights(numVisibleLabel->getText().getIntValue(), numVisibleYLabel->getText().getIntValue(), numHiddenLabel->getText().getIntValue());
|
|
||||||
}
|
|
||||||
addAndMakeVisible(m_pRbmComponent[id] = new RbmComponent(*m_weights[id], m_trainingData, *this));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
shouldAddItem = m_pRbmComponent[id] == nullptr;
|
|
||||||
m_weights[id] = nullptr;
|
|
||||||
m_pRbmComponent[id] = nullptr;
|
|
||||||
m_weights[id] = new Weights(m_weights[id-1]->getNumHidden(), 1, numHiddenLabel->getText().getIntValue());
|
|
||||||
addAndMakeVisible(m_pRbmComponent[id] = new RbmComponent(*m_weights[id], m_pRbmComponent[id-1], *this));
|
|
||||||
}
|
|
||||||
m_pLayer = m_pRbmComponent[id];
|
|
||||||
m_weightsCurr = m_weights[id];
|
|
||||||
m_pLayer->setBounds (16, 140*id+16, 430, 130);
|
|
||||||
m_pLayer->batchchanged();
|
|
||||||
m_pLayer->redrawReconstruction();
|
|
||||||
m_pLayer->redrawWeights();
|
|
||||||
|
|
||||||
if (((id+1) < DBN_SIZE) and shouldAddItem)
|
|
||||||
m_rbmSelect->addItem(String(id+1), id+2);
|
|
||||||
#endif
|
|
||||||
updateControls();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainComponent::destroy()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const juce::String& MainComponent::getBaseDir()
|
const juce::String& MainComponent::getBaseDir()
|
||||||
{
|
{
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
|||||||
@@ -90,8 +90,6 @@ private:
|
|||||||
int m_weightIndex;
|
int m_weightIndex;
|
||||||
int m_trainingIndex;
|
int m_trainingIndex;
|
||||||
void save();
|
void save();
|
||||||
void create(juce::String const &projectName);
|
|
||||||
void destroy();
|
|
||||||
const juce::String& getBaseDir();
|
const juce::String& getBaseDir();
|
||||||
void run();
|
void run();
|
||||||
String m_baseDir;
|
String m_baseDir;
|
||||||
|
|||||||
+28
-2
@@ -217,10 +217,9 @@ arma::mat Stack::loadTraining()
|
|||||||
{
|
{
|
||||||
uint32_t numTraining = 0;
|
uint32_t numTraining = 0;
|
||||||
uint32_t numVisible = 0;
|
uint32_t numVisible = 0;
|
||||||
FILE *pFile;
|
|
||||||
|
|
||||||
std::string filename = m_name + ".training.dat";
|
std::string filename = m_name + ".training.dat";
|
||||||
pFile = fopen(filename.c_str(), "r");
|
FILE *pFile = fopen(filename.c_str(), "r");
|
||||||
|
|
||||||
if (!pFile)
|
if (!pFile)
|
||||||
{
|
{
|
||||||
@@ -257,6 +256,33 @@ arma::mat Stack::loadTraining()
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Stack::saveTraining(const arma::mat& batch)
|
||||||
|
{
|
||||||
|
std::string filename = m_name + ".training.dat";
|
||||||
|
FILE *pFile = fopen(filename.c_str(), "w");
|
||||||
|
|
||||||
|
if (!pFile)
|
||||||
|
{
|
||||||
|
std::cout << "Could not open " << filename << "!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(pFile, "%u\n", (uint32_t)batch.n_rows);
|
||||||
|
fprintf(pFile, "%u\n", (uint32_t)batch.n_cols);
|
||||||
|
|
||||||
|
uint32_t i, j;
|
||||||
|
|
||||||
|
for (i=0; i < batch.n_rows; i++)
|
||||||
|
{
|
||||||
|
for (j=0; j < batch.n_cols; j++)
|
||||||
|
{
|
||||||
|
fprintf(pFile, "%3.6f\n", batch(i, j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(pFile);
|
||||||
|
}
|
||||||
|
|
||||||
size_t Stack::numTraining(const arma::mat &batch)
|
size_t Stack::numTraining(const arma::mat &batch)
|
||||||
{
|
{
|
||||||
return batch.n_rows;
|
return batch.n_rows;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
static void addTraining(arma::mat &batch, const arma::mat &toAdd);
|
static void addTraining(arma::mat &batch, const arma::mat &toAdd);
|
||||||
static void delTraining(arma::mat &batch, int index);
|
static void delTraining(arma::mat &batch, int index);
|
||||||
arma::mat loadTraining();
|
arma::mat loadTraining();
|
||||||
|
void saveTraining(const arma::mat &batch);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|||||||
Reference in New Issue
Block a user