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

Introduced the kwargs activation_func to margarine for choosing activ… #57

Merged
merged 3 commits into from
Feb 27, 2024
Merged
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
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
Loading