generate_stimulus_sequence

for t = 1:stim_time

  tprev = max(1, t-1);

  Scs(t,:) = rand(1,numCS) < CS(t,:);
  Pcs(t,:) = (rand(1,numCS) < V(tprev,:)) .* Scs(t,:);
  Tcs(t,:) = max(Scs(t,:),(1-theta)*Tcs(tprev,:));
  Phics(t,:) = Tcs(t,:) .* (1-Tcs(t,:));

  if (any(Pcs(t,:)==1) | US(t) == 1) & rand(1) < (1-Rfi(tprev))
    Afi(t) = Afi(tprev) + delta1 * (1 - Afi(tprev));
    Sfi(t) = 1;
  else
    Afi(t) = Afi(tprev) - delta2 * Afi(tprev);
  end
  
  if Afi(t) > Rthresh
    Rfi(t) = 1;
  else
    Rfi(t) = (1-Rtheta) * Rfi(tprev);
  end

  if any(Pcs(t,:)==1) | Sfi(t)==1 | US(t) == 1
    Amn(t) = Amn(tprev) + delta1 * (1 - Amn(tprev));
  else
    Amn(t) = Amn(tprev) - delta2 * Amn(tprev);
  end

  if get(hnegacc,'Value') == 0
    % regular learning rule
    V(t,:) = V(tprev,:) + ...
	(rand(1,numCS)<Phics(t,:)) .* beta1 .* V(tprev,:) * Afi(t) + ...
	Pcs(t,:) .* -beta2 .* V(tprev,:);
  else
    % negatively accelerated learning rule
    V(t,:) = V(tprev,:) + ...
	(rand(1,numCS)<Phics(t,:)) .* beta1 .* V(tprev,:) .* (1-V(tprev,:)) * Afi(t) + ...
	Pcs(t,:) .* -beta2 .* V(tprev,:);
  end
end
