Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n3fit prepro initialisation #2249

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion n3fit/src/n3fit/backends/keras_backend/MetaLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
For instance: np_to_tensor is just a call to K.constant
"""

from keras.initializers import Constant, RandomUniform, glorot_normal, glorot_uniform
from keras.initializers import Constant, RandomUniform, glorot_normal, glorot_uniform, RandomNormal
from keras.layers import Layer

# Define in this dictionary new initializers as well as the arguments they accept (with default values if needed be)
initializers = {
"random_uniform": (RandomUniform, {"minval": -0.5, "maxval": 0.5}),
"glorot_uniform": (glorot_uniform, {}),
"glorot_normal": (glorot_normal, {}),
"random_normal": (RandomNormal, {"mean": 0.0, "stddev": 0.05}),
}


Expand Down
12 changes: 6 additions & 6 deletions n3fit/src/n3fit/layers/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def generate_weight(self, name: str, kind: str, dictionary: dict, set_to_zero: b
single_replica_initializer = MetaLayer.init_constant(0.0)
trainable = False
else:
minval, maxval = dictionary[kind]
prepro_kwargs = dictionary[kind]
trainable = dictionary.get("trainable", True)
# Seeds will be set in the wrapper MultiInitializer
single_replica_initializer = MetaLayer.select_initializer(
"random_uniform", minval=minval, maxval=maxval
)
single_replica_initializer = MetaLayer.select_initializer(**prepro_kwargs)
# If we are training, constrain the weights to be within the limits
if trainable:
constraint = constraints.MinMaxWeight(minval, maxval)
if trainable and prepro_kwargs["ini_name"] == "random_uniform":
constraint = constraints.MinMaxWeight(
prepro_kwargs["minval"], prepro_kwargs["maxval"]
)

initializer = MultiInitializer(single_replica_initializer, self._replica_seeds, base_seed=0)
# increment seeds for the next coefficient
Expand Down
Loading