def exponential(data, precision): independent_variable = dimension(data, 1) dependent_variable = dimension(data, 2) independent_matrix = [] dependent_matrix = [] for i in range(len(data)): independent_matrix.append([independent_variable[i], 1]) dependent_matrix.append([log(dependent_variable[i])]) solution = solve(independent_matrix, dependent_matrix, precision) constants = [exp(solution[1]), exp(solution[0])] coefficients = [ rounding(constants[0], precision), rounding(constants[1], precision) ] equation = exponential_equation(*coefficients) derivative = exponential_derivative(*coefficients) integral = exponential_integral(*coefficients)['evaluation'] first_derivative = derivative['first']['evaluation'] second_derivative = derivative['second']['evaluation'] points = key_points('exponential', solution, equation, first_derivative, second_derivative, precision) five_numbers = five_number_summary(independent_variable, precision) min_value = five_numbers['minimum'] max_value = five_numbers['maximum'] q1 = five_numbers['q1'] q3 = five_numbers['q3'] accumulated_range = accumulation(integral, min_value, max_value, precision) accumulated_iqr = accumulation(integral, q1, q3, precision) averages_range = average_values('exponential', equation, integral, min_value, max_value, coefficients, precision) averages_iqr = average_values('exponential', equation, integral, q1, q3, coefficients, precision) predicted = [] for i in range(len(data)): predicted.append(equation(independent_variable[i])) accuracy = correlation(dependent_variable, predicted, precision) evaluations = { 'equation': equation, 'derivative': first_derivative, 'integral': integral } points = { 'roots': points['roots'], 'maxima': points['maxima'], 'minima': points['minima'], 'inflections': points['inflections'] } accumulations = {'range': accumulated_range, 'iqr': accumulated_iqr} averages = {'range': averages_range, 'iqr': averages_iqr} result = { 'constants': coefficients, 'evaluations': evaluations, 'points': points, 'accumulations': accumulations, 'averages': averages, 'correlation': accuracy } return result
def logarithmic(data, precision): independent_variable = dimension(data, 1) dependent_variable = dimension(data, 2) independent_matrix = [] dependent_matrix = column(dependent_variable) for i in range(len(data)): independent_matrix.append([log(independent_variable[i]), 1]) solution = solve(independent_matrix, dependent_matrix, precision) equation = logarithmic_equation(*solution) derivative = logarithmic_derivative(*solution) integral = logarithmic_integral(*solution)['evaluation'] first_derivative = derivative['first']['evaluation'] second_derivative = derivative['second']['evaluation'] points = key_points('logarithmic', solution, equation, first_derivative, second_derivative, precision) five_numbers = five_number_summary(independent_variable, precision) min_value = five_numbers['minimum'] max_value = five_numbers['maximum'] q1 = five_numbers['q1'] q3 = five_numbers['q3'] accumulated_range = accumulation(integral, min_value, max_value, precision) accumulated_iqr = accumulation(integral, q1, q3, precision) averages_range = average_values('logarithmic', equation, integral, min_value, max_value, solution, precision) averages_iqr = average_values('logarithmic', equation, integral, q1, q3, solution, precision) predicted = [] for i in range(len(data)): predicted.append(equation(independent_variable[i])) accuracy = correlation(dependent_variable, predicted, precision) evaluations = { 'equation': equation, 'derivative': first_derivative, 'integral': integral } points = { 'roots': points['roots'], 'maxima': points['maxima'], 'minima': points['minima'], 'inflections': points['inflections'] } accumulations = { 'range': accumulated_range, 'iqr': accumulated_iqr } averages = { 'range': averages_range, 'iqr': averages_iqr } result = { 'constants': solution, 'evaluations': evaluations, 'points': points, 'accumulations': accumulations, 'averages': averages, 'correlation': accuracy } return result
def sinusoidal(data, precision): independent_variable = dimension(data, 1) dependent_variable = dimension(data, 2) dependent_max = max(dependent_variable) dependent_min = min(dependent_variable) dependent_range = dependent_max - dependent_min solution = [] def sinusoidal_fit(variable, first_constant, second_constant, third_constant, fourth_constant): evaluation = first_constant * sin( second_constant * (variable - third_constant)) + fourth_constant return evaluation parameters, covariance = curve_fit(sinusoidal_fit, independent_variable, dependent_variable, bounds=[(-1 * dependent_range, -inf, -inf, dependent_min), (dependent_range, inf, inf, dependent_max)]) solution = list(parameters) constants = [] for number in solution: constants.append(rounding(number, precision)) equation = sinusoidal_equation(*solution) derivative = sinusoidal_derivative(*solution) integral = sinusoidal_integral(*solution)['evaluation'] first_derivative = derivative['first']['evaluation'] second_derivative = derivative['second']['evaluation'] points = key_points('sinusoidal', solution, equation, first_derivative, second_derivative, precision) five_numbers = five_number_summary(independent_variable, precision) min_value = five_numbers['minimum'] max_value = five_numbers['maximum'] q1 = five_numbers['q1'] q3 = five_numbers['q3'] accumulated_range = accumulation(integral, min_value, max_value, precision) accumulated_iqr = accumulation(integral, q1, q3, precision) averages_range = average_values('sinusoidal', equation, integral, min_value, max_value, solution, precision) averages_iqr = average_values('sinusoidal', equation, integral, q1, q3, solution, precision) predicted = [] for i in range(len(data)): predicted.append(equation(independent_variable[i])) accuracy = correlation(dependent_variable, predicted, precision) evaluations = { 'equation': equation, 'derivative': first_derivative, 'integral': integral } points = { 'roots': points['roots'], 'maxima': points['maxima'], 'minima': points['minima'], 'inflections': points['inflections'] } accumulations = {'range': accumulated_range, 'iqr': accumulated_iqr} averages = {'range': averages_range, 'iqr': averages_iqr} result = { 'constants': constants, 'evaluations': evaluations, 'points': points, 'accumulations': accumulations, 'averages': averages, 'correlation': accuracy } return result
def logistic(data, precision): independent_variable = dimension(data, 1) dependent_variable = dimension(data, 2) halved_data = halve_dimension(data, 1) dependent_lower = dimension(halved_data['lower'], 2) dependent_upper = dimension(halved_data['upper'], 2) mean_lower = mean(dependent_lower) mean_upper = mean(dependent_upper) dependent_max = max(dependent_variable) dependent_min = min(dependent_variable) dependent_range = dependent_max - dependent_min solution = [] def logistic_fit(variable, first_constant, second_constant, third_constant): evaluation = first_constant / (1 + exp(-1 * second_constant * (variable - third_constant))) return evaluation if mean_upper >= mean_lower: parameters, covariance = curve_fit( logistic_fit, independent_variable, dependent_variable, bounds=[(dependent_max - dependent_range, 0, -inf), (dependent_max + dependent_range, inf, inf)]) solution = list(parameters) else: parameters, covariance = curve_fit( logistic_fit, independent_variable, dependent_variable, bounds=[(dependent_max - dependent_range, -inf, -inf), (dependent_max + dependent_range, 0, inf)]) solution = list(parameters) constants = [] for number in solution: constants.append(rounding(number, precision)) equation = logistic_equation(*solution) derivative = logistic_derivative(*solution) integral = logistic_integral(*solution)['evaluation'] first_derivative = derivative['first']['evaluation'] second_derivative = derivative['second']['evaluation'] points = key_points('logistic', solution, equation, first_derivative, second_derivative, precision) five_numbers = five_number_summary(independent_variable, precision) min_value = five_numbers['minimum'] max_value = five_numbers['maximum'] q1 = five_numbers['q1'] q3 = five_numbers['q3'] accumulated_range = accumulation(integral, min_value, max_value, precision) accumulated_iqr = accumulation(integral, q1, q3, precision) averages_range = average_values('logistic', equation, integral, min_value, max_value, solution, precision) averages_iqr = average_values('logistic', equation, integral, q1, q3, solution, precision) predicted = [] for i in range(len(data)): predicted.append(equation(independent_variable[i])) accuracy = correlation(dependent_variable, predicted, precision) evaluations = { 'equation': equation, 'derivative': first_derivative, 'integral': integral } points = { 'roots': points['roots'], 'maxima': points['maxima'], 'minima': points['minima'], 'inflections': points['inflections'] } accumulations = {'range': accumulated_range, 'iqr': accumulated_iqr} averages = {'range': averages_range, 'iqr': averages_iqr} result = { 'constants': constants, 'evaluations': evaluations, 'points': points, 'accumulations': accumulations, 'averages': averages, 'correlation': accuracy } return result