function glu_in_cleft_over_time=synaptic_dynamics_model_optimizer%(real data input for comparison)

% seed values for the parameters of the coupled differential equation-based model of a single synapse are set by the user
% these values are used by that model to generate PSCs following APs from a train (the multiple values for the first IPI are handled sequentially...,
% there being no interaction between sweeps)
% because of the stochastic components of that model, larger numbers of iterations are run at a given set of seed values and mean/SD PSCs are taken
% all possible trains are run at the given set of parameters
% these mean simulated PSCs are compared to recorded PSCs from a microperfusion experiment (e.g. using least squares) and new values for the parameters are chosen -- simplex style
%the essential approach is to combine modeling with statistical methods of analyzing data to get the most accurate model
%the top handful of solutions should be saved, not just the best solution
%the reason for this is during comparison of before and after STDP, we want to see what single value can be changed to best capture the new curves -- so we may need to try a few start points

hy=[25 50 100 200 400]
iterations_for_montecarlo=10;

%seed_values -- all of these represent means around which variation occurs at the beginning of each trial
membrane_potential_due_to_AP=40;      %in mV (this will have a fixed decay)
cytosolic_calcium_conc=.005;       %in the presynaptic cytoplasm, in mM
number_ca_channels=5;     %in numbers
ca_channel_conductance=10; %in picosiemens
ca_channel_close_tau=5;     %in ms
cytosolic_calcium_decay_tau=0.97;%the tau governing decay of [Ca++] in the terminal, in ms
RRP_size=4;              %in vesicles
RP_to_RRP_tau=.003;     %the tau of RRP refill from RP, in ms
RP_size=100;             %in vesicles
PEP_size=0;              %in vesicles (the post-exocytotic pool)
PEP_to_RP_tau=.005;     %the tau of RP refill from PEP, in ms
PEP_to_RRP_tau=0;       %the tau of RRP refill from PEP, in ms %RP to RRP and PE to RRP sum to the RRP refilling rate
glu_per_vesicle=3;       %in effective pA(?)
glutamate_cleft_tau=.8;  %the tau of [glutamate] decay in the cleft, in ms
cleft_glutamate_conc=0;  %in mM

% exocytosis_unlikelihood=10;  %this is multiplied by a random number -- if the result is greater than [Ca]bouton, release is impossible

%For now, this is a STRICTLY PRESYNAPTIC model 
% number_of_ampars=3000;
% ampar_bound=zeros(1,number_of_ampars);  %at the beginning, none is bound
% ampar_open=ampar_bound;                 %therefore none is open
% ampar_conductance=ampar_bound;          %therefore there is no conductance
% initial_ampar_conductance=.1;   %in pA/time step
% ampar_open_threshold=.7;    %used for determining whether a bound, closed ampar moves to the bound, open state
% ampar_unbind_threshold=.3;  %used for determining whether a bound, closed ampar moves to the unbound, closed state
% ampar_close_threshold=.1;   %used for determining whether a bound,open ampar moves to the bound, closed state
% ampar_binding_unlikelihood=20; %larger values make it less likely that an unbound receptor will bind glutamate at a given [glu]cleft
% ampar_conductance_persistence=.9;
% synaptic_conductance=0;

%the simplex process below is repeated over and over to converge on the right values

seed_values=[membrane_potential_due_to_AP, cytosolic_calcium_conc, number_ca_channels, ca_channel_conductance, ca_channel_close_tau, cytosolic_calcium_decay_tau, RRP_size, ...
        RP_to_RRP_tau, RP_size,PEP_size, PEP_to_RP_tau, PEP_to_RRP_tau, glu_per_vesicle, glutamate_cleft_tau, cleft_glutamate_conc];

% z=size(seed_values)
% error('z')

glu_in_cleft_over_time={};
for i=1:1%length(hy)
    times_over_which_to_solve=[hy(i) 50 200];   %in ms
    s_c=single_syn_stsd_for_montecarlo(seed_values,times_over_which_to_solve,iterations_for_montecarlo);
    glu_in_cleft_over_time{i}=s_c;
end

% average the response curves and compare to the predicted value
% %hard part
% take the differences between recorded and predicted and generate new seed values, then go around again
% %even once the simplex is figured out -- how doe simplex approaches behave with stochastic systems?