%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%           M. Oh, S. Zhao, V. Matveev and F. Nadim (2012)
%    Neuromodulatory changes in short-term synaptic dynamics may be 
%   mediated by two distinct mechanisms of presynaptic calcium entry
%            Journal of Computational Neuroscience. 
%
% Lowest-level fitness: short-term plasticity and voltage time course
%                     Victor Matveev, 2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [cost, factors] = costBalancedInfo( Dev, Vend, Vmax )
    
  D1 = Vmax(2,10) / Vmax(2,2);
  D2 = Vmax(4,10) / Vmax(4,2);
  F  = Vmax(3,10) / Vmax(3,2);
  
  interP =  Vend(1:4,9) ./ Vmax(1:4,8); 
  Tail   =  Vmax(2:4,3) ./ Vmax(2:4,2);
  Tiny   = -log( Vmax(2:4,2) );
      
  Dcontrol = (D1 > 0.85) * (D1 - 0.85) * 100;
  Dproc    = (D2 > 0.85) * (D2 - 0.85) * 100;
  Fproc    = (F  < 2.00) * (2.00 - F ) * 15;
  
  interpulseRatio = (interP > 0.1)' * (interP - 0.1) * 0.5; 
  tailCurrent     = (Tail > 1)' * (Tail - 1) * 1.5; % changed from 2
  tinyFloat       = (Tiny > 8)' * (Tiny - 8);

  totalDev        = [7 1 3 1] * Dev * 0.5; 
  % 200 points instead of 100 (see getData.m) - multiply Dev by 0.5
  
  factors = [totalDev Dcontrol Dproc Fproc interpulseRatio tailCurrent tinyFloat];
  cost    = sum(factors);
            
end

