Skip to content

Instantly share code, notes, and snippets.

@WhatIThinkAbout
Last active March 5, 2021 16:56
Show Gist options
  • Select an option

  • Save WhatIThinkAbout/6927bd8a71bb8964e3ed3d1e89b150df to your computer and use it in GitHub Desktop.

Select an option

Save WhatIThinkAbout/6927bd8a71bb8964e3ed3d1e89b150df to your computer and use it in GitHub Desktop.
Update function for conjugate prior hyper-parameters for normal distribution with known mean and unknown variance
def update(self,x):
''' increase the number of times this socket has been used and improve the estimate of the
variance by updating the gamma distribution's hyper-parameters using the new value 'x' '''
self.n += 1
self.x.append(x) # append the new value to the list of samples
self.α = self.n/2
self.β = ((np.array(self.x) - self.μ)**2).sum()/2
# estimate the variance from the gamma hyper-parameters
self.v_0 = self.β / (self.α + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment