From 472b674cfb99ef7d5d64b1b6888764fb67e6aa5c Mon Sep 17 00:00:00 2001 From: Aron Date: Thu, 11 Jan 2024 09:05:51 +0100 Subject: [PATCH] Replace old dense layer everywhere --- .../backends/keras_backend/base_layers.py | 7 ++++--- n3fit/src/n3fit/checks.py | 7 +++---- n3fit/src/n3fit/model_gen.py | 4 ++-- .../src/n3fit/tests/regressions/weights_1.h5 | Bin 29232 -> 29232 bytes .../src/n3fit/tests/regressions/weights_2.h5 | Bin 29232 -> 29232 bytes n3fit/src/n3fit/tests/test_modelgen.py | 13 +++++++------ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/n3fit/src/n3fit/backends/keras_backend/base_layers.py b/n3fit/src/n3fit/backends/keras_backend/base_layers.py index 3f1726fe16..2a8d9b66a7 100644 --- a/n3fit/src/n3fit/backends/keras_backend/base_layers.py +++ b/n3fit/src/n3fit/backends/keras_backend/base_layers.py @@ -92,7 +92,7 @@ def dense_per_flavour(basis_size=8, kernel_initializer="glorot_normal", **dense_ # Need to generate a list of dense layers dense_basis = [ - base_layer_selector("dense", kernel_initializer=initializer, **dense_kwargs) + base_layer_selector("single_dense", kernel_initializer=initializer, **dense_kwargs) for initializer in kernel_initializer ] @@ -122,7 +122,7 @@ def apply_dense(xinput): layers = { - "multi_dense": ( + "dense": ( MultiDense, { "input_shape": (1,), @@ -134,7 +134,8 @@ def apply_dense(xinput): "replica_input": True, }, ), - "dense": ( + # This one is only used inside dense_per_flavour + "single_dense": ( Dense, { "input_shape": (1,), diff --git a/n3fit/src/n3fit/checks.py b/n3fit/src/n3fit/checks.py index 7c0f57d672..d93f3b1d9a 100644 --- a/n3fit/src/n3fit/checks.py +++ b/n3fit/src/n3fit/checks.py @@ -111,7 +111,7 @@ def check_initializer(initializer): def check_layer_type_implemented(parameters): """Checks whether the layer_type is implemented""" layer_type = parameters.get("layer_type") - implemented_types = ["dense", "multi_dense", "dense_per_flavour"] + implemented_types = ["dense", "dense_per_flavour"] if layer_type not in implemented_types: raise CheckError( f"Layer type {layer_type} not implemented, must be one of {implemented_types}" @@ -427,10 +427,9 @@ def check_fiatlux_pdfs_id(replicas, fiatlux): f"Cannot generate a photon replica with id larger than the number of replicas of the PDFs set {luxset.name}:\nreplica id={max_id}, replicas of {luxset.name} = {pdfs_ids}" ) + @make_argcheck def check_multireplica_qed(replicas, fiatlux): if fiatlux is not None: if len(replicas) > 1: - raise CheckError( - "At the moment, running a multireplica QED fits is not allowed." - ) + raise CheckError("At the moment, running a multireplica QED fits is not allowed.") diff --git a/n3fit/src/n3fit/model_gen.py b/n3fit/src/n3fit/model_gen.py index d3c2c0a2d4..50a0581b13 100644 --- a/n3fit/src/n3fit/model_gen.py +++ b/n3fit/src/n3fit/model_gen.py @@ -741,7 +741,7 @@ def initializer_generator(seed, i_layer): # list_of_pdf_layers[d][r] is the layer at depth d for replica r list_of_pdf_layers = [] for i_layer, (nodes_out, activation) in enumerate(zip(nodes_list, activations)): - if layer_type == "multi_dense": + if layer_type == "dense": layers = base_layer_selector( layer_type, replica_seeds=replica_seeds, @@ -777,7 +777,7 @@ def initializer_generator(seed, i_layer): list_of_pdf_layers[-1] = [lambda x: concat(layer(x)) for layer in list_of_pdf_layers[-1]] # Apply all layers to the input to create the models - if layer_type == "multi_dense": + if layer_type == "dense": pdfs = x_input for layer in list_of_pdf_layers: pdfs = layer(pdfs) diff --git a/n3fit/src/n3fit/tests/regressions/weights_1.h5 b/n3fit/src/n3fit/tests/regressions/weights_1.h5 index 7f9f9301844822e6cb8ab0e0271f2bc8f538119f..9ffdaea7f343830a67cf36c433d6d7b3c0fe91e1 100644 GIT binary patch delta 740 zcmdn+gmD89X|OVCY(A*Z&ctXj*^ph_GPg9RBr`rGHLo}|-k5=b0hw=t#y17>8G#rC z6eb@GliWOu{U2k!2t))`tA0{uVzHG0NQw_CFNQ^(seX29QC?~eNF_g19-DclNahKk znwN=YF~UGWJO&yg87PEmAc}d$NDkZ_z{SDL)WEelk++O%lf(wbK(LoMAlgBufSnHI zgKS5Z2RR#Ao)=9X6igzU8KvGcF-lDSD5DOHCrMdGMt%#RI56CqAtBE=*-%cL5kzKA zP6*(bcp`1GgR#J74S6q4c{G(^eTW$2pS;jdd~%0I6ja~l0?k!Sn5OH1P1ng}%$RsE z7h<-q7b5|)xgciiA+7LH_u}K$5_wD00B@1 z`bn9I#a0Fk3@~v46nRtq?9`&X)Ep}VeyBK19Ynt=Tt7@7jE0#H(=Q0oZwa>uqQDq# zfDqIIR0E9R4%pnl#lg(9fot*z=Dj7 zj8Msi8i|Y@6A$)oF3?=X1l9-(Hm=EzI#7+eA&iU?le3v+CvVUTf-2X)1X0cfHi&_N wV{)L8_~ZtoAdp>?<>a|G2N-)XqS?nWxzNaSvXH3+*pSH!!X!3tFm12_0I>UQ#{d8T diff --git a/n3fit/src/n3fit/tests/regressions/weights_2.h5 b/n3fit/src/n3fit/tests/regressions/weights_2.h5 index 51061a63f24a1d41d1d392f048a5ac31d231212f..18c593da9eb1def31cadbdbc74d654c561c4dc64 100644 GIT binary patch delta 740 zcmdn+gmD89X|OVCY(A*Z&ctXj*^ph_GPg9RBr`rGHLo}|-k5=b0hw=t#y17>8G#rC z6eb@GliWOu{U2k!2t))`tA0{uVzHG0NQw_CFNQ^(seX29QC?~eNF_g19-DclNahKk znwN=YF~UGWJO&yg87PEmAc}d$NDkZ_z{SDL)WEelk++O%lf(wbK(LoMAlgBufSnHI zgKS5Z2RR#Ao)=9X6igzU8KvGcF-lDSD5DOHCrMdGMt%#RI56CqAtBE=*-%cL5kzKA zP6*(bcp`1GgR#J74S6q4c{G(^eTW$2pS;jdd~%0I6ja~l0?k!Sn5OH1P1ng}%$RsE z7h<-q7b5|)xgciiA+7LH_u}K$5_wD00B@1 z`bn9I#a0Fk3@~v46nRtq?9`&X)Ep}VeyBK19Ynt=Tt7@7jE0#H(=Q0oZwa>uqQDq# zfDqIIR0E9R4%pnl#lg(9fot*z=Dj7 zj8Msi8i|Y@6A$)oF3?=X1l9-(Hm=EzI#7+eA&iU?le3v+CvVUTf-2X)1X0cfHi&_N wV{)L8_~ZtoAdp>?<>a|G2N-)XqS?nWxzNaSvXH3+*pSH!!X!3tFm12_0I>UQ#{d8T diff --git a/n3fit/src/n3fit/tests/test_modelgen.py b/n3fit/src/n3fit/tests/test_modelgen.py index 1178b59b71..aceffbe054 100644 --- a/n3fit/src/n3fit/tests/test_modelgen.py +++ b/n3fit/src/n3fit/tests/test_modelgen.py @@ -25,16 +25,17 @@ def test_generate_dense_network(): - nn = generate_nn("dense", **COMMON_ARGS).get_layer("NN_0") + nn = generate_nn("dense", **COMMON_ARGS) # The number of layers should be input layer + len(OUT_SIZES) assert len(nn.layers) == len(OUT_SIZES) + 1 # Check that the number of parameters is as expected - # We expect 4 weights where the two first ones are - # (INSIZE, OUT_SIZE[0]) (OUT_SIZE[0],) - # and the second one - # (OUT_SIZE[0], OUT_SIZE[1]) (OUT_SIZE[1],) - expected_sizes = [(INSIZE, OUT_SIZES[0]), (OUT_SIZES[0],), OUT_SIZES, (OUT_SIZES[1],)] + expected_sizes = [ + (1, INSIZE, OUT_SIZES[0]), + (1, 1, OUT_SIZES[0]), + (1, *OUT_SIZES), + (1, 1, OUT_SIZES[1]), + ] for weight, esize in zip(nn.weights, expected_sizes): assert weight.shape == esize