
Menstrual Cycle Tracking Is Pattern Recognition With Biological Noise
The average menstrual cycle is 28 days. But averages hide enormous variation. Normal cycles range from 21 to 35 days and individual cycle length varies by several days from month to month. Prediction accuracy depends on capturing this variability. The prediction model The simplest prediction method uses a rolling average of recent cycle lengths: function predictNextPeriod ( cycleDates ) { // cycleDates: array of period start dates, most recent last if ( cycleDates . length < 2 ) return null ; const cycleLengths = []; for ( let i = 1 ; i < cycleDates . length ; i ++ ) { const diff = ( cycleDates [ i ] - cycleDates [ i - 1 ]) / ( 1000 * 60 * 60 * 24 ); cycleLengths . push ( diff ); } const avgLength = cycleLengths . reduce (( a , b ) => a + b ) / cycleLengths . length ; const lastPeriod = cycleDates [ cycleDates . length - 1 ]; const nextPeriod = new Date ( lastPeriod ); nextPeriod . setDate ( nextPeriod . getDate () + Math . round ( avgLength )); const stdDev = Math . sqrt ( cycleLength
Continue reading on Dev.to Beginners
Opens in a new tab




