Structural Time Series Model using Hamiltonian Monte Carlo for Rice Price

– Although forecasts of future events are simply uncertain, predicting is one of the most important aspects of future planning. Accurate rice price predictions tend to be helpful for wholesalers, producers, and farmers to develop plans and strategies to reduce the risks that can be faced. Structural time series models are the most plausible alternative for long-term forecasting. This paper proposes an alternate method for modeling average rice prices using structural time series along with Bayesian parameter inference via Hamiltonian Monte Carlo (HMC). The model has been built using the monthly average wholesale rice price from January 2010 to December 2019. For working out both structural time series and HMC, the TensorFlow Probability Library was used. Linear trend, seasonal, and autoregressive components were combined as an additive model to the structural time model. The proposed Hamiltonian parameter produces an optimal acceptance rate. Their trace plot was used to diagnose the convergence of their chain. One of the predictive accuracy of models was assessed using the mean absolute percent error (MAPE). Through both single and multiple chain iterations, the prediction accuracy of a year-ahead is highly accurate, with MAPE less than 2%. Long-term iteration draws during Hamiltonian Monte Carlo should be considered when attempting to achieve more convergence.


I. INTRODUCTION
Indonesia is the greatest rice-consuming nation in Southeast Asia because of its culture, which views rice as a necessary daily staple (Aryani, 2021) market operation cannot influence consumer rice prices at the national level because this policy is incidental.The rice import variable will have an effect on reducing consumer rice prices at lag 6, meaning that the decline in rice prices will be seen in the next six months.Mapping based on Tinbergen framework, exsogenous variables consist of: policy instruments (Rice HPP, Market Operation, Rice Import.Among the main products that trigger inflation is rice.Essentially, the rice price is determined by various levels of supply and demand at any given moment.Rice prices often experience rapid fluctuations.The government conducts various rice price stability plans to ensure that rice prices benefit farmers and consumers.Although forecasts of future events are simply uncertain, predicting is one of main components of future planning.Predicting rice prices could help the government keep rice prices affordable for consumers and establish policies that enhance the lives of all people.Accurate prediction may be utilized by wholesalers, producers, and farmers to produce plans and strategies for selling rice supplies to reduce the threats that will be addressed. Studies on predicting rice prices have been widely conducted.The classical autoregressive integrated moving average (ARIMA) model has been conducted to predict rice price, and it is suitable to predict medium-quality rice price (Ohyver & Pudjihastuti, 2018).The ARIMA model was also found to be the most appropriate model to forecast rice prices on the farmer level, wholesale level, and international level (Anandyani et al., 2021;Fajari et al., 2021;Ramadhani et al., 2020) almost all Indonesians consume rice derived from rice.Therefore, it is very important to pay attention to the increase and decrease in the price of rice every month so that the price of rice can be maintained stable and does not burden the community.
This study aims to find the best forecasting model for the average rice price at the Indonesian wholesale or wholesale trade level for July 2020 to June 2021 using the SARIMA (Seasonal Autoregressive Integrated Moving Average.Other forecasting techniques have also been applied, such as Holt's double exponential smoothing and Cheng's fuzzy time series method (Sulpaiyah et al., 2022).The application of the backpropagation method for rice price prediction also works well (Nafi'iyah & Khudori, 2022;Natasya et al., 2021).A study using the least squares method gave small error (Shidiq et al., 2022).Past studies relied on shortterm methods resulting the forecasting should be applied regularly.According to Ohyver and Pudjihastuti (2018), we should develop a reliable forecasting approach.The prediction using the recurrent neural network long short term memory (RNN-LSTM) shows that this method can be used to predict the price of rice at the wholesale level quite well (Sanjaya & Heksaputra, 2020).However, they recommend forecasting with other long-term approaches and compare them with theirs.
The structural time series models are family of probability models for time series that includes and generalizes many standard time-series modeling ideas, including autoregressive processes, moving averages, local linear trends, seasonality, regression, and other time series potentially related to the series of interest.Structural time series models have been referred to as Bayesian structural time series (BSTS).Both classic ARIMA and BSTS are equally effective for short-term forecasting, while BSTS with local levels is the most plausible alternative for longterm forecasting (Almarashi & Khan, 2020) the same approach can be applied to complex engineering process involving lead times.Results from the current study were compared with classical Autoregressive Integrated\n Moving Average (ARIMA.The BSTS model in terms of oil price can predict prices with significant precision which challenges forecasting using classic statistical approaches.Predicting prices is more complex and difficult to model since price movements are non-linear, unstable, and extremely volatile.BSTS have proven to be exceptionally successful at forecasting nonlinear and complex time series (AL-Moders & Kadhim, 2021).The BSTS models, in brief, are stochastic state-space models that can separately explore the trend, seasonality, and regression components (Feroze, 2020).
As an alternative approach, this study proposed modeling structural time series to predict wholesale rice prices using Hamiltonian Monte Carlo as Bayesian parameter inference.Hamiltonian Monte Carlo (HMC) is a Markov chain Monte Carlo (MCMC) method that uses the derivatives of the density function being sampled to generate efficient transitions spanning the posterior.MCMC methods are regarded as the standard of Bayesian inference, given appropriate conditions and with an infinite number of draws, they yield samples from the real posterior distribution.HMC proposes samples using gradients of the model's log-density function, allowing it to utilize posterior geometry.It performs the Metropolis acceptance step after running an approximation Hamiltonian dynamics simulation based on numerical integration.The advantage of this approach is that this ratio may be close to 100%, far higher than the typical optimal acceptance ratios for other MCMC algorithms, which are typically between 20% and 60% (Kramer et al., 2014).

II. METHODS
We gathered the data from Central Bureau of Statistics Indonesia publications.Data in the form of the monthly average rice price, i.e., the wholesale price of rice per kilogram (in rupiah units).The study requires no ethical approval, considering we used prior information.Nowcasting was described as forecasting the next year (to 2020/12) using a time series from 2010/01 to 2019/12.Nowcasting mistakes were interpreted as variations in measured and nowcast data.This study following proposed research steps as displayed in Figure 1.Initially, time-series data were decomposed using naive decomposition.Decomposition methods were favored as additive models.The decomposition findings are generated by first predicting the trend in the data using a convolution filter.The trend is then removed from the series, and the average of this de-trended series for each period is the returning seasonal component.
The Bayesian technique creates analytical models based on prior experience and data (likelihood function).The prior distribution can include expert opinion, and the likelihood function takes into relevant patent data about current patterns.The prior information is paired with the likelihood function to update the information, resulting in the posterior distribution, a final Bayesian model.The analytical computation of the Bayesian posterior distribution, on the other hand, is highly complex.As a result, the numerical computations are performed using Markov Chain Monte Carlo (MCMC).
The posterior predictive density is a joint distribution over all data points, and the posterior distribution of the model parameters are estimated using Hamiltonian Monte Carlo (HMC) with a sample draw of 1000.For more details about HMC, see explanation by Neal (2011), Betancourt (2017) and Cordeiro et al. (2022).It is computationally demanding and relatively tunable.Given samples from the posterior over parameters for the number of steps to anticipate timesteps, a predictive distribution over future observations are generated.Accuracy measures Mean Absolute Error (MAE), Root Mean Squared Error (RMSE), Mean Absolute Percent Error (MAPE) used as an indicator of the forecast accuracy.Tables and graphs are used to display the results.We put the structural time-series into action using TensorFlow Probability library for forecasting time series.

III. RESULTS AND DISCUSSION
There are three components in this time-series data decomposition: trend, seasonality, and noise.These components combine to form an observation.The observed rice price data in 1 obviously shows that it increased over a period.However, it is hard to detect repeated behavior patterns every year.It should be clear upon inspection that this series contains both a long-term trend and monthly seasonal variation.
The trend plot shows that the rice price has increased.The overall trend or the local linear trend model component in Figure 2 posits a level and slope, each evolving via a Gaussian random walk.The seasonal plot shows that rice prices go down at the beginning of each year and reach their peak towards the end.We could see that rice prices have seasonal patterns.A seasonal effect model component posits a fixed set of recurring events, each of which is active for a fixed number of timesteps and, while active, contributes a different effect to the time series.The result represents regular, recurring monthly patterns.The third component is residual noise.It shows random and irregular data points that cannot be attributed to either trends or seasonality.The residuals show a period of high variability in the early period between 2011 and 2012.A noisy linear combination at each timestep is constructed as an autoregressive (AR) model component.All the time series components are composed as an additive model.This model inherits the parameters (with priors) of its components and adds an observation noise scale parameter governing the level of noise in the rice price time series.Parameter inference for this structural time series model starts with a special initial set of parameters.The Hamiltonian function is simply the negative log joint distribution of the rice price time series model and is used to calculate Hamiltonian trajectories according to the differential equations as defined in Kramer et al. (2014).For a given number of iterations with a single chain, a new momentum vector is sampled, and the current value of the parameter is updated using the leapfrog integrator with discretization time and the number of leapfrog steps according to the Hamiltonian dynamics.The Hamiltonian dynamics proposed a new pair of parameters, as stored in Table I.It takes total CPU-times 2409 seconds and wall time 1545 seconds using Colab's notebook runtime environment.We need to make sure that the HMC sampler explores the parameter space efficiently, i.e., doesn't reject or accept too many proposals.Because of the heavier computation in computing the proposal, the optimal acceptance rate for HMC is higher, an acceptance rate of approximately 0.8 is in general a good target (Gentle, 2009).The final state for parameter inference of the rice price structural time series has an acceptance rate of 0.961, a high acceptance probability.In other words, based on its acceptance rate, the set of proposed parameters is balanced and convergences to the desired distribution.
To diagnose the convergence of its chain, we should look at the trace plot in Figure 3.The graph for the observation noise scale, seasonal drift scale, and autoregressive coefficient parameter demonstrates good mixing behavior since it well explores the region with the highest density (bounded by the blue dotted line) and bounces from one point to another.It gradually converges to a steady distribution (the posterior).The linear trend parameter reveals slow mixing.It is requiring many more iterations to converge.On a linear trend, the level scale parameter tends to stay at one point for quite time, and it takes certain iterations to move to that point.Although the slope scale moves to a new location in each iteration, the jump is rather tiny, so it takes time to travel from one end of the distribution to the other.Multiple chains may aid in the diagnosis of convergence issues and allow us to generate samples using vectorization.The posterior mean from the multiple chain of HMC demonstration are presented on Table II.It takes total CPU-times 2801 seconds and wall time 1740 seconds using Colab's notebook runtime environment.Their mean proposed parameters computation offered differ value for level scale parameter in linear trend and autoregressive component.As we discussed on single chain topic, there were poor mixing trace for them.
The multiple chain trace plot in Figure 4 was built only for scalar parameters.The observation noise scale trace plot shows that all the chain mixing well, form similar density and explores the center region of density.Similar trace plot case applied for slope scale of linear trend and drift scale of seasonal component.Their trace plot tells us the chain is mixing well.The chains have reached stationarity because the distribution of points is not changing as the chain progresses.The stationarity recognized from their trace plot had relatively constant mean and variance.This chain traverses its posterior space rapidly, and it can jump from one remote region of the posterior to another in relatively few steps.
The density of the linear trend component's level scale parameter results in a bimodal distribution form.It indicated poor mixing for its parameter, resulting in a distinct value for each demonstration.As well as for the autoregressive level scale.This finding suggests that extra actions will be required to bring those parameters into alignment.More strategies are required to improve its convergence.This style of trace plot is generally associated with strong sample autocorrelation.We need to run the chain for much longer to get a few thousand independent samples.As the convergence issue worsens, multiple chain acceptance rates for proposals decline.This acceptance rate, however, is still regarded as an optimal or good target.Rice prices are expected to rise from the beginning of the year until February 2020, according to the predicted figures indicated in Table III and Figure 6.The average price of rice then fell to its lowest point in May 2020, before rising again.The effect of seasonal components in the time series model causes fluctuations in the average rice price prediction.We can see in Figure 6 that the nowcast uncertainty of shading within 2 standard deviations increases over time, as the linear trend model becomes less confident in its extrapolation of the slope.The mean forecast combines the seasonal variation with a linear extrapolation of the existing trend, which appears to slightly underestimate the accelerating growth in rice prices, but the true values are still within the 95% predictive interval.On average, our nowcast is less than 2% off the actual average rice price, which is commonly considered to be excellent value.In this study, the average difference between predictions and actual is 191.49, and the weighted

Figure 1 .
Figure 1.The research steps

Figure 3 .
Figure 3. Trace Plot for Single Chain

Figure 4 .
Figure 4. Trace Plot for Multiple Chain The posterior marginal distributions on the process modeled are mapping by each component of rice price structural time series.Using the component distributions, we can visualize the uncertainty for each component as displayed on Figure 5.

Table I .
Single Chain Parameter Inference

Table II .
Multiple Chain Parameter Inference

Table III .
Nowcasting Result