Skip to content

Commit

Permalink
finalize 0.7.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogaardt committed Oct 23, 2020
1 parent 49d2bf1 commit 6412ff7
Show file tree
Hide file tree
Showing 79 changed files with 1,313 additions and 1,425 deletions.
7 changes: 7 additions & 0 deletions chainladder/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def _get_full_triangle(full_expectation_, triangle_):

class Common:
""" Class that contains common properties of a "fitted" Triangle. """
@property
def has_ldf(self):
if hasattr(self, "ldf_"):
return True
else:
return False


@property
def cdf_(self):
Expand Down
20 changes: 12 additions & 8 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,28 @@ def incr_to_cum(self, inplace=False):
if not self.is_cumulative:
if self.is_pattern:
values = xp.nan_to_num(self.values[..., ::-1])
if self.array_backend == "sparse":
xp = np
values = self.set_backend('numpy').values
values[values == 0] = 1.0
values = xp.cumprod(values, -1)[..., ::-1]
self.values = values = values * self.nan_triangle
if self.array_backend == "sparse":
self.values = self.get_array_module()(self.values)
else:
ddims = self.ddims
if self.array_backend != "sparse":
self.values = (
num_to_nan(xp.cumsum(xp.nan_to_num(self.values), 3))
* self.nan_triangle[None, None, ...]
)
else:
l1 = lambda i: self.iloc[..., 0 : (i + 1)]
l2 = lambda i: l1(i) * self.nan_triangle[..., i : i + 1]
l3 = lambda i: l2(i).sum(3, auto_sparse=False, keepdims=True)
self = concat(
[l3(i).rename(3, [i]) for i in range(self.shape[-1])], 3,
)
self.ddims = ddims
values = xp.nan_to_num(self.values)
nan_triangle = xp.nan_to_num(self.nan_triangle)
l1 = lambda i: values[..., 0 : (i + 1)]
l2 = lambda i: l1(i) * nan_triangle[..., i : i + 1]
l3 = lambda i: l2(i).sum(3, keepdims=True)
out = [l3(i) for i in range(self.shape[-1])]
self.values = num_to_nan(xp.concatenate(out, axis=3))
self.is_cumulative = True
return self
else:
Expand Down
7 changes: 5 additions & 2 deletions chainladder/development/clark.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def G_(self, age):
if type(age) == list:
age = xp.array([age]).astype("float64")
obj = self.incremental_act_.copy()
obj.odims = xp.array(["(All)"])
obj.odims = obj.odims[0:1]
obj.values = 1 / self._G(age)
obj.ddims = age
return obj
Expand Down Expand Up @@ -185,8 +185,11 @@ def solver(x):
cdf = self._G(
latest_age - age_offset, theta=params[..., 1:2], omega=params[..., 0:1]
)
obj.values = xp.repeat(cdf[..., :-1] / cdf[..., 1:], len(obj.odims), 2)
obj.values = cdf[..., :-1] / cdf[..., 1:]
obj.ddims = X.link_ratio.ddims
obj.odims = obj.odims[0:1]
obj.is_pattern = True
obj.is_cumulative = False
obj._set_slicers()
self.ldf_ = obj
self.ldf_.valuation_date = pd.to_datetime(ULT_VAL)
Expand Down
1 change: 1 addition & 0 deletions chainladder/development/munich.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def fit(self, X, y=None, sample_weight=None):
self.ldf_ = self._set_ldf(
obj, self._get_mcl_cdf(obj, self.munich_full_triangle_)
)
self.ldf_.is_cumulative = False
self.ldf_.valuation_date = pd.to_datetime(ULT_VAL)
self._map = {
(list(X.columns).index(x)): (num % 2, num // 2)
Expand Down
2 changes: 1 addition & 1 deletion chainladder/methods/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _include_process_variance(self):
return process_var

def validate_weight(self, X, sample_weight):
if sample_weight and X.shape[:-1] != sample_weight.shape[:-1]:
if sample_weight and X.shape[:-1] != sample_weight.shape[:-1] and sample_weight.shape[2] != 1 and sample_weight.shape[0] > 1:
warnings.warn(
"X and sample_weight are not aligned. Broadcasting may occur.\n"
)
2 changes: 1 addition & 1 deletion chainladder/utils/templates/triangle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Sheet:
{% endfor %}
{% endif %}

{% if triangle.ldf_ %}
{% if triangle.has_ldf %}
- CSpacer:
height: 1
- Series:
Expand Down
Binary file modified docs/auto_examples/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified docs/auto_examples/auto_examples_python.zip
Binary file not shown.
Binary file modified docs/auto_examples/images/sphx_glr_plot_bootstrap_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/images/sphx_glr_plot_clarkldf_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/images/thumb/sphx_glr_plot_clarkldf_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions docs/auto_examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,14 @@ Examples

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="There are several aspects of the chainladder module that are demonstrated with this example.">
<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how you can can use the Overdispersed Poisson Bootstrap sampler and g...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png
:alt: Stochastic Bornhuetter Ferguson
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png
:alt: ODP Bootstrap Example

:ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py`
:ref:`sphx_glr_auto_examples_plot_bootstrap.py`

.. raw:: html

Expand All @@ -387,18 +387,18 @@ Examples
.. toctree::
:hidden:

/auto_examples/plot_stochastic_bornferg
/auto_examples/plot_bootstrap

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to recreate the normalized residual plots in Clarks LDF Curve-Fit...">
<div class="sphx-glr-thumbcontainer" tooltip="There are several aspects of the chainladder module that are demonstrated with this example.">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_clarkldf_resid_thumb.png
:alt: Clark Residual Plots
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png
:alt: Stochastic Bornhuetter Ferguson

:ref:`sphx_glr_auto_examples_plot_clarkldf_resid.py`
:ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py`

.. raw:: html

Expand All @@ -408,18 +408,18 @@ Examples
.. toctree::
:hidden:

/auto_examples/plot_clarkldf_resid
/auto_examples/plot_stochastic_bornferg

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how you can can use the Overdispersed Poisson Bootstrap sampler and g...">
<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to recreate the normalized residual plots in Clarks LDF Curve-Fit...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png
:alt: ODP Bootstrap Example
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_clarkldf_resid_thumb.png
:alt: Clark Residual Plots

:ref:`sphx_glr_auto_examples_plot_bootstrap.py`
:ref:`sphx_glr_auto_examples_plot_clarkldf_resid.py`

.. raw:: html

Expand All @@ -429,7 +429,7 @@ Examples
.. toctree::
:hidden:

/auto_examples/plot_bootstrap
/auto_examples/plot_clarkldf_resid

.. raw:: html

Expand Down
2 changes: 1 addition & 1 deletion docs/auto_examples/plot_bootstrap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"import chainladder as cl\nimport matplotlib.pyplot as plt\n\n# Grab a Triangle\ntri = cl.load_sample('genins')\n# Generate bootstrap samples\nsims = cl.BootstrapODPSample().fit_transform(tri)\n# Calculate LDF for each simulation\nsim_ldf = cl.Development().fit(sims).ldf_\nsim_ldf = sim_ldf[sim_ldf.origin==sim_ldf.origin.max()]\n\n# Plot the Data\nfig, ((ax00, ax01), (ax10, ax11)) = plt.subplots(ncols=2, nrows=2, figsize=(10,10))\n# Plot 1\ntri.T.plot(ax=ax00, grid=True).set(title='Raw Data', xlabel='Development', ylabel='Incurred')\n# Plot 2\nsims.mean().T.plot(ax=ax01, grid=True).set(title='Mean Simulation', xlabel='Development')\n# Plot 3\nsim_ldf.T.plot(legend=False, color='lightgray', ax=ax10, grid=True).set(\n title='Simulated LDF', xlabel='Development', ylabel='LDF')\ncl.Development().fit(tri).ldf_.drop_duplicates().T.plot(\n legend=False, color='red', ax=ax10, grid=True)\n# Plot 4\nsim_ldf.T.loc['12-24'].plot(\n kind='hist', bins=50, alpha=0.5, ax=ax11 , grid=True).set(\n title='Age 12-24 LDF Distribution', xlabel='LDF');"
"import chainladder as cl\nimport matplotlib.pyplot as plt\n\n# Grab a Triangle\ntri = cl.load_sample('genins')\n# Generate bootstrap samples\nsims = cl.BootstrapODPSample().fit_transform(tri)\n# Calculate LDF for each simulation\nsim_ldf = cl.Development().fit(sims).ldf_\n\n# Plot the Data\nfig, ((ax00, ax01), (ax10, ax11)) = plt.subplots(ncols=2, nrows=2, figsize=(10,10))\n# Plot 1\ntri.T.plot(ax=ax00, grid=True).set(title='Raw Data', xlabel='Development', ylabel='Incurred')\n# Plot 2\nsims.mean().T.plot(ax=ax01, grid=True).set(title='Mean Simulation', xlabel='Development')\n# Plot 3\nsim_ldf.T.plot(legend=False, color='lightgray', ax=ax10, grid=True).set(\n title='Simulated LDF', xlabel='Development', ylabel='LDF')\ncl.Development().fit(tri).ldf_.drop_duplicates().T.plot(\n legend=False, color='red', ax=ax10, grid=True)\n# Plot 4\nsim_ldf.T.loc['12-24'].plot(\n kind='hist', bins=50, alpha=0.5, ax=ax11 , grid=True).set(\n title='Age 12-24 LDF Distribution', xlabel='LDF');"
]
}
],
Expand Down
1 change: 0 additions & 1 deletion docs/auto_examples/plot_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
sims = cl.BootstrapODPSample().fit_transform(tri)
# Calculate LDF for each simulation
sim_ldf = cl.Development().fit(sims).ldf_
sim_ldf = sim_ldf[sim_ldf.origin==sim_ldf.origin.max()]

# Plot the Data
fig, ((ax00, ax01), (ax10, ax11)) = plt.subplots(ncols=2, nrows=2, figsize=(10,10))
Expand Down
2 changes: 1 addition & 1 deletion docs/auto_examples/plot_bootstrap.py.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d69313408bdb72d6709775b307368f26
a4b7163692b2b29b03d9eed31d4a4d32
5 changes: 2 additions & 3 deletions docs/auto_examples/plot_bootstrap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Bootstrap sampler and get various properties about parameter uncertainty.

.. code-block:: none
c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\core\pandas.py:264: RuntimeWarning: Mean of empty slice
c:\users\jboga\onedrive\documents\github\chainladder-python\chainladder\core\pandas.py:280: RuntimeWarning: Mean of empty slice
obj.values = func(obj.values, axis=axis, *args, **kwargs)
[Text(0.5, 0, 'LDF'), Text(0.5, 1.0, 'Age 12-24 LDF Distribution')]
Expand All @@ -52,7 +52,6 @@ Bootstrap sampler and get various properties about parameter uncertainty.
sims = cl.BootstrapODPSample().fit_transform(tri)
# Calculate LDF for each simulation
sim_ldf = cl.Development().fit(sims).ldf_
sim_ldf = sim_ldf[sim_ldf.origin==sim_ldf.origin.max()]
# Plot the Data
fig, ((ax00, ax01), (ax10, ax11)) = plt.subplots(ncols=2, nrows=2, figsize=(10,10))
Expand All @@ -73,7 +72,7 @@ Bootstrap sampler and get various properties about parameter uncertainty.
.. rst-class:: sphx-glr-timing

**Total running time of the script:** ( 0 minutes 2.300 seconds)
**Total running time of the script:** ( 0 minutes 2.244 seconds)


.. _sphx_glr_download_auto_examples_plot_bootstrap.py:
Expand Down
Binary file modified docs/auto_examples/plot_bootstrap_codeobj.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/auto_examples/plot_clarkldf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ age.
.. rst-class:: sphx-glr-timing

**Total running time of the script:** ( 0 minutes 1.304 seconds)
**Total running time of the script:** ( 0 minutes 0.956 seconds)


.. _sphx_glr_download_auto_examples_plot_clarkldf.py:
Expand Down
Binary file modified docs/auto_examples/plot_clarkldf_codeobj.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/auto_examples/plot_clarkldf_resid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Clarks LDF Curve-Fitting paper (2003).
.. rst-class:: sphx-glr-timing

**Total running time of the script:** ( 0 minutes 0.376 seconds)
**Total running time of the script:** ( 0 minutes 0.345 seconds)


.. _sphx_glr_download_auto_examples_plot_clarkldf_resid.py:
Expand Down
Binary file modified docs/auto_examples/plot_clarkldf_resid_codeobj.pickle
Binary file not shown.
18 changes: 9 additions & 9 deletions docs/auto_examples/sg_execution_times.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

