FitRegularization
詳細
- FitおよびFindFitは,一般に,norm(res)を最小化するパラメータ pars を求める.res はデータの座標点におけるモデルと応答データの差として定義された残差ベクトルである.FitRegularization->rfun のとき,最小化する目的は norm(residuals)+rfun(pars)である.
- FitおよびFindFitは,ノルム
を最小化するパラメータ
を求める.
は
で与えられる成分の残差ベクトルである.ここで,
はデータ座標,
はデータ値で,model はパラメータに依存する. - 以下は,使用可能な設定である.
-
None 正則化は行わない rfun rfun[a]で正則化 {"Tikhonov", λ}
で正則化{"LASSO",λ}
で正則化{"Variation",λ}
で正則化{"TotalVariation",λ}
で正則化{"Curvature",λ}
で正則化{r1,r2,…} r1,…からの項の和で正則化
例題
すべて開く すべて閉じる例 (2)
チホノフ(Tikhonov)正則化は最適フィットパラメータのサイズを制御する:
data = {{0., 0.}, {0.001, 1}, {0.01, 1}};Fit[data, {1, x, x ^ 2}, x, FitRegularization -> {"Tikhonov", 1}]Fit[data, {1, x, x ^ 2}, x]LASSO正則化は最も効果的な基底要素の選択に使うことができる:
data = {{-5, -16.15}, {-4, -10.46}, {-3, -6.91}, {-2, -4.26}, {-1, -1.91}, {0, -0.1}, {1, 2.09}, {2, 3.94}, {3, 5.29}, {4, 5.34}, {5, 3.65}};Fit[data, {1, x, x ^ 2, x ^ 3, x ^ 4}, x, FitRegularization -> {"LASSO", 2}]アプリケーション (5)
正則化を使って数値解
を
に安定させる.ただし,
は摂動している:
a = N[HilbertMatrix[47]];
xexact = Table[t * (1 - t), {t, 0., 1., 1 / 46}];
b = a.xexact + 10^ - 8 RandomReal[{-1, 1}, 47];LinearSolveで求まった解は非常に多くの項を持つ:
ListPlot[LinearSolve[a, b]]
xreg = Table[Fit[{a, b}, FitRegularization -> {"Tikhonov", 10 ^ -ll}], {ll, 0, 3, 2}];ListPlot[Prepend[xreg, xexact], PlotStyle -> PointSize[0.025]]n = 201;
m = 201;
times = Range[m];m1 = Round[m / 5]; m2 = Round[m / 4]; m3 = Round[m / 4];output = ConstantArray[0, m];
output[[m1 + Range[m2]]] = 1;
output[[m1 + m2 + Range[m3]]] = -1;
op = ListLinePlot[output]h = (1/9)(1 - .4Cos[2 times]) * .9 ^ times;hmat = ToeplitzMatrix[h, Prepend[ConstantArray[0, n - 1], h[[1]]]];正則化なしでは,予測される応答は信号に非常に近くなるが,計算された信号は振動が多い:
{input, predicted} = Fit[{hmat, output}, {"BestFitParameters", "PredictedResponse"}];
Row[{ListLinePlot[input], ListLinePlot[{predicted, output}]}]{input, predicted} = Fit[{hmat, output}, {"BestFitParameters", "PredictedResponse"}, FitRegularization -> {"Variation", .3}];
Row[{ListLinePlot[input], ListLinePlot[{predicted, output}]}]{input, predicted} = Fit[{hmat, output}, {"BestFitParameters", "PredictedResponse"}, FitRegularization -> {{"Variation", .3}, {"Tikhonov", .01}}];
Row[{ListLinePlot[input], ListLinePlot[{predicted, output}]}]n = 4000;
times = N[Range[0, n - 1]];
original = .5 Sin[2 Pi times / n] * Sin[.01 times];
corrupted = original + RandomReal[{-.05, .05}, n];
ListLinePlot[corrupted]id = IdentityMatrix[n, SparseArray];tradeoff = Table[{smoothed, residual} = Fit[{id, corrupted}, {"BestFitParameters", "FitResiduals"}, FitRegularization -> {"Variation", 2 ^ logλ}];Tooltip[{Norm[Differences[smoothed]], Norm[residual]}, 2. ^ logλ], {logλ, -10, 20}];ListPlot[tradeoff, Joined -> True, Mesh -> All]smoothed = Fit[{id, corrupted}, "BestFitParameters", FitRegularization -> {"Variation", 100}];ListLinePlot[{corrupted, smoothed}]n = 2000;
id = IdentityMatrix[n, SparseArray];
times = Range[0, n - 1];
temp = ConstantArray[1, n / 4];
original = Join[temp, -temp, temp, -temp] + .5 Sin[2 Pi times / n];
corrupted = original + RandomReal[{-.1, .1}, n];
ListLinePlot[{corrupted, original}]smoothed = Fit[{id, corrupted}, "BestFitParameters", FitRegularization -> {"TotalVariation", 2.}];ListLinePlot[{smoothed, original}]
のより小さい値を使うとあまり滑らかではなくなるが,残差ノルムは小さくなる:
lesssmoothed = Fit[{id, corrupted}, "BestFitParameters", FitRegularization -> {"TotalVariation", .1}];ListLinePlot[{lesssmoothed, original}]{Norm[original - smoothed], Norm[original - lesssmoothed]}LASSO(L1)正則化を使って疎なフィットを求める(基底追跡):
σ = 0.05;
nτ = 500;
times = Subdivide[0., 1., nτ];
nω = 30;signal = (1 + .5 Sin[11 times])Sin[30 Sin[5 times]];
sdata = Transpose[{times, signal}];
ListLinePlot[sdata]目標は,何千ものガボール(Gabor)基底関数のほんの一部を使って信号を近似することである:
Length[basis = Flatten[
Table[Exp[-(((t - τ)/σ))^2]
{1, Table[{Cos[ω t], Sin[ω t]}, {ω, Drop[Subdivide[0., 150., nω], 1]}]},
{τ, Subdivide[0., 1., nτ]}]]]AbsoluteTiming[sparseFit = Fit[sdata, basis, t, "BestFitParameters", FitRegularization -> {"LASSO", 1.}]]fitt = basis.sparseFit /. t -> times;
ListLinePlot[Transpose[{times, signal - fitt}]]基底の重要な要素が求まったら,これらの要素の最小二乗フィットを求めることで誤差が削減できる:
bpos = Flatten[sparseFit["NonzeroPositions"]];
sbasis = basis[[bpos]];
sbfit = Fit[sdata, sbasis, t];
ListLinePlot[Transpose[{times, signal - (sbfit /. t -> times)}], PlotRange -> All]
というより小さい値を使うと,フィットを求めるためにより多くの基底要素が必要になる:
AbsoluteTiming[sparseFit = Fit[sdata, basis, t, "BestFitParameters", FitRegularization -> {"LASSO", 0.1}]]fitt = basis.sparseFit /. t -> times;
ListLinePlot[Transpose[{times, signal - fitt}]]テキスト
Wolfram Research (2019), FitRegularization, Wolfram言語関数, https://reference.wolfram.com/language/ref/FitRegularization.html.
CMS
Wolfram Language. 2019. "FitRegularization." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FitRegularization.html.
APA
Wolfram Language. (2019). FitRegularization. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FitRegularization.html
BibTeX
@misc{reference.wolfram_2026_fitregularization, author="Wolfram Research", title="{FitRegularization}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/FitRegularization.html}", note=[Accessed: 10-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_fitregularization, organization={Wolfram Research}, title={FitRegularization}, year={2019}, url={https://reference.wolfram.com/language/ref/FitRegularization.html}, note=[Accessed: 10-November-2026]}