import pickle import glob from tqdm import tqdm import torch import torch.nn as nn…
- User
import pickle import glob from tqdm import tqdm import torch import torch.nn as nn import torch.nn.functional as F import numpy as np import torch from torch.utils.data import Dataset, DataLoader from tqdm import tqdm from scipy.interpolate import splev import logging
path = '/gpfs/mvoronina/MT/Project/Seq/sequences_7959_sequences.pt' data = torch.load(path)
labels = torch.load('/gpfs/mvoronina/MT/Project/Seq/sequences_labels.pt') labels_part = labels[-459:]
def bs(x, df=None, knots=None, degree=3, intercept=False): """ df : int The number of degrees of freedom to use for this spline. The return value will have this many columns. You must specify at least one of
dfandknots. knots : list(float) The interior knots of the spline. If unspecified, then equally spaced quantiles of the input data are used. You must specify at least one ofdfandknots. degree : int The degree of the piecewise polynomial. Default is 3 for cubic splines. intercept : bool IfTrue, the resulting spline basis will span the intercept term (i.e. the constant function). IfFalse(the default) then this will not be the case, which is useful for avoiding overspecification in models that include multiple spline terms and/or an intercept term.code""" order = degree + 1 inner_knots = [] if df is not None and knots is None: n_inner_knots = df - order + (1 - intercept) if n_inner_knots < 0: n_inner_knots = 0 print("df was too small; have used %d" % (order - (1 - intercept))) if n_inner_knots > 0: inner_knots = np.percentile( x, 100 * np.linspace(0, 1, n_inner_knots + 2)[1:-1]) elif knots is not None: inner_knots = knots all_knots = np.concatenate( ([np.min(x), np.max(x)] * order, inner_knots)) all_knots.sort() n_basis = len(all_knots) - (degree + 1) basis = np.empty((x.shape[0], n_basis), dtype=float) for i in range(n_basis): coefs = np.zeros((n_basis,)) coefs[i] = 1 basis[:, i] = splev(x, (all_knots, coefs, degree)) if not intercept: basis = basis[:, 1:] return basis - Assistant