Has anyone developed a custom tweedie distribution for sampling? How to implement once developed?

Hey Lucianopaz i have tried with custom tweedie distribution but i got the following error: below the given inputs are in numpy array. Please help me to solve this.

import scipy.special as sp

# Define the log probability function for the Tweedie distribution
def tweedie_logp(value, mu, p, phi):
    # Ensure positive values for mu, p, and phi
    mu = np.maximum(mu, 1e-10)
    p = np.maximum(p, 1e-10)
    phi = np.maximum(phi, 1e-10)

    # Calculate the log probability using the provided parameters and observed value
    logp_value = (
        (1 - p) * np.log(value / mu) - (value / (mu ** p * phi)) - np.log(phi)
        + np.log((1 - p) * mu ** (1 - p))
    )



    return logp_value.sum()


with pm.Model() as model:
    # Prior distributions for the unknown parameters

    # Prior distributions for the unknown parameters
    mu = pm.Normal('mu', mu=0, sigma=10)
    p = pm.Normal('p', mu=1.5, sigma=1)
    phi = pm.Gamma('phi', alpha=1, beta=1)

    # Priors for the binary variables
    offline_campaign_prior = pm.Bernoulli('MISX_campaign_prior', p=0.5)
    discounts_prior = pm.Bernoulli('PA_prior', p=0.5)
    promotion_events_prior = pm.Bernoulli('promotion_events_prior', p=0.5)

    # Compute the expected sales based on the variables
    expected_sales = (storedata['day_of_week'].values + storedata['month'].values + storedata['year'].values + storedata['MISX'].values * offline_campaign_prior +
                      storedata['Status'].values * discounts_prior +
                      storedata['event'].values * promotion_events_prior)
    

    # Define the observed sales as a data variable
    sales_observed = storedata['Rslr_Sales_Amount'].values


    # Define the likelihood using the custom Tweedie distribution
    sales = pm.DensityDist('sales_observed', logp=tweedie_logp, observed={'value': sales_observed, 'mu': expected_sales, 'p': p, 'phi': phi})
    

    # Define the model
    trace = pm.sample(1000, tune=1000)



error: TypeError                                 Traceback (most recent call last)
Cell In[123], line 45
     41 sales_observed = storedata['Rslr_Sales_Amount'].values
     44 # Define the likelihood using the custom Tweedie distribution
---> 45 sales = pm.DensityDist('sales_observed', logp=tweedie_logp, observed={'value': sales_observed, 'mu': expected_sales, 'p': p, 'phi': phi})
     48 # Define the model
     49 trace = pm.sample(1000, tune=1000)

File ~\AppData\Roaming\Python\Python38\site-packages\pymc\distributions\distribution.py:944, in CustomDist.__new__(cls, name, dist, random, logp, logcdf, moment, ndim_supp, ndims_params, dtype, *dist_params, **kwargs)
    929 def __new__(
    930     cls,
    931     name,
   (...)
    941     **kwargs,
    942 ):
    943     if isinstance(kwargs.get("observed", None), dict):
--> 944         raise TypeError(
    945             "Since ``v4.0.0`` the ``observed`` parameter should be of type"
    946             " ``pd.Series``, ``np.array``, or ``pm.Data``."
    947             " Previous versions allowed passing distribution parameters as"
    948             " a dictionary in ``observed``, in the current version these "
    949             "parameters are positional arguments."
    950         )
    951     dist_params = cls.parse_dist_params(dist_params)
    952     cls.check_valid_dist_random(dist, random, dist_params)

TypeError: Since ``v4.0.0`` the ``observed`` parameter should be of type ``pd.Series``, ``np.array``, or ``pm.Data``. Previous versions allowed passing distribution parameters as a dictionary in ``observed``, in the current version these parameters are positional arguments.