%% License Info
%A Model of Feedforward, Global, and Lateral Inhibition in the Locust Visual System.

%This model examines the architecture and function of inhibitory mechanisms in the 
%visual system of locusts, namely those involved in the processing of inputs to a
%key looming-sensitive neuron, the lobula giant movement detector (LGMD).

%Copyright (c) 2026, Erik Olson, Travis Wiens, and Jack Gray

%CITATION:
%When using the model code for scientific publications, cite the following work:
%Olson EGN, Wiens TK, Gray JR. A model of feedforward, global, and lateral inhibition 
%in the locust visual system predicts responses to looming stimuli. Biol Cybern. 2021 
%Jun;115(3):245-265. doi: 10.1007/s00422-021-00876-8. Epub 2021 May 16. PMID: 33997912.

%This program is free software: you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or
%(at your option) any later version.

%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%GNU General Public License for more details.

%You should have received a copy of the GNU General Public License
%along with this program.  If not, see <https://www.gnu.org/licenses/>.

%Contact: erik.olson@usask.ca

%% Code

%Demonstration of the C, showing firing
%rate of the FFI neurons in the dorsal uncrossed bundle for looming stimuli
%with multiple l/v and offsets from the eye centerlines. Multiple inhibition 
%schemes such as the removal of global and lateral inhibition are also
%tested.  This file generates and saves the necessary data for Figures 8, 9
%and 10.

%Access the parameters for the model
parFile = 'FFIModelParams_16_02_2021.mat';

%Set any potential modifications to inhibition to be ignored for now (by
%setting them to NaN).  Otherwise, the first value would override the
%existing lateral inhibitory gain value, and the second would override the
%global inhibitory gain value.
inhibition_mod = [NaN,NaN];

%Create a parallel pool using all possible cores (delete this if the
%Parallel Computing Toolbox is not present)
delete(gcp('nocreate'));
parpool(feature('numcores'));

%For an explanation of outputs from FFITrialFunction, see the description
%in its code file.

%1st run: l/v = 20 ms
l_over_v = 0.02;
[f_output,f_all,theta,raw,t_raw,V_trace] = FFITrialFunction(parFile,20,l_over_v,inhibition_mod);
save('FFI_l_over_v_20ms_Data.mat','l_over_v','f_output','f_all','theta','raw','t_raw','V_trace');

%2nd run: l/v = 40 ms
l_over_v = 0.04;
[f_output,f_all,theta,raw,t_raw,V_trace] = FFITrialFunction(parFile,20,l_over_v,inhibition_mod);
save('FFI_l_over_v_40ms_Data.mat','l_over_v','f_output','f_all','theta','raw','t_raw','V_trace');
 
%3rd run: l/v = 80 ms
l_over_v = 0.08;
[f_output,f_all,theta,raw,t_raw,V_trace] = FFITrialFunction(parFile,20,l_over_v,inhibition_mod);
save('FFI_l_over_v_80ms_Data.mat','l_over_v','f_output','f_all','theta','raw','t_raw','V_trace');

%4th run: l/v = 20 ms, no global inhibition
l_over_v = 0.02;
inhibition_mod = [NaN,0]; %set global inhibition to zero
[f_output,f_all,theta,raw,t_raw,V_trace] = FFITrialFunction(parFile,20,l_over_v,inhibition_mod);
save('FFI_l_over_v_20ms_no_global_Data.mat','l_over_v','f_output','f_all','theta','raw','t_raw','V_trace');

%5th run: l/v = 20 ms, no lateral inhibition
l_over_v = 0.02;
inhibition_mod = [0,NaN]; %set lateral inhibition to zero
[f_output,f_all,theta,raw,t_raw,V_trace] = FFITrialFunction(parFile,20,l_over_v,inhibition_mod);
save('FFI_l_over_v_20ms_no_lateral_Data.mat','l_over_v','f_output','f_all','theta','raw','t_raw','V_trace');