Skip to content

Commit

Permalink
improve init assert
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Moreau <[email protected]>
  • Loading branch information
vloison and tomMoral authored Jul 4, 2024
1 parent 2f5b2a0 commit 5de7dda
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions fadin/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,18 @@ def __init__(self, n_dim, kernel, init='random', optim_mask=None,
self.alpha_mask = optim_mask['alpha']

# Initialization option for Hawkes parameters
s = ['random', 'moment_matching_max', 'moment_matching_mean']
if isinstance(init, str):
s = ['random', 'moment_matching_max', 'moment_matching_mean']
assert init in s, \
assert init in s, (
f"Invalid string init {init}. init must be a dict or in {s}."
)
else:
keys_ok = set(init.keys()) == set(['baseline', 'alpha', 'kernel'])
keys = set(['baseline', 'alpha', 'kernel'])
is_dict = isinstance(init, dict)
assert is_dict and len(init.keys()) == 3 and keys_ok, \
"Dict init must contain keys 'baseline', 'alpha' and 'kernel'"
assert is_dict and set(init.keys()) == keys, (
f"If init is not a str, it should be a dict with keys {keys}. "
f"Got {init}."
)
self.init = init

# If the learning rate is not given, fix it to 1e-3
Expand Down

0 comments on commit 5de7dda

Please sign in to comment.