Computation times
=================
**00:02.058** total execution time for **auto_examples** files:
**00:03.546** total execution time for **auto_examples** files:

+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` (``plot_stochastic_bornferg.py``) | 00:01.796 | 0.0 MB |
| :ref:`sphx_glr_auto_examples_plot_bootstrap.py` (``plot_bootstrap.py``) | 00:02.244 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` (``plot_bf_apriori_from_cl.py``) | 00:00.261 | 0.0 MB |
| :ref:`sphx_glr_auto_examples_plot_clarkldf.py` (``plot_clarkldf.py``) | 00:00.956 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_clarkldf_resid.py` (``plot_clarkldf_resid.py``) | 00:00.345 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_ave_analysis.py` (``plot_ave_analysis.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
Expand All @@ -20,18 +22,14 @@ Computation times
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_berqsherm_closure.py` (``plot_berqsherm_closure.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_bondy_sensitivity.py` (``plot_bondy_sensitivity.py``) | 00:00.000 | 0.0 MB |
| :ref:`sphx_glr_auto_examples_plot_bf_apriori_from_cl.py` (``plot_bf_apriori_from_cl.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_bootstrap.py` (``plot_bootstrap.py``) | 00:00.000 | 0.0 MB |
| :ref:`sphx_glr_auto_examples_plot_bondy_sensitivity.py` (``plot_bondy_sensitivity.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_bootstrap_comparison.py` (``plot_bootstrap_comparison.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_capecod.py` (``plot_capecod.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_clarkldf.py` (``plot_clarkldf.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_clarkldf_resid.py` (``plot_clarkldf_resid.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_development_periods.py` (``plot_development_periods.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_exhibits.py` (``plot_exhibits.py``) | 00:00.000 | 0.0 MB |
Expand All @@ -50,6 +48,8 @@ Computation times
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_munich_resid.py` (``plot_munich_resid.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py` (``plot_stochastic_bornferg.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_tailcurve_compare.py` (``plot_tailcurve_compare.py``) | 00:00.000 | 0.0 MB |
+-----------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_plot_triangle_from_pandas.py` (``plot_triangle_from_pandas.py``) | 00:00.000 | 0.0 MB |
Expand Down
Empty file.
10 changes: 5 additions & 5 deletions docs/modules/generated/chainladder.BootstrapODPSample.examples
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Examples using ``chainladder.BootstrapODPSample``

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="There are several aspects of the chainladder module that are demonstrated with this example.">
<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how you can can use the Overdispersed Poisson Bootstrap sampler and g...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_stochastic_bornferg_thumb.png
:alt: Stochastic Bornhuetter Ferguson
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_bootstrap_thumb.png
:alt: ODP Bootstrap Example

:ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py`
:ref:`sphx_glr_auto_examples_plot_bootstrap.py`

.. raw:: html

</div>

.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_stochastic_bornferg.py`
* :ref:`sphx_glr_auto_examples_plot_bootstrap.py`
Empty file.
Empty file.
Empty file.
19 changes: 0 additions & 19 deletions docs/modules/generated/chainladder.Common.T.examples
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@
Examples using ``chainladder.Common.T``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="All IBNR models spin off several results triangles including inbr_, ultimate_, full_expectation...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_ibnr_runoff_thumb.png
:alt: IBNR Runoff

:ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py`

.. raw:: html

</div>

.. only:: not html

* :ref:`sphx_glr_auto_examples_plot_ibnr_runoff.py`

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how you can can use the Overdispersed Poisson Bootstrap sampler and g...">
Expand Down
Loading

0 comments on commit 6412ff7

Please sign in to comment.