ARCS6 AR6-REV.24062600
読み取り中…
検索中…
一致する文字列を見つけられません
IrisDatasets.hh
[詳解]
1
8//
9// Copyright (C) 2011-2020 Yokokura, Yuki
10// This program is free software;
11// you can redistribute it and/or modify it under the terms of the FreeBSD License.
12// For details, see the License.txt file.
13
14#ifndef IRISDATASETS
15#define IRISDATASETS
16
17#include <cassert>
18#include <array>
19#include "Matrix.hh"
20#include "Shuffle.hh"
21#include "BatchProcessor.hh"
22
23// ARCS組込み用マクロ
24#ifdef ARCS_IN
25 // ARCSに組み込まれる場合
26 #include "ARCSassert.hh"
27 #include "ARCSeventlog.hh"
28#else
29 // ARCSに組み込まれない場合
30 #define arcs_assert(a) (assert(a))
31 #define PassedLog()
32 #define EventLog(a)
33 #define EventLogVar(a)
34#endif
35
36namespace ARCS { // ARCS名前空間
39template <size_t M>
41 public:
42 // データセット情報の定義
43 static constexpr size_t D = 150;
44 static constexpr size_t N = 4;
45 static constexpr size_t C = 1;
46 static constexpr size_t FinalMinbatNum = D/M - 1;
47
48 // アヤメの分類の定義
49 static constexpr double IRIS_SETOSA = 1;
50 static constexpr double IRIS_VERSICOLOR = 2;
51 static constexpr double IRIS_VIRGINICA = 3;
54
57 : MeasuredData(), ClassData(), Shfl()
58 {
59 PassedLog();
60 MeasuredData.LoadArray(IrisMeasurement); // 計測データを行列として読み込み
61 ClassData.LoadArray(IrisClassification); // 分類データを行列として読み込み
62 ShuffleDatasets(); // シャッフルの実行
63 }
64
72
75 PassedLog();
76 }
77
79 void DispMeasuredData(void){
80 printf("\nIris Mesurement Data:\n");
81 PrintMatrix(MeasuredData, "% 3.1f");
82 }
83
85 void DispClassData(void){
86 printf("\nIris Classification Data:\n");
87 PrintMatrix(ClassData, "% 1.0f");
88 }
89
93 void GetMeasuredBatchData(const size_t i, Matrix<M,N>& Y){
94 arcs_assert(i <= FinalMinbatNum); // ミニバッチ番号の範囲チェック
95 Y = BatchProcessor::GetMiniBatchData<N,D,M>(MeasuredData, i); // データセットを切り出してミニバッチにする
96 }
97
101 void GetClassBatchData(const size_t i, Matrix<M,C>& y){
102 arcs_assert(i <= FinalMinbatNum); // ミニバッチ番号の範囲チェック
103 y = BatchProcessor::GetMiniBatchData<C,D,M>(ClassData, i); // データセットを切り出してミニバッチにする
104 }
105
107 void ShuffleDatasets(void){
108 Shfl.ShuffleMatrixRow(MeasuredData, ClassData); // シャッフルの実行
109 }
110
111 private:
112 IrisDatasets(const IrisDatasets&) = delete;
113 const IrisDatasets& operator=(const IrisDatasets&) = delete;
114 Shuffle Shfl;
115
118 static constexpr std::array<std::array<double, N>, D> IrisMeasurement = {{
119 {5.1,3.5,1.4,0.2},
120 {4.9,3.0,1.4,0.2},
121 {4.7,3.2,1.3,0.2},
122 {4.6,3.1,1.5,0.2},
123 {5.0,3.6,1.4,0.2},
124 {5.4,3.9,1.7,0.4},
125 {4.6,3.4,1.4,0.3},
126 {5.0,3.4,1.5,0.2},
127 {4.4,2.9,1.4,0.2},
128 {4.9,3.1,1.5,0.1},
129 {5.4,3.7,1.5,0.2},
130 {4.8,3.4,1.6,0.2},
131 {4.8,3.0,1.4,0.1},
132 {4.3,3.0,1.1,0.1},
133 {5.8,4.0,1.2,0.2},
134 {5.7,4.4,1.5,0.4},
135 {5.4,3.9,1.3,0.4},
136 {5.1,3.5,1.4,0.3},
137 {5.7,3.8,1.7,0.3},
138 {5.1,3.8,1.5,0.3},
139 {5.4,3.4,1.7,0.2},
140 {5.1,3.7,1.5,0.4},
141 {4.6,3.6,1.0,0.2},
142 {5.1,3.3,1.7,0.5},
143 {4.8,3.4,1.9,0.2},
144 {5.0,3.0,1.6,0.2},
145 {5.0,3.4,1.6,0.4},
146 {5.2,3.5,1.5,0.2},
147 {5.2,3.4,1.4,0.2},
148 {4.7,3.2,1.6,0.2},
149 {4.8,3.1,1.6,0.2},
150 {5.4,3.4,1.5,0.4},
151 {5.2,4.1,1.5,0.1},
152 {5.5,4.2,1.4,0.2},
153 {4.9,3.1,1.5,0.1},
154 {5.0,3.2,1.2,0.2},
155 {5.5,3.5,1.3,0.2},
156 {4.9,3.1,1.5,0.1},
157 {4.4,3.0,1.3,0.2},
158 {5.1,3.4,1.5,0.2},
159 {5.0,3.5,1.3,0.3},
160 {4.5,2.3,1.3,0.3},
161 {4.4,3.2,1.3,0.2},
162 {5.0,3.5,1.6,0.6},
163 {5.1,3.8,1.9,0.4},
164 {4.8,3.0,1.4,0.3},
165 {5.1,3.8,1.6,0.2},
166 {4.6,3.2,1.4,0.2},
167 {5.3,3.7,1.5,0.2},
168 {5.0,3.3,1.4,0.2},
169 {7.0,3.2,4.7,1.4},
170 {6.4,3.2,4.5,1.5},
171 {6.9,3.1,4.9,1.5},
172 {5.5,2.3,4.0,1.3},
173 {6.5,2.8,4.6,1.5},
174 {5.7,2.8,4.5,1.3},
175 {6.3,3.3,4.7,1.6},
176 {4.9,2.4,3.3,1.0},
177 {6.6,2.9,4.6,1.3},
178 {5.2,2.7,3.9,1.4},
179 {5.0,2.0,3.5,1.0},
180 {5.9,3.0,4.2,1.5},
181 {6.0,2.2,4.0,1.0},
182 {6.1,2.9,4.7,1.4},
183 {5.6,2.9,3.6,1.3},
184 {6.7,3.1,4.4,1.4},
185 {5.6,3.0,4.5,1.5},
186 {5.8,2.7,4.1,1.0},
187 {6.2,2.2,4.5,1.5},
188 {5.6,2.5,3.9,1.1},
189 {5.9,3.2,4.8,1.8},
190 {6.1,2.8,4.0,1.3},
191 {6.3,2.5,4.9,1.5},
192 {6.1,2.8,4.7,1.2},
193 {6.4,2.9,4.3,1.3},
194 {6.6,3.0,4.4,1.4},
195 {6.8,2.8,4.8,1.4},
196 {6.7,3.0,5.0,1.7},
197 {6.0,2.9,4.5,1.5},
198 {5.7,2.6,3.5,1.0},
199 {5.5,2.4,3.8,1.1},
200 {5.5,2.4,3.7,1.0},
201 {5.8,2.7,3.9,1.2},
202 {6.0,2.7,5.1,1.6},
203 {5.4,3.0,4.5,1.5},
204 {6.0,3.4,4.5,1.6},
205 {6.7,3.1,4.7,1.5},
206 {6.3,2.3,4.4,1.3},
207 {5.6,3.0,4.1,1.3},
208 {5.5,2.5,4.0,1.3},
209 {5.5,2.6,4.4,1.2},
210 {6.1,3.0,4.6,1.4},
211 {5.8,2.6,4.0,1.2},
212 {5.0,2.3,3.3,1.0},
213 {5.6,2.7,4.2,1.3},
214 {5.7,3.0,4.2,1.2},
215 {5.7,2.9,4.2,1.3},
216 {6.2,2.9,4.3,1.3},
217 {5.1,2.5,3.0,1.1},
218 {5.7,2.8,4.1,1.3},
219 {6.3,3.3,6.0,2.5},
220 {5.8,2.7,5.1,1.9},
221 {7.1,3.0,5.9,2.1},
222 {6.3,2.9,5.6,1.8},
223 {6.5,3.0,5.8,2.2},
224 {7.6,3.0,6.6,2.1},
225 {4.9,2.5,4.5,1.7},
226 {7.3,2.9,6.3,1.8},
227 {6.7,2.5,5.8,1.8},
228 {7.2,3.6,6.1,2.5},
229 {6.5,3.2,5.1,2.0},
230 {6.4,2.7,5.3,1.9},
231 {6.8,3.0,5.5,2.1},
232 {5.7,2.5,5.0,2.0},
233 {5.8,2.8,5.1,2.4},
234 {6.4,3.2,5.3,2.3},
235 {6.5,3.0,5.5,1.8},
236 {7.7,3.8,6.7,2.2},
237 {7.7,2.6,6.9,2.3},
238 {6.0,2.2,5.0,1.5},
239 {6.9,3.2,5.7,2.3},
240 {5.6,2.8,4.9,2.0},
241 {7.7,2.8,6.7,2.0},
242 {6.3,2.7,4.9,1.8},
243 {6.7,3.3,5.7,2.1},
244 {7.2,3.2,6.0,1.8},
245 {6.2,2.8,4.8,1.8},
246 {6.1,3.0,4.9,1.8},
247 {6.4,2.8,5.6,2.1},
248 {7.2,3.0,5.8,1.6},
249 {7.4,2.8,6.1,1.9},
250 {7.9,3.8,6.4,2.0},
251 {6.4,2.8,5.6,2.2},
252 {6.3,2.8,5.1,1.5},
253 {6.1,2.6,5.6,1.4},
254 {7.7,3.0,6.1,2.3},
255 {6.3,3.4,5.6,2.4},
256 {6.4,3.1,5.5,1.8},
257 {6.0,3.0,4.8,1.8},
258 {6.9,3.1,5.4,2.1},
259 {6.7,3.1,5.6,2.4},
260 {6.9,3.1,5.1,2.3},
261 {5.8,2.7,5.1,1.9},
262 {6.8,3.2,5.9,2.3},
263 {6.7,3.3,5.7,2.5},
264 {6.7,3.0,5.2,2.3},
265 {6.3,2.5,5.0,1.9},
266 {6.5,3.0,5.2,2.0},
267 {6.2,3.4,5.4,2.3},
268 {5.9,3.0,5.1,1.8}
269 }};
270
272 static constexpr std::array<std::array<double, C>, D> IrisClassification = {{
273 {IRIS_SETOSA},
274 {IRIS_SETOSA},
275 {IRIS_SETOSA},
276 {IRIS_SETOSA},
277 {IRIS_SETOSA},
278 {IRIS_SETOSA},
279 {IRIS_SETOSA},
280 {IRIS_SETOSA},
281 {IRIS_SETOSA},
282 {IRIS_SETOSA},
283 {IRIS_SETOSA},
284 {IRIS_SETOSA},
285 {IRIS_SETOSA},
286 {IRIS_SETOSA},
287 {IRIS_SETOSA},
288 {IRIS_SETOSA},
289 {IRIS_SETOSA},
290 {IRIS_SETOSA},
291 {IRIS_SETOSA},
292 {IRIS_SETOSA},
293 {IRIS_SETOSA},
294 {IRIS_SETOSA},
295 {IRIS_SETOSA},
296 {IRIS_SETOSA},
297 {IRIS_SETOSA},
298 {IRIS_SETOSA},
299 {IRIS_SETOSA},
300 {IRIS_SETOSA},
301 {IRIS_SETOSA},
302 {IRIS_SETOSA},
303 {IRIS_SETOSA},
304 {IRIS_SETOSA},
305 {IRIS_SETOSA},
306 {IRIS_SETOSA},
307 {IRIS_SETOSA},
308 {IRIS_SETOSA},
309 {IRIS_SETOSA},
310 {IRIS_SETOSA},
311 {IRIS_SETOSA},
312 {IRIS_SETOSA},
313 {IRIS_SETOSA},
314 {IRIS_SETOSA},
315 {IRIS_SETOSA},
316 {IRIS_SETOSA},
317 {IRIS_SETOSA},
318 {IRIS_SETOSA},
319 {IRIS_SETOSA},
320 {IRIS_SETOSA},
321 {IRIS_SETOSA},
322 {IRIS_SETOSA},
423 }};
424};
425}
426
427#endif
428
ARCS イベントログクラス
#define PassedLog()
イベントログ用マクロ(ファイルと行番号のみ記録版)
Definition ARCSeventlog.hh:26
ARCS用ASSERTクラス
#define arcs_assert(a)
ARCS用assertマクロ a : assert条件
Definition ARCSassert.hh:17
バッチ処理器クラス
行列/ベクトル計算クラス(テンプレート版)
#define PrintMatrix(a, b)
行列要素表示マクロ(フォーマット指定あり版)
Definition Matrix.hh:35
シャッフルクラス
static Matrix< M, N > GetMiniBatchData(const Matrix< N, D > &U, const size_t i)
i番目のミニバッチデータを取得する関数
Definition BatchProcessor.hh:44
機械学習試験用アヤメデータセットクラス(分類番号版)
Definition IrisDatasets.hh:40
IrisDatasets(IrisDatasets &&r)
ムーブコンストラクタ
Definition IrisDatasets.hh:67
static constexpr double IRIS_SETOSA
ヒオウギアヤメ
Definition IrisDatasets.hh:49
~IrisDatasets()
デストラクタ
Definition IrisDatasets.hh:74
void DispMeasuredData(void)
計測データを表示する関数
Definition IrisDatasets.hh:79
static constexpr double IRIS_VIRGINICA
バージニカ
Definition IrisDatasets.hh:51
Matrix< C, D > ClassData
前処理済みのアヤメの分類データ
Definition IrisDatasets.hh:53
static constexpr double IRIS_VERSICOLOR
ブルーフラッグ
Definition IrisDatasets.hh:50
Matrix< N, D > MeasuredData
前処理済みのアヤメの計測データ
Definition IrisDatasets.hh:52
static constexpr size_t D
データセット数
Definition IrisDatasets.hh:43
void GetMeasuredBatchData(const size_t i, Matrix< M, N > &Y)
i番目のミニバッチ計測データを取得する関数
Definition IrisDatasets.hh:93
static constexpr size_t C
訓練データチャネル数
Definition IrisDatasets.hh:45
void DispClassData(void)
分類データを表示する関数
Definition IrisDatasets.hh:85
void ShuffleDatasets(void)
データセットをシャッフルする関数
Definition IrisDatasets.hh:107
static constexpr size_t N
計測データチャネル数
Definition IrisDatasets.hh:44
void GetClassBatchData(const size_t i, Matrix< M, C > &y)
i番目のミニバッチ分類データを取得する関数
Definition IrisDatasets.hh:101
IrisDatasets()
コンストラクタ
Definition IrisDatasets.hh:56
static constexpr size_t FinalMinbatNum
最後のミニバッチ番号
Definition IrisDatasets.hh:46
行列/ベクトル計算クラス(テンプレート版)
Definition Matrix.hh:44
constexpr void LoadArray(const std::array< TT, MM > &Array)
1次元std::array配列を縦ベクトルとして読み込む関数
Definition Matrix.hh:424
シャッフルクラス
Definition Shuffle.hh:37
void ShuffleMatrixRow(Matrix< N, M > &U)
行列の行をランダムに入れ替える
Definition Shuffle.hh:62