File: ut_cure.py

package info (click to toggle)
python-pyclustering 0.10.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 38,888; python: 24,311; sh: 384; makefile: 105
file content (115 lines) | stat: -rwxr-xr-x 5,288 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""!

@brief Unit-tests for CURE algorithm.

@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause

"""


import unittest

# Generate images without having a window appear.
import matplotlib
matplotlib.use('Agg')

from pyclustering.samples.definitions import SIMPLE_SAMPLES, FCPS_SAMPLES

from pyclustering.cluster.tests.cure_templates import CureTestTemplates


class CureUnitTest(unittest.TestCase):
    def testClusterAllocationSampleSimple1(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, [5, 5], 2)

    def testClusterAllocationSampleSimple1OneRepresentor(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, [5, 5], 2, 1, 0.5)

    def testClusterAllocationSampleSimple1NumPy(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, [5, 5], 2, numpy_usage=True)

    def testClusterAllocationSampleSimple2(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, [10, 5, 8], 3)

    def testClusterAllocationSampleSimple2NoCompression(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, [10, 5, 8], 3, 5, 0.0)

    def testClusterAllocationSampleSimple2NumPy(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, [10, 5, 8], 3, numpy_usage=True)

    def testClusterAllocationSampleSimple3(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, [10, 10, 10, 30], 4)

    def testClusterAllocationSampleSimple3OneRepresentor(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, [10, 10, 10, 30], 4, 1, 0.5)

    def testClusterAllocationSampleSimple3NumPy(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, [10, 10, 10, 30], 4, numpy_usage=True)

    def testClusterAllocationSampleSimple4(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, [15, 15, 15, 15, 15], 5)

    def testClusterAllocationSampleSimple4NumPy(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, [15, 15, 15, 15, 15], 5, numpy_usage=True)

    def testClusterAllocationSampleSimple5(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, [15, 15, 15, 15], 4)

    def testClusterAllocationSampleSimple5NumPy(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, [15, 15, 15, 15], 4, numpy_usage=True)

    def testClusterAllocationSampleTwoDiamonds(self):
        CureTestTemplates.template_cluster_allocation(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, [399, 401], 2, 5, 0.3)

    def testClusterAllocationSampleLsun(self):
        CureTestTemplates.template_cluster_allocation(FCPS_SAMPLES.SAMPLE_LSUN, [100, 101, 202], 3, 5, 0.3)

    def testOneClusterAllocationSampleSimple1(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, [10], 1)

    def testOneClusterAllocationSampleSimple2(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, [23], 1)

    def testOneClusterAllocationSampleSimple3(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, [60], 1)

    def testOneClusterAllocationSampleSimple4(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, [75], 1)

    def testOneClusterAllocationSampleSimple5(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, [60], 1)


    def testClusterAllocationOneDimensionData(self):
        CureTestTemplates.templateClusterAllocationOneDimensionData(False)


    def testClusterAllocationTheSameData1(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE9, [10, 20], 2, 5, 0.3)

    def testClusterAllocationTheSameData2(self):
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE12, [5, 5, 5], 3, 5, 0.3)
        CureTestTemplates.template_cluster_allocation(SIMPLE_SAMPLES.SAMPLE_SIMPLE12, [5, 10], 2, 5, 0.3)


    def testEncoderProcedure(self):
        CureTestTemplates.templateEncoderProcedures(False)


    def test_argument_invalid_amount_clusters(self):
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 0, 5, 0.3, False)
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE2, -1, 5, 0.3, False)

    def test_argument_invalid_amount_representatives(self):
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0, 0.3, False)
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 2, -2, 0.3, False)
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 2, -4, 0.3, False)

    def test_argument_invalid_compression(self):
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 1, -0.3, False)
        CureTestTemplates.exception(ValueError, SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 2, 2, -2.0, False)

    def test_argument_empty_data(self):
        CureTestTemplates.exception(ValueError, [], 3, 5, 0.3, False)