Objective

We are using genetic algorithms, a type of stochastic optimization, to calibrate the following model coefficients:

Each model coefficient is documented within its submodel and can be viewed using the internal R documentation. For example:

?surv_adult_enroute

Packages

library(GA)
library(fallRunDSM)
library(DSMCalibrationData)
library(tidyverse)

We are using the GA R package to implement our genetic algorithms search to calibrate the above intercepts for the fallRunDSM::fall_run_model() function of the fallRunDSM R package.

Additionally, we are using DSMCalibrationData to access calibration related data.

Calibrating Data

GrandTab

We will be minimizing the error between GrandTab estimated escapement data for the years 1998-2017 to natural spawners predicted by the DSM. We are further weighting this error by a weight representng the amount of observed data available for a givn. Given that GrandTab includes both hatchery and natural spawners, we will scale GrandTab escapement values using the predicted proportion natural spawners for a given year generated by the model. This will allow us to compare predicted natural spawners to psuedo GrandTab natural spawners.

For calibration, we have prepared the GrandTab data in two ways:

  1. DSMCalibrationData::grandtab_observed - This data will be used in the fitness function to measure the difference between model predictions and observed escapement. Missing values are NA and we made all records less than 100 NA to account for a lack of confidence for counts less than 100.

  2. DSMCalibrationData::grandtab_imputed - This data will be used to calculate the number of juveniles during the 20 year simulation. The GrandTab data is incomplete for many watersheds during the 20 year period of calibration. For watersheds with no GrandTab data, we used 40 as the default escapement value. For watersheds with incomplete data, we used the mean escapement value.

grandtab_observed$fall
grandtab_imputed$fall

Selected Proxy Years

The data inputs to the DSM are for years 1980-1999. We selected proxy years for 1998-2017 from the 1980-1999 model inputs by comparing the DWR water year indices in this analysis. These inputs are generated by calling DSMCalibrationData::set_synth_years(params), with a params object from the life cycle model ex: fallRunDSM::params. See the documentation for more details on the DSMCalibrationData R package.

Spawning Inputs Proxy Years

tibble::tibble(
  `Calibration Year` = names(DSMCalibrationData::calibration_year_spawn_index), 
  `Selected Proxy Year` = DSMCalibrationData::calibration_year_spawn_index) %>% 
  knitr::kable()

Rearing Inputs Proxy Years

tibble::tibble(
  `Calibration Year` = names(DSMCalibrationData::calibration_year_index), 
  `Selected Proxy Year` = DSMCalibrationData::calibration_year_index) %>% 
  knitr::kable()

Fitness Function

We are minimizing the sum of squared errors of simulated natural adults and grandtab adults scaled using simulated proportion natural, normalized by mean escapement. The purpose of normalizing is to prevent watersheds with large escapement values from dominating the calibration.

All intercepts that need calibration are described in the Objective section of this document. Note, ..surv_adult_enroute_int and ..ocean_entry_success_int are vectors and expanded within the fitness function arguments.

