improve f_zero slope error, increase trials for fi_curve_model
This commit is contained in:
parent
2f0c19ea5a
commit
0dfff5768c
@ -321,7 +321,7 @@ class FICurveCellData(FICurve):
|
||||
|
||||
class FICurveModel(FICurve):
|
||||
|
||||
def __init__(self, model, stimulus_values, eod_frequency, trials=1):
|
||||
def __init__(self, model, stimulus_values, eod_frequency, trials=5):
|
||||
self.eod_frequency = eod_frequency
|
||||
self.model = model
|
||||
self.trials = trials
|
||||
|
35
Fitter.py
35
Fitter.py
@ -175,7 +175,9 @@ class Fitter:
|
||||
self.f_inf_slope = 0
|
||||
|
||||
self.f_zero_values = []
|
||||
self.f_zero_slopes = []
|
||||
# self.f_zero_slopes = []
|
||||
self.f_zero_slope_at_straight = 0
|
||||
self.f_zero_straight_contrast = 0
|
||||
self.f_zero_fit = []
|
||||
|
||||
self.tau_a = 0
|
||||
@ -200,7 +202,9 @@ class Fitter:
|
||||
|
||||
self.f_zero_values = fi_curve.f_zero_frequencies
|
||||
self.f_zero_fit = fi_curve.f_zero_fit
|
||||
self.f_zero_slopes = [fi_curve.get_f_zero_fit_slope_at_stimulus_value(c) for c in self.fi_contrasts]
|
||||
# self.f_zero_slopes = [fi_curve.get_f_zero_fit_slope_at_stimulus_value(c) for c in self.fi_contrasts]
|
||||
self.f_zero_slope_at_straight = fi_curve.get_f_zero_fit_slope_at_straight()
|
||||
self.f_zero_straight_contrast = self.f_zero_fit[3]
|
||||
|
||||
# around 1/3 of the value at straight
|
||||
# self.f_zero_slope = fi_curve.get_fi_curve_slope_at(fi_curve.get_f_zero_and_f_inf_intersection())
|
||||
@ -385,15 +389,13 @@ class Fitter:
|
||||
serial_correlation = model_baseline.get_serial_correlation(self.sc_max_lag)
|
||||
coefficient_of_variation = model_baseline.get_coefficient_of_variation()
|
||||
|
||||
# f_infinities, f_infinities_slope = self.base_model.calculate_fi_markers(self.fi_contrasts, self.eod_freq)
|
||||
|
||||
fi_curve_model = get_fi_curve_class(self.base_model, self.fi_contrasts, self.eod_freq)
|
||||
f_zeros = fi_curve_model.get_f_zero_frequencies()
|
||||
f_infinities = fi_curve_model.get_f_inf_frequencies()
|
||||
f_infinities_slope = fi_curve_model.get_f_inf_slope()
|
||||
f_zero_slopes = [fi_curve_model.get_f_zero_fit_slope_at_stimulus_value(x) for x in self.fi_contrasts]
|
||||
# f_zero_slopes = [fi_curve_model.get_f_zero_fit_slope_at_stimulus_value(x) for x in self.fi_contrasts]
|
||||
f_zero_slope_at_straight = fi_curve_model.get_f_zero_fit_slope_at_stimulus_value(self.f_zero_straight_contrast)
|
||||
|
||||
# print("fi-curve features calculated!")
|
||||
# calculate errors with reference values
|
||||
error_bf = abs((baseline_freq - self.baseline_freq) / self.baseline_freq)
|
||||
error_vs = abs((vector_strength - self.vector_strength) / self.vector_strength)
|
||||
@ -404,14 +406,16 @@ class Fitter:
|
||||
error_sc = abs((serial_correlation[i] - self.serial_correlation[i]) / self.serial_correlation[i])
|
||||
error_sc = error_sc / self.sc_max_lag
|
||||
|
||||
error_f_inf_slope = abs((f_infinities_slope - self.f_inf_slope) / self.f_inf_slope)
|
||||
error_f_inf_slope = abs((f_infinities_slope - self.f_inf_slope) / (self.f_inf_slope/20))
|
||||
error_f_inf = calculate_list_error(f_infinities, self.f_inf_values)
|
||||
|
||||
error_f_zero_slopes = calculate_list_error(f_zero_slopes, self.f_zero_slopes)
|
||||
# error_f_zero_slopes = calculate_list_error(f_zero_slopes, self.f_zero_slopes)
|
||||
error_f_zero_slope_at_straight = abs(self.f_zero_slope_at_straight - f_zero_slope_at_straight) \
|
||||
/ (self.f_zero_slope_at_straight / 20)
|
||||
error_f_zero = calculate_list_error(f_zeros, self.f_zero_values)
|
||||
|
||||
error_list = [error_bf, error_vs, error_sc, error_cv,
|
||||
error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slopes]
|
||||
error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope_at_straight]
|
||||
|
||||
if error_weights is not None and len(error_weights) == len(error_list):
|
||||
for i in range(len(error_weights)):
|
||||
@ -437,8 +441,8 @@ class Fitter:
|
||||
self.f_inf_slope, f_infinities_slope, error_f_inf_slope),
|
||||
"f-infinity values:\nexpected:", np.around(self.f_inf_values), "\ncurrent: ", np.around(f_infinities),
|
||||
"\nerror: {:.3f}\n".format(error_f_inf),
|
||||
"f-zero slopes:\nexpected:", np.around(self.f_zero_slopes), "\ncurrent: ", np.around(f_zero_slopes),
|
||||
"\nerror: {:.3f}".format(error_f_zero_slopes),
|
||||
"f-zero slope - expected: {:.0f}, current: {:.0f}, error: {:.3f}\n".format(
|
||||
self.f_zero_slope_at_straight, f_zero_slope_at_straight, error_f_zero_slope_at_straight),
|
||||
"f-zero values:\nexpected:", np.around(self.f_zero_values), "\ncurrent: ", np.around(f_zeros),
|
||||
"\nerror: {:.3f}".format(error_f_zero))
|
||||
return error_list
|
||||
@ -447,16 +451,17 @@ class Fitter:
|
||||
def calculate_list_error(fit, reference):
|
||||
error = 0
|
||||
for i in range(len(reference)):
|
||||
# TODO ??? add a constant to f_inf to allow for small differences in small values
|
||||
# example: 1 vs 3 would result in way smaller error.
|
||||
constant = 10
|
||||
error += abs((fit[i] - reference[i])+constant) / (abs(reference[i]) + constant)
|
||||
error += abs_freq_error(fit[i] - reference[i])
|
||||
|
||||
norm_error = error / len(reference)
|
||||
|
||||
return norm_error
|
||||
|
||||
|
||||
def abs_freq_error(diff, factor=10):
|
||||
return abs(diff) / factor
|
||||
|
||||
|
||||
def create_init_simples(x0, search_scale=3.):
|
||||
dim = len(x0)
|
||||
simplex = [[x0[0]/search_scale], [x0[0]*search_scale]]
|
||||
|
Loading…
Reference in New Issue
Block a user