Skip to content

Instantly share code, notes, and snippets.

@WhatIThinkAbout
Last active March 3, 2021 13:36
Show Gist options
  • Select an option

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

Select an option

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