CostFunction#
- class xesn.CostFunction(ESN, train_data, macro_data, config, test_data=None)#
A class used to evaluate an ESN architecture, which can be used in
xesn.optimize(). See this page of the documentation for example usage. Currently the following generic cost function is implemented\[\mathcal{J}_\text{macro}(\mathbf{\theta}) = \dfrac{1}{N_\text{macro}}\sum_{j=1}^{N_\text{macro}} \left\{\gamma_1\text{NRMSE}(j) + \gamma_2 \text{PSD}\_\text{NRMSE}(j)\right\}\]\[\text{NRMSE}(j) = \sqrt{\dfrac{1}{N_v N_\text{steps}}\sum_{n=1}^{N_\text{steps}}\sum_{i=1}^{N_v}\left(\dfrac{\hat{v}_j(i, n) - v_j(i, n)}{SD_j}\right)^2 }\]\[\text{PSD}\_\text{NRMSE}(j) = \sqrt{\dfrac{1}{N_K N_\text{steps}}\sum_{n=1}^{N_\text{steps}}\sum_{i=1}^{N_K}\left(\dfrac{\hat{\psi}_j(k, n) - \psi_j(k, n)}{SD_j(k)}\right)^2 }\]where:
\(\mathbf{\theta}\) is our vector of parameters to be optimized, defined by
config["macro_training"]["parameters"]\(N_\text{macro}\) =
config["macro_training"]["forecast"]["n_samples"]is the number of sample forecasts\(\gamma_1\) and \(\gamma_2\) determine the overall weighting for the Normalized Root Mean Square Error (NRMSE) and Power Spectral Density NRMSE (PSD_NRMSE) terms, respectively. These are controlled with
config["macro_training"]["cost_terms"]\(i\) is the index for each non-time index
\(n\) is the temporal index, and \(N_\text{steps}\) =
config["macro_training"]["forecast"]["n_steps"]is the length of each sample forecast in terms of the number of time steps\(j\) is the index for each sample forecast
\(k\) is the index for each spectral mode of the PSD
\(\psi_j(k,n)\) is the \(k^{th}\) mode’s amplitude, for sample \(j\) at time step \(n\)
The standard deviation used in the NRMSE calculation is
\[SD_j = \sqrt{\dfrac{\sum_{i=1}^{N_v}\sum_{n=1}^{N_{\text{steps}}}\left(v_j(i, n) - \mu_j\right)^2}{(N_{\text{steps}}-1)(N_v-1)}}\]\(SD_j(k)\) used in the PSD_NRMSE calculation is defined similarly as above, but in spectral space, and note that each mode is normalized separately as different modes can vary by vastly different orders of magnitude
\(\mu_j\) is the average taken over space and time
\[\mu_j = \dfrac{1}{N_v N_\text{steps}} \sum_{n=1}^{N_\text{steps}} \sum_{i=1}^{N_v} v_j(i,n)\]the average used for PSD_NRMSE \(\mu_j(k)\) is similarly defined for PSD except the summation is only taken over time
- Parameters:
train_data (xarray.DataArray) – containing the training data used train the readout weights \(\mathbf{W}_\text{out}\)
macro_data (List[xarray.DataArray]) – containing the sample trajectories to compute the cost function with
config (dict) – with sections
"macro_training","training",esnorlazyesndepending on which class is used, and optionally"testing"in order to useevaluate()on the test data. See here for an example on how to set this up.test_data (xarray.DataArray, optional) – separate test data passed here for convenience to be used with
evaluate()
Methods
CostFunction.__call__(macro_param_sets[, ...])Evaluate the cost function for a given set of parameter values
CostFunction.evaluate(parameters[, ...])Evaluate this parameter set by building an ESN and testing it on either the
macro_dataortest_data.Attributes
CostFunction.ESNCostFunction.train_dataCostFunction.macro_dataCostFunction.configCostFunction.test_data