Skip to content

Commit

Permalink
Started with MEGAN
Browse files Browse the repository at this point in the history
  • Loading branch information
PatReis committed Dec 8, 2023
1 parent cfdac31 commit 6f266a3
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 1 deletion.
1 change: 1 addition & 0 deletions kgcnn/literature/AttentiveFP/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dropout": 0.1,
"verbose": 10,
"output_embedding": "graph",
"output_scaling": None,
"output_to_tensor": True, # deprecated
"output_tensor_type": "padded",
"output_mlp": {"use_bias": [True, True, False], "units": [25, 10, 1],
Expand Down
4 changes: 3 additions & 1 deletion kgcnn/literature/GIN/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ def set_scale(*args, **kwargs):
"depth": 3, "dropout": 0.0, "verbose": 10,
"last_mlp": {"use_bias": [True, True, True], "units": [64, 64, 64],
"activation": ["relu", "relu", "linear"]},
"output_embedding": 'graph', "output_to_tensor": True,
"output_embedding": 'graph',
"output_to_tensor": None,
"output_scaling": None,
"output_tensor_type": "padded",
"output_mlp": {"use_bias": True, "units": 1,
"activation": "softmax"}
Expand Down
31 changes: 31 additions & 0 deletions kgcnn/literature/MEGAN/_layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from keras import Layer
from keras import ops


class ExplanationSparsityRegularization(Layer):

def __init__(self,
factor: float = 1.0,
**kwargs):
super(ExplanationSparsityRegularization, self).__init__(**kwargs)
self.factor = factor

def build(self, input_shape):
super(ExplanationSparsityRegularization, self).build(input_shape)

def call(self, inputs, **kwargs):
r"""Computes a loss from importance scores.
Args:
inputs: Importance tensor of shape ([batch], [N], K) .
Returns:
None.
"""
# importances: ([batch], [N], K)
importances = inputs

loss = ops.mean(ops.abs(importances))
loss = loss * self.factor
self.add_loss(loss)
return loss
Empty file added kgcnn/literature/MEGAN/_make.py
Empty file.
Loading

0 comments on commit 6f266a3

Please sign in to comment.