Ejemplo n.º 1
0
def test_load_data_ndarray_data():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])

    t = Topology()
    t.load_data(data)

    assert_array_equal(t.number_data, data)
Ejemplo n.º 2
0
def test_map():
    data = np.array([[0., 0.],
                     [0.25, 0.25],
                     [0.5, 0.5],
                     [0.75, 0.75],
                     [1., 1.],
                     [1., 0.],
                     [0.25, 0.75],
                     [0.75, 0.25],
                     [0., 1.]])

    t = Topology()
    t.load_data(data)
    t.fit_transform(metric=None, lens=None)

    t.map(resolution=2, overlap=0.3, eps=0.3, min_samples=3)

    test_nodes = np.array([[0.25, 0.25],
                           [0.25, 0.75],
                           [0.75, 0.25],
                           [0.75, 0.75]])

    test_edges = np.array([[0, 1],
                           [0, 2],
                           [0, 3],
                           [1, 2],
                           [1, 3],
                           [2, 3]])

    assert_array_equal(t.nodes, test_nodes)
    assert_array_equal(t.edges, test_edges)
Ejemplo n.º 3
0
def test_search_number_data():
    data = np.array([[0., 0.],
                     [0.1, 0.1],
                     [0.2, 0.2],
                     [0.2, 0.8],
                     [0.1, 0.9],
                     [0., 1.],
                     [0.8, 0.8],
                     [0.9, 0.9],
                     [1., 1.]])

    target = np.array([[0], [0], [0],
                       [1], [1], [1],
                       [2], [2], [2]])

    text_data = np.array([["a"], ["a"], ["a"],
                          ["b"], ["b"], ["b"],
                          ["c"], ["c"], ["c"]])

    t = Topology()
    t.load_data(data, text_data=text_data)
    t.fit_transform(metric=None, lens=None)
    t.map(resolution=2, overlap=0.3)
    t.color(target, color_method="mean", color_type="rgb", normalize=True)
    search_dicts = [{
        "data_type": "number",
        "operator": ">",
        "column": 0,
        "value": 0.7
    }]
    t.search_from_values(search_dicts=search_dicts, target=None, search_type="and")

    test_color = ['#cccccc', '#cccccc', '#b20000']
    assert t.hex_colors == test_color
Ejemplo n.º 4
0
def test_color_mean_gray():
    data = np.array([[0., 0.],
                     [0.1, 0.1],
                     [0.2, 0.2],
                     [0.2, 0.8],
                     [0.1, 0.9],
                     [0., 1.],
                     [0.8, 0.8],
                     [0.9, 0.9],
                     [1., 1.]])

    target = np.array([[0], [0], [0],
                       [1], [1.1], [0.9],
                       [2], [2], [2]])

    t = Topology()
    t.load_data(data)
    t.fit_transform(metric=None, lens=None)

    t.map(resolution=2, overlap=0.3, eps=0.2, min_samples=3)

    t.color(target, color_method="mean", color_type="gray", normalize=True)

    test_color = ['#dcdcdc', '#787878', '#141414']

    assert t.hex_colors == test_color
Ejemplo n.º 5
0
def test_load_data_text_data_columns_text_data_is_none():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])
    text_data = None
    text_data_columns = ["columns1", "columns2"]

    t = Topology()
    with pytest.raises(ValueError):
        t.load_data(data, text_data=text_data, text_data_columns=text_data_columns)
Ejemplo n.º 6
0
def test_load_data_text_data_ndarray():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])
    text_data = np.array([["data1"], ["data2"]])

    t = Topology()
    t.load_data(data, text_data=text_data)

    assert_array_equal(t.text_data, text_data)
Ejemplo n.º 7
0
def test_load_data_number_data_columns_ndarray():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])
    data_columns = np.array(["data1", "data2"])

    t = Topology()
    t.load_data(data, number_data_columns=data_columns)

    assert_array_equal(t.number_data_columns, data_columns)
Ejemplo n.º 8
0
def test_load_data_text_data_columns_text_data_diff_columns():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])
    text_data = np.array([["data1-1", "data1-2"], ["data2-1", "data2-2"]])
    text_data_columns = ["columns1"]

    t = Topology()
    with pytest.raises(ValueError):
        t.load_data(data, text_data=text_data, text_data_columns=text_data_columns)
