You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
import numpy as np
import math
from scipy.linalg import eigh
from iminuit import Minuit
Define the loop function h1 (same as f1)
def h1(x):
return -1 / (16 * np.pi2) * (np.log(x2) - 1)
def h2(x):
return -1 / (4 * 16 * np.pi2) * (2.0 * np.log(x2) - 1)
def f2(t):
return -1 / (4 * 16 * np.pi2) * (2.0 * np.log(t2) - 1)
def funcMN(mm, rr):
if mm == rr:
return h1(mm)
def funcloop(c, t):
if c == 1:
raise ValueError("Input c must not be 1 to avoid division by zero.")
Generate real symmetric matrix from flattened parameters
def generate_real_symmetric_matrix_from_params(params, shape):
assert shape[0] == shape[1], "Matrix must be square."
matrix = np.zeros(shape)
indices = np.triu_indices(shape[0])
matrix[indices] = params
matrix[(indices[1], indices[0])] = params # Make symmetric
return matrix
Generate complex matrix from flattened parameters
def generate_complex_matrix_from_params(params, shape):
half = len(params) // 2
real_part = np.reshape(params[:half], shape)
imaginary_part = np.reshape(params[half:], shape)
return real_part + 1j * imaginary_part
Define the chi-square function
def chi_square(params, Md_expected, Mu_expected, Me_expected):
# Split parameters into matrices
y1_params = params[:3]
y2_params = params[3:21]
y3_params = params[21:24]
MT_param = params[24]
MN_param = params[25]
MV_param = 2.0
Example usage and minimization
initial_params_y1_real = np.random.uniform(low=-math.sqrt(4math.pi), high=math.sqrt(4math.pi), size=(3,))
initial_params_y2_real = np.random.uniform(low=-math.sqrt(4math.pi), high=math.sqrt(4math.pi), size=(9,))
initial_params_y2_imag = np.random.uniform(low=-math.sqrt(4math.pi), high=math.sqrt(4math.pi), size=(9,))
initial_params_y3_real = np.random.uniform(low=-math.sqrt(4math.pi), high=math.sqrt(4math.pi), size=(3,))
initial_params_MT = np.random.uniform(low=1e-5, high=1e3, size=1)[0]
initial_params_MN = np.random.uniform(low=1e-5, high=1e3, size=1)[0]
initial_params = np.hstack((initial_params_y1_real, initial_params_y2_real, initial_params_y2_imag, initial_params_y3_real, initial_params_MT, initial_params_MN))
Mu_expected = np.array([2.81e-6, 0.00142, 0.427])
Md_expected = np.array([6.14e-6, 1.25e-4, 5.80e-3])
Me_expected = np.array([2.75e-6, 5.72e-4, 9.68e-3])
st12exp = 0.2286
st23exp = 0.04579
st13exp = 0.00424
User-defined errors for each element
y1_real_errors = [1e-7, 1e-4, 1e-2]
y2_real_errors = [1e-7, 1e-7, 1e-7, 1e-4, 1e-4, 1e-4, 1e-2, 1e-2, 1e-2]
y2_imag_errors = [1e-7, 1e-7, 1e-7, 1e-4, 1e-4, 1e-4, 1e-2, 1e-2, 1e-2]
y3_real_errors = [1e-4, 1e-1, 1e-1]
MT_error = [1e1]
MN_error = [1e-1]
error_array = np.array(y1_real_errors + y2_real_errors + y2_imag_errors + y3_real_errors + MT_error + MN_error)
def minimize_chi_square():
def chi_square_wrapper(*params):
return chi_square(np.array(params), Md_expected, Mu_expected, Me_expected)
minuit, final_chisq = minimize_chi_square()
Print the optimized parameters
print("Optimized Parameters:")
print(minuit.values)
Print final chi-square value
final_chisq = minuit.fval
print("Final Chi-square:", final_chisq)
Beta Was this translation helpful? Give feedback.
All reactions