Approximate entropy (ApEn) is a technique used to quantify the amount of regularity and the unpredictability of fluctuations over time-series data (wikipedia and Pincus, S. M. (1991). "Approximate entropy as a measure of system complexity". PNAS 88 (6): 2297–2301). I have coded the algorithm but in some cases it gives me negative values which I think makes no sense at all. Am I wrong?