actuarialnam 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- actuarialnam/__init__.py +110 -0
- actuarialnam/api.py +1571 -0
- actuarialnam/lattice.py +544 -0
- actuarialnam/losses.py +186 -0
- actuarialnam/model.py +460 -0
- actuarialnam/optimizer.py +376 -0
- actuarialnam/sparsity.py +749 -0
- actuarialnam/subnet.py +194 -0
- actuarialnam/utils.py +327 -0
- actuarialnam-0.3.0.dist-info/METADATA +164 -0
- actuarialnam-0.3.0.dist-info/RECORD +13 -0
- actuarialnam-0.3.0.dist-info/WHEEL +4 -0
- actuarialnam-0.3.0.dist-info/licenses/LICENSE +21 -0
actuarialnam/__init__.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ANAM - Actuarial Neural Additive Model
|
|
3
|
+
|
|
4
|
+
A PyTorch implementation of Neural Additive Models with extensions for
|
|
5
|
+
actuarial applications including monotonicity constraints, smoothness
|
|
6
|
+
penalties, and interaction effects.
|
|
7
|
+
|
|
8
|
+
Quickstart::
|
|
9
|
+
|
|
10
|
+
from actuarialnam import ANAM
|
|
11
|
+
model = ANAM(distribution="poisson", exposure="expo",
|
|
12
|
+
monotone={"bm": "increasing"}, smoothness=1e-3)
|
|
13
|
+
model.fit(train, train["nclaims"], X_val=val, y_val=val["nclaims"])
|
|
14
|
+
model.plot_effects(["ageph", "bm", "power"]); model.predict(val)
|
|
15
|
+
|
|
16
|
+
The headline export ``ANAM`` is the user-facing wrapper: it owns preprocessing,
|
|
17
|
+
maps ``distribution`` to a loss + link, treats ``exposure`` as an offset column,
|
|
18
|
+
runs variable selection by default (``features="auto"``/``interactions="auto"``),
|
|
19
|
+
and plots shape functions in original units. Power users can build the raw
|
|
20
|
+
engine directly via ``ANAMModule`` and the lower-level helpers, all still
|
|
21
|
+
exported below.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from actuarialnam.model import ANAMModule
|
|
25
|
+
|
|
26
|
+
# The headline export ``ANAM`` is the user-facing wrapper (api.py). Power users
|
|
27
|
+
# who want the raw nn.Module engine can use ``ANAMModule``.
|
|
28
|
+
from actuarialnam.api import ANAM
|
|
29
|
+
from actuarialnam.losses import (
|
|
30
|
+
gamma_nll,
|
|
31
|
+
poisson_nll,
|
|
32
|
+
gaussian_nll,
|
|
33
|
+
smoothness_penalty,
|
|
34
|
+
marginal_clarity_penalty,
|
|
35
|
+
DISTRIBUTIONS,
|
|
36
|
+
resolve_distribution,
|
|
37
|
+
)
|
|
38
|
+
from actuarialnam.subnet import Subnet, EmbeddingSubnet
|
|
39
|
+
from actuarialnam.lattice import PWLCalibration, Lattice, Lattice1D, MonotonicSubnet
|
|
40
|
+
from actuarialnam.optimizer import train_anam, TrainingConfig, prepare_data
|
|
41
|
+
from actuarialnam.utils import (
|
|
42
|
+
generate_synthetic_data,
|
|
43
|
+
build_feature_configs,
|
|
44
|
+
remove_outliers_iqr,
|
|
45
|
+
train_val_test_split,
|
|
46
|
+
plot_shape_function,
|
|
47
|
+
plot_interaction_heatmap,
|
|
48
|
+
plot_variable_importance,
|
|
49
|
+
)
|
|
50
|
+
from actuarialnam.sparsity import (
|
|
51
|
+
SparsityConfig,
|
|
52
|
+
SelectionResult,
|
|
53
|
+
train_ensemble_main_effects,
|
|
54
|
+
compute_ensemble_importance,
|
|
55
|
+
select_main_effects,
|
|
56
|
+
train_main_effects_model,
|
|
57
|
+
evaluate_candidate_interactions,
|
|
58
|
+
select_interactions,
|
|
59
|
+
run_variable_selection,
|
|
60
|
+
plot_main_effect_importance,
|
|
61
|
+
plot_interaction_selection,
|
|
62
|
+
_find_elbow,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
__version__ = "0.3.0"
|
|
66
|
+
__all__ = [
|
|
67
|
+
# Model
|
|
68
|
+
"ANAM",
|
|
69
|
+
"ANAMModule",
|
|
70
|
+
# Subnets
|
|
71
|
+
"Subnet",
|
|
72
|
+
"EmbeddingSubnet",
|
|
73
|
+
# Lattice
|
|
74
|
+
"PWLCalibration",
|
|
75
|
+
"Lattice",
|
|
76
|
+
"Lattice1D",
|
|
77
|
+
"MonotonicSubnet",
|
|
78
|
+
# Losses
|
|
79
|
+
"gamma_nll",
|
|
80
|
+
"poisson_nll",
|
|
81
|
+
"gaussian_nll",
|
|
82
|
+
"smoothness_penalty",
|
|
83
|
+
"marginal_clarity_penalty",
|
|
84
|
+
"DISTRIBUTIONS",
|
|
85
|
+
"resolve_distribution",
|
|
86
|
+
# Training
|
|
87
|
+
"train_anam",
|
|
88
|
+
"TrainingConfig",
|
|
89
|
+
"prepare_data",
|
|
90
|
+
# Sparsity / Variable Selection
|
|
91
|
+
"SparsityConfig",
|
|
92
|
+
"SelectionResult",
|
|
93
|
+
"train_ensemble_main_effects",
|
|
94
|
+
"compute_ensemble_importance",
|
|
95
|
+
"select_main_effects",
|
|
96
|
+
"train_main_effects_model",
|
|
97
|
+
"evaluate_candidate_interactions",
|
|
98
|
+
"select_interactions",
|
|
99
|
+
"run_variable_selection",
|
|
100
|
+
"plot_main_effect_importance",
|
|
101
|
+
"plot_interaction_selection",
|
|
102
|
+
# Utilities
|
|
103
|
+
"generate_synthetic_data",
|
|
104
|
+
"build_feature_configs",
|
|
105
|
+
"remove_outliers_iqr",
|
|
106
|
+
"train_val_test_split",
|
|
107
|
+
"plot_shape_function",
|
|
108
|
+
"plot_interaction_heatmap",
|
|
109
|
+
"plot_variable_importance",
|
|
110
|
+
]
|