Exemple #1
0
        def testit():

            for f, f2 in [(self.frame, self.frame2),
                          (self.mixed, self.mixed2)]:

                for op, op_str in [('add', '+'), ('sub', '-'), ('mul', '*'),
                                   ('div', '/'), ('pow', '**')]:

                    op = getattr(operator, op, None)
                    if op is not None:
                        result = expr._can_use_numexpr(op, op_str, f, f,
                                                       'evaluate')
                        self.assert_(result == (not f._is_mixed_type))

                        result = expr.evaluate(op,
                                               op_str,
                                               f,
                                               f,
                                               use_numexpr=True)
                        expected = expr.evaluate(op,
                                                 op_str,
                                                 f,
                                                 f,
                                                 use_numexpr=False)
                        assert_array_equal(result, expected.values)

                        result = expr._can_use_numexpr(op, op_str, f2, f2,
                                                       'evaluate')
                        self.assert_(result == False)
Exemple #2
0
        def testit():
            for f, f2 in [(self.frame, self.frame2),
                          (self.mixed, self.mixed2)]:

                f11 = f
                f12 = f + 1

                f21 = f2
                f22 = f2 + 1

                for op, op_str in [('gt', '>'), ('lt', '<'), ('ge', '>='),
                                   ('le', '<='), ('eq', '=='), ('ne', '!=')]:

                    op = getattr(operator, op)

                    result = expr._can_use_numexpr(op, op_str, f11, f12,
                                                   'evaluate')
                    self.assert_(result == (not f11._is_mixed_type))

                    result = expr.evaluate(op,
                                           op_str,
                                           f11,
                                           f12,
                                           use_numexpr=True)
                    expected = expr.evaluate(op,
                                             op_str,
                                             f11,
                                             f12,
                                             use_numexpr=False)
                    assert_array_equal(result, expected.values)

                    result = expr._can_use_numexpr(op, op_str, f21, f22,
                                                   'evaluate')
                    self.assert_(result == False)
Exemple #3
0
        def testit():

            for f, f2 in [(self.frame, self.frame2), (self.mixed, self.mixed2)]:

                for op, op_str in [("add", "+"), ("sub", "-"), ("mul", "*"), ("div", "/"), ("pow", "**")]:

                    op = getattr(operator, op)
                    result = expr._can_use_numexpr(op, op_str, f, f, "evaluate")
                    self.assert_(result == (not f._is_mixed_type))

                    result = expr.evaluate(op, op_str, f, f, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f, f, use_numexpr=False)
                    assert_array_equal(result, expected.values)

                    result = expr._can_use_numexpr(op, op_str, f2, f2, "evaluate")
                    self.assert_(result == False)
Exemple #4
0
        def testit():

            for f, f2 in [ (self.frame, self.frame2), (self.mixed, self.mixed2) ]:

                for op, op_str in [('add','+'),('sub','-'),('mul','*'),('div','/'),('pow','**')]:

                    op = getattr(operator,op)
                    result   = expr._can_use_numexpr(op, op_str, f, f)
                    self.assert_(result == (not f._is_mixed_type))

                    result   = expr.evaluate(op, op_str, f, f, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f, f, use_numexpr=False)
                    assert_array_equal(result,expected.values)
                
                    result   = expr._can_use_numexpr(op, op_str, f2, f2)
                    self.assert_(result == False)
Exemple #5
0
        def testit():
            for f, f2 in [(self.frame, self.frame2), (self.mixed, self.mixed2)]:

                f11 = f
                f12 = f + 1

                f21 = f2
                f22 = f2 + 1

                for op, op_str in [("gt", ">"), ("lt", "<"), ("ge", ">="), ("le", "<="), ("eq", "=="), ("ne", "!=")]:

                    op = getattr(operator, op)

                    result = expr._can_use_numexpr(op, op_str, f11, f12, "evaluate")
                    self.assert_(result == (not f11._is_mixed_type))

                    result = expr.evaluate(op, op_str, f11, f12, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f11, f12, use_numexpr=False)
                    assert_array_equal(result, expected.values)

                    result = expr._can_use_numexpr(op, op_str, f21, f22, "evaluate")
                    self.assert_(result == False)
Exemple #6
0
        def testit():
            for f, f2 in [ (self.frame, self.frame2), (self.mixed, self.mixed2) ]:

                f11 = f
                f12 = f + 1
            
                f21 = f2
                f22 = f2 + 1

                for op, op_str in [('gt','>'),('lt','<'),('ge','>='),('le','<='),('eq','=='),('ne','!=')]:

                    op = getattr(operator,op)

                    result   = expr._can_use_numexpr(op, op_str, f11, f12, 'evaluate')
                    self.assert_(result == (not f11._is_mixed_type))

                    result   = expr.evaluate(op, op_str, f11, f12, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f11, f12, use_numexpr=False)
                    assert_array_equal(result,expected.values)
                    
                    result   = expr._can_use_numexpr(op, op_str, f21, f22, 'evaluate')
                    self.assert_(result == False)
Exemple #7
0
                  nr_runs=5,
                  nr_init=9,
                  max_iter=30,
                  delta=0.1,
                  labels=None,
                  entropy_cutoff=None)

classes = m4.classify(dat)

m4.shortInitEM(dat, 5, 5, 5, 0.1)
m4.EM(seq3, 20, 0.1)
print "####Finish\n", m4

dat.printClustering(2, pred)

evaluate(pred, true)

#  ----------------------------- Example 4 -----------------------------
m5 = MixtureModel(1, [1.0], [NormalDistribution(3.0, 2.5)])

seq4 = m5.sample(1800)

#print "var = ", variance(seq4)

m6 = MixtureModel(1, [1.0], [NormalDistribution(-1.5, 2.5)])

#m6.EM(seq4,1,5)
#print m6

#seq5 = numarray.zeros(900,numarray.Float)
#for i in range(900):
Exemple #8
0
dat = DataSet()
dat.fromArray(seq3)

print "vorher ------\n", m4
pred = m4.cluster(dat, nr_runs=5, nr_init=9, max_iter=30, delta=0.1, labels=None, entropy_cutoff=None)

classes = m4.classify(dat)

m4.shortInitEM(dat, 5, 5, 5, 0.1)
m4.EM(seq3, 20, 0.1)
print "####Finish\n", m4

dat.printClustering(2, pred)

evaluate(pred, true)


#  ----------------------------- Example 4 -----------------------------
m5 = MixtureModel(1, [1.0], [NormalDistribution(3.0, 2.5)])

seq4 = m5.sample(1800)

# print "var = ", variance(seq4)

m6 = MixtureModel(1, [1.0], [NormalDistribution(-1.5, 2.5)])

# m6.EM(seq4,1,5)
# print m6

# seq5 = numarray.zeros(900,numarray.Float)