CreateErrorCrit_GAPX.R 1.31 KB
Newer Older
Dorchies David's avatar
Dorchies David committed
1
2
3
4
5
6
7
8
CreateErrorCrit_GAPX <- function(FUN_TRANSFO) {

  FUN_CRIT <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = TRUE) {
    ## Arguments check
    if (!inherits(OutputsModel, "OutputsModel")) {
      stop("'OutputsModel' must be of class 'OutputsModel'")
    }

9
    OutputsModel$RunOptions$ParamT <- FUN_TRANSFO(OutputsModel$RunOptions$Param, "RT")
Dorchies David's avatar
Dorchies David committed
10
11
12
13
14
15
16
17
18
19
20

    EC <- .ErrorCrit(InputsCrit = InputsCrit, Crit = "GAPX", OutputsModel = OutputsModel, warnings = warnings)

    CritValue <- NA

    if (EC$CritCompute) {

      ParamApr <- EC$VarObs[!EC$TS_ignore]
      ParamOpt <- EC$VarSim[!EC$TS_ignore]

      ## ErrorCrit
21
      Crit <- 1 - sum(((ParamApr - ParamOpt) / 20)^2)^0.5
Dorchies David's avatar
Dorchies David committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

      if (is.numeric(Crit) & is.finite(Crit)) {
        CritValue <- Crit
      }

      ## Verbose
      if (verbose) {
        message(sprintf("Crit. %s = %.4f", EC$CritName, CritValue))
      }
    }

    ## Output
    OutputsCrit <- list(CritValue       = CritValue,
                        CritName        = EC$CritName,
                        CritBestValue   = EC$CritBestValue,
                        Multiplier      = EC$Multiplier,
                        Ind_notcomputed = EC$Ind_TS_ignore)

    class(OutputsCrit) <- c("GAPX", "ErrorCrit")
    return(OutputsCrit)
  }

  class(FUN_CRIT) <- c("FUN_CRIT", class(FUN_CRIT))

  return(FUN_CRIT)
}