Ejemplo n.º 9
0
def test_load_data_text_data_columns():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])
    text_data = np.array([["data1-1", "data1-2"], ["data2-1", "data2-2"]])
    text_data_columns = ["columns1", "columns2"]

    t = Topology()
    t.load_data(data, text_data=text_data, text_data_columns=text_data_columns)

    assert_array_equal(t.text_data_columns, np.array(text_data_columns))
Ejemplo n.º 10
0
def test_load_data_standardize_true():
    data = np.array([[0.0, 0.0], [1.0, 1.0]])

    t = Topology()
    t.load_data(data, standardize=True)

    scaler = preprocessing.StandardScaler()
    test_data = scaler.fit_transform(data)
    assert_array_equal(t.std_number_data, test_data)
Ejemplo n.º 11
0
def test_transform_none_none():
    data = np.array([[0., 0.], [1., 1.]])

    t = Topology()
    t.load_data(data)

    metric = None
    lens = None
    t.fit_transform(metric=metric, lens=lens)

    test_data = np.array([[0., 0.], [1., 1.]])

    assert_array_equal(t.point_cloud, test_data)
Ejemplo n.º 12
0
def test_transform_multi_lens():
    data = np.array([[0., 0.], [0., 1.], [1., 1.]])

    t = Topology()
    t.load_data(data)

    metric = "hamming"
    lens = [L1Centrality(), GaussianDensity(h=0.25)]
    t.fit_transform(metric=metric, lens=lens)

    test_data = np.array([[1., 0.], [0., 1.], [1., 0.]])

    assert_array_equal(t.point_cloud, test_data)
Ejemplo n.º 13
0
def test_transform_none_pca():
    data = np.array([[0., 1.], [1., 0.]])

    t = Topology()
    t.load_data(data)

    metric = None
    lens = [PCA(components=[0])]
    t.fit_transform(metric=metric, lens=lens)

    test_data = np.array([0., 1.])
    test_data = test_data.reshape(test_data.shape[0], 1)

    assert_array_equal(t.point_cloud, test_data)
Ejemplo n.º 14
0
def test_map_min_samples_under_zero():
    data = np.array([[0., 0.],
                     [0.25, 0.25],
                     [0.5, 0.5],
                     [0.75, 0.75],
                     [1., 1.],
                     [1., 0.],
                     [0.25, 0.75],
                     [0.75, 0.25],
                     [0., 1.]])

    t = Topology()
    t.load_data(data)
    t.fit_transform(metric=None, lens=None)
    with pytest.raises(Exception):
        t.map(min_samples=-1)
Ejemplo n.º 15
0
def test_color_different_size_input():
    data = np.array([[0., 0.],
                     [0.1, 0.1],
                     [0.2, 0.2],
                     [0.2, 0.8],
                     [0.1, 0.9],
                     [0., 1.],
                     [0.8, 0.8],
                     [0.9, 0.9],
                     [1., 1.]])

    target = np.array([0, 1, 2])

    t = Topology()
    t.load_data(data)
    t.fit_transform()
    t.map()

    with pytest.raises(Exception):
        t.color(target)
Ejemplo n.º 16
0
def test_color_ctype():
    data = np.array([[0., 0.],
                     [0.1, 0.1],
                     [0.2, 0.2],
                     [0.2, 0.8],
                     [0.1, 0.9],
                     [0., 1.],
                     [0.8, 0.8],
                     [0.9, 0.9],
                     [1., 1.]])

    target = np.array([[0], [0], [0],
                       [1], [1], [1],
                       [2], [2], [2]])

    t = Topology()
    t.load_data(data)
    t.fit_transform()
    t.map(resolution=2, overlap=0.3)

    with pytest.raises(Exception):
        t.color(target, color_type="hoge")
Ejemplo n.º 17
0
def test_load_data_none():
    data = None

    t = Topology()
    with pytest.raises(ValueError):
        t.load_data(data)
Ejemplo n.º 18
0
def test_load_data_not_2d_array():
    data = [[[0.0, 0.0], [1.0, 1.0]]]

    t = Topology()
    with pytest.raises(ValueError):
        t.load_data(data)