Skip to content

Commit

Permalink
Deterministic Clustering (#46)
Browse files Browse the repository at this point in the history
* fix for deterministic clusterMAF sampling with repeated loads

* bumping version number

* moving random seed set to load function

* setting seed for cluster choice then reset after

* setting random seed for cluster choice based on hypercube sample
  • Loading branch information
htjb authored Oct 26, 2023
1 parent 91258ed commit 5fcb811
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 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.1.3
:Version: 1.1.4
:Homepage: https://github.com/htjb/margarine
:Documentation: https://margarine.readthedocs.io/

Expand Down
10 changes: 8 additions & 2 deletions margarine/clustered.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ def log_like(self, params, logevidence, prior_de=None):

return loglike

@tf.function(jit_compile=True)
def __call__(self, u):
#@tf.function(jit_compile=True)
def __call__(self, u, seed=1420):

r"""
Expand All @@ -373,6 +373,9 @@ def __call__(self, u):
u: **numpy array**
| Samples on the uniform hypercube.
seed: **int / default=1420**
| Set the seed for the cluster choice.
"""

Expand All @@ -381,8 +384,11 @@ def __call__(self, u):
flow_weights = np.array(flow_weights)
probabilities = flow_weights / np.sum(flow_weights)
options = np.arange(0, self.cluster_number)

np.random.seed(int(round(u[0][0]*1000)))
choice = np.random.choice(options,
p=probabilities, size=len(u))
np.random.seed(None)

totals = [len(choice[choice == options[i]])
for i in range(len(options))]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def readme(short=False):

setup(
name='margarine',
version='1.1.3',
version='1.1.4',
description='margarine: Posterior Sampling and Marginal Bayesian Statistics',
long_description=readme(),
author='Harry T. J. Bevins',
Expand Down

0 comments on commit 5fcb811

Please sign in to comment.