Пример #1
0
def each_chisq(para, m1_obs, m1_sig):
    a, mbh_max, mbh_min = para
    if 1.1 < a < 3 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        x = np.logspace(
            np.log10(m1_obs.min() / np.exp(m_noise_level)**5 / 1.1),
            np.log10(m1_obs.max() * np.exp(m_noise_level)**5 * 1.1), 300)
        y = cov_twofun(x,
                       a=a,
                       mbh_max=mbh_max,
                       mbh_min=mbh_min,
                       sigma=m_noise_level)
        f = interpolate.interp1d(x, y)
        poss_m1_i = f(m1_obs)
        return poss_m1_i
    else:
        return np.inf
Пример #2
0
def point_Chisq(para, m1_obs, m_noise_level):
    a, mbh_max, mbh_min = para
    if 1.1 < a < 3 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        x = np.logspace(np.log10(m1_obs.min() / 1.1),
                        np.log10(m1_obs.max() * 1.1), 300)
        y = cov_twofun(x,
                       a=a,
                       mbh_max=mbh_max,
                       mbh_min=mbh_min,
                       sigma=m_noise_level)
        f = interpolate.interp1d(x, y)
        #        poss_m1_i = likelihood(m1_obs,m1_sig, a=a, mbh_max=mbh_max, mbh_min=mbh_min, use_method='med',f=f)
        poss_m1_i = f(m1_obs)
        chisq = -np.sum(np.log(poss_m1_i))
        #        print a, mbh_max, mbh_min, chisq
        return chisq
    else:
        return np.inf
Пример #3
0
def each_likeli(para, m1_obs, m1_sig, prior):
    a, mbh_max, mbh_min = para
    if 1.1 < a < 3 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        x = np.logspace(
            np.log10(m1_obs.min() / np.exp(m_noise_level)**5 / 1.1),
            np.log10(m1_obs.max() * np.exp(m_noise_level)**5 * 1.1), 300)
        y = cov_twofun(x,
                       a=a,
                       mbh_max=mbh_max,
                       mbh_min=mbh_min,
                       sigma=m_noise_level)
        f = interpolate.interp1d(x, y)
        #        poss_m1_i = likelihood(m1_obs,m1_sig, a=a, mbh_max=mbh_max, mbh_min=mbh_min, use_method='med', f=f)
        poss_m1_i = f(m1_obs)
        post = poss_m1_i  #(1/ prior)
        #        print a, mbh_max, mbh_min, chisq
        return post
    else:
        return np.inf
Пример #4
0
def posterior(para, m1_obs, m_noise_level, sf_factor, z):
    a0, a1, mbh_max, mbh_min = para
    #    a_z = a0 + a1 * z
    #    if 1.1 < a0 < 3 and -0.5 < a1 < 0.5  and 50 < mbh_max < 100 and 2 < mbh_min < 8:
    a_z = a0 + a1 * z / (1 + z)
    if 1.1 < a0 < 3 and -0.5 < a1 < 1.5 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        x = np.logspace(np.log10(m1_obs.min() / 1.1),
                        np.log10(m1_obs.max() * 1.1),
                        50)  #!!! 50 could be big enough?
        post, az_lib, y_lib = [], [], []
        for i in range(len(z)):
            if a_z[i] not in az_lib:
                y = cov_twofun(x,
                               a=a_z[i],
                               mbh_max=mbh_max,
                               mbh_min=mbh_min,
                               sigma=m_noise_level)  #!!!
            else:
                j = np.where(np.asarray(az_lib) == a_z[i])[0][0]
                y = y_lib[j]
            az_lib.append(a_z[i])
            y_lib.append(y)
            f = interpolate.interp1d(x, y)
            poss_m1_i = f(m1_obs[i])
            post.append(poss_m1_i)
            if i / 300 > (i - 1) / 300:
                print i
        post = np.array(post)
        chisq = -0.5 * np.sum(np.log(post) * sf_factor)
        t2 = time.time()
        t_cost = (t2 - t1)
        t_per_cost = t_cost / step
        t_remain = t_per_cost * (step_total - step)
        step = np.sum(sampler.flatchain != 0) / (ndim * nwalkers)
        if step != 0:
            print "step:", step, "percent", round(
                step / (step_total / 100),
                2), "%", "\r", "para:", para, "time remain:", round(t_remain /
                                                                    60), 'mins'
        return chisq
    else:
        return np.inf
