Example #1
0
def test_function_1(empty_folders):
    in_folder, out_folder, rep_folder = empty_folders
    in_folder = in_folder.strpath
    out_folder = out_folder.strpath
    rep_folder = rep_folder.strpath

    # Ass this folders are not parameters of the function, mock them.
    with mock.patch('functions.OUTPUT_FOLDER', out_folder):
        with mock.patch('functions.REPORTS_FOLDER', rep_folder):
            function1()
Example #2
0
def metBissecao(a, b):
    iterations = 0
    while abs(a - b) > 7e-6:
        m = abs(a + b) / 2.0
        print(
            str(iterations) + ". M: " + str(m) + "\t a: " + str(a) + "\t b:" +
            str(b))
        if (f.function1(a) * f.function1(m)) < 0:
            b = m
        else:
            a = m
        iterations += 1

    print("Total de iteracoes: " + str(iterations))
    print("Melhor apoximacao: " + str(m))
    return (str(iterations), str(m))
Example #3
0
def test_function_1_2(empty_folders):
    in_folder, out_folder, rep_folder = empty_folders
    in_folder = in_folder.strpath
    out_folder = out_folder.strpath
    rep_folder = rep_folder.strpath

    # With this mock imported constant
    with mock.patch('functions.OUTPUT_FOLDER', out_folder):

        # With this, patch arguments default values
        # Python 2
        # function2.func_defaults = (out_folder, in_folder)
        # Python 3
        function2.__defaults__ = (out_folder, rep_folder)
        function1.__defaults__ = (out_folder, )

        function1()
Example #4
0
def metTangente(x):
    iterations = 0
    old_x = 0
    while abs(old_x - x) > 7e-6:
        old_x = x
        x = (x - f.function1(x) / f.derived_function1(x))
        print(str(iterations) + ". M: " + str(x))
        iterations += 1

    print("Total de iteracoes: " + str(iterations))
    print("Melhor apoximacao: " + str(x))
    return (str(iterations), str(x))
Example #5
0
def metCorda(a, b):
    iterations = 0
    zero = (a + b) / 2
    old_a = a
    while abs(old_a - zero) > 7e-6:
        old_a = a
        zero = (a * f.function1(b) - b * f.function1(a)) / (f.function1(b) -
                                                            f.function1(a))
        print(
            str(iterations) + ". M: " + str(zero) + "\t a: " + str(a) +
            "\t b:" + str(b))
        if (f.function1(a) * f.function1(zero)) < 0:
            b = zero
        else:
            a = zero
        iterations += 1

    print("Total de iteracoes: " + str(iterations))
    print("Melhor apoximacao: " + str(zero))
    return (str(iterations), str(zero))
Example #6
0
from functions import function1, function2

function1()

function2()
Example #7
0
from __future__ import division
import numpy as np
from matplotlib import pyplot as plt
from functions import function1, taninv, trapezoid_integrate, trapezoid_integrate_for_loop

# Step 2

start = 0.0
stop = 5.0
num = 51  # to include the last element and avoid obo error
vector = np.linspace(start, stop, num)  # calling x vector

values = function1(vector)

##########
# Step 3

plt.plot(vector, values, "bo")
plt.xlabel("x")
plt.ylabel("$f(x)$")
plt.title("""Plot of $f(x) = 1/(1+x^2) $""")
plt.show()
plt.close()

###########
# Step 4

taninv_calculated = np.array(taninv(
    vector)[:, 0])  # remember that the quad function returns (integral, error)
taninv_actual = np.arctan(vector)
#with open("table.txt","w") as f:
Example #8
0
    viv_data = pd.read_csv(viv_file_path, usecols=['U_MPIO', 'VA1_ESTRATO', 'VB_ACU', 'VF_INTERNET'])
    health_providers_data = pd.read_csv(health_providers_file, usecols=['depa_nombre', 'muni_nombre','nombre_prestador'])

    #####################################################################################################
    # Inicio del código
    #####################################################################################################

    state_code = int(states[i][0:2])
    state_name = normalize(states[i][2:].upper())

    #####################################################################################################
    # Se van a encontrar las variables posibles en el archivo de 'Personas' y 'Viviendas'
    #####################################################################################################

    # s será la matriz de salida de tamaño (N°deMunicipios,26)
    s = function1(people_data, viv_data)

    #######################################################################################
    # Ahora se va a calcular el numero de hospitales por km2 y el numero de hogares por km2
    #######################################################################################

    s[:,24:26] = function2(state_code, state_name, municipality_data, health_providers_data, municipality_area_data, houses_data)
    # Redondeamos todos los resultados a dos decimales y se escriben como porcentaje, menos las ultimas dos filas
    s[:,1:-8] = np.round(s[:,1:-8]*100,2)
    s[:,-8:] = np.round(s[:,-8:],6)
    # Se ajustan los codigos de cada municipio para el merge final
    s[:,0] = s[:,0] + state_code*1000

    #####################################################################################################
    # Merging with the main file
    #####################################################################################################
 def test_three_items(self):
     input = [1, 9, 9, 10, 10, 10, 10, 11]
     output = [-7.75, .25, .25, 1.25, 1.25, 1.25, 1.25, 2.25]
     self.assertEquals(output, function1(input))
 def test_two_items(self):
     self.assertEquals([-.5, .5], function1([0, 1]))
     self.assertEquals([-2.5, 2.5], function1([3, 8]))
 def test_one_item(self):
     self.assertEquals([0], function1([0]))
     self.assertEquals([0], function1([9]))
     self.assertEquals([0], function1([-10]))
 def test_blank_list(self):
     self.assertEquals([], function1([]))
Example #13
0
 def evaluate(self, agent):
     self.fitness = fun.function1(self.x, agent)