Skip to main content
added 461 characters in body
Source Link
VladM
  • 93
  • 7

I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[[i]]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use. Example:

data = Array[{Random[], Random[]} &, 8];
function[x_] := a1*x + a2*x^2 + a3*x^3 + a4*x^4;

FindFit[data, function[x], {a1, a2, a3, a4}, x]

{a1 -> 4.5591977, a2 -> -14.980712, a3 -> 19.958318, a4 -> -9.0979829}

g[a_] := Sum[a[[i]]*10^(4 - i), {i, 1, 4}];

FindFit[data, function[x], {a1, a2, a3, a4}, x, 
 FitRegularization -> g]

FindFit::bdfitreg: The fit regularization g should be a function or named regularization.


I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[[i]]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use.

I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[[i]]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use. Example:

data = Array[{Random[], Random[]} &, 8];
function[x_] := a1*x + a2*x^2 + a3*x^3 + a4*x^4;

FindFit[data, function[x], {a1, a2, a3, a4}, x]

{a1 -> 4.5591977, a2 -> -14.980712, a3 -> 19.958318, a4 -> -9.0979829}

g[a_] := Sum[a[[i]]*10^(4 - i), {i, 1, 4}];

FindFit[data, function[x], {a1, a2, a3, a4}, x, 
 FitRegularization -> g]

FindFit::bdfitreg: The fit regularization g should be a function or named regularization.


added 2 characters in body
Source Link
VladM
  • 93
  • 7

I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[i]*10^=Sum[a[[i]]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use.

I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[i]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use.

I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[[i]]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use.

Source Link
VladM
  • 93
  • 7

FitRegularization with a user function

I am trying to use FindFit with a user-defined function g[a] for FitRegularizaton as specified in the document. Say, I have parameters a1,a2,a3,a4 and define g[a] as

g[a_]:=Sum[a[i]*10^(4-i),{i,1,4}]

i.e. I want the parameters of the fit to decrease as powers of 10. However, when I write

FindFit[data,function,{a1,a2,a3,a4},x,FitRegularization->g],

I get the error FindFit: The fit regularization g should be a function or named regularization.

What is the correct way of writing it? I tried "g" instead of g and other variants, it is not working. I also can not find any examples of its use.