-
最近の投稿
最近のコメント
Archive
カテゴリー
メタ情報
投稿者「n3956」のアーカイブ
カーブフィットパラメータの取得
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
fitfunc = TF1("fitfunc", "gaus") # guas, expo, pol1, pol2, etc. fitfunc.SetLineColor(1) fitfunc.SetParameter(0, 100.) # A fitfunc.SetParameter(1, 5.0) # mu fitfunc.SetParameter(2, 0.01) # sigma hist.Fit("fitfunc", "M", "") # function, algorithm, draw option #save fit param with open("fit.log", "w") as fitlog: fitlog.write("# Function: %s\n" % (fitfunc.GetTitle(),)) fitlog.write("# No.\tparam\terror\n") for i in range(fitfunc.GetNpar()): fitlog.write("%s\t%s\t%s\n" % (i, fitfunc.GetParameter(i), fitfunc.GetParError(i))) |
ガウス関数の FWHM を Mathematica の数式処理で求める
g[x_, mu_, sigma_] := 1/(Sqrt[2 *Pi]*sigma)*Exp[-(x – mu)^2/(2*sigma^2)] x = mu で最大値を取るので,その値の 1/2 になる x … 続きを読む
python ファイル名の操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import os filename = "../mydir/hoge.txt" root, ext = os.path.splitext(filename) dirname = os.path.dirname(root) basename = os.path.basename(root) print(root) ../mydir/hoge print(dirname) ../mydir print(basename) hoge print(ext) .txt |
フィッティング Scipy optimize curve_fit
1 2 3 4 5 6 7 8 9 10 |
import numpy as np from scipy.optimize import curve_fit param_initial = np.array((10., 100., 0.2, 0.0)) # initial guess param_bounds = ((0.0, -np.inf, 0.1, -np.pi), (np.inf, np.inf, 0.25, np.pi)) # bounds for parameter popt, pcov = curve_fit(fit_func, x, y, p0=param_initial, sigma=err, bounds=param_bounds) print(popt) # optimized parameters print(np.sqrt(np.diag(pcov))) # standard error |
パラメータの値をある範囲内に指定するときは,bounds option を使う. 値の与え方は, bounds = ((min1, max1), (min … 続きを読む