Пример #5
0
def posterior(para, m1_obs, m_noise_level, sf_factor):
    a, mbh_max, mbh_min = para
    if 1.1 < a < 3 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        x = np.logspace(np.log10(m1_obs.min() / 1.1),
                        np.log10(m1_obs.max() * 1.1), 300)
        y = cov_twofun(x,
                       a=a,
                       mbh_max=mbh_max,
                       mbh_min=mbh_min,
                       sigma=m_noise_level)
        f = interpolate.interp1d(x, y)
        poss_m1_i = f(m1_obs)
        post = poss_m1_i
        #        if prior_true is not None:
        #            prior[np.where(prior<prior_true.min())]  = prior_true.min()
        #        sf_factor[np.where(sf_factor>75)]  = 75  # Do it in other place
        chisq = -0.5 * np.sum(np.log(post) * sf_factor)
        return chisq
    else:
        return np.inf
Пример #6
0
def posterior(para, m1_obs, m_noise_level, sf_factor, z):
    a0, a1, mbh_max, mbh_min = para
    #    a_z = a0 + a1 * z
    #    if 1.1 < a0 < 3 and -0.5 < a1 < 0.5  and 50 < mbh_max < 100 and 2 < mbh_min < 8:
    a_z = a0 + a1 * z / (1 + z)
    if 0.1 < a0 < 3.5 and -3. < a1 < 3.0 and 30 < mbh_max < 115 and 2 < mbh_min < 8:
        post = []
        for i in range(len(z)):
            poss_m1_i = cov_twofun(m1_obs[i],
                                   a=a_z[i],
                                   mbh_max=mbh_max,
                                   mbh_min=mbh_min,
                                   sigma=m_noise_level)
            post.append(poss_m1_i)
        post = np.array(post)
        chisq = -0.5 * np.sum(np.log(post) * sf_factor)
        #        print para, chisq
        global mini_count
        if mini_count / 50 > (mini_count - 1) / 50:
            print "State of count {0}".format(mini_count), para, chisq
        mini_count = mini_count + 1
        return chisq
    else:
        return np.inf
Пример #7
0
def posterior(para, m1_obs, m_noise_level, sf_factor, z, r_detail=False):
    a0, a1, mbh_max, mbh_min = para
    a_z = a0 + a1 * z
    if 1.1 < a0 < 3 and -0.5 < a1 < 0.5 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        #    a_z = a0 + a1 * z/(1+z)
        #    if 1.1 < a0 < 3 and -0.5 < a1 < 1.5 and 50 < mbh_max < 100 and 2 < mbh_min < 8:
        x = np.logspace(np.log10(m1_obs.min() / 1.1),
                        np.log10(m1_obs.max() * 1.1),
                        50)  #!!! 50 could be big enough?
        post, az_lib, y_lib = [], [], []
        for i in range(len(z)):
            if a_z[i] not in az_lib:
                y = cov_twofun(x,
                               a=a_z[i],
                               mbh_max=mbh_max,
                               mbh_min=mbh_min,
                               sigma=m_noise_level)  #!!!
            else:
                j = np.where(np.asarray(az_lib) == a_z[i])[0][0]
                y = y_lib[j]
            az_lib.append(a_z[i])
            y_lib.append(y)
            f = interpolate.interp1d(x, y)
            poss_m1_i = f(m1_obs[i])
            post.append(poss_m1_i)
            if i / 300 > (i - 1) / 300:
                print i
        post = np.array(post)
        chisq = -0.5 * np.sum(np.log(post) * sf_factor)
        print para, ": Chisq:", chisq
        if r_detail == False:
            return chisq
        elif r_detail == True:
            return chisq, -0.5 * np.log(post) * sf_factor
    else:
        return np.inf