Forum > TAChart

regression testing with gnu

(1/2) > >>

flori:
hi!
I got gnuplot_laz from WP. I am very grateful! :)
I tried Simple Linear Regression on gnuplot. I calculated R2 which I put on the linear.png

Does anyone know how  can I show png on TImage  on the TForm? How to display in real time? (beacuse just export to folder)
has anyone tried this before?
watch demo

Thanks


Thaddy:
LoadFromFile? Or LoadFromStream?

wp:
It's already prepared in the GnuplotSettings. The output is written to the GnuplotSettings.OutputFilename. This filename is hard-coded in your gnuplot script (set output 'linear.png'). Therefore, you should set GnuplotSettings.outputFileName := 'linear.png'. You can do this in the OnCreate handler of the form.

There are other issues, though:

* In your program the script is defined in the memo. The memo, however, has word-wrap on. Therefore, long lines are wrapped into multiple lines, and gnuplot gets confused. Simply set the memo's WordWrap to false and turn on the memo's Scrollbars.
* The gnuplot text output was originally thought to be an error message only (FCmdThreadErrMsg). However, you catch the calculation results in it. That's fine, but it's not an error message any more. Look at TMainform.CmdThreadTerminate. The image is loaded only if (FCmdThread.Runner.ExitStatus = 0) and (FCmdThreadErrMsg = ''). FCmdThreadErrMsg, however, is the gnuplot text output and is not empty. So simply remove this condition from the "if" and the program should work.
* There is one final, less important, issue: the plot does not look very nicely. Your script defines the plot file to have the size 1024x746, which does not match the values in the GnuPlotSettings. Therefore the large png file is scaled down to the smaller TImage size defined by the GnuPlotSettings, which degrades quality because of the thin drawing lines. Set GnuPlotSettings.OutputWidth to 1024 and GnuPlotSettings.OutputHeight to 746, and the plot should be okI am attaching a modified version of the program which contains all these changes.

When I comes to linear fitting only, you can do the same job even with the TAChart package which comes with Lazarus. In this case you can even create an interactive chart with zooming and panning etc. Just add a TFitSeries to the chart, and set its "FitEquation" to feLinear - that's all. If you need the fit parameters you can query them from the Param[index] property, and you get statistics on fit quality etc in the FitStatistics record. See https://wiki.lazarus.freepascal.org/TAChart_documentation#Fit_series and the extensive demo program in folder components/tachart/demo/fit of your Lazarus installation.

[EDIT]
I am attaching also a TAChart version of the fit. Note, however, that TAChart can only do linear (or linearizable) fits. If you need a non-linear fit you'll be back with gnuplot.

flori:
Thank you.  :)
I can only see it now.. before I just tested other data. I used y (log10). I just tried.
All the best

Its also non linear model !

wp:
Is this a question?

y = a exp (b*x) is not linear, but after taking the log on both sides, log(y) = log(a) + b*x, and replacing log(y) by Y and log(y) by A , it becomes linear: Y = A + b*x. - That's what I meant with "linearizable".

There is not need to calculate the logs yourself. The fit series has the exponential fit as an option in the property FitEquation. And to get the log axis you can add the logarithmic axis transformation to the chart. There is a tutorial about exponential fitting and log axis: https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_ListChartSource,_Logarithmic_Axis,_Fitting. Ask again if you do not get the log axis right.

Navigation

[0] Message Index

[#] Next page

Go to full version