14#ifndef FEEDFORWARDNEURALNET3
15#define FEEDFORWARDNEURALNET3
33 #define arcs_assert(a) (assert(a))
36 #define EventLogVar(a)
68 : InputLayer(), HiddenLayer(), OutputLayer(),
69 X(), ZIn(), ZHid(), Y(), D(), WDeltaOut(), WDeltaHid(), WDeltaIn(),
70 EpochNumbers(), TrainLoss(), TestLoss(),
71 XTest(), ZInTest(), ZHidTest(), YTest(), DTest(),
80 : InputLayer(r.InputLayer), HiddenLayer(r.HiddenLayer), OutputLayer(r.OutputLayer),
81 X(r.X), ZIn(r.ZIn), ZHid(r.ZHid), Y(r.Y), D(r.D), WDeltaOut(r.WDeltaOut), WDeltaHid(r.WDeltaHid), WDeltaIn(r.WDeltaIn),
82 EpochNumbers(r.EpochNumbers), TrainLoss(r.TrainLoss), TestLoss(r.TestLoss),
83 XTest(r.XTest), ZInTest(r.ZInTest), ZHidTest(r.ZHidTest), YTest(r.YTest), DTest(r.DTest),
84 zin(r.zin), zhid(r.zhid)
123 Datasets.GetMeasuredBatchData(Datasets.FinalMinbatNum, XTest);
124 Datasets.GetClassBatchData(Datasets.FinalMinbatNum, DTest);
127 printf(
"\nBackpropagation Training:\n");
128 printf(
"Epoch : Train Loss [dB] Test Loss [dB]\n");
129 for(
size_t i = 0; i < Epoch; ++i){
131 for(
size_t j = 0; j < MinbatNum; ++j){
133 Datasets.GetMeasuredBatchData(j + 1, X);
134 Datasets.GetClassBatchData(j + 1, D);
147 HiddenLayer.
CalcDelta(WDeltaOut, WDeltaHid);
148 InputLayer.
CalcDelta(WDeltaHid, WDeltaIn);
155 if constexpr(DsShfl == NnShuffle::ENABLE) Datasets.ShuffleDatasets();
164 TrainLoss[i] = 10.0*log10(OutputLayer.
GetLoss(Y, D));
165 TestLoss[i] = 10.0*log10(OutputLayer.
GetLoss(YTest, DTest));
168 if(i % (Epoch/EpochDisp) == 0){
169 printf(
"%5lu : % 16.8f, % 16.8f\n", i, TrainLoss[i], TestLoss[i]);
176 printf(
"\nWeight Matrices of All Layers:\n");
184 printf(
"\nBias Vectors of All Layers:\n");
192 printf(
"\nNeural Network Settings:\n");
200 printf(
"\nFinal Test Data Comfirmation:\n");
212 CuiPlot Plot(FG, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT);
214 Plot.
SetRanges(0, Epoch, (
double)Ymin, (
double)Ymax);
217 Plot.
DrawLegend(1,
"Training", FGcolors::CYAN);
218 Plot.
DrawLegend(2,
"Test", FGcolors::MAGENTA);
219 Plot.
Plot(EpochNumbers, TrainLoss, CuiPlotTypes::PLOT_BOLDSTAIRS, FGcolors::CYAN);
220 Plot.
Plot(EpochNumbers, TestLoss, CuiPlotTypes::PLOT_BOLDSTAIRS, FGcolors::MAGENTA);
239 InputLayer.
SaveWeightAndBias(FileName +
"-InputLayerW.csv", FileName +
"-InputLayerb.csv");
240 HiddenLayer.
SaveWeightAndBias(FileName +
"-HiddenLayerW.csv", FileName +
"-HiddenLayerb.csv");
241 OutputLayer.
SaveWeightAndBias(FileName +
"-OutputLayerW.csv", FileName +
"-OutputLayerb.csv");
247 InputLayer.
LoadWeightAndBias(FileName +
"-InputLayerW.csv", FileName +
"-InputLayerb.csv");
248 HiddenLayer.
LoadWeightAndBias(FileName +
"-HiddenLayerW.csv", FileName +
"-HiddenLayerb.csv");
249 OutputLayer.
LoadWeightAndBias(FileName +
"-OutputLayerW.csv", FileName +
"-OutputLayerb.csv");
255 InputLayer.
SaveSettings(FileName +
"-InputLayerSet.csv");
256 HiddenLayer.
SaveSettings(FileName +
"-HiddenLayerSet.csv");
257 OutputLayer.
SaveSettings(FileName +
"-OutputLayerSet.csv");
263 InputLayer.
LoadSettings(FileName +
"-InputLayerSet.csv");
264 HiddenLayer.
LoadSettings(FileName +
"-HiddenLayerSet.csv");
265 OutputLayer.
LoadSettings(FileName +
"-OutputLayerSet.csv");
273 static constexpr int GRAPH_WIDTH = 1000;
274 static constexpr int GRAPH_HEIGHT = 500;
290 std::array<double, Epoch> EpochNumbers;
291 std::array<double, Epoch> TrainLoss;
292 std::array<double, Epoch> TestLoss;
#define PassedLog()
イベントログ用マクロ(ファイルと行番号のみ記録版)
Definition ARCSeventlog.hh:26
#define PrintMatrix(a, b)
行列要素表示マクロ(フォーマット指定あり版)
Definition Matrix.hh:35
ActvFunc
活性化関数のタイプの定義
Definition ActivationFunctions.hh:35
フレームグラフィックスクラスV2(新型テンプレート版)
NnInitTypes
重み初期化のタイプの定義
Definition NeuralNetParamDef.hh:19
NnShuffle
エポック毎にデータセットをシャッフルするかどうか
Definition NeuralNetParamDef.hh:41
NnDropout
ドロップアウトの定義
Definition NeuralNetParamDef.hh:35
NnDescentTypes
勾配降下法のタイプの定義
Definition NeuralNetParamDef.hh:25
CuiPlot(新型きゅいプロットV2)
Definition CuiPlot.hh:54
void SetRanges(double xmin, double xmax, double ymin, double ymax)
グラフの範囲を設定する関数
Definition CuiPlot.hh:130
void Plot(const double x, const double y, const CuiPlotTypes type, const uint32_t color)
1点のデータをプロットする関数(バイナリ色データ版)
Definition CuiPlot.hh:250
void SetGridLabelFormat(const std::string &xformat, const std::string &yformat)
グリッドラベルの書式を設定する関数
Definition CuiPlot.hh:153
void SetAxisLabels(const std::string &xlabel, const std::string &ylabel)
軸ラベルを設定する関数
Definition CuiPlot.hh:145
void DrawAxis(void)
グラフの軸を描画する関数
Definition CuiPlot.hh:170
void DrawLegend(size_t i, const std::string &name, const FGcolors &color)
凡例を描画する関数
Definition CuiPlot.hh:188
多層パーセプトロンクラス3層版
Definition FeedforwardNeuralNet3.hh:64
void WriteLeaningCurvePNG(const std::string &FileName, const int Ymin, const int Ymax)
学習曲線グラフのPNG画像ファイルを書き出す関数
Definition FeedforwardNeuralNet3.hh:209
FeedforwardNeuralNet3(FeedforwardNeuralNet3 &&r)
ムーブコンストラクタ
Definition FeedforwardNeuralNet3.hh:79
void DispFinalTestData(void)
最後の学習結果を使った順伝播出力値と正解値の確認
Definition FeedforwardNeuralNet3.hh:199
void SetGainOfMomentumSGD(double epsilon, double alpha)
モーメンタム確率的勾配降下法の更新ゲイン(学習率)の設定
Definition FeedforwardNeuralNet3.hh:104
void LoadWeightAndBias(const std::string &FileName)
CSVファイルから各レイヤの重み行列とバイアスベクトルに読み込む関数
Definition FeedforwardNeuralNet3.hh:246
void LoadSettings(const std::string &FileName)
CSVファイルから各レイヤのパーセプトロンの設定値を読み込む関数
Definition FeedforwardNeuralNet3.hh:262
FeedforwardNeuralNet3()
コンストラクタ
Definition FeedforwardNeuralNet3.hh:67
void Train(DsName &Datasets)
誤差逆伝播法による訓練をする関数
Definition FeedforwardNeuralNet3.hh:120
~FeedforwardNeuralNet3()
デストラクタ
Definition FeedforwardNeuralNet3.hh:90
void InitWeight(void)
重み行列の初期化
Definition FeedforwardNeuralNet3.hh:95
void SaveSettings(const std::string &FileName)
各レイヤのパーセプトロンの設定値をCSVファイルとして保存する関数
Definition FeedforwardNeuralNet3.hh:254
void DispBias(void)
バイアスベクトルの表示
Definition FeedforwardNeuralNet3.hh:183
void Estimate(const Matrix< 1, InSize > &x, Matrix< 1, OutSize > &y)
訓練済みニューラルネットワークを使った推定計算
Definition FeedforwardNeuralNet3.hh:227
void DispSettings(void)
パーセプトロン設定値の表示
Definition FeedforwardNeuralNet3.hh:191
void DispWeight(void)
重み行列の表示
Definition FeedforwardNeuralNet3.hh:175
void SetDropoutRate(double DropoutRate)
ドロップアウト率の設定
Definition FeedforwardNeuralNet3.hh:112
void SaveWeightAndBias(const std::string &FileName)
各レイヤの重み行列とバイアスベクトルをCSVファイルとして保存する関数
Definition FeedforwardNeuralNet3.hh:238
フレームグラフィックスクラス(新型テンプレート版)
Definition FrameGraphics.hh:91
void SavePngImageFile(const std::string &FileName)
PNG画像ファイルを保存する関数
Definition FrameGraphics.hh:200
行列/ベクトル計算クラス(テンプレート版)
Definition Matrix.hh:44
単層パーセプトロンクラス
Definition SingleLayerPerceptron.hh:59
void UpdateWeight(const Matrix< M, N > &Zprev)
重み行列とバイアスベクトルの更新
Definition SingleLayerPerceptron.hh:263
void DispSettings(void)
パーセプトロン設定値の表示
Definition SingleLayerPerceptron.hh:287
void SaveSettings(const std::string &SettingName)
パーセプトロンの設定をCSVファイルに保存する関数
Definition SingleLayerPerceptron.hh:356
void InitWeight(size_t Nprev)
重み行列の初期化
Definition SingleLayerPerceptron.hh:100
void LoadWeightAndBias(const std::string &WeightName, const std::string &BiasName)
重み行列とバイアスベクトルをCSVファイルとして入力する関数
Definition SingleLayerPerceptron.hh:349
void CalcForwardForTraining(const Matrix< 1, N > &zprev, Matrix< 1, P > &z)
順伝播計算(ベクトル入出力訓練版)
Definition SingleLayerPerceptron.hh:173
void SetGainOfMomentumSGD(double epsilon, double alpha)
モーメンタム確率的勾配降下法の更新ゲイン(学習率)の設定
Definition SingleLayerPerceptron.hh:120
void NormalizeInput(Matrix< 1, P > &x)
入力データの正規化(標準化)
Definition SingleLayerPerceptron.hh:334
void NomalizeDataset(Matrix< NN, MM > &x)
生計測データセットの正規化(標準化)
Definition SingleLayerPerceptron.hh:326
void SaveWeightAndBias(const std::string &WeightName, const std::string &BiasName)
重み行列とバイアスベクトルをCSVファイルとして出力する関数
Definition SingleLayerPerceptron.hh:341
void CalcDropout(void)
ドロップアウトマスクの計算
Definition SingleLayerPerceptron.hh:245
void DispBias(void)
バイアスベクトルの表示
Definition SingleLayerPerceptron.hh:282
void CalcForwardForEstimation(const Matrix< 1, N > &zprev, Matrix< 1, P > &z)
順伝播計算(ベクトル入出力推定版)
Definition SingleLayerPerceptron.hh:186
void SetDropoutRate(double DropoutRate)
ドロップアウト率の設定
Definition SingleLayerPerceptron.hh:166
double GetLoss(const Matrix< M, P > &Y, const Matrix< M, P > &D)
訓練/テスト誤差を返す関数
Definition SingleLayerPerceptron.hh:301
void CalcDeltaForOutputLayer(const Matrix< M, P > &Y, const Matrix< M, P > &D, Matrix< M, N > &WDelta)
出力層用の誤差行列の計算
Definition SingleLayerPerceptron.hh:239
void CalcDelta(const Matrix< M, P > &WDeltaNext, Matrix< M, N > &WDelta)
入力層と内部層(隠れ層)用の誤差行列の計算
Definition SingleLayerPerceptron.hh:225
void DispWeight(void)
重み行列の表示
Definition SingleLayerPerceptron.hh:277
void LoadSettings(const std::string &SettingName)
CSVファイルからパーセプトロンの設定を読み込む関数
Definition SingleLayerPerceptron.hh:364