Skip to content

Commit

Permalink
Introduced the kwargs activation_func to margarine for choosing activ… (
Browse files Browse the repository at this point in the history
#57)

* Introduced the kwargs activation_func to margarine for choosing activation function. The default one is tanh.

* Added description of the new activation_func kwargs to the class MAF. Added activation_fuc kwarg to clustered.py in line 229.

* Added description of the new activation_func arguments to clustered.py.
  • Loading branch information
DilyOng authored Feb 27, 2024
1 parent 93471be commit 12405af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Introduction

:margarine: Marginal Bayesian Statistics
:Authors: Harry T.J. Bevins
:Version: 1.2.4
:Version: 1.2.5
:Homepage: https://github.com/htjb/margarine
:Documentation: https://margarine.readthedocs.io/

Expand Down
9 changes: 8 additions & 1 deletion margarine/clustered.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class clusterMAF():
each neural network. The default is two hidden layers with
50 nodes each and each network in the chain has the same hidden
layer structure.
activation_func: **string / default = 'tanh'**
| The choice of activation function. It must be an activation
function keyword recognisable by TensorFlow. The default is
'tanh', the hyperbolic tangent activation function.
cluster_labels: **list / default = None**
| If clustering has been performed externally to margarine you can
Expand Down Expand Up @@ -77,6 +82,7 @@ def __init__(self, theta, **kwargs):
self.cluster_labels = kwargs.pop('cluster_labels', None)
self.cluster_number = kwargs.pop('cluster_number', None)
self.parameters = kwargs.pop('parameters', None)
self.activation_func = kwargs.pop('activation_func', 'tanh')

# Avoid unintended side effects by copying theta
theta = theta.copy()
Expand Down Expand Up @@ -232,7 +238,8 @@ def __init__(self, theta, **kwargs):
learning_rate=self.learning_rate,
hidden_layers=self.hidden_layers,
theta_min=self.theta_min,
theta_max=self.theta_max))
theta_max=self.theta_max,
activation_func=self.activation_func))

def train(self, epochs=100, early_stop=False, loss_type='sum'):

Expand Down
8 changes: 7 additions & 1 deletion margarine/maf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class MAF:
50 nodes each and each network in the chain has the same hidden
layer structure.
activation_func: **string / default = 'tanh'**
| The choice of activation function. It must be an activation
function keyword recognisable by TensorFlow. The default is
'tanh', the hyperbolic tangent activation function.
theta_max: **numpy array**
| The true upper limits of the priors used to generate the samples
that we want the MAF to learn.
Expand Down Expand Up @@ -85,6 +90,7 @@ def __init__(self, theta, **kwargs):
self.learning_rate = kwargs.pop('learning_rate', 1e-3)
self.hidden_layers = kwargs.pop('hidden_layers', [50, 50])
self.parameters = kwargs.pop('parameters', None)
self.activation_func = kwargs.pop('activation_func', 'tanh')

# Avoids unintended side effects outside the class
if not isinstance(theta, tf.Tensor):
Expand Down Expand Up @@ -176,7 +182,7 @@ def gen_mades(self):
"""Generating the masked autoregressive flow."""

self.mades = [tfb.AutoregressiveNetwork(params=2,
hidden_units=self.hidden_layers, activation='tanh',
hidden_units=self.hidden_layers, activation=self.activation_func,
input_order='random')
for _ in range(self.number_networks)]

Expand Down

0 comments on commit 12405af

Please sign in to comment.