コード例 #1
0
def createGroups(clusters0, clusters1, num_groups):
    d = clusters1.getDimension()
    (a, e0, e1) = assignClustersToGroups(clusters0, clusters1, num_groups)

    outliers_0 = getOutliers(e0, clusters0)
    outliers_1 = getOutliers(e1, clusters1)

    groups = GroupContainer(d)

    for clstr in clusters1.getClusters():
        groups.addSamples(getGroupIndex(a, clstr, num_groups),
                          clstr.getSamples() - outliers_1.getSamples())

    return (groups, removeOutliers(clusters0, outliers_0))
コード例 #2
0
    def test_createRegions_trivial4D(self):
        d = 4
        groups = GroupContainer(d)
        groups.addSamples(1, [Sample((5.0, 4.0, 0.0, 0.0))])
        clusters = ClusterContainer([Cluster([(7.0, 4.0, 0.0, 0.0)], d)], d)
        regions = createRegions(groups, clusters)
        hiperplanes = regions[0].getHyperplanes().pop()

        self.assertTrue(
            0.999999950215 < hiperplanes.getCoefficient(0)
            and 0.999999950216 > hiperplanes.getCoefficient(0),
            "0.99999995001 debe multiplicar la primer incognita")
        self.assertEquals(0.0, hiperplanes.getCoefficient(1),
                          "0.0 debe multiplicar la segunda incognita")
        self.assertTrue(
            5.9999997013 > hiperplanes.getIntercept()
            and 5.9999997012 < hiperplanes.getIntercept(),
            "alfa debe ser 5.9999997013")
コード例 #3
0
    def test_equals4D(self):
        d = 4
        d4 = 3
        g1 = Group([(0.0, 0.0, 0.0, 0.0), (1.0, 1.0, 0.0, 0.0)], d)
        g2 = Group([(1.0, 1.0, 0.0, 0.0), (2.0, 2.0, 0.0, 0.0)], d)

        container1 = GroupContainer(d)
        container1.addSamples(1, g1.getSamples())
        container1.addSamples(2, g2.getSamples())

        container2 = GroupContainer(d)
        container2.addSamples(1, g1.getSamples())
        container2.addSamples(2, g2.getSamples())

        container3 = GroupContainer(d)
        container3.addSamples(1, g1.getSamples())

        container4 = GroupContainer(d4)
        container4.addSamples(1, g1.getSamples())

        self.assertEqual(container1, container2,
                         "el container 1 y 2 deben ser iguales")
        self.assertNotEquals(container1, container3,
                             "el container 1 y 3 deberia ser distintos")
        self.assertNotEquals(container3, container4,
                             "los container no son de la misma dimension")