ARCS6 AR6-REV.24062600
読み取り中…
検索中…
一致する文字列を見つけられません
Shuffle.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 SHUFFLE
15#define SHUFFLE
16
17#include <cassert>
18#include <cmath>
19#include "Matrix.hh"
20#include "RandomGenerator.hh"
21
22// ARCS組込み用マクロ
23#ifdef ARCS_IN
24 // ARCSに組み込まれる場合
25 #include "ARCSassert.hh"
26 #include "ARCSeventlog.hh"
27#else
28 // ARCSに組み込まれない場合
29 #define arcs_assert(a) (assert(a))
30 #define PassedLog()
31 #define EventLog(a)
32 #define EventLogVar(a)
33#endif
34
35namespace ARCS { // ARCS名前空間
37class Shuffle {
38 public:
41 : Rand(0,1) // 0~1の範囲の乱数
42 {
43
44 }
45
49 : Rand(std::move(r.Rand))
50 {
51
52 }
53
56
57 }
58
61 template <size_t N, size_t M>
63 // フィッシャー-イェーツのシャッフルアルゴリズム
64 size_t j = 0;
65 for(size_t i = M - 1; i != 0; --i){
66 j = std::floor(Rand.GetDoubleRandom()*i);
67 swaprow(U, j+1, i+1);
68 }
69 }
70
74 template <size_t N, size_t M, size_t L>
76 // フィッシャー-イェーツのシャッフルアルゴリズム
77 size_t j = 0;
78 for(size_t i = M - 1; i != 0; --i){
79 j = std::floor(Rand.GetDoubleRandom()*i);
80 swaprow(U1, j+1, i+1);
81 swaprow(U2, j+1, i+1);
82 }
83 }
84
85 private:
86 Shuffle(const Shuffle&) = delete;
87 const Shuffle& operator=(const Shuffle&) = delete;
88 RandomGenerator Rand;
89};
90}
91
92#endif
93
ARCS イベントログクラス
ARCS用ASSERTクラス
乱数生成器
行列/ベクトル計算クラス(テンプレート版)
行列/ベクトル計算クラス(テンプレート版)
Definition Matrix.hh:44
乱数生成器
Definition RandomGenerator.hh:22
double GetDoubleRandom(void)
一様乱数を返す関数(浮動小数点版)
Definition RandomGenerator.hh:58
シャッフルクラス
Definition Shuffle.hh:37
void ShuffleMatrixRow(Matrix< N, M > &U)
行列の行をランダムに入れ替える
Definition Shuffle.hh:62
void ShuffleMatrixRow(Matrix< N, M > &U1, Matrix< L, M > &U2)
行列1と行列2の行を同時にランダムに入れ替える
Definition Shuffle.hh:75
~Shuffle()
デストラクタ
Definition Shuffle.hh:55
Shuffle(Shuffle &&r)
ムーブコンストラクタ
Definition Shuffle.hh:48
Shuffle()
コンストラクタ
Definition Shuffle.hh:40