[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Nonlinear Estimation with Optimize
From: |
etienne |
Subject: |
Re: Nonlinear Estimation with Optimize |
Date: |
Sat, 23 Aug 2008 19:35:46 -0700 (PDT) |
User-agent: |
SquirrelMail/1.4.13 |
Hi Thomas,
I just switched from lists (a historic data structure in octave) to cells in
the minimization backend used by "minimize", which is nelder_mead_min(). I
send you a replacement in attachment.
I also had to fix your function, because as you wrote it, it does not return
a scalar, but a vector and minimizing a vector is not what you want to do.
octave:103> function r = fit (a0, b, c), r = sum ((c -
[b.^2,b,ones(7,1)]*a0).^2); end
octave:111> x0 = [0,0,0]';
octave:112> t = [3.3598, 26.4377, 89.6760, 211.5766, 414.1391, 716.1501,
1128.1406 ]';
octave:113> s = 1000*(1:7)';
octave:114> [x,v,n] = minimize ("fit",{x0,s,t});
octave:115> x
x =
3.9283e-05
-1.3290e-01
1.1586e+02
octave:116> v
v = 2046.5
octave:117> n
n = 435
Check the result for correctness, because I have not.
I also note that your values in t & s are very big and the order of
magnitude of x's elements are very different. You may want to normalize
that:
octave:118> s2 = (1:7)'
s2 =
1
2
3
4
5
6
7
octave:119> t2 = [3.3598, 26.4377, 89.6760, 211.5766, 414.1391, 716.1501,
1128.1406 ]'/1000;
octave:123> [x2,v2,n2] = minimize ("fit",{x0,s2,t2});
octave:124> x2
x2 =
0.039283
-0.132897
0.115857
octave:125> v2
v2 = 0.0020465
octave:127> n2
n2 = 233
octave:128> x2 ./ [1e6; 1000; 1]
ans =
3.9283e-08
-1.3290e-04
1.1586e-01
octave:129> x
x =
3.9283e-05
-1.3290e-01
1.1586e+02
Ok, the two results look pretty much the same, normalization was not an
issue.
Hth,
Etienne
PS: I could not check my fixes in octave-forge, I forgot my password. I should
do that soon enough.
On Sat, August 23, 2008 14:34, Thomas D. Dean wrote:
# Octave 3.0.2
#
# I installed optim-1.0.3.tar.gz, and changed is_list() to islist() to
# remove a warning message. The files are:
# optim-1.0.3/minimize.m
# optim-1.0.3/d2_min.m
# optim-1.0.3/nelder_mead_min.m
#
# I have a problem with argument syntax. I think I need to use minimize()
# and pass a function that uses three arguments. I have a simplified
# example.
#
# Here is what I want to do (wrong?):
#
# t = [3.3598, 26.4377, 89.6760, 211.5766, 414.1391, ...
# 716.1501, 1128.1406 ]';
# for i=1:7
# s(i,1)=1000*i;
# end;
# ## I wanted to use s(i)=1000*i and then s=s'
# ## but, octave seemed to ignore that.
# x0=[0,0,0]';
# l={x0,s,t}; ## a list to pass to minimize
#
# function r = fit(l)
# a0=nth(l,1); b=nth(l,2); c=nth(l,3);
# r = c - [b.^2,b,ones(7,1)]*a0;
# end
#
# [x,v,n]=minimize("fit",l) ## I want to use fit(x0,s,t)
#
# What am I doing wrong?
#
# tomdean
#
# _______________________________________________
# Help-octave mailing list
# address@hidden
# https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
#
--
http://www.isr.ist.utl.pt/~etienne
nelder_mead_min.m
Description: Text Data