Tabular distribution
Examples
In app.py
:
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.Table(
id='Forecast',
datatable={'editable': True, 'row_deletable': True},
row_addable=True,
smoother=True
),
html.Div(id='graphs')
], className='container')
dist.Table.register_callbacks(app)
@app.callback(
Output('graphs', 'children'),
[Input(dist.Table.get_id('Forecast'), 'children')]
)
def update_graphs(dist_state):
distribution = dist.Table.load(dist_state)
pdf = go.Figure([distribution.pdf_plot(), distribution.bar_plot()])
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.Table
class dash_fcast.distributions.Table(id, bins=[0, 0.25, 0.5, 0.75, 1], prob=[0.25, 0.25, 0.25, 0.25], editable_cols=['bin-start', 'bin-end', 'pdf', 'cdf'], datatable= {}, row_addable=False, scalable=False, smoother=False, *args, **kwargs) [source]
Tabular distribution elicitation.
Parameters and attributes: | id : str, default
Distribution identifier. bins : list of scalars, default=[0, .25, .5, .75, 1]
List of 'break points' for the bins. The first bin starts at
Probability density function. This is the amount of probability mass in each bin. Must sum to 1 and Keyword arguments for the datatable associated with the table distribution. See https://dash.plotly.com/datatable. row_addable : bool, default=FalseIndicates whether the forecaster can add rows. scalable : bool, default=FalseProvides a scaling function for the table bins. smoother : bool, default=FalseIndicates whether to use a smoother for interpolation. See https://dsbowen.github.io/smoother/. *args, **kwargs :
Arguments and keyword arguments passed to |
---|
Methods
elicitation(self, bins=[0, 0.25, 0.5, 0.75, 1], prob=[0.25, 0.25, 0.25, 0.25], editable_cols=['bin-start', 'bin-end', 'pdf', 'cdf'], datatable= {}, row_addable=False, scalable=False) [source]
Parameters: | bins : list of scalars or numpy.array, default=[0, .25, .5, .75, 1]
prob : list of scalars or numpy.array, default=[.25, .25, .25, .25] datatable : dict, default={} row_addable : bool, default=False scalable : bool, default=False
|
---|---|
Returns: | elicitation elements : list of dash elements
Dash elements used to elicit the distribution. |
get_columns(self, editable_cols=['bin-start', 'bin-end', 'pdf', 'cdf']) [source]
Returns: | columns : list of dict
List of dictionaries specifying the datatable columns. See https://dash.plotly.com/datatable, |
---|
get_data(self, bins=None, prob=None) [source]
Parameters: | bins : list of scalars or numpy.array or None, default=None
If
If |
---|---|
Returns: | records : list of dict
Datatable data in records format. |
register_callbacks(cls, app) [source]
Register dash callbacks for table distributions.
Parameters: | app : dash.Dash
App with which to register callbacks. |
---|
fit(self, bins=None, prob=None, derivative=2) [source]
Fit the smoother given masses constraints.
Parameters: | bins : list of scalars or numpy.array
Ordered list of bin break points. If
Probability density function. This is the amount of probability mass in each bin. Must sum to 1 and
Deriviate of the derivative smoothing function to maximize. e.g. |
---|---|
Returns: | self :
|
dump(self) [source]
Dump the table distribution state dictionary in JSON format.
Returns: | state : dict, JSON
|
---|
load(cls, state_dict) [source]
Load a table distribution from its state dictionary.
Parameters: | state_dict : dict
Output of |
---|---|
Returns: | table : Table
|
pdf(self, x) [source]
cdf(self, x) [source]
pdf_plot(self, **kwargs) [source]
Parameters: | **kwargs :
Keyword arguments for |
---|---|
Returns: | scatter : go.Scatter.
Scatter plot of the pdf. |
cdf_plot(self, **kwargs) [source]
Parameters: | **kwargs :
Keyword arguments for |
---|---|
Returns: | scatter : go.Scatter
Scatter plot of the cdf. |
bar_plot(self, **kwargs) [source]
Parameters: | **kwargs :
Keyword arguments for |
---|---|
Returns: | bar plot : go.Bar
Bar plot of the pdf in the datatable. |