add ability to fit contrast flipped cells, change error for frequency lists
This commit is contained in:
parent
405424b6eb
commit
89ebeb7fd0
23
Fitter.py
23
Fitter.py
@ -60,10 +60,19 @@ class Fitter:
|
|||||||
self.burstiness = data_baseline.get_burstiness()
|
self.burstiness = data_baseline.get_burstiness()
|
||||||
|
|
||||||
fi_curve = get_fi_curve_class(cell_data, cell_data.get_fi_contrasts(), save_dir=cell_data.get_data_path())
|
fi_curve = get_fi_curve_class(cell_data, cell_data.get_fi_contrasts(), save_dir=cell_data.get_data_path())
|
||||||
|
self.f_inf_slope = fi_curve.get_f_inf_slope()
|
||||||
|
if self.f_inf_slope < 0:
|
||||||
|
contrasts = np.array(cell_data.get_fi_contrasts()) * -1
|
||||||
|
# print("old contrasts:", cell_data.get_fi_contrasts())
|
||||||
|
# print("new contrasts:", contrasts)
|
||||||
|
contrasts = sorted(contrasts)
|
||||||
|
fi_curve = get_fi_curve_class(cell_data, contrasts)
|
||||||
|
|
||||||
self.fi_contrasts = fi_curve.stimulus_values
|
self.fi_contrasts = fi_curve.stimulus_values
|
||||||
self.f_inf_values = fi_curve.f_inf_frequencies
|
self.f_inf_values = fi_curve.f_inf_frequencies
|
||||||
self.f_inf_slope = fi_curve.get_f_inf_slope()
|
self.f_inf_slope = fi_curve.get_f_inf_slope()
|
||||||
|
|
||||||
|
|
||||||
self.f_zero_values = fi_curve.f_zero_frequencies
|
self.f_zero_values = fi_curve.f_zero_frequencies
|
||||||
self.f_zero_fit = fi_curve.f_zero_fit
|
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]
|
||||||
@ -325,12 +334,12 @@ class Fitter:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
error_f_inf_slope = abs((f_infinities_slope - self.f_inf_slope) / (self.f_inf_slope/20))
|
error_f_inf_slope = abs((f_infinities_slope - self.f_inf_slope) / abs(self.f_inf_slope+1/20))
|
||||||
error_f_inf = calculate_list_error(f_infinities, self.f_inf_values)
|
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) \
|
error_f_zero_slope_at_straight = abs(self.f_zero_slope_at_straight - f_zero_slope_at_straight) \
|
||||||
/ (self.f_zero_slope_at_straight / 10)
|
/ abs(self.f_zero_slope_at_straight+1 / 10)
|
||||||
error_f_zero = calculate_list_error(f_zeros, self.f_zero_values)
|
error_f_zero = calculate_list_error(f_zeros, self.f_zero_values)
|
||||||
|
|
||||||
error_list = [error_bf, error_vs, error_sc, error_cv, error_bursty,
|
error_list = [error_bf, error_vs, error_sc, error_cv, error_bursty,
|
||||||
@ -341,6 +350,8 @@ class Fitter:
|
|||||||
error_list[i] = error_list[i] * error_weights[i]
|
error_list[i] = error_list[i] * error_weights[i]
|
||||||
elif error_weights is not None:
|
elif error_weights is not None:
|
||||||
warn("Error: weights had different length than errors and were ignored!")
|
warn("Error: weights had different length than errors and were ignored!")
|
||||||
|
if sum(error_list) < 0:
|
||||||
|
print("Error negative: ", error_list)
|
||||||
if np.isnan(sum(error_list)):
|
if np.isnan(sum(error_list)):
|
||||||
print("--------SOME ERROR VALUE(S) IS/ARE NaN:")
|
print("--------SOME ERROR VALUE(S) IS/ARE NaN:")
|
||||||
print(error_list)
|
print(error_list)
|
||||||
@ -352,13 +363,17 @@ class Fitter:
|
|||||||
def calculate_list_error(fit, reference):
|
def calculate_list_error(fit, reference):
|
||||||
error = 0
|
error = 0
|
||||||
for i in range(len(reference)):
|
for i in range(len(reference)):
|
||||||
error += abs_freq_error(fit[i] - reference[i])
|
# error += abs_freq_error(fit[i] - reference[i])
|
||||||
|
error += normed_quadratic_freq_error(fit[i], reference[i])
|
||||||
norm_error = error / len(reference)
|
norm_error = error / len(reference)
|
||||||
|
|
||||||
return norm_error
|
return norm_error
|
||||||
|
|
||||||
|
|
||||||
|
def normed_quadratic_freq_error(fit, ref, factor=2):
|
||||||
|
return (abs(fit-ref)/factor)**2 / ref
|
||||||
|
|
||||||
|
|
||||||
def abs_freq_error(diff, factor=10):
|
def abs_freq_error(diff, factor=10):
|
||||||
return abs(diff) / factor
|
return abs(diff) / factor
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user