function smoothed_probs = smooth_bin_probabilities(bin_probs, window_size, sigma)
    if mod(window_size, 2) == 0
        error('Window size must be odd.');
    end

    % Gaussian kernel
    half_width = (window_size - 1) / 2;
    x = -half_width:half_width;
    gauss_kernel = exp(-0.5 * (x / sigma).^2);
    gauss_kernel = gauss_kernel / sum(gauss_kernel);  % Normalize

    % Smooth via convolution
    smoothed_probs = conv(bin_probs, gauss_kernel, 'same');

    % Ensure valid probability vector
    smoothed_probs = max(smoothed_probs, 0);  % Clip negatives
    smoothed_probs = smoothed_probs / sum(smoothed_probs);  % Normalize to sum to 1
end