Prev: Need Google AdSense Account
Next: how to calculate diameter of the circle in a image from ccd camera?
From: Greig on 10 Aug 2010 03:10 I need some advice on a minimizing routine. I have two functions given by: func_DIST=@(E) lognpdf(E,log(kB.*T0), sigma); func_P=@(E) ((1./exp(1)).* ((E./(kB.*T)) + (1 - log(t.*f0)) ) ) .* func_DIST (E); I then calculate the following: Mfit=quadv(func_P,E1,E2)+quadv(func_DIST,E2,E3); Mfit=Mfit./Mfit(1); In all of this kB, and f0 are known scalars, and T, t, E1, E2, and E3 are known vectors of equal length. Ideally, E3 should be inf, but I think I can get away with a very large number and use quadv instead of looping quadgk. I want to find values for T0 and sigma that minimize: Err=sum( (M-Mfit).^2); Ultimately, I want to find the optimal values for T0, sigma and f0, but I want to start by looking at how T0 and sigma vary with set values of f0. I guess that using something like ‘fminunc’ or ‘fminsearch’ is the way forward, but I am not too sure about how to plug it all in. Some tips to get me started would be greatly appreciated. Cheers
From: Yi Cao on 10 Aug 2010 05:13 "Greig " <greig(a)abc.com> wrote in message <i3qu1d$mf3$1(a)fred.mathworks.com>... > I need some advice on a minimizing routine. I have two functions given by: > > func_DIST=@(E) lognpdf(E,log(kB.*T0), sigma); > > func_P=@(E) ((1./exp(1)).* ((E./(kB.*T)) + (1 - log(t.*f0)) ) ) .* func_DIST (E); > > I then calculate the following: > > Mfit=quadv(func_P,E1,E2)+quadv(func_DIST,E2,E3); > Mfit=Mfit./Mfit(1); > > In all of this kB, and f0 are known scalars, and T, t, E1, E2, and E3 are known vectors of equal length. Ideally, E3 should be inf, but I think I can get away with a very large number and use quadv instead of looping quadgk. > I want to find values for T0 and sigma that minimize: > > Err=sum( (M-Mfit).^2); > > Ultimately, I want to find the optimal values for T0, sigma and f0, but I want to start by looking at how T0 and sigma vary with set values of f0. > I guess that using something like ‘fminunc’ or ‘fminsearch’ is the way forward, but I am not too sure about how to plug it all in. Some tips to get me started would be greatly appreciated. Cheers According to your cost function, it is better to use lsqnonlin. It is very efficient to solve this kind problems. All you need is to provide a function to calculate the residuals. HTH Yi
From: Alan Weiss on 10 Aug 2010 08:35 If you have Optimization Toolbox, I recommend using lsqcurvefit or lsqnonlin. For an example of curve fitting, see http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4noo.html#brp3l6v-1 For a simplified example that does not use Optimization Toolbox, see http://www.mathworks.com/access/helpdesk/help/techdoc/math/bsgpq6p-12.html Alan Weiss MATLAB mathematical toolbox documentation On 8/10/2010 3:10 AM, Greig wrote: > I need some advice on a minimizing routine. I have two functions given by: > > func_DIST=@(E) lognpdf(E,log(kB.*T0), sigma); > func_P=@(E) ((1./exp(1)).* ((E./(kB.*T)) + (1 - log(t.*f0)) ) ) .* > func_DIST (E); > > I then calculate the following: > > Mfit=quadv(func_P,E1,E2)+quadv(func_DIST,E2,E3); > Mfit=Mfit./Mfit(1); > > In all of this kB, and f0 are known scalars, and T, t, E1, E2, and E3 > are known vectors of equal length. Ideally, E3 should be inf, but I > think I can get away with a very large number and use quadv instead of > looping quadgk. > I want to find values for T0 and sigma that minimize: > > Err=sum( (M-Mfit).^2); > > Ultimately, I want to find the optimal values for T0, sigma and f0, but > I want to start by looking at how T0 and sigma vary with set values of f0. > I guess that using something like ‘fminunc’ or > ‘fminsearch’ is the way forward, but I am not too sure about > how to plug it all in. Some tips to get me started would be greatly > appreciated. Cheers
From: Greig on 11 Aug 2010 22:41
Hi, Thanks for the advice. I've used fminsearchbnd to optimize the parameters so I can put boundaries on sigma and T0 (both >0). The fit is OK, but not great... I guess it's time to tweak the model. Cheers Alan Weiss <aweiss(a)mathworks.com> wrote in message <i3rh2f$jib$1(a)fred.mathworks.com>... > If you have Optimization Toolbox, I recommend using lsqcurvefit or > lsqnonlin. For an example of curve fitting, see > http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4noo.html#brp3l6v-1 > > For a simplified example that does not use Optimization Toolbox, see > http://www.mathworks.com/access/helpdesk/help/techdoc/math/bsgpq6p-12.html > > Alan Weiss > MATLAB mathematical toolbox documentation > > On 8/10/2010 3:10 AM, Greig wrote: > > I need some advice on a minimizing routine. I have two functions given by: > > > > func_DIST=@(E) lognpdf(E,log(kB.*T0), sigma); > > func_P=@(E) ((1./exp(1)).* ((E./(kB.*T)) + (1 - log(t.*f0)) ) ) .* > > func_DIST (E); > > > > I then calculate the following: > > > > Mfit=quadv(func_P,E1,E2)+quadv(func_DIST,E2,E3); > > Mfit=Mfit./Mfit(1); > > > > In all of this kB, and f0 are known scalars, and T, t, E1, E2, and E3 > > are known vectors of equal length. Ideally, E3 should be inf, but I > > think I can get away with a very large number and use quadv instead of > > looping quadgk. > > I want to find values for T0 and sigma that minimize: > > > > Err=sum( (M-Mfit).^2); > > > > Ultimately, I want to find the optimal values for T0, sigma and f0, but > > I want to start by looking at how T0 and sigma vary with set values of f0. > > I guess that using something like ‘fminunc’ or > > ‘fminsearch’ is the way forward, but I am not too sure about > > how to plug it all in. Some tips to get me started would be greatly > > appreciated. Cheers |