[chronojump] Added 4 photocells with corrected time



commit 3bc710e3cd93eabedd8477ebb351d903d99682e5
Author: Xavier Padullés <testing chronojump org>
Date:   Mon Jan 11 13:50:34 2021 +0100

    Added 4 photocells with corrected time

 r-scripts/tests/shortsLibrary/validation.R | 99 ++++++++++++++++--------------
 1 file changed, 54 insertions(+), 45 deletions(-)
---
diff --git a/r-scripts/tests/shortsLibrary/validation.R b/r-scripts/tests/shortsLibrary/validation.R
index ac0b8a42..717d7022 100644
--- a/r-scripts/tests/shortsLibrary/validation.R
+++ b/r-scripts/tests/shortsLibrary/validation.R
@@ -1,5 +1,50 @@
 
 require(shorts)
+
+getModelWithOptimalTimeCorrection <- function(split_times)
+{
+    # print("In getModelWithOptimalTimeCorrection()")
+    bestTimeCorrection = 0
+    currentTimeCorrection = bestTimeCorrection
+    
+    model <- with(
+        split_times,
+        model_using_splits(position, time, time_correction = bestTimeCorrection)
+    )
+    
+    # print("### Without correction ###")
+    # print(model)
+    
+    minError = 1E6
+    
+    #TODO: Use better algorithm for finding optimal correction
+    while(model$model_fit$RSE < minError){
+        minError = model$model_fit$RSE
+        # print(paste("New minError:", minError))
+        # print(paste("current RSE:", model$model_fit$RSE))
+        currentTimeCorrection = currentTimeCorrection + 0.001
+        # Simple model
+        model <- with(
+            split_times,
+            model_using_splits(position, time, time_correction = currentTimeCorrection)
+        )
+        # print(model$model_fit$RSE)
+        if (model$model_fit$RSE < minError){
+            bestTimeCorrection = currentTimeCorrection
+        }
+    }
+    
+    model <- with(
+        split_times,
+        model_using_splits(position, time, time_correction = bestTimeCorrection)
+    )
+    
+    # print("### With optimal correction ###")
+    # print(paste("Time correction:", bestTimeCorrection))
+    # print(model)
+    
+    return(model)
+}
 WorlChampionshipSplitTimes <- 
read.csv2("~/chronojump/r-scripts/tests/shortsLibrary/WorlChampionshipSplitTimes.csv")
 
 resultsColumns = c("Vmax3P", "Tau3P", "RSE3P"
@@ -7,7 +52,7 @@ resultsColumns = c("Vmax3P", "Tau3P", "RSE3P"
           , "Vmax3S", "Tau3S", "RSE3S"
           , "Vmax3CorrectedS", "Tau3CorrectedS", "RSE3CorrectedS"
           , "Vmax4P", "Tau4P", "RSE4P"
-          , "Vmax4CorrectedP", "Tau4CorrectedP", "RSE4PCorrectedP"
+          , "Vmax4CorrectedP", "Tau4CorrectedP", "RSE4CorrectedP"
           , "Vmax4S", "Tau4S", "RSE4S"
           , "Vmax4CorrectedS", "Tau4CorrectedS", "RSE4CorrectedS"
           , "Vmax5CorrectedS", "Tau5CorrectedS", "RSE5CorrectedS"
@@ -64,6 +109,14 @@ for(i in 1:length(WorlChampionshipSplitTimes[,1])){
     results[i, "Tau4P"] = summary(model)$parameters[1]
     results[i, "RSE4P"] = summary(model)$sigma
     
+    # Padu's 4 split times model with correction
+    model = nls(position ~ Vmax*(time + T0 + (1/K)*exp(-K*(time + T0))) -Vmax/K, splitTimes4
+                , start = list(K = 0.81, Vmax = 10, T0 = 0.2), control=nls.control(warnOnly=TRUE))
+    # print(paste("P --- Vmax:", summary(model)$parameters[2], "Tau:", 1/summary(model)$parameters[1]))
+    results[i, "Vmax4CorrectedP"] = summary(model)$parameters[2]
+    results[i, "Tau4CorrectedP"] = summary(model)$parameters[1]
+    results[i, "RSE4CorrectedP"] = summary(model)$sigma
+    
     #Shorts 4 split times model without correction
     model = with(
         splitTimes4,
@@ -96,48 +149,4 @@ for(i in 1:length(WorlChampionshipSplitTimes[,1])){
     
 }
 
-getModelWithOptimalTimeCorrection <- function(split_times)
-{
-    # print("In getModelWithOptimalTimeCorrection()")
-    bestTimeCorrection = 0
-    currentTimeCorrection = bestTimeCorrection
-    
-    model <- with(
-        split_times,
-        model_using_splits(position, time, time_correction = bestTimeCorrection)
-    )
-    
-    # print("### Without correction ###")
-    # print(model)
-    
-    minError = 1E6
-    
-    #TODO: Use better algorithm for finding optimal correction
-    while(model$model_fit$RSE < minError){
-        minError = model$model_fit$RSE
-        # print(paste("New minError:", minError))
-        # print(paste("current RSE:", model$model_fit$RSE))
-        currentTimeCorrection = currentTimeCorrection + 0.001
-        # Simple model
-        model <- with(
-            split_times,
-            model_using_splits(position, time, time_correction = currentTimeCorrection)
-        )
-        # print(model$model_fit$RSE)
-        if (model$model_fit$RSE < minError){
-            bestTimeCorrection = currentTimeCorrection
-        }
-    }
-    
-    model <- with(
-        split_times,
-        model_using_splits(position, time, time_correction = bestTimeCorrection)
-    )
-    
-    # print("### With optimal correction ###")
-    # print(paste("Time correction:", bestTimeCorrection))
-    # print(model)
-    
-    return(model)
-}
 print(results)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]