summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex')
-rw-r--r--graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex113
1 files changed, 76 insertions, 37 deletions
diff --git a/graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex b/graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex
index c169f730d4..f8f2888305 100644
--- a/graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex
+++ b/graphics/pgf/contrib/pgfplots/tex/pgfplotstable.code.tex
@@ -675,6 +675,10 @@
/pgfplots/table/create col/linear regression/variance/.initial=,%
/pgfplots/table/create col/linear regression/variance list/.initial=,%
/pgfplots/table/create col/linear regression/variance src/.initial=,%
+ /pgfplots/table/create col/linear regression/variance format/.is choice,%
+ /pgfplots/table/create col/linear regression/variance format/linear/.code={\def\pgfplotstable@regression@variance@format{l}},%
+ /pgfplots/table/create col/linear regression/variance format/log/.code={\def\pgfplotstable@regression@variance@format{m}},%
+ /pgfplots/table/create col/linear regression/variance format/log,%
/pgfplots/table/create col/linear regression/xmode/.initial=,% auto
/pgfplots/table/create col/linear regression/ymode/.initial=,% auto
/pgfplots/table/create col/quotient/.style={%
@@ -2789,48 +2793,83 @@
\pgfplotslistpopfront\pgfplotstable@X\to\pgfplotstable@x
\pgfplotslistpopfront\pgfplotstable@Y\to\pgfplotstable@y
%
- \pgfplotstableparsex{\pgfplotstable@x}%
- \let\pgfplotstable@x=\pgfmathresult
- \expandafter\pgfplotslistpushback\pgfmathresult\to\pgfplotstable@Xparsed
- \pgfplotstableparsey{\pgfplotstable@y}%
- \let\pgfplotstable@y=\pgfmathresult
- %
- \pgfplotslistcheckempty\pgfplotstable@VARIANCE
- \ifpgfplotslistempty
- \pgfmathfloatcreate{1}{1.0}{0}%
- \let\pgfplotstable@invsqr=\pgfmathresult
+ % if either the x or y entry is empty, skip this point
+ \ifx\pgfplotstable@x\pgfutil@empty
+ \else\ifx\pgfplotstable@y\pgfutil@empty
\else
- \pgfplotslistpopfront\pgfplotstable@VARIANCE\to\pgfplotstable@variance
- \pgfmathfloatparsenumber{\pgfplotstable@variance}%
- \let\pgfplotstable@variance=\pgfmathresult
+ \pgfplotstableparsex{\pgfplotstable@x}%
+ \let\pgfplotstable@x=\pgfmathresult
+ \expandafter\pgfplotslistpushback\pgfmathresult\to\pgfplotstable@Xparsed
+ \pgfplotstableparsey{\pgfplotstable@y}%
+ \let\pgfplotstable@y=\pgfmathresult
+ %
+ \pgfplotslistcheckempty\pgfplotstable@VARIANCE
+ \ifpgfplotslistempty
+ \pgfmathfloatcreate{1}{1.0}{0}%
+ \let\pgfplotstable@variance=\pgfmathresult
+ \else
+ \pgfplotslistpopfront\pgfplotstable@VARIANCE\to\pgfplotstable@variance
+ \pgfmathfloatparsenumber{\pgfplotstable@variance}%
+ \let\pgfplotstable@variance=\pgfmathresult
+ \fi
+ %
+ % if we're in y log mode, then instead of y +- dy, we have log_b(y +- dy)
+ % which Taylor expands to log_b(y) +- dy/(y ln(b)) + O(dy^2)
+ % However, this might introduce a division-by-zero in the exceptional case
+ % where b=1 or log_b(0) = -infinity, so instead of computing 1/(dy/(y ln b))^2
+ % we will compute (y ln b)^2*1/dy^2. Note that we don't factor out the ^2
+ % because floating point operations don't commute and the historical behavior
+ % was to compute 1/dy^2.
+ %
\pgfmathfloatmultiply@{\pgfplotstable@variance}{\pgfplotstable@variance}%
\let\pgfplotstable@sqr=\pgfmathresult
\pgfmathfloatreciprocal@{\pgfplotstable@sqr}%
\let\pgfplotstable@invsqr=\pgfmathresult
- \fi
- %
- \pgfmathfloatadd@{\pgfplotstable@S}{\pgfplotstable@invsqr}%
- \let\pgfplotstable@S=\pgfmathresult
- %
- \pgfmathfloatmultiply@{\pgfplotstable@x}{\pgfplotstable@invsqr}%
- \let\pgfplots@table@accum=\pgfmathresult
- \pgfmathfloatadd@{\pgfplotstable@Sx}{\pgfplots@table@accum}%
- \let\pgfplotstable@Sx=\pgfmathresult
- %
- \pgfmathfloatmultiply@{\pgfplotstable@x}{\pgfplots@table@accum}%
- \let\pgfplots@table@accum=\pgfmathresult
- \pgfmathfloatadd@{\pgfplotstable@Sxx}{\pgfplots@table@accum}%
- \let\pgfplotstable@Sxx=\pgfmathresult
- %
- \pgfmathfloatmultiply@{\pgfplotstable@y}{\pgfplotstable@invsqr}%
- \let\pgfplots@table@accum=\pgfmathresult
- \pgfmathfloatadd@{\pgfplotstable@Sy}{\pgfplots@table@accum}%
- \let\pgfplotstable@Sy=\pgfmathresult
- %
- \pgfmathfloatmultiply@{\pgfplotstable@x}{\pgfplots@table@accum}%
- \let\pgfplots@table@accum=\pgfmathresult
- \pgfmathfloatadd@{\pgfplotstable@Sxy}{\pgfplots@table@accum}%
- \let\pgfplotstable@Sxy=\pgfmathresult
+ \ifx\pgfplotstableparseylogbase\pgfutil@empty
+ \else
+ \if m\pgfplotstable@regression@variance@format
+ % variance format=log
+ \else
+ % variance format=linear
+ % N.B. at this point, \pgfplotstable@invsqr, \pgfplotstable@sqr, and \pgfplotstable@variance are
+ % all missing log-scaling. We update \pgfplotstable@invsqr now, but leave \pgfplotstable@sqr
+ % and \pgfplotstable@variance alone because they are not used below this point.
+ \pgfplotstableparseyinv@{\pgfplotstable@y}% y
+ \let\pgfplotstable@tmp=\pgfmathresult
+ \pgfmathfloatmultiply@{\pgfplotstable@tmp}{\pgfplotstableparseylogofbasefloat}% y * ln(b)
+ \let\pgfplotstable@ylnb=\pgfmathresult
+ \pgfmathfloatmultiply@{\pgfplotstable@ylnb}{\pgfplotstable@ylnb}% (y * ln(b))^2
+ \let\pgfplotstable@ylnbsqr=\pgfmathresult
+ % since \pgfplotstable@invsqr is used, but \pgfplotstable@sqr and \pgfplotstable@variance are not
+ % we only need to update \pgfplotstable@invsqr
+ \pgfmathfloatmultiply@{\pgfplotstable@invsqr}{\pgfplotstable@ylnbsqr}% (y * ln(b))^2 / dy^2
+ \let\pgfplotstable@invsqr=\pgfmathresult
+ \fi
+ \fi
+ %
+ \pgfmathfloatadd@{\pgfplotstable@S}{\pgfplotstable@invsqr}%
+ \let\pgfplotstable@S=\pgfmathresult
+ %
+ \pgfmathfloatmultiply@{\pgfplotstable@x}{\pgfplotstable@invsqr}%
+ \let\pgfplots@table@accum=\pgfmathresult
+ \pgfmathfloatadd@{\pgfplotstable@Sx}{\pgfplots@table@accum}%
+ \let\pgfplotstable@Sx=\pgfmathresult
+ %
+ \pgfmathfloatmultiply@{\pgfplotstable@x}{\pgfplots@table@accum}%
+ \let\pgfplots@table@accum=\pgfmathresult
+ \pgfmathfloatadd@{\pgfplotstable@Sxx}{\pgfplots@table@accum}%
+ \let\pgfplotstable@Sxx=\pgfmathresult
+ %
+ \pgfmathfloatmultiply@{\pgfplotstable@y}{\pgfplotstable@invsqr}%
+ \let\pgfplots@table@accum=\pgfmathresult
+ \pgfmathfloatadd@{\pgfplotstable@Sy}{\pgfplots@table@accum}%
+ \let\pgfplotstable@Sy=\pgfmathresult
+ %
+ \pgfmathfloatmultiply@{\pgfplotstable@x}{\pgfplots@table@accum}%
+ \let\pgfplots@table@accum=\pgfmathresult
+ \pgfmathfloatadd@{\pgfplotstable@Sxy}{\pgfplots@table@accum}%
+ \let\pgfplotstable@Sxy=\pgfmathresult
+ \fi\fi
\pgfutil@repeat
%
\pgfmathparse{\pgfplotstable@S * \pgfplotstable@Sxx - \pgfplotstable@Sx *\pgfplotstable@Sx}%