Moments distribution

This elicitation method asks forecasters to input the 'bounds and moments' of the distribution. (Specifically, the moments are the mean and standard deviation). It then fits a distribution based on these inputs:

  1. Lower bound and upper bound => uniform
  2. Lower bound and mean or standard deviation => exponential
  3. Upper bound and mean or standard deviation => 'reflected' exponential
  4. Mean and standard deviation => Gaussian
  5. Otherwise => non-parametric maximum entropy distribution. See https://dsbowen.github.io/smoother/.

Examples

In app.py:

import dash_fcast as fcast
import dash_fcast.distributions as dist

import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
from dash.dependencies import Input, Output

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = html.Div([
    html.Br(),
    dist.Moments(id='Forecast'),
    html.Br(),
    fcast.Table(
        id='Table',
        datatable={'editable': True, 'row_deletable': True},
        row_addable=True
    ),
    html.Div(id='graphs')
], className='container')

dist.Moments.register_callbacks(app)
fcast.Table.register_callbacks(app)

@app.callback(
    Output('graphs', 'children'),
    [
        Input(dist.Moments.get_id('Forecast'), 'children'),
        Input(fcast.Table.get_id('Table'), 'children')
    ]
)
def update_graphs(dist_state, table_state):
    distribution = dist.Moments.load(dist_state)
    table = fcast.Table.load(table_state)
    pdf = go.Figure([distribution.pdf_plot(), table.bar_plot('Forecast')])
    pdf.update_layout(transition_duration=500, title='PDF')
    cdf = go.Figure([distribution.cdf_plot()])
    cdf.update_layout(transition_duration=500, title='CDF')
    return [dcc.Graph(figure=pdf), dcc.Graph(figure=cdf)]

if __name__ == '__main__':
    app.run_server(debug=True)

Run the app with:

$ python app.py

Open your browser and navigate to http://localhost:8050/.

dash_fcast.distributions.Moments

class dash_fcast.distributions.Moments(id, lb=0, ub=1, mean=None, std=None, *args, **kwargs) [source]

Distribution generated from moments elicitation.

Parameters: id : str

Distribution identifier.

lb : scalar or None, default=0

Lower bound of the distribution. F(x)=0 for all x<lb. If None, the distribution has no lower bound.

ub : scalar or None, default=1

Upper bound of the distribution. F(x)=1 for all x>ub. If None, the distribution has no upper bound.

mean : scalar or None, default=None

Mean of the distribution. If None, the mean is inferred as halfway between the lower and upper bound.

std : scalar or None, default=None

Standard deviation of the distribution. If None, the standard deviation is inferred as the standard deviation which maximizes entropy.

*args, **kwargs :

Arguments and keyword arguments are passed to the smoother constructor.

Attributes: id : str

Set from the id parameter.

Methods

elicitation(self, lb=0, ub=1, mean=None, std=None) [source]

Creates the layout for eliciting bounds and moments. Parameters for this method are analogous to the constructor parameters.

Parameters: lb : scalar, default=0

ub : scalar, default=1

mean : scalar or None, default=None

std : scalar or None, default=None

decimals : int, default=2

Number of decimals to which the recommended maximum standard deviation is rounded.

Returns: layout : list of dash elements.

Elicitation layout.

register_callbacks(cls, app, decimals=2) [source]

Register dash callbacks for moments distributions.

Parameters: app : dash.Dash

App with which to register callbacks.

decimals : int, default=2

Number of decimals to which to round the standard deviation placeholder.

fit(self, lb=None, ub=None, mean=None, std=None) [source]

Fit the smoother given bounds and moments constraints. Parameters are analogous to those of the constructor.

Parameters: lb : scalar or None, default=None

ub : scalar or None, default=None

mean : scalar or None, default=None

std : scalar or None, default=None

Returns: self : dash_fcast.distributions.Moments

dump(self) [source]

Returns: state dictionary : str (JSON)

load(cls, state_dict) [source]

Parameters: state_dict : str (JSON)

Moments distribution state dictionary (output of Moments.dump).

Returns: distribution : dash_fcast.distributions.Moments

Moments distribution specified by the state dictionary.

mean(self) [source]

std(self) [source]

pdf(self, x) [source]

cdf(self, x) [source]

ppf(self, q) [source]

pdf_plot(self, **kwargs) [source]

Parameters: **kwargs :

Keyword arguments passed to go.Scatter.

Returns: scatter : go.Scatter

Scatter plot of the probability density function.

cdf_plot(self, **kwargs) [source]

Parameters: ** kwargs :

Keyword arguments passed to go.Scatter.

Returns: scatter : go.Scatter

Scatter plot of the cumulative distribution function.