Smoothed Collocation

Smoothed collocation, also referred to as the two-stage method, allows for fitting differential equations to time series data without relying on a numerical differential equation solver by building a smoothed collocating polynomial and using this to estimate the true (u',u) pairs, at which point u'-f(u,p,t) can be directly estimated as a loss to determine the correct parameters p. This method can be extremely fast and robust to noise, though, because it does not accumulate through time, is not as exact as other methods.

DiffEqFlux.collocate_dataFunction
u′,u = collocate_data(data,tpoints,kernel=SigmoidKernel())

Computes a non-parametrically smoothed estimate of u' and u given the data, where each column is a snapshot of the timeseries at tpoints[i].

For kernels, the following exist:

  • EpanechnikovKernel
  • UniformKernel
  • TriangularKernel
  • QuarticKernel
  • TriweightKernel
  • TricubeKernel
  • GaussianKernel
  • CosineKernel
  • LogisticKernel
  • SigmoidKernel
  • SilvermanKernel

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2631937/

source

Non-Allocating Forward-Mode L2 Collocation Loss

The following is an example of a loss function over the collocation that is non-allocating and compatible with forward-mode automatic differentiation:

du = DiffEqBase.dualcache(similar(prob.u0))
preview_est_sol = [@view estimated_solution[:,i] for i in 1:size(estimated_solution,2)]
preview_est_deriv = [@view estimated_derivative[:,i] for i in 1:size(estimated_solution,2)]

function construct_iip_cost_function(f,du,preview_est_sol,preview_est_deriv,tpoints)
  function (p)
      _du = DiffEqBase.get_tmp(du,p)
      vecdu = vec(_du)
      cost = zero(first(p))
      for i in 1:length(preview_est_sol)
        est_sol = preview_est_sol[i]
        f(_du,est_sol,p,tpoints[i])
        vecdu .= vec(preview_est_deriv[i]) .- vec(_du)
        cost += sum(abs2,vecdu)
      end
      sqrt(cost)
  end
end
cost_function = construct_iip_cost_function(f,du,preview_est_sol,preview_est_deriv,tpoints)