#include <linlsq.h>
Used to hold gradient of line fit
Definition at line 35 of file linlsq.h.
LLSQ::LLSQ | ( | ) | [inline] |
void LLSQ::add | ( | double | x, | |
double | y | |||
) |
Add an element to the accumulator.
Definition at line 57 of file linlsq.cpp.
References n, sigx, sigxx, sigxy, sigy, and sigyy.
Referenced by PDLSQ::add(), and WERD::baseline_normalise_x().
00060 { 00061 n++; //count elements 00062 sigx += x; //update accumulators 00063 sigy += y; 00064 sigxx += x * x; 00065 sigxy += x * y; 00066 sigyy += y * y; 00067 }
double LLSQ::c | ( | double | m | ) |
void LLSQ::clear | ( | ) |
Function to initialize a LLSQ.
Definition at line 44 of file linlsq.cpp.
References n, sigx, sigxx, sigxy, sigy, and sigyy.
Referenced by PDLSQ::clear(), and LLSQ().
00044 { //initialize 00045 n = 0; //no elements 00046 sigx = 0; //update accumulators 00047 sigy = 0; 00048 sigxx = 0; 00049 sigxy = 0; 00050 sigyy = 0; 00051 }
INT32 LLSQ::count | ( | ) | [inline] |
Definition at line 51 of file linlsq.h.
References n.
Referenced by WERD::baseline_normalise_x(), and PDLSQ::count().
00051 { //no of elements 00052 return n; 00053 }
double LLSQ::m | ( | ) |
Get gradient
Return the gradient of the line fit.
Definition at line 94 of file linlsq.cpp.
References n, sigx, sigxx, sigxy, and sigy.
Referenced by WERD::baseline_normalise_x().
00094 { //get gradient 00095 if (n > 1) 00096 return (sigxy - sigx * sigy / n) / (sigxx - sigx * sigx / n); 00097 else 00098 return 0; //too little 00099 }
void LLSQ::remove | ( | double | x, | |
double | y | |||
) |
Delete an element from the acculuator.
Definition at line 73 of file linlsq.cpp.
References ABORT, EMPTY_LLSQ, ERRCODE::error(), n, NULL, sigx, sigxx, sigxy, sigy, and sigyy.
Referenced by PDLSQ::remove().
00076 { 00077 if (n <= 0) 00078 //illegal 00079 EMPTY_LLSQ.error ("LLSQ::remove", ABORT, NULL); 00080 n--; //count elements 00081 sigx -= x; //update accumulators 00082 sigy -= y; 00083 sigxx -= x * x; 00084 sigxy -= x * y; 00085 sigyy -= y * y; 00086 }
double LLSQ::rms | ( | double | m, | |
double | c | |||
) |
Get Error
Return the rms error of the fit.
Definition at line 122 of file linlsq.cpp.
References n, sigx, sigxx, sigxy, sigy, and sigyy.
00125 { 00126 double error; //total error 00127 00128 if (n > 0) { 00129 error = 00130 sigyy + m * (m * sigxx + 2 * (c * sigx - sigxy)) + c * (n * c - 00131 2 * sigy); 00132 if (error >= 0) 00133 error = sqrt (error / n); //sqrt of mean 00134 else 00135 error = 0; 00136 } 00137 else 00138 error = 0; //too little 00139 return error; 00140 }
double LLSQ::spearman | ( | ) |
Get error
Return the spearman correlation coefficient.
Definition at line 148 of file linlsq.cpp.
References n, sigx, sigxx, sigxy, sigy, and sigyy.
00148 { //get error 00149 double error; //total error 00150 00151 if (n > 1) { 00152 error = (sigxx - sigx * sigx / n) * (sigyy - sigy * sigy / n); 00153 if (error > 0) { 00154 error = (sigxy - sigx * sigy / n) / sqrt (error); 00155 } 00156 else 00157 error = 1; 00158 } 00159 else 00160 error = 1; //too little 00161 return error; 00162 }
double LLSQ::sigx [private] |
Definition at line 65 of file linlsq.h.
Referenced by add(), c(), clear(), PDLSQ::fit(), m(), remove(), rms(), and spearman().
double LLSQ::sigxx [private] |
Definition at line 67 of file linlsq.h.
Referenced by add(), clear(), PDLSQ::fit(), m(), remove(), rms(), and spearman().
double LLSQ::sigxy [private] |
Definition at line 68 of file linlsq.h.
Referenced by add(), clear(), PDLSQ::fit(), m(), remove(), rms(), and spearman().
double LLSQ::sigy [private] |
Definition at line 66 of file linlsq.h.
Referenced by add(), c(), clear(), PDLSQ::fit(), m(), remove(), rms(), and spearman().
double LLSQ::sigyy [private] |
Definition at line 69 of file linlsq.h.
Referenced by add(), clear(), PDLSQ::fit(), remove(), rms(), and spearman().