|
From: Guilherme P. <gpo...@gm...> - 2010-02-23 04:25:20
|
Hi! I am a new user of gnuplot and my version is 4.2 patchlevel 6. I'm having a trouble with "fit" function when I use xdata time as X axis values. Here my script and data set. # watthour.gnu # =========== < cut here reset set terminal png size 800,500 font comic 12 enhanced truecolor set output "watthour.png" set xdata time set timefmt "%Y/%m/%d %H:%M" set label "Powered by GnuPlot 4.2" at graph 0.87,-1.7 center font "lhandw,10" textcolor rgb "#800080" show label set key below left vertical title "Variables" set border 3 set xtics rotate by 45 offset graph -0.075,-0.30 textcolor rgb "#008000" nomirror set ytics nomirror textcolor rgb "#008000" nomirror set format x "%d%b %Hh" set format x "%N" set format y "%6.1f" set xtics 86400 set ytics 2 set mxtics 12 set mytics 5 f(x)=a + b*x fit f(x) "watthour.txt" using 1:4 via a,b set title "Kilowatts - 2010\n Fit Model: f(t) = a + b.t " font "comic, 12" textcolor rgb "#800080" plot f(x) t"Projection" with lines 2, "watthour.txt" using 1:4 t "KWh" with points 3 # =========== < cut here # watthour.txt # =========== < cut here #YYYY MM DD hh mm U KWh 2010/02/19 23:36 3 22835.1 2010/02/20 08:05 3 22839.0 2010/02/20 10:32 3 22839.8 2010/02/20 11:32 3 22840.1 2010/02/20 12:49 3 22840.8 2010/02/20 23:28 3 22845.5 2010/02/21 01:40 3 22846.8 2010/02/21 13:45 3 22851.5 2010/02/21 22:09 3 22855.6 2010/02/22 18:06 3 22864.5 2010/02/22 22:14 3 22866.0 # =========== < cut here I believe that are a problem with "fit" function when I use xdata time, because X values are converted to second since 2000/01/01 ( I think! ) and this number get big compared to Y values... the algorith to "fit" the data to the model has some dificulties with this. The curve not pass near of the points, of course, it not pass over them, but should be pass so near because it is a adjustment with "least squares"!! My data set file don't have outliers to cause the problem that I report here. I tried do some tests with this same data, changing time near year 2000 and the fit curv was diferent, but it curve should be the same angular coeficient. Is it a bug or I'm commiting a mistake. Thank you very much! __________________________________ Guilherme Poleszuk dos Santos Rosa São Paulo, Brazil |
|
From: Thomas S. <t.s...@fz...> - 2010-02-23 11:59:17
|
just set the 'origin' of the fit in the middle of your time data:
toffset=strptime("%Y/%m/%d %H:%M","2010/02/20 23:28")
f(x)=a + b*(x-toffset)
fit f(x) "watthour.txt" using 1:4 via a,b
so that 'a' and 'b' are not influencing each other.
Guilherme Poleszuk wrote:
>
> Hi!
>
> I am a new user of gnuplot and my version is 4.2 patchlevel 6. I'm having
> a
> trouble with "fit" function when I use xdata time as X axis values. Here
> my
> script and data set.
>
> # watthour.gnu
> # =========== < cut here
> reset
> set terminal png size 800,500 font comic 12 enhanced truecolor
> set output "watthour.png"
> set xdata time
> set timefmt "%Y/%m/%d %H:%M"
> set label "Powered by GnuPlot 4.2" at graph 0.87,-1.7 center font
> "lhandw,10"
> textcolor rgb "#800080"
> show label
> set key below left vertical title "Variables"
> set border 3
> set xtics rotate by 45 offset graph -0.075,-0.30 textcolor rgb "#008000"
> nomirror
> set ytics nomirror textcolor rgb "#008000" nomirror
> set format x "%d%b %Hh"
> set format x "%N"
> set format y "%6.1f"
> set xtics 86400
> set ytics 2
> set mxtics 12
> set mytics 5
> f(x)=a + b*x
> fit f(x) "watthour.txt" using 1:4 via a,b
> set title "Kilowatts - 2010\n Fit Model: f(t) = a + b.t " font "comic, 12"
> textcolor rgb "#800080"
> plot f(x) t"Projection" with lines 2, "watthour.txt" using 1:4 t "KWh"
> with
> points 3
> # =========== < cut here
>
>
>
> # watthour.txt
> # =========== < cut here
> #YYYY MM DD hh mm U KWh
> 2010/02/19 23:36 3 22835.1
> 2010/02/20 08:05 3 22839.0
> 2010/02/20 10:32 3 22839.8
> 2010/02/20 11:32 3 22840.1
> 2010/02/20 12:49 3 22840.8
> 2010/02/20 23:28 3 22845.5
> 2010/02/21 01:40 3 22846.8
> 2010/02/21 13:45 3 22851.5
> 2010/02/21 22:09 3 22855.6
> 2010/02/22 18:06 3 22864.5
> 2010/02/22 22:14 3 22866.0
> # =========== < cut here
>
>
>
> I believe that are a problem with "fit" function when I use xdata time,
> because X values are converted to second since 2000/01/01 ( I think! ) and
> this number get big compared to Y values... the algorith to "fit" the data
> to
> the model has some dificulties with this. The curve not pass near of the
> points, of course, it not pass over them, but should be pass so near
> because
> it is a adjustment with "least squares"!! My data set file don't have
> outliers
> to cause the problem that I report here.
>
> I tried do some tests with this same data, changing time near year 2000
> and
> the fit curv was diferent, but it curve should be the same angular
> coeficient.
> Is it a bug or I'm commiting a mistake.
>
> Thank you very much!
>
> __________________________________
> Guilherme Poleszuk dos Santos Rosa
> São Paulo, Brazil
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> gnuplot-info mailing list
> gnu...@li...
> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>
>
--
View this message in context: http://old.nabble.com/Fit-trouble-when-I-use-xdata-time-%28fit-isn%27t-so-good%29-tp27698343p27702229.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|
|
From: GPS <gpo...@gm...> - 2010-02-23 14:30:15
|
Hi Mr Thomas
Thank you very much for help me. Your tip helps a lot!
Have a very nice day!
__________________________________
Guilherme Poleszuk dos Santos Rosa
2010/2/23 Thomas Sefzick <t.s...@fz...>
>
> just set the 'origin' of the fit in the middle of your time data:
>
> toffset=strptime("%Y/%m/%d %H:%M","2010/02/20 23:28")
> f(x)=a + b*(x-toffset)
> fit f(x) "watthour.txt" using 1:4 via a,b
>
> so that 'a' and 'b' are not influencing each other.
>
>
> Guilherme Poleszuk wrote:
> >
> > Hi!
> >
> > I am a new user of gnuplot and my version is 4.2 patchlevel 6. I'm having
> > a
> > trouble with "fit" function when I use xdata time as X axis values. Here
> > my
> > script and data set.
> >
> > # watthour.gnu
> > # =========== < cut here
> > reset
> > set terminal png size 800,500 font comic 12 enhanced truecolor
> > set output "watthour.png"
> > set xdata time
> > set timefmt "%Y/%m/%d %H:%M"
> > set label "Powered by GnuPlot 4.2" at graph 0.87,-1.7 center font
> > "lhandw,10"
> > textcolor rgb "#800080"
> > show label
> > set key below left vertical title "Variables"
> > set border 3
> > set xtics rotate by 45 offset graph -0.075,-0.30 textcolor rgb "#008000"
> > nomirror
> > set ytics nomirror textcolor rgb "#008000" nomirror
> > set format x "%d%b %Hh"
> > set format x "%N"
> > set format y "%6.1f"
> > set xtics 86400
> > set ytics 2
> > set mxtics 12
> > set mytics 5
> > f(x)=a + b*x
> > fit f(x) "watthour.txt" using 1:4 via a,b
> > set title "Kilowatts - 2010\n Fit Model: f(t) = a + b.t " font "comic,
> 12"
> > textcolor rgb "#800080"
> > plot f(x) t"Projection" with lines 2, "watthour.txt" using 1:4 t "KWh"
> > with
> > points 3
> > # =========== < cut here
> >
> >
> >
> > # watthour.txt
> > # =========== < cut here
> > #YYYY MM DD hh mm U KWh
> > 2010/02/19 23:36 3 22835.1
> > 2010/02/20 08:05 3 22839.0
> > 2010/02/20 10:32 3 22839.8
> > 2010/02/20 11:32 3 22840.1
> > 2010/02/20 12:49 3 22840.8
> > 2010/02/20 23:28 3 22845.5
> > 2010/02/21 01:40 3 22846.8
> > 2010/02/21 13:45 3 22851.5
> > 2010/02/21 22:09 3 22855.6
> > 2010/02/22 18:06 3 22864.5
> > 2010/02/22 22:14 3 22866.0
> > # =========== < cut here
> >
> >
> >
> > I believe that are a problem with "fit" function when I use xdata time,
> > because X values are converted to second since 2000/01/01 ( I think! )
> and
> > this number get big compared to Y values... the algorith to "fit" the
> data
> > to
> > the model has some dificulties with this. The curve not pass near of the
> > points, of course, it not pass over them, but should be pass so near
> > because
> > it is a adjustment with "least squares"!! My data set file don't have
> > outliers
> > to cause the problem that I report here.
> >
> > I tried do some tests with this same data, changing time near year 2000
> > and
> > the fit curv was diferent, but it curve should be the same angular
> > coeficient.
> > Is it a bug or I'm commiting a mistake.
> >
> > Thank you very much!
> >
> > __________________________________
> > Guilherme Poleszuk dos Santos Rosa
> > São Paulo, Brazil
> >
> >
> >
> ------------------------------------------------------------------------------
> > Download Intel® Parallel Studio Eval
> > Try the new software tools for yourself. Speed compiling, find bugs
> > proactively, and fine-tune applications for parallel performance.
> > See why Intel Parallel Studio got high marks during beta.
> > http://p.sf.net/sfu/intel-sw-dev
> > _______________________________________________
> > gnuplot-info mailing list
> > gnu...@li...
> > https://lists.sourceforge.net/lists/listinfo/gnuplot-info
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Fit-trouble-when-I-use-xdata-time-%28fit-isn%27t-so-good%29-tp27698343p27702229.html
> Sent from the Gnuplot - User mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> gnuplot-info mailing list
> gnu...@li...
> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>
|
|
From: Hans-Bernhard B. <HBB...@t-...> - 2010-02-23 23:20:30
|
Guilherme Poleszuk wrote: > I believe that are a problem with "fit" function when I use xdata time, > because X values are converted to second since 2000/01/01 ( I think! ) and > this number get big compared to Y values... Exactly. Fit is somewhat allergic to parameter values of wildly different magnitude. The issue is not unique to time-date axes, but those do have a tendency to get hit by it more often than others because they tend to pick up big figures, like the number of seconds in a day (or a year, even), as factors that end up in the parameters. The solution is to shift or scale the problem to get the expected parameters into similar magnitude ranges. E.g. it might help to define your model function to take days instead of seconds as its argument fit f(x/86400) 'data' u 1:4 via a, b or (like Thomas suggested already), shift the zero point of your x axis. Note that the usual simple forms of the straight line equation y = m*x + y0 y = m*(x -x0) may suffer from ginormous extrapolation from a very short piece of curve all the way to the point of x=0 (or y=0), causing parameters like x0 or y0 to be entirely dominated by rounding error. |
|
From: GPS <gpo...@gm...> - 2010-02-24 02:34:00
|
Hi Mr. Hans-Bernhard! Your explanation is very interesting and it should be appear in the next edition of "Gnuplot in action" book as well the explaning that Mr. Thomas posted about this issue. Those tips explained what was my problem.... thank you very much!!! I'm using the Thomas' suggest but think in a scale factor is interesting too... As we brazilian sometimes say: "Living and learning", for today I learn a bit more with you. Thanks again!! Sorry my english :| __________________________________ Guilherme Poleszuk dos Santos Rosa 2010/2/23 Hans-Bernhard Bröker <HBB...@t-...> > Guilherme Poleszuk wrote: > > I believe that are a problem with "fit" function when I use xdata time, >> because X values are converted to second since 2000/01/01 ( I think! ) and >> this number get big compared to Y values... >> > > Exactly. Fit is somewhat allergic to parameter values of wildly different > magnitude. The issue is not unique to time-date axes, but those do have a > tendency to get hit by it more often than others because they tend to pick > up big figures, like the number of seconds in a day (or a year, even), as > factors that end up in the parameters. > > The solution is to shift or scale the problem to get the expected > parameters into similar magnitude ranges. E.g. it might help to define your > model function to take days instead of seconds as its argument > > fit f(x/86400) 'data' u 1:4 via a, b > > or (like Thomas suggested already), shift the zero point of your x axis. > > Note that the usual simple forms of the straight line equation > > y = m*x + y0 > y = m*(x -x0) > > may suffer from ginormous extrapolation from a very short piece of curve > all the way to the point of x=0 (or y=0), causing parameters like x0 or y0 > to be entirely dominated by rounding error. > > > |