  Throughout human history, epidemics have been a constant presence.
Understanding their dynamics is essential to predict scenarios and make
substantiated decisions. Mathematical models are powerful tools to describe an
epidemic behavior. Among the most used, the compartmental ones stand out,
dividing population into classes with well-defined characteristics. One of the
most known is the $SIR$ model, based on a set of differential equations
describing the rates of change of three categories over time. These equations
take into account parameters such as the disease transmission rate and the
recovery rate, which both change over time. However, classical models use
constant parameters and can not describe the behavior of a disease over long
periods. In this work, it is proposed a $SIR$ model with time-varying
transmission rate parameter with a method to estimate this parameter based on
an optimization problem, which minimizes the sum of the squares of the errors
between the model and historical data. Additionally, based on the infection
rates determined by the algorithm, the model's ability to predict disease
activity in future scenarios was also investigated. Epidemic data released by
the government of the State of Rio Grande do Sul in Brazil was used to evaluate
the models, where the models shown a very good forecasting ability, resulting
in errors for predicting the total number of accumulated infected persons of
0.13% for 7 days ahead and 0.6% for 14 days ahead.
