Initialize logistic growth. Provides a strong initialization for logistic growth by calculating the growth and offset parameters that pass the function through the first and last points in the time series. Parameters ---------- df: pd.DataFrame with
(df)
| 1057 | |
| 1058 | @staticmethod |
| 1059 | def logistic_growth_init(df): |
| 1060 | """Initialize logistic growth. |
| 1061 | |
| 1062 | Provides a strong initialization for logistic growth by calculating the |
| 1063 | growth and offset parameters that pass the function through the first |
| 1064 | and last points in the time series. |
| 1065 | |
| 1066 | Parameters |
| 1067 | ---------- |
| 1068 | df: pd.DataFrame with columns ds (date), cap_scaled (scaled capacity), |
| 1069 | y_scaled (scaled time series), and t (scaled time). |
| 1070 | |
| 1071 | Returns |
| 1072 | ------- |
| 1073 | A tuple (k, m) with the rate (k) and offset (m) of the logistic growth |
| 1074 | function. |
| 1075 | """ |
| 1076 | i0, i1 = df['ds'].idxmin(), df['ds'].idxmax() |
| 1077 | T = df['t'].iloc[i1] - df['t'].iloc[i0] |
| 1078 | |
| 1079 | # Force valid values, in case y > cap or y < 0 |
| 1080 | C0 = df['cap_scaled'].iloc[i0] |
| 1081 | C1 = df['cap_scaled'].iloc[i1] |
| 1082 | y0 = max(0.01 * C0, min(0.99 * C0, df['y_scaled'].iloc[i0])) |
| 1083 | y1 = max(0.01 * C1, min(0.99 * C1, df['y_scaled'].iloc[i1])) |
| 1084 | |
| 1085 | r0 = C0 / y0 |
| 1086 | r1 = C1 / y1 |
| 1087 | |
| 1088 | if abs(r0 - r1) <= 0.01: |
| 1089 | r0 = 1.05 * r0 |
| 1090 | |
| 1091 | L0 = np.log(r0 - 1) |
| 1092 | L1 = np.log(r1 - 1) |
| 1093 | |
| 1094 | # Initialize the offset |
| 1095 | m = L0 * T / (L0 - L1) |
| 1096 | # And the rate |
| 1097 | k = (L0 - L1) / T |
| 1098 | return (k, m) |
| 1099 | |
| 1100 | @staticmethod |
| 1101 | def flat_growth_init(df): |
no outgoing calls