kNNpy.Auxiliary.Fisher
1import numpy as np 2 3def constructingFishermatrix(data_vectors, covariance_matrix, dtheta, n_params_p_m, n_params_p=0): 4 """ 5 Constructs the Fisher matrix from data vectors and a covariance matrix. 6 7 Parameters: 8 data_vectors (list of numpy arrays): The data vectors for which the Fisher matrix is to be constructed. The ith element is an array containing two vectors: 9 - The first vector corresponds to the simulation for parameter p. 10 - The second vector corresponds to the simulation for parameter m OR The second vector corresponds to the simulation for fiducial parameters. 11 Also, if n_params_p!=0, all such parameters, must necessarily come after the parameters with both simulations for p and m. 12 covariance_matrix (numpy array): The covariance matrix associated with the data vectors. 13 n_params_p_m (int): The number of parameters with both simulations for p and m. 14 n_params_p (int): The number of parameters with just simulations for p. 15 dtheta (list of float): The parameter step sizes for the derivatives. Also, if n_params_p!=0, all such parameters, must necessarily come after the parameters 16 with both simulations for p and m. 17 n (int): The number of realizations. 18 19 Returns: 20 numpy array: The constructed Fisher matrix. #Give the expression 21 22 Raises ValueError: 23 -If the length of data_vectors are not of equal length 24 -If the covariance matrix is not square or does not match the length of data_vectors 25 - If length of dtheta and n_params_p_m + n_params_p do not match 26 """ 27 # Checking all the input parameters 28 p=len(data_vectors[0][0]) 29 for i in range(len(data_vectors)): 30 for j in range(2): 31 if len(data_vectors[i][j]) != p: 32 raise ValueError("All data vectors must be of equal length.") 33 if np.shape(covariance_matrix)[0] != np.shape(covariance_matrix)[1]: 34 raise ValueError("Covariance matrix must be square.") 35 if np.shape(covariance_matrix)[0] != len(data_vectors): 36 raise ValueError("Covariance matrix must match the length of data vectors.") 37 if len(dtheta) != n_params_p_m + n_params_p: 38 raise ValueError("Length of dtheta must match n_params_p_m + n_params_p.") 39 # Constructing the derivatives 40 d = np.zeros([n_params_p_m+n_params_p,len(data_vectors)]) 41 for i in range(n_params_p_m): 42 43 d_p = data_vectors[i][0] 44 d_m = data_vectors[i][1] 45 delt = d_p - d_m 46 d[i] = delt/(2*dtheta[i]) 47 48 if n_params_p > 0: 49 for j in range(n_params_p_m, n_params_p_m + n_params_p): 50 d_p= data_vectors[i][0] 51 d_0= data_vectors[i][1] 52 delt = d_p - d_0 53 d[j] = delt/(dtheta[j]) 54 55 # The Fisher matrix 56 c_inv=np.linalg.inv(covariance_matrix) 57 F = np.zeros([n_params_p+n_params_p_m,n_params_p_m+n_params_p]) 58 for i in range(0, n_params_p_m + n_params_p): 59 for j in range(0, n_params_p_m + n_params_p): 60 F[i][j] = (np.transpose(d[i])).dot(c_inv).dot(d[j])
4def constructingFishermatrix(data_vectors, covariance_matrix, dtheta, n_params_p_m, n_params_p=0): 5 """ 6 Constructs the Fisher matrix from data vectors and a covariance matrix. 7 8 Parameters: 9 data_vectors (list of numpy arrays): The data vectors for which the Fisher matrix is to be constructed. The ith element is an array containing two vectors: 10 - The first vector corresponds to the simulation for parameter p. 11 - The second vector corresponds to the simulation for parameter m OR The second vector corresponds to the simulation for fiducial parameters. 12 Also, if n_params_p!=0, all such parameters, must necessarily come after the parameters with both simulations for p and m. 13 covariance_matrix (numpy array): The covariance matrix associated with the data vectors. 14 n_params_p_m (int): The number of parameters with both simulations for p and m. 15 n_params_p (int): The number of parameters with just simulations for p. 16 dtheta (list of float): The parameter step sizes for the derivatives. Also, if n_params_p!=0, all such parameters, must necessarily come after the parameters 17 with both simulations for p and m. 18 n (int): The number of realizations. 19 20 Returns: 21 numpy array: The constructed Fisher matrix. #Give the expression 22 23 Raises ValueError: 24 -If the length of data_vectors are not of equal length 25 -If the covariance matrix is not square or does not match the length of data_vectors 26 - If length of dtheta and n_params_p_m + n_params_p do not match 27 """ 28 # Checking all the input parameters 29 p=len(data_vectors[0][0]) 30 for i in range(len(data_vectors)): 31 for j in range(2): 32 if len(data_vectors[i][j]) != p: 33 raise ValueError("All data vectors must be of equal length.") 34 if np.shape(covariance_matrix)[0] != np.shape(covariance_matrix)[1]: 35 raise ValueError("Covariance matrix must be square.") 36 if np.shape(covariance_matrix)[0] != len(data_vectors): 37 raise ValueError("Covariance matrix must match the length of data vectors.") 38 if len(dtheta) != n_params_p_m + n_params_p: 39 raise ValueError("Length of dtheta must match n_params_p_m + n_params_p.") 40 # Constructing the derivatives 41 d = np.zeros([n_params_p_m+n_params_p,len(data_vectors)]) 42 for i in range(n_params_p_m): 43 44 d_p = data_vectors[i][0] 45 d_m = data_vectors[i][1] 46 delt = d_p - d_m 47 d[i] = delt/(2*dtheta[i]) 48 49 if n_params_p > 0: 50 for j in range(n_params_p_m, n_params_p_m + n_params_p): 51 d_p= data_vectors[i][0] 52 d_0= data_vectors[i][1] 53 delt = d_p - d_0 54 d[j] = delt/(dtheta[j]) 55 56 # The Fisher matrix 57 c_inv=np.linalg.inv(covariance_matrix) 58 F = np.zeros([n_params_p+n_params_p_m,n_params_p_m+n_params_p]) 59 for i in range(0, n_params_p_m + n_params_p): 60 for j in range(0, n_params_p_m + n_params_p): 61 F[i][j] = (np.transpose(d[i])).dot(c_inv).dot(d[j])
Constructs the Fisher matrix from data vectors and a covariance matrix.
Parameters: data_vectors (list of numpy arrays): The data vectors for which the Fisher matrix is to be constructed. The ith element is an array containing two vectors: - The first vector corresponds to the simulation for parameter p. - The second vector corresponds to the simulation for parameter m OR The second vector corresponds to the simulation for fiducial parameters. Also, if n_params_p!=0, all such parameters, must necessarily come after the parameters with both simulations for p and m. covariance_matrix (numpy array): The covariance matrix associated with the data vectors. n_params_p_m (int): The number of parameters with both simulations for p and m. n_params_p (int): The number of parameters with just simulations for p. dtheta (list of float): The parameter step sizes for the derivatives. Also, if n_params_p!=0, all such parameters, must necessarily come after the parameters with both simulations for p and m. n (int): The number of realizations.
Returns: numpy array: The constructed Fisher matrix. #Give the expression
Raises ValueError: -If the length of data_vectors are not of equal length -If the covariance matrix is not square or does not match the length of data_vectors
- If length of dtheta and n_params_p_m + n_params_p do not match