I am able to run models and use functions, but I have not worked with pytensor before and have what I assume is a basic question.
I am playing around with a marketing mix model, and try to create a brand equity function which builds up over time from what you do, and then a certain percentage of that is lost every week. (Not important, but in case you are in the field)
brand_equity = pm.Deterministic(
name="brand_equity",
var=brand_equity(brand_channel_contributions, brand_loss=brand_loss),
dims=("date", "channel"),
)
And then I have a function something similar to this. I guess this is not how to work with pytensors at all, but how should I approach the problem?
If I do not think about pytensors, my solution would be something like this:
def brand_equity(brand_channel_contributions, brand_loss):
# Ensure brand_loss is a scalar
brand_loss = brand_loss.eval()
brand_loss = brand_loss.item() # Convert numpy array to scalar
brand_channel_size=brand_channel_contributions.eval()
brand_channel_size_num=brand_channel_size.shape[0]
brand_equity = np.zeros(brand_channel_size_num)
for t in range(brand_channel_size_num):
brand_equity[t] = brand_equity[t - 1] * (1 - brand_loss) #+ brand_channel_contributions[t]
return brand_equity
But then get an error like ValueError: order must be one of ‘C’, ‘F’, ‘A’, or ‘K’ (got ‘brand_equity’)
Which makes sense to me. The problem is that I do not now how to fix this in pyTensor. This is one of my tries
def brand_equity(brand_channel_contributions, brand_loss):
# Ensure brand_loss is a scalar
brand_loss = brand_loss.eval()
#brand_loss = brand_loss.numpy() # Convert tensor to numpy array
brand_loss = brand_loss.item() # Convert numpy array to scalar
brand_channel_size=brand_channel_contributions.eval()
brand_channel_size_num=brand_channel_size.shape[0]
brand_equity = pt.zeros(brand_channel_size_num)
for i in range(brand_channel_size_num):
if i == 0 :
brand_equity = pt.set_subtensor(brand_equity[i], brand_channel_contributions[i])
else:
brand_equity = pt.set_subtensor(brand_equity[i], brand_equity[i - 1] * (1 - brand_loss))
return brand_equity
Here I get an
TypeError: Trying to increment a 0-dimensional subtensor with a 1-dimensional value.
Guess this is quite basic, but anyone have a pointer to what I should do?