La Paste
Create new paste
Pastes Archive
2023-02-18 13:29:50
copy
raw
download
function forecastHoltWinters($data) { $alpha = 0.2; $beta = 0.1; $forecast_length = 1; $data_length = count($data); $level = $data[0]; $trend = ($data[1] - $data[0]) / 2; for ($i = 2; $i < $data_length; $i++) { $last_level = $level; $last_trend = $trend; $level = $alpha * $data[$i] + (1 - $alpha) * ($last_level + $last_trend); $trend = $beta * ($level - $last_level) + (1 - $beta) * $last_trend; } $last_level = $level; $last_trend = $trend; for ($i = 0; $i < $forecast_length; $i++) { $forecast = $last_level + $last_trend * ($i + 1); } return ($forecast); }
↑