def test_get_output_obj(self, csv_fileobj): dataset = MatrixDataset.from_csv(csv_fileobj) alg = Sums(iterator=FixedIterator(5)) # Default should be all fields if none are given, but not accuracy # unless supervised data given results = alg.run(dataset) out1 = BaseClient().get_output_obj(results) exp_keys = { f.value for f in OutputFields if f != OutputFields.ACCURACY } assert set(out1.keys()) == exp_keys sup_data = SupervisedData.from_csv(csv_fileobj) sup_results = alg.run(sup_data.data) out2 = BaseClient().get_output_obj(sup_results, sup_data=sup_data) assert set(out2.keys()) == {f.value for f in OutputFields} assert out2["trust"] == sup_results.trust assert out2["belief"] == sup_results.belief out3 = BaseClient().get_output_obj(results, output_fields=[OutputFields.TRUST]) assert set(out3.keys()) == {"trust"}
def test_basic(self, data): """ Perform Sums on a small graph. The expected results were obtained by finding eigenvectors of suitable matrices (using numpy "by hand"), as per Kleinberg paper for Hubs and Authorities """ sums = Sums(iterator=ConvergenceIterator(DistanceMeasures.L1, 0.00001)) results = sums.run(data) assert np.isclose(results.trust["s1"], 1) assert np.isclose(results.trust["s2"], 0.53208889) assert np.isclose(results.trust["s3"], 0.34729636) assert set(results.belief["x"].keys()) == {"one"} assert np.isclose(results.belief["x"]["one"], 1) assert set(results.belief["y"].keys()) == {"eight", "nine"} assert np.isclose(results.belief["y"]["nine"], 0.65270364) assert np.isclose(results.belief["y"]["eight"], 0.34729636) assert set(results.belief["z"].keys()) == {"seven"} assert np.isclose(results.belief["z"]["seven"], 0.87938524)