1

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.

Sebastian
  • 21
  • 1

1 Answers1

0

This somehow looks a bit like a homework assignment... ;)

From your code sample it seems that you may be struggling with the idea of functions (in the sense of functions in programming, not in mathematics) and how their arguments work and how arguments are passed to functions, i.e. how you call a function. I suggest you look up the documentation of scipys minimize function and try to find out how you should design your objective function and its arguments. Inside of your objective function you can then call your model function and calculate the objective value.

Sunday
  • 631
  • 1
  • 7
  • 14
  • This is more of a comment than an answer. – user3483203 Sep 17 '18 at 16:46
  • I already did read the docs but still cant figure out how to do this properly. I tried differnt ways to implement the function but didnt find a solution.The code I wrote is thought more as a way to explain the problem, rather than code that needs to be fixed. – Sebastian Sep 17 '18 at 16:55