fall_run_fitness <- function(
  known_adults,
  seeds,
  surv_adult_enroute,
  surv_adult_prespawn,
  surv_egg_to_fry,
  uppermidsactribs_surv_juv,
  bypass_surv_juv,
  upsac_surv_juv,
  butte_surv_juv,
  deer_surv_juv,
  mill_surv_juv,
  sac_surv_juv,
  bear_surv_juv,
  feather_surv_juv,
  yuba_surv_juv,
  american_surv_juv,
  deltatribs_surv_juv,
  moke_surv_juv,
  merced_surv_juv,
  stan_surv_juv,
  tuol_surv_juv,
  sj_surv_juv, 
  surv_juv_rear_contact_points,
  surv_juv_rear_prop_diversions,
  surv_juv_rear_total_diversions,
  surv_juv_bypass_int,
  surv_juv_delta_int,
  surv_juv_delta_contact_points,
  surv_juv_delta_total_diverted,
  surv_juv_outmigration_sj_int,
  surv_juv_outmigration_sac_int_one,
  surv_juv_outmigration_sac_prop_diversions,
  surv_juv_outmigration_sac_total_diversions,
  surv_juv_outmigration_sac_int_two,
  default_ocean_entry_surv,
  upsac_ocean_entry_surv,
  butte_ocean_entry_surv,
  deer_ocean_entry_surv,
  mill_ocean_entry_surv,
  midsactribs_ocean_entry_surv,
  yuba_ocean_entry_surv,
  american_ocean_entry_surv,
  deltatribs_ocean_entry_surv,
  moke_ocean_entry_surv,
  merced_ocean_entry_surv,
  stan_ocean_entry_surv,
  tuol_ocean_entry_surv) {
  params_init <- fallRunDSM::params

  params_init$..surv_adult_enroute_int = surv_adult_enroute
  params_init$..surv_adult_prespawn_int = surv_adult_prespawn
  params_init$..surv_egg_to_fry_int = surv_egg_to_fry
  params_init$..surv_juv_rear_int = c(`Upper Sacramento River` = upsac_surv_juv, 
                                      `Antelope Creek` = uppermidsactribs_surv_juv,
                                      `Battle Creek` = uppermidsactribs_surv_juv,
                                      `Bear Creek` = uppermidsactribs_surv_juv, 
                                      `Big Chico Creek` = uppermidsactribs_surv_juv, 
                                      `Butte Creek` = butte_surv_juv,
                                      `Clear Creek` = uppermidsactribs_surv_juv, 
                                      `Cottonwood Creek` = uppermidsactribs_surv_juv, 
                                      `Cow Creek` = uppermidsactribs_surv_juv,
                                      `Deer Creek` = deer_surv_juv, 
                                      `Elder Creek` = uppermidsactribs_surv_juv, 
                                      `Mill Creek` = mill_surv_juv,
                                      `Paynes Creek` = uppermidsactribs_surv_juv, 
                                      `Stony Creek` = uppermidsactribs_surv_juv, 
                                      `Thomes Creek` = uppermidsactribs_surv_juv,
                                      `Upper-mid Sacramento River` = sac_surv_juv, 
                                      `Sutter Bypass` = bypass_surv_juv,
                                      `Bear River` = uppermidsactribs_surv_juv, 
                                      `Feather River` = uppermidsactribs_surv_juv, 
                                      `Yuba River` = yuba_surv_juv,
                                      `Lower-mid Sacramento River` = sac_surv_juv,
                                      `Yolo Bypass` = bypass_surv_juv, 
                                      `American River` = american_surv_juv,
                                      `Lower Sacramento River` = sac_surv_juv, 
                                      `Calaveras River` = deltatribs_surv_juv, 
                                      `Cosumnes River` = deltatribs_surv_juv,
                                      `Mokelumne River` = moke_surv_juv, 
                                      `Merced River` = merced_surv_juv, 
                                      `Stanislaus River` = stan_surv_juv,
                                      `Tuolumne River` = tuol_surv_juv, 
                                      `San Joaquin River` = sj_surv_juv)
  params_init$..surv_juv_rear_contact_points = surv_juv_rear_contact_points
  params_init$..surv_juv_rear_prop_diversions = surv_juv_rear_prop_diversions
  params_init$..surv_juv_rear_total_diversions = surv_juv_rear_total_diversions
  params_init$..surv_juv_bypass_int = surv_juv_bypass_int
  params_init$..surv_juv_delta_int = surv_juv_delta_int
  params_init$..surv_juv_delta_contact_points = surv_juv_delta_contact_points
  params_init$..surv_juv_delta_total_diverted = surv_juv_delta_total_diverted
  params_init$..surv_juv_outmigration_sj_int = surv_juv_outmigration_sj_int
  params_init$..surv_juv_outmigration_sac_int_one = surv_juv_outmigration_sac_int_one
  params_init$..surv_juv_outmigration_sac_prop_diversions = surv_juv_outmigration_sac_prop_diversions
  params_init$..surv_juv_outmigration_sac_total_diversions = surv_juv_outmigration_sac_total_diversions
  params_init$..surv_juv_outmigration_sac_int_two = surv_juv_outmigration_sac_int_two
  params_init$..ocean_entry_success_int = c(
    `Upper Sacramento River` = upsac_ocean_entry_surv,
    `Antelope Creek` = default_ocean_entry_surv,
    `Battle Creek` = default_ocean_entry_surv,
    `Bear Creek` = default_ocean_entry_surv,
    `Big Chico Creek` = default_ocean_entry_surv,
    `Butte Creek` = butte_ocean_entry_surv,
    `Clear Creek` = default_ocean_entry_surv,
    `Cottonwood Creek` = default_ocean_entry_surv,
    `Cow Creek` = default_ocean_entry_surv,
    `Deer Creek` = deer_ocean_entry_surv,
    `Elder Creek` = default_ocean_entry_surv,
    `Mill Creek` = mill_ocean_entry_surv,
    `Paynes Creek` = default_ocean_entry_surv,
    `Stony Creek` = default_ocean_entry_surv,
    `Thomes Creek` = default_ocean_entry_surv,
    `Upper-mid Sacramento River` = default_ocean_entry_surv,
    `Sutter Bypass` = default_ocean_entry_surv,
    `Bear River` = midsactribs_ocean_entry_surv,
    `Feather River` = midsactribs_ocean_entry_surv,
    `Yuba River` = yuba_ocean_entry_surv,
    `Lower-mid Sacramento River` = default_ocean_entry_surv,
    `Yolo Bypass` = default_ocean_entry_surv,
    `American River` = american_ocean_entry_surv,
    `Lower Sacramento River` = default_ocean_entry_surv,
    `Calaveras River` = deltatribs_ocean_entry_surv,
    `Cosumnes River` = deltatribs_ocean_entry_surv,
    `Mokelumne River` = moke_ocean_entry_surv,
    `Merced River` = merced_ocean_entry_surv,
    `Stanislaus River` = stan_ocean_entry_surv,
    `Tuolumne River` = tuol_ocean_entry_surv,
    `San Joaquin River` = default_ocean_entry_surv)


  set.seed(1)
  preds <- fall_run_model(mode = "calibrate", 
                          seeds = seeds,
                          ..params = params_init)

  sum(((preds$natural_spawners - (known_adults * preds$proportion_natural)) /
         rowMeans(known_adults, na.rm = TRUE)) ^ 2, na.rm = TRUE)
}
library(GA)

res <- ga(type = "real-valued", 
          fitness = 
            function(x) -fall_run_fitness(
              known_adults = DSMCalibrationData::grandtab_observed$fall,
              seeds = DSMCalibrationData::grandtab_imputed$fall,
              x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], 
              x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19], 
              x[20], x[21], x[22], x[23], x[24], x[25], x[26], x[27], x[28], 
              x[29], x[30], x[31], x[32], x[33], x[34], x[35], x[36], x[37], 
              x[38], x[39], x[40], x[41], x[42], x[43], x[44], x[45]
            ), 
          lower = rep(-3.5, 45), 
          upper = rep(3.5, 45), 
          popSize = 100, 
          maxiter = 10, 
          run = 20, 
          parallel = TRUE)


CVPIA-OSC/lateFallRunDSM documentation built on June 30, 2022, 10:04 p.m.