Skip to content

Instantly share code, notes, and snippets.

@chelseaparlett
Created October 9, 2019 20:30
Show Gist options
  • Save chelseaparlett/2deb9a0372f4b3849da746c5271a9343 to your computer and use it in GitHub Desktop.
Save chelseaparlett/2deb9a0372f4b3849da746c5271a9343 to your computer and use it in GitHub Desktop.
import numpy as np
def randomPrior():
'''randomly chooses a type of distribution then randomly selects
parameters based on limitations of said distribution'''
possPriors = {"Cauchy": {"loc": [-100,100], "scale": [0,100]},
"Normal": {"mean": [-100,100],
"sd": [0,100]},
"InverseGamma": {"a": [0,100], "b":[0,100]},
"Gamma": {"a": [0,100], "b":[0,100]},
"Poisson": {"lambda": [0,100]}}
prior = np.random.choice(list(possPriors.keys()), size = 1)
string = prior[0].upper() + "(" #CAPS name and first paren
selected = possPriors[prior[0]]
for item in selected: #for each parameter
param = int(np.random.uniform(selected[item][0],selected[item][1])) #lazy uniform sampling
string = string + str(param) + ","
string = string[:-1] #get rid of last comma
string += ")!" #close paren
return(string)
print(randomPrior())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment