def dataprops_example(): idp = IdentifierProperty(Key("id")) nps = [NumericProperty(Key("n"), Weight(0.1), ValuePair(0, 10))] cps = [ CategoricalProperty(Key("c1")), CategoricalProperty( Key("c2"), connections=[Connection("val1", "val2", Similarity(0.25))], # type: ignore ), ] return DataProperties(idp, nps, cps)
def dataprops_ten_percent_difference(): idp = IdentifierProperty(Key("id")) nps = [ NumericProperty(key=Key("n1"), measurement_bounds=ValuePair(0, 10)), NumericProperty(key=Key("n2")), ] cps = [ CategoricalProperty(Key("c1")), CategoricalProperty( Key("c2"), connections=[Connection("ye", "yee", 0.5)] # type: ignore ), CategoricalProperty(Key("c3"), Weight(0.25)), ] return DataProperties(idp, nps, cps)
def test_ten_percent_scaled_grid( data_ten_percent_difference, dataprops_ten_percent_difference ): assert Grouper( data_ten_percent_difference, dataprops_ten_percent_difference ).scaled_grid() == { "a": { CategoricalProperty(Key("c1"), Weight(1.0)): "left", CategoricalProperty( Key("c2"), Weight(1.0), connections=[Connection("ye", "yee", 0.5)], # type: ignore ): "ye", CategoricalProperty(Key("c3"), Weight(0.25)): "re", NumericProperty( Key("n1"), Weight(1.0), measurement_bounds=ValuePair(0.0, 10.0), scale_bounds=ValuePair(0.0, 1.0), ): 0.1, NumericProperty(Key("n2"), Weight(1.0)): 0.0, }, "b": { CategoricalProperty(Key("c1"), Weight(1.0)): "right", CategoricalProperty( Key("c2"), Weight(1.0), connections=[Connection("ye", "yee", 0.5)], # type: ignore ): "yee", CategoricalProperty(Key("c3"), Weight(0.25)): "ree", NumericProperty( Key("n1"), Weight(1.0), measurement_bounds=ValuePair(0.0, 10.0) ): 0.3, NumericProperty(Key("n2"), Weight(1.0)): 1.0, }, "c": { CategoricalProperty(Key("c1"), Weight(1.0)): "left", CategoricalProperty( Key("c2"), Weight(1.0), connections=[Connection("ye", "yee", 0.5)], # type: ignore ): "yee", CategoricalProperty(Key("c3"), Weight(0.25)): "re", NumericProperty( Key("n1"), Weight(1.0), measurement_bounds=ValuePair(0.0, 10.0) ): 0.1, NumericProperty(Key("n2"), Weight(1.0)): 0.0, }, }
def test_example_scaled_grid(data_example, dataprops_example): assert Grouper(data_example, dataprops_example).scaled_grid() == { "id1": { CategoricalProperty(Key("c1"), Weight(1.0)): "me", CategoricalProperty( Key("c2"), Weight(1.0), connections=[ Connection( # type: ignore "val1", "val2", Similarity(0.25), ) ], ): "val1", NumericProperty( Key("n"), Weight(0.1), measurement_bounds=ValuePair(0.0, 10.0) ): 0.2, }, "id2": { CategoricalProperty(Key("c1"), Weight(1.0)): "you", CategoricalProperty( Key("c2"), Weight(1.0), connections=[ Connection( # type: ignore "val1", "val2", Similarity(0.25), ) ], ): "val2", NumericProperty( Key("n"), Weight(0.1), measurement_bounds=ValuePair(0.0, 10.0) ): 0.7, }, }
def test_a_split_scaled_grid(data_a_split, dataprops_a_split): assert Grouper(data_a_split, dataprops_a_split).scaled_grid() == { "a": { CategoricalProperty(Key("c1"), Weight(1.0)): "left", CategoricalProperty(Key("c2"), Weight(1.0)): "up", }, "b": { CategoricalProperty(Key("c1"), Weight(1.0)): "right", CategoricalProperty(Key("c2"), Weight(1.0)): "up", }, "c": { CategoricalProperty(Key("c1"), Weight(1.0)): "left", CategoricalProperty(Key("c2"), Weight(1.0)): "down", }, }
def dataprops_a_split(): idp = IdentifierProperty(Key("id")) nps = [] cps = [CategoricalProperty(Key("c1")), CategoricalProperty(Key("c2"))] return DataProperties(idp, nps, cps)
def test_b_unique_scaled_grid(data_b_unique, dataprops_b_unique): assert Grouper(data_b_unique, dataprops_b_unique).scaled_grid() == { "a": {CategoricalProperty(Key("c1"), Weight(1.0)): "left"}, "b": {CategoricalProperty(Key("c1"), Weight(1.0)): "right"}, "c": {CategoricalProperty(Key("c1"), Weight(1.0)): "left"}, }
def dataprops_b_unique(): idp = IdentifierProperty(Key("id")) nps = [] cps = [CategoricalProperty(Key("c1"))] return DataProperties(idp, nps, cps)