Paleted interpolation in python or matlab

I have a Loss Loss function and signals f (t), g (t). I would like to find a function sthat minimizes:L(f(t)-g(t+s(t)))+lambda*integral(s''(t))

Ideally sshould be a polynomial or spline.

Here is the code I wrote to start the problem:

import numpy as np 
from numpy import *
from numpy.linalg import *
import sklearn as sk
import scipy as sp
import scipy.io
from matplotlib.pyplot import * 
from scipy.interpolate import *

#mat = scipy.io.loadmat('/home/luca/Documents/phd_python_code/peak_aligment/john_example.mat')
mat = scipy.io.loadmat('../peak_aligment/john_example.mat')

t1=mat["t1"].squeeze()
t2=mat["t2"].squeeze()
t3=mat["t3"].squeeze()
t=sort(unique(concatenate((t1,t2,t3),axis=0)))
t_min=max(min(t1),min(t2),min(t3))
t_max=min(max(t1),max(t2),max(t3))
t=[val for val in t if t_min<=val<=t_max]
sig1=mat["sig_1"].squeeze()
sig2=mat["sig_2"].squeeze()
sig3=mat["sig_3"].squeeze()

s1=interp1d(t1,sig1,kind="cubic")
s2=interp1d(t2,sig2,kind="cubic")
s3=interp1d(t3,sig3,kind="cubic")

EDIT: I'm closer to the solutions, but I'm still having problems.

I defined a cost function:

def lost_function(p):
    pt=polyval(p,t)

    return norm(s1(t)-s2(pt))/len(index)

And I'm trying to minimize it with scipy.optimize.minize. the main problem is that it ptis often out of range value t. Therefore, when I call s2(pt) i, we get an error. How can I interpolate a function also outside the range of t?

+3
source share

All Articles