Skip to content

Simply OR & Analytics

Loess from scratch in Python + Animation

Introduction Loess is a class of regression models that allows us to estimate the regression function \(f(X)\) by fitting a simple (and different) model to each point in the domain \(X\). This is done by paying attention to the points closest to a particular target point \(x_0 \in X\). In the classic simple linear regression we have the following model: \[ y_i = f(x_i) + \epsilon_i\] where \(f(x_i)\) is: \[f(x_i) = \beta_0 + \beta_1 \cdot x_i\] and in the case of loess with approximate \(f(x_i)\) by a polynomial weigthed by a function \(w_i\) that assigns higher weights to points \(x_i\) that are closer to \(x_0\): \[f(x_i) = w_i(x_0) \cdot [\beta_0 + \beta_1 \cdot x_i + \beta_2 \cdot x_i^2 + \dots]\] Procedure: Let \(x_i\) denote a set of \(n\) values for a particular variable and let \(y_i\) represent the corresponding response variable. Find the \(k\) closest points to the target point \(x_0\). Read more

Workforce scheduling

The mining industry in Chile is a big deal. It represents about 10% of the country GDP. Being a big industry, the possibility to know someone that works there is not difficult. My sister works in one of the plenty mining companies. She has different schedules, like 7 days on 7 days off, or 10 days on 10 days off. That is normal in this kind of industry, so I wanted to create an Integer Programming model for different type of those schedules. First, I will define a work cycle as a pair (M, N), where M is the number of days on, and N is the total length of the work cycle (days on + days off). Second, in a work cycle (M, N) there are N different patterns. Each pattern represents when the employees can start working: day 1, day 2 and so on until day N. Read more

Inventory Series: Reorder point using bootstrap

Introduction The reorder point is the level of inventory at which an order is placed. If the demand rate is a known constant, then the reorder point is: \[ \text{ Reorder Point} = \text{ demand rate}\times \text{ lead time} \] where \(\text{ lead time}\) is the amount of time between the placement of an order and its receipt (assumed constant as well here). For example, if the demand rate is 10 units/day and the lead time is 5 days, then the Reorder Point is going to be 50 units. When the demand is stochastic and/or the lead time is stochastic, the lead-time demand is stochastic and, thus, a stockout is possible. For example: Stochastic demand and constant lead time: suppose the daily demand fluctuates among 9, 10 and 11 units and the lead time is 5 days. Then the lead-time demand is stochastic falling somewhere in the interval between 45 and 55. Read more

Leo Messi's field goals in La Liga (Part I)

Introduction I was curious to model the effectivness of Messi scoring goals in La Liga. He has been Pichichi for the last 3 years, so I guess he is quite effective in scoring goals in the opportunities he has. To model the goals scored by Messi in different seasons, I will use the following bayesian models: Simple model Hierarchical model State space model Simple Model I am going model the number of goals scored against the attempts during each season. Each parameter of the model, for each season, is going to be modeled independently. The models is very simple: \[\textrm{Likelihood: } \quad score_i \sim binomial(N_i, p_i)\] \[\textrm{Prior: } \quad p_i \sim beta(\alpha, \beta)\] where, \(score_i\) number of goals scored in season i \(N_i\) number of attempts in season i \(p_i\) proportion of goals scored against the total attempts in season i \(\alpha\) and \(\beta\) parameters of the beta distribution that I need to figure out Now, I need to figure out those \(\alpha\) and \(\beta\) parameters that model the proportion of goals. Read more