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)
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]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}]}]如果使用 variation 正则化,可求出更加平滑的近似结果:
{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}]使用 total variation 正则化平滑带有跳变的损坏信号:
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]}σ = 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]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 语言. 2019. "FitRegularization." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/FitRegularization.html.
APA
Wolfram 语言. (2019). FitRegularization. Wolfram 语言与系统参考资料中心. 追溯自 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: 15-September-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: 15-September-2026]}