-
-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add DiscreteTimeSum
subclass of pybamm.Symbol
#4485
Comments
@martinjrobins I think we should be able to extract all the information we need from the class DiscreteTimeData(pybamm.Interpolant):
def __init__(self, t, y, children=pybamm.t, ...):
super().__init__(t, y, children, ...) and we can keep essentially the same API, data = pybamm.DiscreteTimeData(data_t, data_y)
model.variable["data_comparison"] = pybamm.DiscreteTimeSum((model.variable["Voltage"] - data)**2) On another topic, one possible edge case with this pybamm.DiscreteTimeSum((model.variable["Voltage"] - data_V)**2 + (model.variable["Temperature"] - data_T)**2) If |
Yea, agree that the # ... model setup
data = pybamm.DiscreteTimeData(data_t, data_y)
model.variable["data_comparison"] = pybamm.DiscreteTimeSum((model.variable["Voltage"] - data)**2)
# .... solver setup
sol = solver.solve(t_eval=[data_t[0], data_t[-1]], t_interp=data_t)
print("sum of squares is:", sol["data_comparison"]) My first thought is that we should raise an error on the last line if the timepoints in |
I think this is the correct way forward, with the solve time taken from the last
I'm not sure we need this constraint, given the above. I think either ensuring that # ... model setup
dataset = pybamm.DiscreteTimeData(data) # Accepts a dictionary of fitting variables and returns a dict of interpolants for each
model.variable["data_comparison"] = pybamm.DiscreteTimeSum((model.variable["Voltage [V]"] - dataset["Voltage [V]")**2)
# .... solver setup
sol = solver.solve(t_eval=[data_t[0], data_t[-1]], t_interp=data_t)
print("sum of squares is:", sol["data_comparison"]) |
after chatting with @BradyPlanden, we came to the following conclusion:
datasets = { name: pybamm.DiscreteTimeData(data) for name, data in pybop_dataset.items() }
model.variable["data_comparison"] = pybamm.DiscreteTimeSum((model.variable["Voltage [V]"] - datasets["Voltage [V]")**2) |
I understand the perspective of optimizing an objective function, but I think we shouldn't be too fancy with this. At a minimum, the only specialization we need for a
Yeah we can do that. This is not an issue with the dataframe example, but for general interpolants, we just need to make sure that they have identical |
@martinjrobins sounds good to me. Since we use a single dataset, we can even automatically name the discrete sum based on the name of the observable/dataframe column (like |
* feat: add discrete time sum expression tree node #4485 * docs: fix math syntax in docstring * remove prints * test casadi solver as well * coverage * coverage * add to changelog and tidy solution test
Description
This would add a new unary operator in a pybamm expression tree that would represent a discrete sum over time. This would be a discrete version of the already existing
pybamm.ExplicitTimeIntegral
class.Motivation
This would give model developers and users the ability to add "sum of squares" type variables to a pybamm model that would calculate the difference between, for example, a solution variable and a user-provided dataset. This would be useful for implementing parameter inference using pybamm
Possible Implementation
Similar to the
ExplicitTimeIntegral
, this would only be evaluated in theSolution
class (see_update_variable
function). I would propose that the sum is done over the list of time points in the solution (rather than have a separate list of points in the expression tree node), that way a user can specify the time-points viat_interp
.I'm a bit unsure how to allow users to provide their data to the expression. Perhaps they would wrap it in an Interpolant:
Additional context
see pybop-team/PyBOP#513
The text was updated successfully, but these errors were encountered: