Skip to content

Instantly share code, notes, and snippets.

@dsuess
Created April 11, 2017 11:56
Show Gist options
  • Save dsuess/ad46faa1a7b461ba4b1aa9f96185584c to your computer and use it in GitHub Desktop.
Save dsuess/ad46faa1a7b461ba4b1aa9f96185584c to your computer and use it in GitHub Desktop.
Haar Distribution in PyMC3
def HaarDistribution(name, dim, model=None):
def transform(x):
pi = np.pi
def component(i):
result = T.cos(pi * x[i])
for j in range(i):
result *= T.sin(pi * x[j])
return result
result = [component(i) for i in range(dim - 2)]
z = T.sin(pi * x[0])
for i in range(1, dim - 2):
z *= T.sin(pi * x[i])
result += [z * T.cos(2 * pi * x[dim - 2])]
result += [z * T.sin(2 * pi * x[dim - 2])]
return T.as_tensor_variable(result)
angles = pm.distributions.Uniform('angles', shape=dim - 1)
return pm.Deterministic(name, transform(angles), model=model)
@dsuess
Copy link
Author

dsuess commented Apr 11, 2017

Not the prettiest nor the most pythonic, but it works ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment