deriveExtCPParameters established Initial parameters estimates before
the data verification steps so when data don't meet the minimum
criteria for estimation those initial parameters are returned.
This change moves the initialization step after data verification,
similar to what deriveCPParameters does for the envelope fitting case.
Fixes#3862
.. lm(formula, xlist, ylist) - fits a formula to the x,y data using
the levenberg-marquardt OLS algorithm.
the formula is expressed as any other expression and the starting
values must be set beforehand- this is also reinforced by the fact
the parameters must exist before the formula is declared.
the fit returns a vector [ success, RMSE, CV).
.. an example, to fit the morton 3p model to meanmax would be:
# fetch mmp data
mmp <- meanmax(POWER);
secs <- seq(1,length(mmp),1);
# set starting values, then fit Morton 3p to first 20 min data
cp <- 200; W<-11000; pmax <- 1000;
fit <- lm((W / (x - (W/(cp-pmax)))) + cp,
head(secs,1200),
head(mmp,1200));
.. along the way I needed to refactor the way lmfit is managed and
also corrected banister to avoid threading issues.
.. also snuck in a sqrt() function as needed for testing and was
rather an egregious oversight.
.. add option to apply a decay factor to CP and W' when plotting
the model curve in CP Plot.
.. since we always fit to observations <20mins the mostly submax
points at longer durations in the general population do not
impact the fit at all.
.. the decay factors for w' and cp have been fit to the results of:
Effects of Two Hours of Heavy-Intensity Exercise on the Power-
Duration Relationship
Clark IE, Vanhatalo A, Bailey SJ, Wylie LJ, Kirby BS, Wilkins BW,
Jones AM.
https://europepmc.org/abstract/med/29521722
.. using analysis from the opendata proejct we have now
got a normal distribution for CP, W' and Pmax parameters.
.. so we can now plot the percentiles on the CP plot that the
user's values sit in.
.. add fitting option to fit CP2 model to points using
a linear regress.
.. kinda ironic that the most common and straight forward
method for estimating CP/W' is added so late.
.. change the default intervals within the models - these
are used when estimating automatically via envelope and
were too long.
.. truncated the data used by the models to avoid using
MMP data beyond 20 minutes for 2/3p model.
.. results in much more robust estimates in CP History.
.. CP plot modelling will fallback when insufficient data
is available to model reliably, with a precedence:
1. Performance tests
2. Filtered MMP
3. All MMP
.. when modelling for a single ride collect bests/performance
data for the period up to that ride.
This is so as you select older rides the model reflects the
training status at that ride, not for the current period.
.. add adhoc season for 'Last 6 weeks' since it is a common
timeframe to use when tracking impact of training
.. tell user what fit or data was used as there is a cascade back
depending on the model selected and the availability of data.
.. the summary is also now in grey to indicate it is supplementary.
.. RMSE for now, just to get a basic sense
.. what type of fit was performed (since there is a fallback)
.. how many datapoints were used in the fit and RMSE calculation.
.. makes compilation easier and removes a dependency
for what is effectively 2 C-source files.
.. additionally, getting the lmfit lib to compile
on windows with cmake was frought with issues.
.. also fix a debug message left behind by previous
commit.
.. adding an option to select least squares fit to the cp
chart, in addition to the existing envelope fit.
.. additionally, if filter bests option has been selected
the least squares fit will use these points rather than
all the points (since well over 95% will be submaximal).
.. It requires the lmfit library to be available - and this
has been an non-optional install for over a year - we
just haven't used it prior to this commit.
.. Each PD model needs to implement three functions to enable
the least squares fit to work:
* int nparms() - returns the number of parameters
* double f(double t, double *parms) - parametric function
* bool setParms(double *parms) - set the parameters post fit
.. This commit implements it for CP derivatives;
* Classic CP - 2 parameter model
* Morton 3 Parameter - 3 parameter model
* GC Extended CP model - the extended model
BUT: it is implemented and disabled for eCP for now until
we can set parameter constraints correctly.
.. A second commit is needed for the remaining models from
Ward Smith and Mike P. This should also show which of the
filtered points have been used for curve fitting on the
chart (maybe a different color)
Introducing a directory structure to make it a bit less
daunting for new developers and perhaps even old hands.
The main folders all start with an upper character, so src
files are now located in;
* Core - Core data structures
* Gui - Main GUI elements
* Metrics - Models and Metrics
* FileIO - Device and File I/O
* Charts - All the chart types
* Cloud - Working with Web Resources
* Train - Anything Train View specific
* ANT - Our ANT+ Stack
* Resources - Images, Translations, Web etc
Apologies to anyone who needs to merge across this update.