Repo root had ~35 groups of .prj/.dat files loose alongside the build system and source, all sharing one flat namespace. Centralize the new prj/<name>/ convention inside AStack::loadWeights/saveWeights/ loadTrainingBatch/saveTrainingBatch and StackCreator::fromFile/toFile (via a new AStack::projectDir() helper) -- these already have access to the project name, so callers (poet.cpp, the GUI) need no changes at all; they keep passing the same base directory they always did. Filenames inside each project folder are unchanged (e.g. prj/mnist_2/mnist_2.prj, prj/mnist_2/mnist_2.Layer.0.w.dat) -- only the directory moves. Added Matutils::ensureDir() (mkdir -p equivalent; no std::filesystem in C++11) since ofstream won't create directories, used wherever a project is saved for the first time. File migration for existing projects is a separate commit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016K8Gu7Qejd11JbdiHZqYAs
100 lines
2.0 KiB
C++
100 lines
2.0 KiB
C++
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/*
|
|
* File: AStack.hpp
|
|
* Author: jens
|
|
*
|
|
* Created on 16. Januar 2022, 13:55
|
|
*/
|
|
|
|
#ifndef ASTACK_HPP
|
|
#define ASTACK_HPP
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <armadillo>
|
|
#include <jsoncpp/json/json.h>
|
|
#include "Layer.hpp"
|
|
#include <forward_list>
|
|
|
|
class AStack;
|
|
class LayerConstructor
|
|
{
|
|
public:
|
|
LayerConstructor() {}
|
|
virtual ~LayerConstructor() {}
|
|
|
|
virtual Layer* onConstruct(AStack *pStack, const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden, size_t numContext)
|
|
{
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
class AStack
|
|
{
|
|
public:
|
|
enum StackType
|
|
{
|
|
None,
|
|
Deep,
|
|
Rnn,
|
|
NUM_STACKTYPES
|
|
};
|
|
|
|
static const char *stackTypeStrings[NUM_STACKTYPES];
|
|
|
|
AStack(StackType type, const std::string &name);
|
|
AStack(const AStack& orig) = delete;
|
|
virtual ~AStack();
|
|
|
|
StackType type();
|
|
void setName(const std::string &name);
|
|
size_t numLayers() const;
|
|
virtual size_t numContext()
|
|
{
|
|
return 0;
|
|
}
|
|
void addLayer(Layer *pLayer);
|
|
void delLayer(Layer *pLayer);
|
|
|
|
Layer* getLayer(size_t layerId) const;
|
|
Layer* getFirstLayer() const;
|
|
Layer* getLastLayer() const;
|
|
|
|
bool save(const std::string &dir);
|
|
|
|
void weightsInit(double stddev);
|
|
bool loadWeights(const std::string &dir);
|
|
bool saveWeights(const std::string &dir);
|
|
|
|
virtual void train(const arma::mat& batch, Rbm::IListener* pListener) = 0;
|
|
|
|
size_t numTraining();
|
|
void addTraining(const arma::mat &toAdd);
|
|
void delTraining(int index);
|
|
size_t loadTrainingBatch(const std::string &dir, bool doNormalize=false);
|
|
size_t saveTrainingBatch(const std::string &dir);
|
|
arma::mat& trainingBatch();
|
|
|
|
protected:
|
|
StackType m_type;
|
|
std::string m_name;
|
|
Layer *m_pLayers;
|
|
|
|
private:
|
|
arma::mat m_trainingBatch;
|
|
size_t m_numLayers;
|
|
void updateNumLayers();
|
|
|
|
// Every project's files live under {dir}/prj/{m_name}/, not flat at {dir}.
|
|
std::string projectDir(const std::string &dir) const;
|
|
|
|
};
|
|
|
|
#endif /* ASTACK_HPP */
|
|
|