Example #1
0
 def test_eq2(self):
     c = Calculator()
     r1 = c.resolve_eq(3, 4, 1)
     r2 = c.resolve_eq(1, -1, -1)
     r3 = c.resolve_eq(9, -5, 0)
     r4 = c.resolve_eq(5, 0, -4)
     self.assertAlmostEqual(r1[0], [-0.3333333333333333, -1.0][0])
     self.assertAlmostEqual(r2[0], [1.618033988749895,
                                    -0.6180339887498949][0])
     self.assertAlmostEqual(r3[0], [0.5555555555555556, 0.0][0])
     self.assertAlmostEqual(r4[0], [0.894427190999916,
                                    -0.894427190999916][0])
Example #2
0
def generate_data():
    calc = Calculator()
    with open('datasetx1.arff', 'a') as filex1:
        with open('datasetx2.arff', 'a') as filex2:
            filex1.write('@relation eq_segundo_grau_x1\n\n')
            filex1.write('@attribute a NUMERIC\n')
            filex1.write('@attribute b NUMERIC\n')
            filex1.write('@attribute c NUMERIC\n')
            filex1.write('@attribute x1 NUMERIC\n\n')
            filex1.write('@data\n')
            filex2.write('@relation eq_segundo_grau_x2\n\n')
            filex2.write('@attribute a NUMERIC\n')
            filex2.write('@attribute b NUMERIC\n')
            filex2.write('@attribute c NUMERIC\n')
            filex2.write('@attribute x2 NUMERIC\n\n')
            filex2.write('@data\n')
            for i in range(0, 1000000):
                a = 0
                while a is 0:
                    a = randint(-100, 100)
                b = randint(-100, 100)
                c = randint(-100, 100)
                xs = calc.resolve_eq(a, b, c)
                if xs[0] is not "nr":
                    filex1.write(
                        str(a) + ', ' + str(b) + ', ' + str(c) + ', ' +
                        str(xs[0]) + '\n')
                    filex2.write(
                        str(a) + ', ' + str(b) + ', ' + str(c) + ', ' +
                        str(xs[1]) + '\n')
Example #3
0
def generate_controlled_data():
    calc = Calculator()
    file_path = 'data/eq2/'
    generate_file_path(file_path)
    with open(file_path + 'datasetx1.arff', 'a') as filex1:
        with open(file_path + 'datasetx2.arff', 'a') as filex2:
            filex1.write('@relation eq_segundo_grau_x1\n\n')
            filex1.write('@attribute a NUMERIC\n')
            filex1.write('@attribute b NUMERIC\n')
            filex1.write('@attribute c NUMERIC\n')
            filex1.write('@attribute x1 NUMERIC\n\n')
            filex1.write('@data\n')
            filex2.write('@relation eq_segundo_grau_x2\n\n')
            filex2.write('@attribute a NUMERIC\n')
            filex2.write('@attribute b NUMERIC\n')
            filex2.write('@attribute c NUMERIC\n')
            filex2.write('@attribute x2 NUMERIC\n\n')
            filex2.write('@data\n')
            for i in range(-25, 25):
                for j in range(-25, 25):
                    for k in range(-25, 25):
                        if i is not 0:
                            a = i
                            b = j
                            c = k
                            xs = calc.resolve_eq(a, b, c)
                            if xs[0] is not "nr":
                                filex1.write(
                                    str(a) + ', ' + str(b) + ', ' + str(c) +
                                    ', ' + str(xs[0]) + '\n')
                                filex2.write(
                                    str(a) + ', ' + str(b) + ', ' + str(c) +
                                    ', ' + str(xs[1]) + '\n')