statistical-comparison-helpers 0.1.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.
- statistical_comparison_helpers/__init__.py +27 -0
- statistical_comparison_helpers/cld.py +153 -0
- statistical_comparison_helpers/plotting.py +175 -0
- statistical_comparison_helpers/posterior.py +241 -0
- statistical_comparison_helpers-0.1.0.dist-info/METADATA +22 -0
- statistical_comparison_helpers-0.1.0.dist-info/RECORD +9 -0
- statistical_comparison_helpers-0.1.0.dist-info/WHEEL +5 -0
- statistical_comparison_helpers-0.1.0.dist-info/licenses/LICENSE +352 -0
- statistical_comparison_helpers-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Method-agnostic helpers for policy comparison."""
|
|
2
|
+
|
|
3
|
+
from statistical_comparison_helpers.cld import compact_letter_display
|
|
4
|
+
from statistical_comparison_helpers.posterior import (
|
|
5
|
+
Binary,
|
|
6
|
+
Continuous,
|
|
7
|
+
Discrete,
|
|
8
|
+
draw_samples_from_beta_posterior,
|
|
9
|
+
draw_samples_from_dirichlet_posterior,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"compact_letter_display",
|
|
14
|
+
"draw_samples_from_beta_posterior",
|
|
15
|
+
"draw_samples_from_dirichlet_posterior",
|
|
16
|
+
"Binary",
|
|
17
|
+
"Discrete",
|
|
18
|
+
"Continuous",
|
|
19
|
+
"plot_model_comparison",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def __getattr__(name: str):
|
|
24
|
+
if name == "plot_model_comparison":
|
|
25
|
+
from statistical_comparison_helpers.plotting import plot_model_comparison
|
|
26
|
+
return plot_model_comparison
|
|
27
|
+
raise AttributeError(f"module 'statistical_comparison_helpers' has no attribute {name!r}")
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Compact Letter Display (CLD) implementation.
|
|
2
|
+
|
|
3
|
+
Based on "An Algorithm for a Letter-Based Representation of All-Pairwise
|
|
4
|
+
Comparisons" by Piepho (2004).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Tuple
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def compact_letter_display(
|
|
11
|
+
significant_pair_list: List[Tuple[str, str]],
|
|
12
|
+
sorted_model_list: List[str],
|
|
13
|
+
) -> List[str]:
|
|
14
|
+
"""Generates Compact Letter Display (CLD) given a list of significant
|
|
15
|
+
pairs and a list of models.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
significant_pair_list: A list containing tuples of model names that
|
|
19
|
+
were deemed significantly different by each A/B test.
|
|
20
|
+
sorted_model_list: A list of model names sorted by performance in
|
|
21
|
+
descending order.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
A list of letter strings representing CLD for the corresponding
|
|
25
|
+
models, in the same order as sorted_model_list.
|
|
26
|
+
|
|
27
|
+
Raises:
|
|
28
|
+
ValueError: If significant_pair_list contains unknown models,
|
|
29
|
+
duplicate models in sorted_model_list, self-comparisons,
|
|
30
|
+
or duplicate pairs.
|
|
31
|
+
"""
|
|
32
|
+
_validate_inputs(significant_pair_list, sorted_model_list)
|
|
33
|
+
|
|
34
|
+
num_models = len(sorted_model_list)
|
|
35
|
+
if num_models == 0:
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
# Map model names to indices.
|
|
39
|
+
model_to_index = {model: idx for idx, model in enumerate(sorted_model_list)}
|
|
40
|
+
|
|
41
|
+
# Canonicalize pairs: always (lower_index, higher_index) and deduplicate.
|
|
42
|
+
significant_index_pairs = []
|
|
43
|
+
for m1, m2 in significant_pair_list:
|
|
44
|
+
i, j = model_to_index[m1], model_to_index[m2]
|
|
45
|
+
significant_index_pairs.append((min(i, j), max(i, j)))
|
|
46
|
+
|
|
47
|
+
# --- Inner helper to remove redundant columns ---
|
|
48
|
+
def remove_redundant_columns(matrix):
|
|
49
|
+
changed = True
|
|
50
|
+
while changed:
|
|
51
|
+
changed = False
|
|
52
|
+
for i in range(len(matrix)):
|
|
53
|
+
for j in range(len(matrix)):
|
|
54
|
+
if i != j:
|
|
55
|
+
indices_i = {
|
|
56
|
+
idx for idx, char in enumerate(matrix[i]) if char
|
|
57
|
+
}
|
|
58
|
+
indices_j = {
|
|
59
|
+
idx for idx, char in enumerate(matrix[j]) if char
|
|
60
|
+
}
|
|
61
|
+
if indices_i.issubset(indices_j):
|
|
62
|
+
matrix.pop(i)
|
|
63
|
+
changed = True
|
|
64
|
+
break
|
|
65
|
+
if changed:
|
|
66
|
+
break
|
|
67
|
+
return matrix
|
|
68
|
+
|
|
69
|
+
# --- Main algorithm ---
|
|
70
|
+
# Start with a single column of True for all models.
|
|
71
|
+
letter_matrix: List[List[bool]] = [[True] * num_models]
|
|
72
|
+
|
|
73
|
+
# For each significant pair, update the letter matrix.
|
|
74
|
+
for model_idx1, model_idx2 in significant_index_pairs:
|
|
75
|
+
while any(col[model_idx1] and col[model_idx2] for col in letter_matrix):
|
|
76
|
+
for col_index, letter_column in enumerate(letter_matrix):
|
|
77
|
+
if letter_column[model_idx1] and letter_column[model_idx2]:
|
|
78
|
+
new_column = letter_column.copy()
|
|
79
|
+
new_column[model_idx1] = False
|
|
80
|
+
letter_column[model_idx2] = False
|
|
81
|
+
letter_matrix[col_index] = letter_column
|
|
82
|
+
letter_matrix.append(new_column)
|
|
83
|
+
letter_matrix = remove_redundant_columns(letter_matrix)
|
|
84
|
+
break
|
|
85
|
+
|
|
86
|
+
# --- Deterministic letter assignment ---
|
|
87
|
+
# Sort columns with a principled tie-break:
|
|
88
|
+
# 1. Primary: first non-empty position (ascending) — top-ranked groups first.
|
|
89
|
+
# 2. Secondary: number of covered models (descending) — larger groups get
|
|
90
|
+
# earlier letters.
|
|
91
|
+
# 3. Tertiary: tuple of covered positions (ascending) — deterministic
|
|
92
|
+
# tie-break for equal-size groups.
|
|
93
|
+
def column_sort_key(column):
|
|
94
|
+
positions = tuple(i for i, v in enumerate(column) if v)
|
|
95
|
+
first_pos = positions[0] if positions else num_models
|
|
96
|
+
count = len(positions)
|
|
97
|
+
return (first_pos, -count, positions)
|
|
98
|
+
|
|
99
|
+
letter_matrix.sort(key=column_sort_key)
|
|
100
|
+
|
|
101
|
+
# Assign letters and build final output.
|
|
102
|
+
final_display = []
|
|
103
|
+
for model_idx in range(num_models):
|
|
104
|
+
letters = "".join(
|
|
105
|
+
chr(ord("a") + col_idx)
|
|
106
|
+
for col_idx in range(len(letter_matrix))
|
|
107
|
+
if letter_matrix[col_idx][model_idx]
|
|
108
|
+
)
|
|
109
|
+
final_display.append("".join(sorted(letters)))
|
|
110
|
+
|
|
111
|
+
return final_display
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _validate_inputs(
|
|
115
|
+
significant_pair_list: List[Tuple[str, str]],
|
|
116
|
+
sorted_model_list: List[str],
|
|
117
|
+
) -> None:
|
|
118
|
+
"""Validate CLD inputs."""
|
|
119
|
+
# Check for duplicate models.
|
|
120
|
+
if len(sorted_model_list) != len(set(sorted_model_list)):
|
|
121
|
+
seen = set()
|
|
122
|
+
for m in sorted_model_list:
|
|
123
|
+
if m in seen:
|
|
124
|
+
raise ValueError(
|
|
125
|
+
f"Duplicate model in sorted_model_list: '{m}'"
|
|
126
|
+
)
|
|
127
|
+
seen.add(m)
|
|
128
|
+
|
|
129
|
+
model_set = set(sorted_model_list)
|
|
130
|
+
|
|
131
|
+
seen_pairs = set()
|
|
132
|
+
for m1, m2 in significant_pair_list:
|
|
133
|
+
# Check for unknown models.
|
|
134
|
+
if m1 not in model_set:
|
|
135
|
+
raise ValueError(
|
|
136
|
+
f"Unknown model in significant_pair_list: '{m1}'"
|
|
137
|
+
)
|
|
138
|
+
if m2 not in model_set:
|
|
139
|
+
raise ValueError(
|
|
140
|
+
f"Unknown model in significant_pair_list: '{m2}'"
|
|
141
|
+
)
|
|
142
|
+
# Check for self-comparisons.
|
|
143
|
+
if m1 == m2:
|
|
144
|
+
raise ValueError(
|
|
145
|
+
f"Self-comparison in significant_pair_list: ('{m1}', '{m2}')"
|
|
146
|
+
)
|
|
147
|
+
# Check for duplicate pairs (order-independent).
|
|
148
|
+
canonical = (min(m1, m2), max(m1, m2))
|
|
149
|
+
if canonical in seen_pairs:
|
|
150
|
+
raise ValueError(
|
|
151
|
+
f"Duplicate pair in significant_pair_list: ('{m1}', '{m2}')"
|
|
152
|
+
)
|
|
153
|
+
seen_pairs.add(canonical)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Violin plot visualization for policy comparison."""
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional, Union
|
|
4
|
+
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from statistical_comparison_helpers.posterior import (
|
|
9
|
+
Binary,
|
|
10
|
+
Continuous,
|
|
11
|
+
Discrete,
|
|
12
|
+
draw_posterior_samples,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def plot_model_comparison(
|
|
17
|
+
model_name_list: List[str],
|
|
18
|
+
result_arrays: List[np.ndarray],
|
|
19
|
+
cld_letters: List[str],
|
|
20
|
+
rng: np.random.Generator,
|
|
21
|
+
score: Union[Binary, Discrete, Continuous] = Binary(),
|
|
22
|
+
plot_mode: str = "posterior",
|
|
23
|
+
show_empirical_means: bool = True,
|
|
24
|
+
overlay_on_bars: bool = False,
|
|
25
|
+
output_path: Optional[str] = None,
|
|
26
|
+
title: Optional[str] = None,
|
|
27
|
+
add_legend: bool = False,
|
|
28
|
+
unit_width: int = 6,
|
|
29
|
+
height: int = 4,
|
|
30
|
+
dpi: int = 100,
|
|
31
|
+
) -> Optional[plt.Figure]:
|
|
32
|
+
"""Makes a violin plot of score estimates with corresponding CLD letters.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
model_name_list: A list of model names.
|
|
36
|
+
result_arrays: A list of score arrays for each model.
|
|
37
|
+
cld_letters: A list of CLD letters corresponding to each model.
|
|
38
|
+
rng: A numpy random Generator instance for posterior sampling.
|
|
39
|
+
score: Score type specification (Binary, Discrete, or Continuous).
|
|
40
|
+
plot_mode: "posterior" for posterior violin or "raw" for raw data violin.
|
|
41
|
+
show_empirical_means: Whether to show empirical mean dots.
|
|
42
|
+
overlay_on_bars: Whether to draw bar overlays behind violins.
|
|
43
|
+
output_path: Optional file path to save the plot.
|
|
44
|
+
title: Optional title for the plot.
|
|
45
|
+
add_legend: Whether to show legend.
|
|
46
|
+
unit_width: Figure width per model.
|
|
47
|
+
height: Figure height.
|
|
48
|
+
dpi: Resolution of the saved plot.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
If output_path is None, returns a matplotlib Figure object.
|
|
52
|
+
Otherwise, saves the plot and returns None.
|
|
53
|
+
"""
|
|
54
|
+
num_models = len(model_name_list)
|
|
55
|
+
|
|
56
|
+
if plot_mode == "posterior":
|
|
57
|
+
violin_data = []
|
|
58
|
+
posterior_means = []
|
|
59
|
+
for result_array in result_arrays:
|
|
60
|
+
samples = draw_posterior_samples(
|
|
61
|
+
np.asarray(result_array), score, rng
|
|
62
|
+
)
|
|
63
|
+
violin_data.append(samples)
|
|
64
|
+
posterior_means.append(np.mean(samples))
|
|
65
|
+
elif plot_mode == "raw":
|
|
66
|
+
violin_data = [np.asarray(arr) for arr in result_arrays]
|
|
67
|
+
else:
|
|
68
|
+
raise ValueError(f"Unknown plot_mode: '{plot_mode}'. Use 'posterior' or 'raw'.")
|
|
69
|
+
|
|
70
|
+
empirical_means = [np.mean(arr) for arr in result_arrays]
|
|
71
|
+
|
|
72
|
+
fig, ax = plt.subplots(figsize=(max(unit_width, num_models), height), dpi=dpi)
|
|
73
|
+
|
|
74
|
+
cmap = plt.get_cmap("tab10")
|
|
75
|
+
colors = [cmap(i % 10) for i in range(num_models)]
|
|
76
|
+
|
|
77
|
+
if overlay_on_bars:
|
|
78
|
+
ax.bar(
|
|
79
|
+
np.arange(num_models),
|
|
80
|
+
empirical_means,
|
|
81
|
+
color=colors,
|
|
82
|
+
alpha=0.15,
|
|
83
|
+
width=0.8,
|
|
84
|
+
zorder=1,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
parts = ax.violinplot(
|
|
88
|
+
violin_data,
|
|
89
|
+
positions=np.arange(num_models),
|
|
90
|
+
showmeans=False,
|
|
91
|
+
showmedians=False,
|
|
92
|
+
showextrema=False,
|
|
93
|
+
widths=0.8,
|
|
94
|
+
)
|
|
95
|
+
for pc, color in zip(parts["bodies"], colors):
|
|
96
|
+
pc.set_facecolor(color)
|
|
97
|
+
pc.set_alpha(0.6)
|
|
98
|
+
|
|
99
|
+
# Posterior mode: show posterior mean line + empirical mean dot.
|
|
100
|
+
# Raw mode: do NOT draw posterior mean line.
|
|
101
|
+
if plot_mode == "posterior":
|
|
102
|
+
# Posterior mean horizontal lines.
|
|
103
|
+
for i, mean_val in enumerate(posterior_means):
|
|
104
|
+
ax.hlines(
|
|
105
|
+
mean_val,
|
|
106
|
+
i - 0.3,
|
|
107
|
+
i + 0.3,
|
|
108
|
+
colors="black",
|
|
109
|
+
linewidths=1.2,
|
|
110
|
+
zorder=3,
|
|
111
|
+
label="Posterior mean" if i == 0 else None,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
if show_empirical_means:
|
|
115
|
+
ax.scatter(
|
|
116
|
+
np.arange(num_models),
|
|
117
|
+
empirical_means,
|
|
118
|
+
color="black",
|
|
119
|
+
s=30,
|
|
120
|
+
zorder=4,
|
|
121
|
+
marker="o",
|
|
122
|
+
label="Empirical mean",
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
# Add CLD labels.
|
|
126
|
+
label_y = posterior_means if plot_mode == "posterior" else empirical_means
|
|
127
|
+
for i, (x, y, label) in enumerate(
|
|
128
|
+
zip(np.arange(num_models), label_y, cld_letters)
|
|
129
|
+
):
|
|
130
|
+
ax.text(
|
|
131
|
+
x + 0.15,
|
|
132
|
+
y + 0.03,
|
|
133
|
+
label,
|
|
134
|
+
fontsize=12,
|
|
135
|
+
fontweight="bold",
|
|
136
|
+
color="black",
|
|
137
|
+
verticalalignment="center",
|
|
138
|
+
zorder=5,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
ax.set_xticks(np.arange(num_models))
|
|
142
|
+
ax.set_xticklabels(model_name_list, rotation=0, ha="center")
|
|
143
|
+
|
|
144
|
+
# Derive y-limits from score bounds / grid / data.
|
|
145
|
+
if isinstance(score, Binary):
|
|
146
|
+
y_lo, y_hi = 0.0, 1.0
|
|
147
|
+
elif isinstance(score, Continuous):
|
|
148
|
+
if score.grid is not None:
|
|
149
|
+
grid = np.asarray(sorted(score.grid), dtype=float)
|
|
150
|
+
y_lo, y_hi = float(grid[0]), float(grid[-1])
|
|
151
|
+
else:
|
|
152
|
+
y_lo, y_hi = score.bounds
|
|
153
|
+
elif isinstance(score, Discrete):
|
|
154
|
+
y_lo = float(min(score.support))
|
|
155
|
+
y_hi = float(max(score.support))
|
|
156
|
+
else:
|
|
157
|
+
# Fallback: derive from data.
|
|
158
|
+
all_vals = np.concatenate([np.asarray(a) for a in result_arrays])
|
|
159
|
+
y_lo, y_hi = float(np.min(all_vals)), float(np.max(all_vals))
|
|
160
|
+
|
|
161
|
+
padding = (y_hi - y_lo) * 0.05
|
|
162
|
+
ax.set_ylim(y_lo - padding, y_hi + padding)
|
|
163
|
+
ax.set_ylabel("Score")
|
|
164
|
+
if title is not None:
|
|
165
|
+
ax.set_title(title)
|
|
166
|
+
if add_legend:
|
|
167
|
+
ax.legend(loc="best")
|
|
168
|
+
plt.tight_layout()
|
|
169
|
+
|
|
170
|
+
if output_path is not None:
|
|
171
|
+
plt.savefig(output_path, dpi=300)
|
|
172
|
+
plt.close()
|
|
173
|
+
return None
|
|
174
|
+
else:
|
|
175
|
+
return fig
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""Posterior sampling and score-type specifications."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import List, Optional, Union
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from scipy import stats
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class Binary:
|
|
12
|
+
"""Score spec for binary success/failure data. Uses Beta posterior.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
alpha_prior: Alpha parameter for the Beta prior. Defaults to 1.
|
|
16
|
+
beta_prior: Beta parameter for the Beta prior. Defaults to 1.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
alpha_prior: float = 1.0
|
|
20
|
+
beta_prior: float = 1.0
|
|
21
|
+
|
|
22
|
+
def __post_init__(self):
|
|
23
|
+
if self.alpha_prior <= 0:
|
|
24
|
+
raise ValueError("alpha_prior must be > 0.")
|
|
25
|
+
if self.beta_prior <= 0:
|
|
26
|
+
raise ValueError("beta_prior must be > 0.")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class Discrete:
|
|
31
|
+
"""Score spec for discrete partial-progress values.
|
|
32
|
+
|
|
33
|
+
Uses Dirichlet posterior over the exact support. Observed values must lie
|
|
34
|
+
exactly on the support points.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
support: The exact set of possible score values, e.g. [0, 0.25, 0.5, 0.75, 1.0].
|
|
38
|
+
alpha_prior: Symmetric Dirichlet prior concentration per bin. Defaults to 1.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
support: List[float] = field(default_factory=lambda: [0.0, 1.0])
|
|
42
|
+
alpha_prior: float = 1.0
|
|
43
|
+
|
|
44
|
+
def __post_init__(self):
|
|
45
|
+
if len(self.support) < 2:
|
|
46
|
+
raise ValueError("Discrete support must have at least 2 points.")
|
|
47
|
+
arr = np.asarray(self.support, dtype=float)
|
|
48
|
+
if not np.all(np.isfinite(arr)):
|
|
49
|
+
raise ValueError("Discrete support must contain only finite values.")
|
|
50
|
+
if len(np.unique(arr)) != len(arr):
|
|
51
|
+
raise ValueError("Discrete support must not contain duplicates.")
|
|
52
|
+
if self.alpha_prior <= 0:
|
|
53
|
+
raise ValueError("alpha_prior must be > 0.")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class Continuous:
|
|
58
|
+
"""Score spec for bounded continuous scores.
|
|
59
|
+
|
|
60
|
+
Uses Dirichlet posterior over an approximation grid. Observed values are
|
|
61
|
+
snapped to the nearest grid point.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
bounds: (min, max) bounds for the score range. Defaults to (0.0, 1.0).
|
|
65
|
+
num_bins: Number of bins for the approximation grid. The grid has
|
|
66
|
+
num_bins + 1 points. Defaults to 10.
|
|
67
|
+
grid: Explicit grid points. If provided, num_bins and bounds are ignored.
|
|
68
|
+
alpha_prior: Symmetric Dirichlet prior concentration per bin. Defaults to 1.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
bounds: tuple = (0.0, 1.0)
|
|
72
|
+
num_bins: int = 10
|
|
73
|
+
grid: Optional[List[float]] = None
|
|
74
|
+
alpha_prior: float = 1.0
|
|
75
|
+
|
|
76
|
+
def __post_init__(self):
|
|
77
|
+
if self.grid is not None:
|
|
78
|
+
arr = np.asarray(self.grid, dtype=float)
|
|
79
|
+
if len(arr) < 2:
|
|
80
|
+
raise ValueError("Continuous grid must have at least 2 points.")
|
|
81
|
+
if not np.all(np.isfinite(arr)):
|
|
82
|
+
raise ValueError("Continuous grid must contain only finite values.")
|
|
83
|
+
if len(np.unique(arr)) != len(arr):
|
|
84
|
+
raise ValueError("Continuous grid must not contain duplicates.")
|
|
85
|
+
else:
|
|
86
|
+
lo, hi = self.bounds
|
|
87
|
+
if lo >= hi:
|
|
88
|
+
raise ValueError(f"bounds min ({lo}) must be < max ({hi}).")
|
|
89
|
+
if self.num_bins <= 0:
|
|
90
|
+
raise ValueError("num_bins must be > 0.")
|
|
91
|
+
if self.alpha_prior <= 0:
|
|
92
|
+
raise ValueError("alpha_prior must be > 0.")
|
|
93
|
+
|
|
94
|
+
def get_grid(self) -> np.ndarray:
|
|
95
|
+
"""Return the approximation grid as a numpy array."""
|
|
96
|
+
if self.grid is not None:
|
|
97
|
+
return np.asarray(sorted(self.grid), dtype=float)
|
|
98
|
+
lo, hi = self.bounds
|
|
99
|
+
return np.linspace(lo, hi, self.num_bins + 1)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def draw_samples_from_beta_posterior(
|
|
103
|
+
success_array: np.ndarray,
|
|
104
|
+
rng: np.random.Generator,
|
|
105
|
+
num_samples: int = 10000,
|
|
106
|
+
alpha_prior: float = 1,
|
|
107
|
+
beta_prior: float = 1,
|
|
108
|
+
) -> np.ndarray:
|
|
109
|
+
"""Draw samples from the beta posterior distribution given a success array.
|
|
110
|
+
|
|
111
|
+
These samples can be used to estimate the posterior distribution of the
|
|
112
|
+
success rate of a Bernoulli process. The default prior parameters of (1, 1)
|
|
113
|
+
correspond to a uniform prior.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
success_array: A binary array with 0/1 or bool values indicating failure/success.
|
|
117
|
+
rng: A numpy random Generator instance.
|
|
118
|
+
num_samples: Number of samples to draw. Defaults to 10000.
|
|
119
|
+
alpha_prior: Alpha parameter of the beta prior. Defaults to 1.
|
|
120
|
+
beta_prior: Beta parameter of the beta prior. Defaults to 1.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Samples drawn from the beta posterior distribution.
|
|
124
|
+
"""
|
|
125
|
+
if num_samples <= 0:
|
|
126
|
+
raise ValueError("num_samples must be > 0.")
|
|
127
|
+
if alpha_prior <= 0:
|
|
128
|
+
raise ValueError("alpha_prior must be > 0.")
|
|
129
|
+
if beta_prior <= 0:
|
|
130
|
+
raise ValueError("beta_prior must be > 0.")
|
|
131
|
+
success_array = np.asarray(success_array)
|
|
132
|
+
if success_array.size > 0:
|
|
133
|
+
unique_vals = set(np.unique(success_array).tolist())
|
|
134
|
+
if not unique_vals.issubset({0, 1, 0.0, 1.0, True, False}):
|
|
135
|
+
raise ValueError(
|
|
136
|
+
"Binary data must contain only 0/1 or boolean values. "
|
|
137
|
+
f"Found: {unique_vals}"
|
|
138
|
+
)
|
|
139
|
+
n_trials = len(success_array)
|
|
140
|
+
n_successes = np.sum(success_array)
|
|
141
|
+
n_failures = n_trials - n_successes
|
|
142
|
+
posterior = stats.beta(alpha_prior + n_successes, beta_prior + n_failures)
|
|
143
|
+
return posterior.rvs(num_samples, random_state=rng)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def draw_samples_from_dirichlet_posterior(
|
|
147
|
+
progress_array: np.ndarray,
|
|
148
|
+
progress_bins: np.ndarray,
|
|
149
|
+
rng: np.random.Generator,
|
|
150
|
+
num_samples: int = 10000,
|
|
151
|
+
alpha_prior: float = 1,
|
|
152
|
+
) -> np.ndarray:
|
|
153
|
+
"""Draw posterior mean samples via Dirichlet posterior over a discrete grid.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
progress_array: Observed score values. Must lie exactly on progress_bins
|
|
157
|
+
for Discrete, or will be snapped for Continuous.
|
|
158
|
+
progress_bins: Sorted grid points for the Dirichlet posterior.
|
|
159
|
+
rng: A numpy random Generator instance.
|
|
160
|
+
num_samples: Number of samples to draw. Defaults to 10000.
|
|
161
|
+
alpha_prior: Symmetric Dirichlet prior concentration per bin.
|
|
162
|
+
Defaults to 1.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Samples of the posterior mean (weighted average of grid points under
|
|
166
|
+
Dirichlet-sampled probability vectors).
|
|
167
|
+
"""
|
|
168
|
+
if num_samples <= 0:
|
|
169
|
+
raise ValueError("num_samples must be > 0.")
|
|
170
|
+
if alpha_prior <= 0:
|
|
171
|
+
raise ValueError("alpha_prior must be > 0.")
|
|
172
|
+
|
|
173
|
+
progress_bins = np.asarray(sorted(progress_bins), dtype=float)
|
|
174
|
+
progress_array = np.asarray(progress_array, dtype=float)
|
|
175
|
+
|
|
176
|
+
if len(progress_bins) < 2:
|
|
177
|
+
raise ValueError("progress_bins must have at least 2 points.")
|
|
178
|
+
if len(np.unique(progress_bins)) != len(progress_bins):
|
|
179
|
+
raise ValueError("progress_bins must not contain duplicates.")
|
|
180
|
+
if not np.all(np.isfinite(progress_bins)):
|
|
181
|
+
raise ValueError("progress_bins must contain only finite values.")
|
|
182
|
+
|
|
183
|
+
if not np.all(np.isin(np.round(progress_array, 10), np.round(progress_bins, 10))):
|
|
184
|
+
raise ValueError("All progress values must be in progress_bins.")
|
|
185
|
+
|
|
186
|
+
alpha_vec = alpha_prior * np.ones(len(progress_bins))
|
|
187
|
+
progress_counts = np.array(
|
|
188
|
+
[np.sum(np.isclose(progress_array, b)) for b in progress_bins]
|
|
189
|
+
)
|
|
190
|
+
posterior = stats.dirichlet(alpha_vec + progress_counts)
|
|
191
|
+
p_samples = posterior.rvs(size=num_samples, random_state=rng)
|
|
192
|
+
mean_samples = p_samples.dot(progress_bins)
|
|
193
|
+
return mean_samples
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _snap_to_grid(values: np.ndarray, grid: np.ndarray) -> np.ndarray:
|
|
197
|
+
"""Snap continuous values to the nearest grid point."""
|
|
198
|
+
values = np.asarray(values, dtype=float)
|
|
199
|
+
grid = np.asarray(grid, dtype=float)
|
|
200
|
+
# For each value, find the nearest grid point.
|
|
201
|
+
indices = np.abs(values[:, None] - grid[None, :]).argmin(axis=1)
|
|
202
|
+
return grid[indices]
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def draw_posterior_samples(
|
|
206
|
+
data: np.ndarray,
|
|
207
|
+
score: Union[Binary, Discrete, Continuous],
|
|
208
|
+
rng: np.random.Generator,
|
|
209
|
+
num_samples: int = 10000,
|
|
210
|
+
) -> np.ndarray:
|
|
211
|
+
"""Draw posterior samples for the given score type.
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
data: Observed score values.
|
|
215
|
+
score: A score spec (Binary, Discrete, or Continuous).
|
|
216
|
+
rng: A numpy random Generator instance.
|
|
217
|
+
num_samples: Number of samples to draw.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
Posterior mean samples.
|
|
221
|
+
"""
|
|
222
|
+
if isinstance(score, Binary):
|
|
223
|
+
return draw_samples_from_beta_posterior(
|
|
224
|
+
data, rng, num_samples=num_samples,
|
|
225
|
+
alpha_prior=score.alpha_prior, beta_prior=score.beta_prior,
|
|
226
|
+
)
|
|
227
|
+
elif isinstance(score, Discrete):
|
|
228
|
+
bins = np.asarray(sorted(score.support), dtype=float)
|
|
229
|
+
return draw_samples_from_dirichlet_posterior(
|
|
230
|
+
data, bins, rng, num_samples=num_samples,
|
|
231
|
+
alpha_prior=score.alpha_prior,
|
|
232
|
+
)
|
|
233
|
+
elif isinstance(score, Continuous):
|
|
234
|
+
grid = score.get_grid()
|
|
235
|
+
snapped = _snap_to_grid(data, grid)
|
|
236
|
+
return draw_samples_from_dirichlet_posterior(
|
|
237
|
+
snapped, grid, rng, num_samples=num_samples,
|
|
238
|
+
alpha_prior=score.alpha_prior,
|
|
239
|
+
)
|
|
240
|
+
else:
|
|
241
|
+
raise TypeError(f"Unknown score type: {type(score)}")
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: statistical_comparison_helpers
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Method-agnostic helpers for policy comparison: CLD, posterior sampling, and plotting.
|
|
5
|
+
License: CC BY-NC 4.0
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: numpy>=1.21
|
|
10
|
+
Requires-Dist: scipy>=1.7
|
|
11
|
+
Requires-Dist: matplotlib>=3.5
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# License statement
|
|
17
|
+
|
|
18
|
+
The code is provided under a Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license. Under the license, the code is provided royalty free for non-commercial purposes only. The code may be covered by patents and if you want to use the code for commercial purposes, please contact us for a different license.
|
|
19
|
+
|
|
20
|
+
# statistical_comparison_helpers
|
|
21
|
+
|
|
22
|
+
This library is a part of [AnyEval](https://github.com/TRI-ML/AnyEval) software. It provides method-agnostic helpers for policy comparison: CLD, posterior sampling, and plotting.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
statistical_comparison_helpers/__init__.py,sha256=S76FUSxbd1HhjW-yba9DsLzfmKZCMinpBwnruABI8Nw,795
|
|
2
|
+
statistical_comparison_helpers/cld.py,sha256=UBcd70I4OOLwUx3sz8bX9q1etrXGwK3dLb_l1MbwzDM,5674
|
|
3
|
+
statistical_comparison_helpers/plotting.py,sha256=LAirBD2j8ERadFl2nnirwgJl3c1MmEJpzXAcvgf9Yes,5526
|
|
4
|
+
statistical_comparison_helpers/posterior.py,sha256=5HVL9m4f3c5jiYx_ggTUhrpFLflKG5pWMxmeZ5cJHYY,9065
|
|
5
|
+
statistical_comparison_helpers-0.1.0.dist-info/licenses/LICENSE,sha256=mgNWNPeRFQBBSFB9tlT-Tu2q7RNx96r4s1dKJ6RExKE,19916
|
|
6
|
+
statistical_comparison_helpers-0.1.0.dist-info/METADATA,sha256=9C-9ZLd6628I9vCG_ShxrdWG4BXf0FefgIJJ_khH3VY,1000
|
|
7
|
+
statistical_comparison_helpers-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
statistical_comparison_helpers-0.1.0.dist-info/top_level.txt,sha256=K4h3UgVUQdWiELE7iHPOF9XdpLS8X6mYMQIZiemebq0,31
|
|
9
|
+
statistical_comparison_helpers-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
Creative Commons Attribution-NonCommercial 4.0 International
|
|
2
|
+
|
|
3
|
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
|
4
|
+
does not provide legal services or legal advice. Distribution of
|
|
5
|
+
Creative Commons public licenses does not create a lawyer-client or
|
|
6
|
+
other relationship. Creative Commons makes its licenses and related
|
|
7
|
+
information available on an "as-is" basis. Creative Commons gives no
|
|
8
|
+
warranties regarding its licenses, any material licensed under their
|
|
9
|
+
terms and conditions, or any related information. Creative Commons
|
|
10
|
+
disclaims all liability for damages resulting from their use to the
|
|
11
|
+
fullest extent possible.
|
|
12
|
+
|
|
13
|
+
Using Creative Commons Public Licenses
|
|
14
|
+
|
|
15
|
+
Creative Commons public licenses provide a standard set of terms and
|
|
16
|
+
conditions that creators and other rights holders may use to share
|
|
17
|
+
original works of authorship and other material subject to copyright and
|
|
18
|
+
certain other rights specified in the public license below. The
|
|
19
|
+
following considerations are for informational purposes only, are not
|
|
20
|
+
exhaustive, and do not form part of our licenses.
|
|
21
|
+
|
|
22
|
+
- Considerations for licensors: Our public licenses are intended for
|
|
23
|
+
use by those authorized to give the public permission to use
|
|
24
|
+
material in ways otherwise restricted by copyright and certain other
|
|
25
|
+
rights. Our licenses are irrevocable. Licensors should read and
|
|
26
|
+
understand the terms and conditions of the license they choose
|
|
27
|
+
before applying it. Licensors should also secure all rights
|
|
28
|
+
necessary before applying our licenses so that the public can reuse
|
|
29
|
+
the material as expected. Licensors should clearly mark any material
|
|
30
|
+
not subject to the license. This includes other CC-licensed
|
|
31
|
+
material, or material used under an exception or limitation to
|
|
32
|
+
copyright. More considerations for licensors :
|
|
33
|
+
wiki.creativecommons.org/Considerations_for_licensors
|
|
34
|
+
|
|
35
|
+
- Considerations for the public: By using one of our public licenses,
|
|
36
|
+
a licensor grants the public permission to use the licensed material
|
|
37
|
+
under specified terms and conditions. If the licensor's permission
|
|
38
|
+
is not necessary for any reason–for example, because of any
|
|
39
|
+
applicable exception or limitation to copyright–then that use is not
|
|
40
|
+
regulated by the license. Our licenses grant only permissions under
|
|
41
|
+
copyright and certain other rights that a licensor has authority to
|
|
42
|
+
grant. Use of the licensed material may still be restricted for
|
|
43
|
+
other reasons, including because others have copyright or other
|
|
44
|
+
rights in the material. A licensor may make special requests, such
|
|
45
|
+
as asking that all changes be marked or described. Although not
|
|
46
|
+
required by our licenses, you are encouraged to respect those
|
|
47
|
+
requests where reasonable. More considerations for the public :
|
|
48
|
+
wiki.creativecommons.org/Considerations_for_licensees
|
|
49
|
+
|
|
50
|
+
Creative Commons Attribution-NonCommercial 4.0 International Public
|
|
51
|
+
License
|
|
52
|
+
|
|
53
|
+
By exercising the Licensed Rights (defined below), You accept and agree
|
|
54
|
+
to be bound by the terms and conditions of this Creative Commons
|
|
55
|
+
Attribution-NonCommercial 4.0 International Public License ("Public
|
|
56
|
+
License"). To the extent this Public License may be interpreted as a
|
|
57
|
+
contract, You are granted the Licensed Rights in consideration of Your
|
|
58
|
+
acceptance of these terms and conditions, and the Licensor grants You
|
|
59
|
+
such rights in consideration of benefits the Licensor receives from
|
|
60
|
+
making the Licensed Material available under these terms and conditions.
|
|
61
|
+
|
|
62
|
+
- Section 1 – Definitions.
|
|
63
|
+
|
|
64
|
+
- a. Adapted Material means material subject to Copyright and
|
|
65
|
+
Similar Rights that is derived from or based upon the Licensed
|
|
66
|
+
Material and in which the Licensed Material is translated,
|
|
67
|
+
altered, arranged, transformed, or otherwise modified in a
|
|
68
|
+
manner requiring permission under the Copyright and Similar
|
|
69
|
+
Rights held by the Licensor. For purposes of this Public
|
|
70
|
+
License, where the Licensed Material is a musical work,
|
|
71
|
+
performance, or sound recording, Adapted Material is always
|
|
72
|
+
produced where the Licensed Material is synched in timed
|
|
73
|
+
relation with a moving image.
|
|
74
|
+
- b. Adapter's License means the license You apply to Your
|
|
75
|
+
Copyright and Similar Rights in Your contributions to Adapted
|
|
76
|
+
Material in accordance with the terms and conditions of this
|
|
77
|
+
Public License.
|
|
78
|
+
- c. Copyright and Similar Rights means copyright and/or similar
|
|
79
|
+
rights closely related to copyright including, without
|
|
80
|
+
limitation, performance, broadcast, sound recording, and Sui
|
|
81
|
+
Generis Database Rights, without regard to how the rights are
|
|
82
|
+
labeled or categorized. For purposes of this Public License, the
|
|
83
|
+
rights specified in Section 2(b)(1)-(2) are not Copyright and
|
|
84
|
+
Similar Rights.
|
|
85
|
+
- d. Effective Technological Measures means those measures that,
|
|
86
|
+
in the absence of proper authority, may not be circumvented
|
|
87
|
+
under laws fulfilling obligations under Article 11 of the WIPO
|
|
88
|
+
Copyright Treaty adopted on December 20, 1996, and/or similar
|
|
89
|
+
international agreements.
|
|
90
|
+
- e. Exceptions and Limitations means fair use, fair dealing,
|
|
91
|
+
and/or any other exception or limitation to Copyright and
|
|
92
|
+
Similar Rights that applies to Your use of the Licensed
|
|
93
|
+
Material.
|
|
94
|
+
- f. Licensed Material means the artistic or literary work,
|
|
95
|
+
database, or other material to which the Licensor applied this
|
|
96
|
+
Public License.
|
|
97
|
+
- g. Licensed Rights means the rights granted to You subject to
|
|
98
|
+
the terms and conditions of this Public License, which are
|
|
99
|
+
limited to all Copyright and Similar Rights that apply to Your
|
|
100
|
+
use of the Licensed Material and that the Licensor has authority
|
|
101
|
+
to license.
|
|
102
|
+
- h. Licensor means the individual(s) or entity(ies) granting
|
|
103
|
+
rights under this Public License.
|
|
104
|
+
- i. NonCommercial means not primarily intended for or directed
|
|
105
|
+
towards commercial advantage or monetary compensation. For
|
|
106
|
+
purposes of this Public License, the exchange of the Licensed
|
|
107
|
+
Material for other material subject to Copyright and Similar
|
|
108
|
+
Rights by digital file-sharing or similar means is NonCommercial
|
|
109
|
+
provided there is no payment of monetary compensation in
|
|
110
|
+
connection with the exchange.
|
|
111
|
+
- j. Share means to provide material to the public by any means or
|
|
112
|
+
process that requires permission under the Licensed Rights, such
|
|
113
|
+
as reproduction, public display, public performance,
|
|
114
|
+
distribution, dissemination, communication, or importation, and
|
|
115
|
+
to make material available to the public including in ways that
|
|
116
|
+
members of the public may access the material from a place and
|
|
117
|
+
at a time individually chosen by them.
|
|
118
|
+
- k. Sui Generis Database Rights means rights other than copyright
|
|
119
|
+
resulting from Directive 96/9/EC of the European Parliament and
|
|
120
|
+
of the Council of 11 March 1996 on the legal protection of
|
|
121
|
+
databases, as amended and/or succeeded, as well as other
|
|
122
|
+
essentially equivalent rights anywhere in the world.
|
|
123
|
+
- l. You means the individual or entity exercising the Licensed
|
|
124
|
+
Rights under this Public License. Your has a corresponding
|
|
125
|
+
meaning.
|
|
126
|
+
|
|
127
|
+
- Section 2 – Scope.
|
|
128
|
+
|
|
129
|
+
- a. License grant.
|
|
130
|
+
- 1. Subject to the terms and conditions of this Public
|
|
131
|
+
License, the Licensor hereby grants You a worldwide,
|
|
132
|
+
royalty-free, non-sublicensable, non-exclusive, irrevocable
|
|
133
|
+
license to exercise the Licensed Rights in the Licensed
|
|
134
|
+
Material to:
|
|
135
|
+
- A. reproduce and Share the Licensed Material, in whole
|
|
136
|
+
or in part, for NonCommercial purposes only; and
|
|
137
|
+
- B. produce, reproduce, and Share Adapted Material for
|
|
138
|
+
NonCommercial purposes only.
|
|
139
|
+
- 2. Exceptions and Limitations. For the avoidance of doubt,
|
|
140
|
+
where Exceptions and Limitations apply to Your use, this
|
|
141
|
+
Public License does not apply, and You do not need to comply
|
|
142
|
+
with its terms and conditions.
|
|
143
|
+
- 3. Term. The term of this Public License is specified in
|
|
144
|
+
Section 6(a).
|
|
145
|
+
- 4. Media and formats; technical modifications allowed. The
|
|
146
|
+
Licensor authorizes You to exercise the Licensed Rights in
|
|
147
|
+
all media and formats whether now known or hereafter
|
|
148
|
+
created, and to make technical modifications necessary to do
|
|
149
|
+
so. The Licensor waives and/or agrees not to assert any
|
|
150
|
+
right or authority to forbid You from making technical
|
|
151
|
+
modifications necessary to exercise the Licensed Rights,
|
|
152
|
+
including technical modifications necessary to circumvent
|
|
153
|
+
Effective Technological Measures. For purposes of this
|
|
154
|
+
Public License, simply making modifications authorized by
|
|
155
|
+
this Section 2(a)(4) never produces Adapted Material.
|
|
156
|
+
- 5. Downstream recipients.
|
|
157
|
+
- A. Offer from the Licensor – Licensed Material. Every
|
|
158
|
+
recipient of the Licensed Material automatically
|
|
159
|
+
receives an offer from the Licensor to exercise the
|
|
160
|
+
Licensed Rights under the terms and conditions of this
|
|
161
|
+
Public License.
|
|
162
|
+
- B. No downstream restrictions. You may not offer or
|
|
163
|
+
impose any additional or different terms or conditions
|
|
164
|
+
on, or apply any Effective Technological Measures to,
|
|
165
|
+
the Licensed Material if doing so restricts exercise of
|
|
166
|
+
the Licensed Rights by any recipient of the Licensed
|
|
167
|
+
Material.
|
|
168
|
+
- 6. No endorsement. Nothing in this Public License
|
|
169
|
+
constitutes or may be construed as permission to assert or
|
|
170
|
+
imply that You are, or that Your use of the Licensed
|
|
171
|
+
Material is, connected with, or sponsored, endorsed, or
|
|
172
|
+
granted official status by, the Licensor or others
|
|
173
|
+
designated to receive attribution as provided in Section
|
|
174
|
+
3(a)(1)(A)(i).
|
|
175
|
+
- b. Other rights.
|
|
176
|
+
- 1. Moral rights, such as the right of integrity, are not
|
|
177
|
+
licensed under this Public License, nor are publicity,
|
|
178
|
+
privacy, and/or other similar personality rights; however,
|
|
179
|
+
to the extent possible, the Licensor waives and/or agrees
|
|
180
|
+
not to assert any such rights held by the Licensor to the
|
|
181
|
+
limited extent necessary to allow You to exercise the
|
|
182
|
+
Licensed Rights, but not otherwise.
|
|
183
|
+
- 2. Patent and trademark rights are not licensed under this
|
|
184
|
+
Public License.
|
|
185
|
+
- 3. To the extent possible, the Licensor waives any right to
|
|
186
|
+
collect royalties from You for the exercise of the Licensed
|
|
187
|
+
Rights, whether directly or through a collecting society
|
|
188
|
+
under any voluntary or waivable statutory or compulsory
|
|
189
|
+
licensing scheme. In all other cases the Licensor expressly
|
|
190
|
+
reserves any right to collect such royalties, including when
|
|
191
|
+
the Licensed Material is used other than for NonCommercial
|
|
192
|
+
purposes.
|
|
193
|
+
|
|
194
|
+
- Section 3 – License Conditions.
|
|
195
|
+
|
|
196
|
+
Your exercise of the Licensed Rights is expressly made subject to
|
|
197
|
+
the following conditions.
|
|
198
|
+
|
|
199
|
+
- a. Attribution.
|
|
200
|
+
- 1. If You Share the Licensed Material (including in modified
|
|
201
|
+
form), You must:
|
|
202
|
+
- A. retain the following if it is supplied by the
|
|
203
|
+
Licensor with the Licensed Material:
|
|
204
|
+
- i. identification of the creator(s) of the Licensed
|
|
205
|
+
Material and any others designated to receive
|
|
206
|
+
attribution, in any reasonable manner requested by
|
|
207
|
+
the Licensor (including by pseudonym if designated);
|
|
208
|
+
- ii. a copyright notice;
|
|
209
|
+
- iii. a notice that refers to this Public License;
|
|
210
|
+
- iv. a notice that refers to the disclaimer of
|
|
211
|
+
warranties;
|
|
212
|
+
- v. a URI or hyperlink to the Licensed Material to
|
|
213
|
+
the extent reasonably practicable;
|
|
214
|
+
- B. indicate if You modified the Licensed Material and
|
|
215
|
+
retain an indication of any previous modifications; and
|
|
216
|
+
- C. indicate the Licensed Material is licensed under this
|
|
217
|
+
Public License, and include the text of, or the URI or
|
|
218
|
+
hyperlink to, this Public License.
|
|
219
|
+
- 2. You may satisfy the conditions in Section 3(a)(1) in any
|
|
220
|
+
reasonable manner based on the medium, means, and context in
|
|
221
|
+
which You Share the Licensed Material. For example, it may
|
|
222
|
+
be reasonable to satisfy the conditions by providing a URI
|
|
223
|
+
or hyperlink to a resource that includes the required
|
|
224
|
+
information.
|
|
225
|
+
- 3. If requested by the Licensor, You must remove any of the
|
|
226
|
+
information required by Section 3(a)(1)(A) to the extent
|
|
227
|
+
reasonably practicable.
|
|
228
|
+
- 4. If You Share Adapted Material You produce, the Adapter's
|
|
229
|
+
License You apply must not prevent recipients of the Adapted
|
|
230
|
+
Material from complying with this Public License.
|
|
231
|
+
|
|
232
|
+
- Section 4 – Sui Generis Database Rights.
|
|
233
|
+
|
|
234
|
+
Where the Licensed Rights include Sui Generis Database Rights that
|
|
235
|
+
apply to Your use of the Licensed Material:
|
|
236
|
+
|
|
237
|
+
- a. for the avoidance of doubt, Section 2(a)(1) grants You the
|
|
238
|
+
right to extract, reuse, reproduce, and Share all or a
|
|
239
|
+
substantial portion of the contents of the database for
|
|
240
|
+
NonCommercial purposes only;
|
|
241
|
+
- b. if You include all or a substantial portion of the database
|
|
242
|
+
contents in a database in which You have Sui Generis Database
|
|
243
|
+
Rights, then the database in which You have Sui Generis Database
|
|
244
|
+
Rights (but not its individual contents) is Adapted Material;
|
|
245
|
+
and
|
|
246
|
+
- c. You must comply with the conditions in Section 3(a) if You
|
|
247
|
+
Share all or a substantial portion of the contents of the
|
|
248
|
+
database.
|
|
249
|
+
|
|
250
|
+
For the avoidance of doubt, this Section 4 supplements and does not
|
|
251
|
+
replace Your obligations under this Public License where the
|
|
252
|
+
Licensed Rights include other Copyright and Similar Rights.
|
|
253
|
+
|
|
254
|
+
- Section 5 – Disclaimer of Warranties and Limitation of Liability.
|
|
255
|
+
|
|
256
|
+
- a. Unless otherwise separately undertaken by the Licensor, to
|
|
257
|
+
the extent possible, the Licensor offers the Licensed Material
|
|
258
|
+
as-is and as-available, and makes no representations or
|
|
259
|
+
warranties of any kind concerning the Licensed Material, whether
|
|
260
|
+
express, implied, statutory, or other. This includes, without
|
|
261
|
+
limitation, warranties of title, merchantability, fitness for a
|
|
262
|
+
particular purpose, non-infringement, absence of latent or other
|
|
263
|
+
defects, accuracy, or the presence or absence of errors, whether
|
|
264
|
+
or not known or discoverable. Where disclaimers of warranties
|
|
265
|
+
are not allowed in full or in part, this disclaimer may not
|
|
266
|
+
apply to You.
|
|
267
|
+
- b. To the extent possible, in no event will the Licensor be
|
|
268
|
+
liable to You on any legal theory (including, without
|
|
269
|
+
limitation, negligence) or otherwise for any direct, special,
|
|
270
|
+
indirect, incidental, consequential, punitive, exemplary, or
|
|
271
|
+
other losses, costs, expenses, or damages arising out of this
|
|
272
|
+
Public License or use of the Licensed Material, even if the
|
|
273
|
+
Licensor has been advised of the possibility of such losses,
|
|
274
|
+
costs, expenses, or damages. Where a limitation of liability is
|
|
275
|
+
not allowed in full or in part, this limitation may not apply to
|
|
276
|
+
You.
|
|
277
|
+
- c. The disclaimer of warranties and limitation of liability
|
|
278
|
+
provided above shall be interpreted in a manner that, to the
|
|
279
|
+
extent possible, most closely approximates an absolute
|
|
280
|
+
disclaimer and waiver of all liability.
|
|
281
|
+
|
|
282
|
+
- Section 6 – Term and Termination.
|
|
283
|
+
|
|
284
|
+
- a. This Public License applies for the term of the Copyright and
|
|
285
|
+
Similar Rights licensed here. However, if You fail to comply
|
|
286
|
+
with this Public License, then Your rights under this Public
|
|
287
|
+
License terminate automatically.
|
|
288
|
+
- b. Where Your right to use the Licensed Material has terminated
|
|
289
|
+
under Section 6(a), it reinstates:
|
|
290
|
+
|
|
291
|
+
- 1. automatically as of the date the violation is cured,
|
|
292
|
+
provided it is cured within 30 days of Your discovery of the
|
|
293
|
+
violation; or
|
|
294
|
+
- 2. upon express reinstatement by the Licensor.
|
|
295
|
+
|
|
296
|
+
For the avoidance of doubt, this Section 6(b) does not affect
|
|
297
|
+
any right the Licensor may have to seek remedies for Your
|
|
298
|
+
violations of this Public License.
|
|
299
|
+
|
|
300
|
+
- c. For the avoidance of doubt, the Licensor may also offer the
|
|
301
|
+
Licensed Material under separate terms or conditions or stop
|
|
302
|
+
distributing the Licensed Material at any time; however, doing
|
|
303
|
+
so will not terminate this Public License.
|
|
304
|
+
- d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
|
305
|
+
License.
|
|
306
|
+
|
|
307
|
+
- Section 7 – Other Terms and Conditions.
|
|
308
|
+
|
|
309
|
+
- a. The Licensor shall not be bound by any additional or
|
|
310
|
+
different terms or conditions communicated by You unless
|
|
311
|
+
expressly agreed.
|
|
312
|
+
- b. Any arrangements, understandings, or agreements regarding the
|
|
313
|
+
Licensed Material not stated herein are separate from and
|
|
314
|
+
independent of the terms and conditions of this Public License.
|
|
315
|
+
|
|
316
|
+
- Section 8 – Interpretation.
|
|
317
|
+
|
|
318
|
+
- a. For the avoidance of doubt, this Public License does not, and
|
|
319
|
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
|
320
|
+
conditions on any use of the Licensed Material that could
|
|
321
|
+
lawfully be made without permission under this Public License.
|
|
322
|
+
- b. To the extent possible, if any provision of this Public
|
|
323
|
+
License is deemed unenforceable, it shall be automatically
|
|
324
|
+
reformed to the minimum extent necessary to make it enforceable.
|
|
325
|
+
If the provision cannot be reformed, it shall be severed from
|
|
326
|
+
this Public License without affecting the enforceability of the
|
|
327
|
+
remaining terms and conditions.
|
|
328
|
+
- c. No term or condition of this Public License will be waived
|
|
329
|
+
and no failure to comply consented to unless expressly agreed to
|
|
330
|
+
by the Licensor.
|
|
331
|
+
- d. Nothing in this Public License constitutes or may be
|
|
332
|
+
interpreted as a limitation upon, or waiver of, any privileges
|
|
333
|
+
and immunities that apply to the Licensor or You, including from
|
|
334
|
+
the legal processes of any jurisdiction or authority.
|
|
335
|
+
|
|
336
|
+
Creative Commons is not a party to its public licenses. Notwithstanding,
|
|
337
|
+
Creative Commons may elect to apply one of its public licenses to
|
|
338
|
+
material it publishes and in those instances will be considered the
|
|
339
|
+
"Licensor." The text of the Creative Commons public licenses is
|
|
340
|
+
dedicated to the public domain under the CC0 Public Domain Dedication.
|
|
341
|
+
Except for the limited purpose of indicating that material is shared
|
|
342
|
+
under a Creative Commons public license or as otherwise permitted by the
|
|
343
|
+
Creative Commons policies published at creativecommons.org/policies,
|
|
344
|
+
Creative Commons does not authorize the use of the trademark "Creative
|
|
345
|
+
Commons" or any other trademark or logo of Creative Commons without its
|
|
346
|
+
prior written consent including, without limitation, in connection with
|
|
347
|
+
any unauthorized modifications to any of its public licenses or any
|
|
348
|
+
other arrangements, understandings, or agreements concerning use of
|
|
349
|
+
licensed material. For the avoidance of doubt, this paragraph does not
|
|
350
|
+
form part of the public licenses.
|
|
351
|
+
|
|
352
|
+
Creative Commons may be contacted at creativecommons.org.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
statistical_comparison_helpers
|