def test_wrp_metric_params(): def metric(x, y, **kwargs): return np.linalg.norm(x - y) metric_params = {"parameter": 0.} wrp = WeightedRipsPersistence(metric=metric, metric_params=metric_params) wrp.fit_transform(X_pc)
def test_wrp_same_as_vrp_when_zero_weights(X, metric, weight_params, collapse_edges, max_edge_weight, infinity_values): wrp = WeightedRipsPersistence(weights=lambda x: np.zeros(x.shape[0]), weight_params=weight_params, metric=metric, collapse_edges=collapse_edges, max_edge_weight=max_edge_weight, infinity_values=infinity_values) # This is not generally true, it is only a way to obtain the res array # in this specific case X_exp = X_vrp_exp.copy() X_exp[:, :, :2][X_exp[:, :, :2] >= max_edge_weight] = infinity_values assert_almost_equal(wrp.fit_transform(X), X_exp)
def test_wrp_infinity_error(): with pytest.raises(ValueError, match="Input contains"): wrp = WeightedRipsPersistence(metric='precomputed') wrp.fit_transform(X_dist_disconnected)
def test_wrp_transform(X, metric, weight_params, collapse_edges): wrp = WeightedRipsPersistence(weight_params=weight_params, metric=metric, collapse_edges=collapse_edges) assert_almost_equal(wrp.fit_transform(X), X_wrp_exp[weight_params['p']])
def test_wrp_params(): metric = 'not_defined' wrp = WeightedRipsPersistence(metric=metric) with pytest.raises(ValueError): wrp.fit_transform(X_pc)