human
I am working on the file "IMH.ipynb".
The first task is:
[ベイズ推論]</P>
<p>確率変数X_1, X_2,..., X_nが互いに独立に平均がμ、分散が1であるような正規分布に従うとする。</p>
<p>μの事前分布にt分布を仮定する。
Can you write Python code for it?

=====
Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

class IMH:
    def __init__(self, X):
        self.mu_0 = 1
        self.freedom = 5.0
        self.x_var = np.mean(X)
        
    def prior_dist(self, t):
        ft = math.gamma((self.freedom+1.0)/2.0)/(math.sqrt(self.freedom*math.pi)*math.gamma((self.freedom)/2.0))*pow(1+pow(t, 2)/self.freedom, -(self.freedom+1)/2.0)
        return ft
        
    def prop_dist(self):
        mu = np.random.normal(self.x_var, 1.0/10.0)
        return mu
    
    def accept(self, mu_new, mu):
        return min([1, self.prior_dist(mu_new)/self.prior_dist(mu)])
    
    def simulate(self):
        mu = np.zeros(11000)
        mu[0] = self.mu_0
        for i in range(1,11000):
            mu_new = self.prop_dist()
            u = np.random.uniform()
            if u <= self.accept(mu_new, mu[i-1]):
                mu[i] = mu_new
            else:
                mu[i] = mu[i-1]
        return mu

imh = IMH(X)

mu = imh.simulate()

plt.plot(mu)

plt.hist(mu)

plt.hist(mu[1000:])