I have developped an extension of the standard Bass Model and now I want to estimate the parameters of this model using minimization.
The model is: SVe(t) = θ[t-tv ] * { p*m + (q-p) * ∑SVe(t-1) + (q/m) * ∑SVe(t-1)^2 }
Objective function is: Minimize ∑(SVr - SVe)^2
SVr is an array with measured data on daily Youtube video Views. SVe are my estimated views. My goal is to estimate Sve and then use minimization to get close to the real values.
θ[t-tv ] is a heaviside function. This is also an input I have that will look something like:
[[0,1,1,1,1,1][0,0,0,1,1,1][0,0,0,0,1,1]]
p, q and m are the parameters im intrested in and that I want to estimate. p and q are between 0 and 1, m is a big positive number. ∑SVe(t-1) is the cummulated Views of the previous periods.
My idea was to define a function that contains the model and an objective function where I use minimization.
import numpy as np
from scipy.optimize import minimize
SV = np.array([100,10000,1000])
heavi = np.array([[0,1,1,1],[0,0,1,1],[0,0,0,1]])
def model(x):
p = x[0]
q = x[1]
m = x[2]
SVe = sum(heavi * (p*m+(q-p)*sum(SVe[:-1])+(q/m)*(sum(SVe[:-1])**2))
return SVe
def objective(SVr):
#Somehow Call model and compare results, then do it again until res is close to 0
return sum(SVr - SVe)**2
x0 = np.array([0.1, 0.1, 10000])
b1 = (0,1)
b2 = (1,1000000000)
bnds = (b1,b1,b2)
res = minimize(objective, x0, method='SLSQP',bounds = bnds)
print(res)
This is just a code sample of my idea that does not work. How would you solve this problem? How can I link my model to my objective, so that it reestimates over and over again, until it finds a close solution? Please feel free to ask for further info.