<commit_before># HydroTrend UQ 2

This is an uncertainty quantification (UQ) experiment
with HydroTrend.

Stochastic expansion method.

Meant to be similiar to UQ-1,
but use polynomial chaos expansions (PCE)
instead of sampling.

LHS is still used.

Third-order polynomial in T.
Use only second-order polynomial in P dimension.

A total of 3 x 2 = 6 HydroTrend simulations are run.
From the results,
construct a polynomial fit to the _Qs hypersurface.
Then, iterate 10000 times over the hypersurface
to get statistics.



---

The input parameters `T` and `P`
are again used.
In this case, though,
we don't know their exact values,
so we set ranges&mdash;approximately &plusmn;10%
of their default values in WMT&mdash;and allow
`T` and `P` to vary uniformly over this range.
Latin Hypercube sampling (LHS)
is used to obtain 24 samples
from the `T-P` parameter space.
Dakota propagates these samples through the model,
and their effect on three output variables:

1. water discharge at the river mouth, `Q`,
1. long-term suspended sediment load at the river mouth, `Qs`, and
1. daily bedload at the river mouth, `Qb`,

is evaluated.

The experiment response functions
are the _median_ values
of the `Q`, `Qs`, and `Qb` series
over the 100-year duration of each HydroTrend run;
they're denoted by `_Q`, `_Qs`, and `_Qb`.
Dakota computes moments and 95% confidence intervals
for the response functions,
giving a measure of the spread of these variables
from the uncertainty in the input parameters.
The `response_levels` keyword is set
to a list of values for `_Q`, `_Qs`, and `_Qb`
at which histograms and CDFs are calculated.
Dakota also calculates several correlation matrices
between the model inputs and responses
(e.g., in this experiment, `_Q` is 99.8% correlated with `P`,
and vanishingly correlated with `T`).
A seed value is specified in order to obtain repeatable results
over multiple runs.

By setting the `asynchronous` keyword
in the Dakota input file,
runs are performed in parallel,
using two (the number of processors on my Mac)
concurrent evaluations.

Run this experiment with:

```bash
$ dakota -i dakota.in -o dakota.out &> run.log
```

or with the **dakota_utils** package script `dakota_run`:

```bash
$ dakota_run .
```

Be sure to view the statistics listed at the end of the 
**dakota.out** file.<commit_msg>Complete write-up of experiment<commit_after># HydroTrend UQ 2

This is an uncertainty quantification (UQ) experiment
with HydroTrend.

Unlike **hydrotrend-uq-1**,
which uses sampling to propagate uncertainties through a model,
this experiment uses 
polynomial chaos expansions (PCE),
a stochastic expansion method.
With this technique,
a polynomial fit to a response function is generated;
UQ statistics are
calculated from it
both analytically and by sampling.
Further,
estimates are made for the amount of uncertainty
in the response
than can be attributed to the input variables.

As in **hydrotrend-uq-1**,
the input parameters `T` and `P`
are used,
varying uniformly over an interval approximately
&plusmn;10%
of their default values in WMT.
The experiment response function
is the median value
of the `Qs` series
over the 100-year duration of a HydroTrend run;
it's denoted by `_Qs`.

A third-order polynomial fit for `_Qs` is requested.
However, by specifying the 
`dimension_preference` keyword,
only a second-order polynomial in the `P` dimension is used.
So,
only 3 x 2 = 6 HydroTrend simulations
are needed to construct the polynomial fit.
LHS is used to select the 6 points in `T-P` space
where HydroTrend is run.
A seed value is specified in order to obtain repeatable results
over multiple runs.

Dakota computes moments analytically
for the polynomial fit to the response function,
giving a measure of the spread of `Qs`
from the uncertainty in the input parameters.
(Note that this experiment uses 
a factor of four fewer HydroTrend runs than in **hydrotrend-uq-1**,
yet it achieves similar moments for `_Qs`.)
Because the `variance_based_decomp` keyword was set,
Dakota computes sensitivity indices,
which show which parameters have the most influence on the output.
In this experiment (see below),
the Sobol' main index for `T` at 0.92 is much larger
the the index for `P`
and the index for the interaction between `T` and `P`.
The sum of the main indices must be less than or equal to 1.0.

From the `_Qs` polynomial fit,
10000 samples are chosen
for calculating statistics.
The `response_levels` keyword
provides a list of values for `_Qs`
at which its PDF and CDF are calculated.
From this experiment,
the probability that `_Qs` is less than 4.5
over the uncertain values of `T` and `P` is 0.75.


## Execution

Run this experiment with:

```bash
$ dakota -i dakota.in -o dakota.out &> run.log
```

or with the **dakota_utils** package script `dakota_run`:

```bash
$ dakota_run .
```

## Results

Be sure to view the statistics listed at the end of the 
**dakota.out** file.

```
Statistics derived analytically from polynomial expansion:

Moment-based statistics for each response function:
                            Mean           Std Dev          Skewness          Kurtosis
_Qs
  expansion:    4.1149444444e+00  4.7941203541e-01
  integration:  4.1149444444e+00  4.7941203541e-01  1.2148683172e-01 -1.0262089453e+00

Covariance matrix for response functions:
[[  2.2983589969e-01 ]] 

Local sensitivities for each response function evaluated at uncertain variable means:
_Qs:
 [  5.3124421565e-01  1.1604740411e+00 ] 

Global sensitivity indices for each response function:
_Qs Sobol' indices:
                                  Main             Total
                      9.2194041115e-01  9.2268235221e-01 T
                      7.7317647791e-02  7.8059588852e-02 P
                           Interaction
                      7.4194106137e-04 T P 

Statistics based on 10000 samples performed on polynomial expansion:

Probability Density Function (PDF) histograms for each response function:
PDF for _Qs:
          Bin Lower          Bin Upper      Density Value
          ---------          ---------      -------------
   3.0000000000e+00   3.5000000000e+00   2.1500000000e-01
   3.5000000000e+00   4.0000000000e+00   6.7220000000e-01
   4.0000000000e+00   4.5000000000e+00   6.0380000000e-01
   4.5000000000e+00   5.0000000000e+00   4.6500000000e-01
   5.0000000000e+00   5.2091494458e+00   1.0518794306e-01

Level mappings for each response function:
Cumulative Distribution Function (CDF) for _Qs:
     Response Level  Probability Level  Reliability Index  General Rel Index
     --------------  -----------------  -----------------  -----------------
   3.0000000000e+00   0.0000000000e+00
   3.5000000000e+00   1.0750000000e-01
   4.0000000000e+00   4.4360000000e-01
   4.5000000000e+00   7.4550000000e-01
   5.0000000000e+00   9.7800000000e-01
```
{'fraction_non_alphanumeric': 0.07903225806451612, 'fraction_numerical': 0.08284457478005865, 'mean_word_length': 3.400645161290323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 23, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4025325', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2009, 'n_words': 895}