Пример #1
0
def ideal_smoothing_mse(mexsmoothing, musmoothing, Vtest, predcoeffs):
    N = Vtest.get_T()
    ideal_coeffs = []
    for i in range(N):
        testridge = expregs.ExpandedRidge(musmoothing, mexsmoothing)
        testridge.fit(Vtest["x"][i], Vtest["y"][i])
        ideal_coeffs.append(testridge.w)
    ideal_coeffs = np.array(ideal_coeffs)
    return ((ideal_coeffs - predcoeffs) ** 2).sum(axis=1).mean()
Пример #2
0
 def __call__(self, X, Y):
     self.ridges = []
     nprobs = len(X)
     if len(Y) != nprobs:
         raise ValueError(
             "Number of problems for input ({}) and target ({}) do not match"
             .format(nprobs, len(Y)))
     w = np.zeros((nprobs, self.funcdict.D))
     for t in range(nprobs):
         ridge = expridge.ExpandedRidge(self.mu, self.funcdict)
         ridge.fit(X[t], Y[t])
         w[t, :] = ridge.w.copy()
         self.ridges.append(ridge)
     return w, self.funcdict.features_basis()
Пример #3
0
Xtest = spatiotemp.LocObsSet(xtest)
Vtest = spatiotemp.LocObsSet(vtest)


# plt.figure()
# for i in range(32):
#     plt.plot(emg[:, i])

# Test for bandwidth parameter
# See if our input smoothing has the means to represent well the input functions
musmoothing = 1
mexhats = funcdicts.MexHatDict((timevec[0], timevec[-1]), np.linspace(timevec[0], timevec[-1], 20), np.linspace(0.01, 0.1, 10))
# lspace = np.linspace(0, 0.69, 501)
# plt.figure()
# plt.plot(lspace, [mexhats.atom(0.3, 0.01, t) for t in lspace])
testridge = expregs.ExpandedRidge(musmoothing, mexhats)
i = 3
testridge.fit(Xtrain["x"][i], Xtrain["y"][i])
pred = testridge.predict(Xtrain["x"][i])
plt.figure()
plt.plot(Xtrain["x"][i], pred, label="predicted")
plt.plot(Xtrain["x"][i], Xtrain["y"][i], label="real")
plt.legend()


# Kernels
kers = kernels.GaussianFuncKernel(sigma=2, funcdict=mexhats, mu=musmoothing)
Ks = kers.compute_K(Xtrain["xy_tuple"])
kers = kernels.GaussianFuncIntKernel(sigma=0.5, funcdict=mexhats, mu=musmoothing, timevec=timevec)
Ks = kers.compute_K(Xtrain["xy_tuple"])
plt.figure()
Пример #4
0
# Kernels
sigmarff = 10
D = 50
rffs = rffridge.RandomFourierFeatures(sigmarff, D, d=1)
kers = kernels.GaussianFuncKernel(sigma=5, funcdict=rffs, mu=musmoothing)
# kers = kernels.GaussianSameLoc(sigma=10)
Ks = kers.compute_K(Xtrain["xy_tuple"])
plt.imshow(Ks)
test = rffs.eval(Vtrain["x"][0])
plt.imshow(test.dot(test.T))

# Test for bandwidth parameter
# To see if our output dictionary has the means to approximate well the output functions
muout = 0.1
# testridge = rffridge.RFFRidge(muout, rffs)
testridge = expregs.ExpandedRidge(muout, rffs)
i = 5
testridge.fit(Vtrain["x"][i], Vtrain["y"][i])
pred = testridge.predict(Vtest["x"][i])
plt.figure()
plt.plot(Vtest["x"][i], pred, label="predicted")
plt.plot(Vtrain["x"][i], Vtrain["y"][i], label="real")
plt.legend()
testridge.w

cc = coefsoncoefs.CoefsOnCoefs(kernels.GaussianKernel(sigma=5), rffsx,
                               musmoothing, rffs, muout, 0)
cc.fit(Xtrain, Vtrain)
pred = cc.predict(Xtest, Vtest["x"][i])
plt.figure()
plt.plot(Vtest["x"][i], pred[0])