Rvdb
Rvdb

Reputation: 11

Time dependant ODE parameters / varaibles in PyMC and Sunode

I have an ODE function ode(y,t,theta, influent) where influent is an array of values at different times (experimental data for input to system).

I have this in my main ode function (not as important):

def ode(y,t,theta, influentData, volumes):
.....

    # if t is a float, use the numerical function. if t is a sympy symbol, use the symbolic   function. Else, throw an error
    if isinstance(t, float):
        plant_inlet = get_influent_at_time_num(influentData, t)
    elif isinstance(t, sp.Symbol):
        plant_inlet = get_influent_at_time_sym(influentData, t)
    else:
        raise ValueError("Time t must be a float or sympy symbol")

Importantly this is where things are complicated. The get_influent_at_time_num function works as intended (through interpolation as follows:):


def get_influent_at_time_num(influentData, t):
        """
    # Throw an error if the influent data is not provided or is empty
    if influentData is None or len(influentData) == 0:
        raise ValueError("Influent data is empty or not provided")
 
    time_data = influentData[:, 0]  # Get the time data, first column of the inputs

    ## Perform linear interpolation for each variable using np.interp
    Qin = np.interp(t, time_data, influentData[:, 1])
    .....

    Influent_data = [Qin, ...]
    return Influent_data

But I cannot figure out how to do something similar with get_influent_at_time_sym. For now I have set it to just using the numerical function at t=0 but obviously I want it to work in a similar way.


This is specifically with focus on using sunode for ode sampling with PyMC. As far as I can tell, sunode uses Sympy for its symbolic solver (sundials) and base PyMC uses TensorVariables during solving. Even if I were to switch to only PyMC's base solver I would have a similar issue because of that.

Please let me know if anyone has any advice or can help with this, it would be greatly appreciated.

I am not sure where to start with doing this as I do not know how to 'extract' the value of t to use or should I try to go the route of fitting a symbolic function to the data

Upvotes: 1

Views: 21

Answers (0)

Related Questions