def test_wrp_notimplemented_string_weights(): wrp = WeightedRipsPersistence(weights="foo") with pytest.raises(ValueError, match="'foo' passed for `weights` but the " "only allowed string is 'DTM'"): wrp.fit(X_pc)
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_fit_transform_plot(X, metric, hom_dims): WeightedRipsPersistence(metric=metric, weight_params={ 'n_neighbors': 1 }).fit_transform_plot(X, sample=0, homology_dimensions=hom_dims)
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_notimplemented_p(): wrp = WeightedRipsPersistence(weight_params={'p': 1.2}) with pytest.raises(ValueError): wrp.fit(X_pc)
def test_wrp_not_fitted(): wrp = WeightedRipsPersistence() with pytest.raises(NotFittedError): wrp.transform(X_pc)
def test_wrp_params(): metric = 'not_defined' wrp = WeightedRipsPersistence(metric=metric) with pytest.raises(ValueError): wrp.fit_transform(X_pc)