function [alpha, beta, gamma, P, R, F] = evaluateNoveltyCurve(X, wavfile, parameter)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Absract evaluation of novelty curves
% Desired properties for onset detection:
%   - large peaks at onset positions
%   - low values at all other positions
%
%   . alpha : mean onset peak values -> the higher the better
%   . beta  : mean of the overall curve -> the lower the better
%   . gamma : alpha/beta    -> the higher the better
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    
try
    a = load([parameter.DirAnnotation wavfile(1:end-4) '__OnsetsAnnotated.mat']);
    parameter.markers = a.f_peaks{1}./1000;
catch me
    parameter.markers = [];
end

onsets = parameter.markers;
parameter.toleranceWindow = 0.050; % sec

% compute novelty curve


 % diff
    d = [X(:,1) diff(X,[],2)];

    % hwr
    d(d<0) = 0;

    % accumulate
    novelty = sum(d);
    
    
if parameter.visualize
    visualize_noveltyCurve(novelty,parameter);
end

   
    





% evaluate novelty curve

featureRate = parameter.featureRate;
tol = (parameter.toleranceWindow.*featureRate);
mean_idx = true(size(novelty));

alpha = 0;
for idx = 1:length(onsets)
    
    t = onsets(idx).*featureRate+1;
    t_l = max(1,round(t-tol));
    t_r = min(length(novelty),round(t+tol));
    
    mean_idx(t_l:t_r) = false;
    
    alpha = alpha + max(novelty(t_l:t_r));
    
end


alpha = alpha ./length(onsets);

beta = mean(novelty(mean_idx));

gamma = alpha./beta;

%%%%%

% P, R, F

output = peaks2(novelty);
output = (output-1)./featureRate;

[P,R,F] = evaluateMIREXOnset(output,onsets,false(size(onsets)),parameter);


%%%%%


%fprintf('alpha: %1.3f \t beta: %1.3f \t gamma: %1.3f',alpha, beta, gamma);
fprintf('%-50s P: %1.3f \t R: %1.3f \t F: %1.3f\n',wavfile(1:min(length(wavfile),50)),P, R, F);