iamlikeme / rainflow

Implementation of the rainflow-counting algorythm in Python
MIT License
105 stars 34 forks source link

inconsistent behavior between small and large values? #55

Closed SaetreS closed 3 years ago

SaetreS commented 3 years ago

Hi, perhaps there's something I don't quite understand, but when I'm taking the unit test and multiplying the series with a high value the RFC algorithm gives back very different counting results.

The unittest is as follows:

series = np.array([-2, 1, -3, 5, -1, 3, -4, 4, -2])
print(count_cycles(series, ndigits=None, nbins=None, binsize=None))

output: [(3, 0.5), (4, 1.5), (6, 0.5), (8, 1.0), (9, 0.5)]

by modifying the unittest slightly the number of cycles changes:

series = np.array([-2, 1, -3, 5, -1, 3, -4, 4, -2])
series *= 100000
print(count_cycles(series, ndigits=None, nbins=None, binsize=None))

output: [(200000, 0.5), (500000, 0.5), (700000, 0.5)]

thoughts?

edit: I figured it out. the above code uses int32 which results in horrible calculation errors in the reversal function. by making sure the values are float before counting produces expected results.

For reference if anyone else is reading this down the road. the following produce expected results:

series = np.array([-2.0, 1.0, -3.0, 5.0, -1.0, 3.0, -4.0, 4.0, -2.0])
series *= 100000
print(count_cycles(series, ndigits=None, nbins=None, binsize=None))

output: [(300000.0, 0.5), (400000.0, 1.5), (600000.0, 0.5), (800000.0, 1.0), (900000.0, 0.5)]