save and plot all error values that occured during fitting, delete unused fit routines
This commit is contained in:
parent
302aee34d6
commit
ab8948ec41
52
Fitter.py
52
Fitter.py
@ -9,6 +9,7 @@ import numpy as np
|
||||
from warnings import warn
|
||||
from scipy.optimize import minimize
|
||||
import time
|
||||
from helperFunctions import plot_errors
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@ -53,6 +54,7 @@ class Fitter:
|
||||
self.f_zero_curve_freq = np.array([])
|
||||
self.f_zero_curve_time = np.array([])
|
||||
|
||||
self.errors = []
|
||||
|
||||
# self.tau_a = 0
|
||||
|
||||
@ -125,51 +127,9 @@ class Fitter:
|
||||
error_weights = (0, 2, 2, 2, 1, 1, 1, 1, 0, 1)
|
||||
fmin = minimize(fun=self.cost_function_all,
|
||||
args=(error_weights,), x0=x0, method="Nelder-Mead",
|
||||
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 600, "maxiter": 1200})
|
||||
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 600, "maxiter": 400})
|
||||
|
||||
return fmin, self.base_model.get_parameters()
|
||||
|
||||
def fit_routine_const_ref_period(self, start_parameters):
|
||||
self.counter = 0
|
||||
# fit only v_offset, mem_tau, input_scaling, dend_tau
|
||||
|
||||
x0 = np.array([start_parameters["mem_tau"], start_parameters["noise_strength"],
|
||||
start_parameters["input_scaling"], self.tau_a, start_parameters["delta_a"],
|
||||
start_parameters["dend_tau"], start_parameters["refractory_period"]])
|
||||
initial_simplex = create_init_simples(x0, search_scale=2)
|
||||
self.base_model.set_variable("refractory_period", start_parameters["refractory_period"])
|
||||
# error_list = [error_bf, error_vs, error_sc, error_cv,
|
||||
# error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
|
||||
error_weights = (0, 1, 1, 1, 1, 1, 1, 1, 1)
|
||||
fmin = minimize(fun=self.cost_function_without_ref_period,
|
||||
args=(error_weights,), x0=x0, method="Nelder-Mead",
|
||||
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 200, "maxiter": 400})
|
||||
|
||||
return fmin, self.base_model.get_parameters()
|
||||
|
||||
# similar results to fit routine 1
|
||||
def fit_routine_2(self, start_parameters):
|
||||
self.counter = 0
|
||||
|
||||
x0 = np.array([start_parameters["mem_tau"], start_parameters["input_scaling"], # mem_tau, input_scaling
|
||||
start_parameters["delta_a"], start_parameters["dend_tau"]]) # delta_a, dend_tau
|
||||
initial_simplex = create_init_simples(x0, search_scale=2)
|
||||
|
||||
error_weights = (0, 1, 1, 1, 1, 3, 2, 3, 2)
|
||||
fmin = minimize(fun=self.cost_function_only_adaption,
|
||||
args=(error_weights,), x0=x0, method="Nelder-Mead",
|
||||
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 100, "maxiter": 400})
|
||||
best_pars = fmin.x
|
||||
x0 = np.array([best_pars[0], start_parameters["noise_strength"],
|
||||
best_pars[1], self.tau_a, best_pars[2],
|
||||
best_pars[3]])
|
||||
initial_simplex = create_init_simples(x0, search_scale=2)
|
||||
# error_list = [error_bf, error_vs, error_sc, error_cv,
|
||||
# error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
|
||||
error_weights = (0, 2, 2, 2, 2, 1, 1, 1, 1)
|
||||
fmin = minimize(fun=self.cost_function_all,
|
||||
args=(error_weights,), x0=x0, method="Nelder-Mead",
|
||||
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 100, "maxiter": 400})
|
||||
plot_errors(self.errors)
|
||||
|
||||
return fmin, self.base_model.get_parameters()
|
||||
|
||||
@ -204,11 +164,11 @@ class Fitter:
|
||||
|
||||
# [error_bf, error_vs, error_sc, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
|
||||
error_list = self.calculate_errors(error_weights)
|
||||
print("sum: {:.2f}, ".format(sum(error_list)))
|
||||
# print("sum: {:.2f}, ".format(sum(error_list)))
|
||||
if sum(error_list) < self.smallest_error:
|
||||
self.smallest_error = sum(error_list)
|
||||
self.best_parameters_found = X
|
||||
|
||||
self.errors.append(error_list)
|
||||
return sum(error_list)
|
||||
|
||||
def cost_function_without_ref_period(self, X, error_weights=None):
|
||||
|
Loading…
Reference in New Issue
Block a user