def _get_parent_graph(parents_neighbors_coeffs, exclude=None): """ Iterates through the input parent-neighghbour coefficient dictionary to return only parent relations (i.e. where tau != 0) """ graph = defaultdict(list) for j, i, tau, _ in pp._iter_coeffs(parents_neighbors_coeffs): if tau != 0 and (i, tau) != exclude: graph[j].append((i, tau)) return dict(graph)
def test_linear_mediation_coeffs(data_frame_a): # Build the dataframe and the model (dataframe, true_parents), links_coeffs = data_frame_a med = LinearMediation(dataframe=dataframe) # Fit the model med.fit_model(all_parents=true_parents, tau_max=3) # Ensure the results make sense for j, i, tau, coeff in pp._iter_coeffs(links_coeffs): np.testing.assert_allclose(med.get_coeff(i=i, tau=tau, j=j), coeff, rtol=1e-1)
def test_covariance_construction(covariance_parameters): """ Test the random noise covariance matrix construction from a set of parameters """ # Unpack the covariance matrix and parameters good_params, covar_matrix = covariance_parameters # Check the values are passed correctly for j, i, _, coeff in pp._iter_coeffs(good_params): covar_coeff = covar_matrix[j, i] err_message = "Node {} and parent node {} have".format(j, i)+\ " coefficient {} for tau == 0,\nbut the".format(coeff)+\ " coefficient in the covariance matrix"+\ " is {} ".format(covar_coeff) np.testing.assert_approx_equal(coeff, covar_coeff, err_msg=err_message)