Skip to content

Commit

Permalink
fix(activation): config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpinet committed Dec 6, 2024
1 parent c7be214 commit 9c03039
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions neuralnetlib/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ def derivative(self, x: np.ndarray) -> np.ndarray:
raise NotImplementedError

def get_config(self) -> dict:
return {}
return {"name": self.__class__.__name__}

@staticmethod
def from_config(config: dict):
name = config['name']
name = config.get('name')
if not name:
raise ValueError('Config must contain "name" field')

constructor_params = {k: v for k, v in config.items()
if k not in ['name', 'config']}

for activation_class in ActivationFunction.__subclasses__():
if activation_class.__name__ == name:
constructor_params = {k: v for k,
v in config.items() if k != 'name'}
return activation_class(**constructor_params)

raise ValueError(f'Unknown activation function: {name}')
Expand Down

0 comments on commit 9c03039

Please sign in to comment.