<s> import os <EOL> import numpy as np <EOL> from montepython . likelihood_class import Likelihood <EOL> class sn ( Likelihood ) : <EOL> def __init__ ( self , path , data , command_line ) : <EOL> Likelihood . __init__ ( self , path , data , command_line ) <EOL> self . z = np . array ( [ ] , '<STR_LIT>' ) <EOL> self . moduli = np . array ( [ ] , '<STR_LIT>' ) <EOL> for line in open ( os . path . join ( <EOL> self . data_directory , self . z_mu_dmu ) , '<STR_LIT:r>' ) : <EOL> if ( line . find ( '<STR_LIT:#>' ) == - <NUM_LIT:1> ) : <EOL> self . z = np . append ( self . z , float ( line . split ( ) [ <NUM_LIT:1> ] ) ) <EOL> self . moduli = np . append ( self . moduli , float ( line . split ( ) [ <NUM_LIT:2> ] ) ) <EOL> self . num_points = np . shape ( self . z ) [ <NUM_LIT:0> ] <EOL> covmat = np . zeros ( ( self . num_points , self . num_points ) , '<STR_LIT>' ) <EOL> if self . has_syscovmat : <EOL> covmat_filename = self . covmat_sys <EOL> else : <EOL> covmat_filename = self . covmat_nosys <EOL> i = <NUM_LIT:0> <EOL> for line in open ( os . path . join ( <EOL> self . data_directory , covmat_filename ) , '<STR_LIT:r>' ) : <EOL> if ( line . find ( '<STR_LIT:#>' ) == - <NUM_LIT:1> ) : <EOL> covmat [ i ] = line . split ( ) <EOL> i += <NUM_LIT:1> <EOL> self . inv_covmat = np . linalg . inv ( covmat ) <EOL> self . inv_covmat_sum = np . sum ( self . inv_covmat ) <EOL> def loglkl ( self , cosmo , data ) : <EOL> difference = np . ndarray ( self . num_points , '<STR_LIT>' ) <EOL> for i in range ( self . num_points ) : <EOL> d = cosmo . angular_distance ( self . z [ i ] ) <EOL> difference [ i ] = <NUM_LIT:5> * np . log ( ( <NUM_LIT:1> + self . z [ i ] ) ** <NUM_LIT:2> * d ) / np . log ( <EOL> <NUM_LIT:10> ) + <NUM_LIT> - self . moduli [ i ] <EOL> AT = np . dot ( difference , np . dot ( self . inv_covmat , difference ) ) <EOL> if self . has_marginalization : <EOL> BT = np . sum ( np . dot ( self . inv_covmat , difference ) ) <EOL> else : <EOL> BT = <NUM_LIT:0> <EOL> chi_squared = AT - ( BT ** <NUM_LIT:2> ) / self . inv_covmat_sum <EOL> lkl = - <NUM_LIT:0.5> * chi_squared <EOL> return lkl </s>
