-
-
Save aldente-hu/33c0e5e7898b648d45b78b2c5d5d911e to your computer and use it in GitHub Desktop.
不確かさの分布が異なる2タイプの(仮想)計測データを各100セット生成します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 以下のファイル等が同じディレクトリにあるものとする。 | |
# - box_muller.rb: Box-Muller法による乱数生成を実装したクラスBoxMullerを持つ。 | |
# https://gist.github.com/aldente-hu/5e913f4c9da5f80ae7fb7d3756a7e9b0 を参照のこと。 | |
# - original.csv: 各測定点における"真の値"を格納している。 | |
# - dataディレクトリ: データファイルの生成先。 | |
# Usage: | |
# ruby generate_sample_data.rb | |
require_relative 'box_muller' | |
b = BoxMuller.new | |
# 1.真の値を計算する | |
x_array = (0..20).map { |x| 0.5*x } | |
model = lambda { |x| 251.0 * Math::exp(-0.232 * x) } | |
truth = x_array.to_h { |x| [x, model.call(x)] } | |
# 2.絶対不確かさが一定の計測データを出力 (CAU: Constant Absolute Uncertainty) | |
sigma = 3.0 | |
File.open("data/cau.csv", 'w') { |file| | |
truth.each do |x, y| | |
file.write "%.1f" % x | |
100.times do | |
file.write ",%.4f" % (y + sigma * b.next) | |
end | |
file.puts | |
end | |
} | |
# 3.相対不確かさが一定の計測データを出力 (CRU: Constant Relative Uncertainty) | |
r_sigma = 0.03 | |
File.open("data/cru.csv", 'w') { |file| | |
truth.each do |x, y| | |
file.write "%.1f" % x | |
100.times do | |
file.write ",%.4f" % (y * (r_sigma * b.next + 1)) | |
end | |
file.puts | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment