diff --git a/neuralfields/potential_based.py b/neuralfields/potential_based.py index 02ceca5..d1a1330 100644 --- a/neuralfields/potential_based.py +++ b/neuralfields/potential_based.py @@ -88,6 +88,8 @@ def __init__( # Initialize the potential dynamics' time constant. self.tau_learnable = tau_learnable + if tau_init <= 0: + raise ValueError("The time constant tau must be initialized positive.") self._log_tau_init = torch.log( torch.as_tensor(tau_init, device=device, dtype=torch.get_default_dtype()).reshape(-1) ) @@ -98,6 +100,8 @@ def __init__( # Initialize the potential dynamics' cubic decay. self.kappa_learnable = kappa_learnable + if kappa_init <= 0: + raise ValueError("The cubic decay kappa must be initialized positive.") self._log_kappa_init = torch.log( torch.as_tensor(kappa_init, device=device, dtype=torch.get_default_dtype()).reshape(-1) ) diff --git a/tests/test_simple_neural_fields.py b/tests/test_simple_neural_fields.py index 78ce218..657e1ba 100644 --- a/tests/test_simple_neural_fields.py +++ b/tests/test_simple_neural_fields.py @@ -159,6 +159,12 @@ def test_simple_neural_fields_fail(): with pytest.raises(ValueError): SimpleNeuralField(input_size=6, output_size=3, potentials_dyn_fcn=pd_capacity_21, activation_nonlin=torch.sqrt) + with pytest.raises(ValueError): + SimpleNeuralField(input_size=6, output_size=3, potentials_dyn_fcn=pd_capacity_21, tau_init=0) + + with pytest.raises(ValueError): + SimpleNeuralField(input_size=6, output_size=3, potentials_dyn_fcn=pd_capacity_21, kappa_init=0) + with pytest.raises(ValueError): pd_linear( p=torch.randn(3), s=torch.randn(3), h=torch.randn(3), tau=torch.tensor(-1.0), kappa=None, capacity=None