Example #1
0
def logproir_2(theta, x, y):
    """log-likelihood"""
    w1, mu1, sig1, w2, mu2, sig2 = theta
    f1 = gauss_fit_fun.gauss_coeff(x, w1, mu1, sig1)
    f2 = gauss_fit_fun.gauss_coeff(x, w2, mu2, sig2)
    f = f1 + f2
    return -0.5 * (numpy.sum((f - y)**2))
Example #2
0
def logproir_1(theta):
    """log-likelihood"""
    w1, mu1, sig1 = theta
    f1 = gauss_fit_fun.gauss_coeff(x, w1, mu1, sig1)
    return -0.5 * (numpy.sum((f1 - gauss_1)**2))
Example #3
0
result = sampler.results

fig, axes = dyplot.cornerplot(result,
                              truths=truths,
                              show_titles=True,
                              title_kwargs={'y': 1.04},
                              labels=labels,
                              fig=plt.subplots(3, 3, figsize=(15, 15)))
plt.show()

exit()
# Gaussian
w1, mu1, sig1 = 0.4, 1.5, 4
w2, mu2, sig2 = 0.6, -2, 5

gauss_1 = gauss_fit_fun.gauss_coeff(x, w1, mu1, sig1)
gauss_2 = gauss_fit_fun.gauss_coeff(x, w2, mu2, sig2)
gauss_total = gauss_1 + gauss_2


# single Gaussina test
def logproir_1(theta):
    """log-likelihood"""
    w1, mu1, sig1 = theta
    f1 = gauss_fit_fun.gauss_coeff(x, w1, mu1, sig1)
    return -0.5 * (numpy.sum((f1 - gauss_1)**2))


def prior_transform_1(utheta):
    uw, umu, usig = utheta
    w = uw * 2 - 1
Example #4
0
def fun_min(para, x, y):
    a, b, c = para[0], para[1], para[2]
    fx = gauss_fit_fun.gauss_coeff(x, a, b, c)
    return numpy.sum((fx - y)**2)
Example #5
0

w1, mu1, sig1 = 0.5, 0.01, 0.3
w2, mu2, sig2 = 0.5, -0.04, 0.3
print("     weight, signal, sigma")
print("True 1:", w1, mu1, sig1)
print("True 2:", w2, mu2, sig2)

# the cache is got from the servers
npz_f = numpy.load("E:/works/multi_shear/cache.npz")
x_fit, y_fit = npz_f["arr_0"], npz_f["arr_1"]

# fit single gauss
fit_res = scipy.optimize.curve_fit(gauss_fit_fun.gauss_coeff, x_fit, y_fit)[0]
# fx_fit = gauss_fit_fun.gauss_coeff(x_fit, fit_res[0],fit_res[1],fit_res[2])
fx_fit = gauss_fit_fun.gauss_coeff(x_fit, 1, 0, fit_res[2])
print("Single gauss fit: %.4f, %.4f, %.4f" %
      (fit_res[0], fit_res[1], fit_res[2]))

fx_ratio = y_fit / fx_fit - 1
fx_sub, fx_sub1, fx_sub2 = fx_sub_approx(3, x_fit, w1, mu1, w2, mu2, sig1)

# fit the ratio expression
idx1 = x_fit < 0.1
idx2 = x_fit > -0.1
idx = idx1 & idx2
# # one fitting method
# ratio_fit_result = scipy.optimize.curve_fit(min_diff_1,x_fit[idx],fx_ratio[idx],p0=[0.1,0.2,0.3,0.3])[0]
# a1,a2,a3,sig = ratio_fit_result
# print("%.7f  %.7f  %.7f  %.4f"%(a1,a2,a3,sig))
# fx_sub_fit = min_diff_1(x_fit, a1, a2, a3,sig)
    img.set_label(0, 0, 0, "Num")
    img.set_label(0, 1, 0, "Num")
    img.axs[0][0].set_yscale("log")
    img.axs[0][1].set_yscale("log")
    img.axs[0][0].set_xscale("log")
    img.axs[0][1].set_xscale("log")
    img.save_img(total_path + "chisq_%d.png" % i)
    img.close_img()
    # img.show_img()
    #
    #
    # plot the good fitting result
    # the input one
    fit_true = gauss_fit_fun.gauss_2_coeff(x_fit, 0.5, signal[0], sigma[0],
                                           0.5, signal[1], sigma[0])
    fit_true1 = gauss_fit_fun.gauss_coeff(x_fit, 0.5, signal[0], sigma[0])
    fit_true2 = gauss_fit_fun.gauss_coeff(x_fit, 0.5, signal[1], sigma[0])
    chisq_true = gauss_fit_fun.fit_chisq_2_coeff(
        [0.5, signal[0], sigma[0], 0.5, signal[1], sigma[0]], x_fit, y_fit)
    print("True chi square: ", chisq_true)

    # one gaussian's fitting
    idx = err_1s == err_1s.min()
    para1 = para_1s[idx][0]
    print("The minimum: %.5f" % err_1s[idx][0], para1)
    fit_s = gauss_fit_fun.gauss_coeff(x_fit, para1[0], para1[1], para1[2])

    # two gaussian's fitting
    idx = err_2s == err_2s.min()
    num1, mu1, sig1, num2, mu2, sig2 = para_2s[idx][0]
    if idx.sum() > 1: