This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.base import BaseEstimator, RegressorMixin | |
from baseline.utils.tools import corr2_coeff | |
def optim_corr_ridge(K,alpha,y,bais_flag): | |
K_r = K+np.eye(K.shape[0])*alpha | |
K_r_inv = np.linalg.inv(K_r) | |
if bais_flag: | |
ones = np.ones((K.shape[0],1)) | |
_x = np.matmul(ones.T,np.matmul(K_r_inv,ones)) | |
_x_inv = np.linalg.inv(_x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.preprocessing import StandardScaler | |
def huafe_transform(x,y,standardlized=True): | |
""" | |
1. Haufe S, Meinecke F, Görgen K, et al. On the interpretation of weight vectors of linear models in multivariate neuroimaging. Neuroimage. 2014;87:96-110. doi:10.1016/J.NEUROIMAGE.2013.10.067 | |
2. He T, An L, Feng J, et al. Meta-matching: a simple framework to translate phenotypic predictive models from big to small data. Nat Neurosci. Published online 2022:2020.08.10.245373. doi:10.1038/s41593-022-01059-9 | |
3. Chen J, Tam A, Kebets V, et al. Shared and unique brain network features predict cognitive, personality, and mental health scores in the ABCD study. Published online 2022. doi:10.1038/s41467-022-29766-8 | |
core formula: | |
w = cov(X,Y)^-1 *varance(Y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
genre_movie = '{"genres":[{"id":28,"name":"动作"},{"id":12,"name":"冒险"},{"id":16,"name":"动画"},{"id":35,"name":"喜剧"},{"id":80,"name":"犯罪"},{"id":99,"name":"纪录"},{"id":18,"name":"剧情"},{"id":10751,"name":"家庭"},{"id":14,"name":"奇幻"},{"id":36,"name":"历史"},{"id":27,"name":"恐怖"},{"id":10402,"name":"音乐"},{"id":9648,"name":"悬疑"},{"id":10749,"name":"爱情"},{"id":878,"name":"科幻"},{"id":10770,"name":"电视电影"},{"id":53,"name":"惊悚"},{"id":10752,"name":"战争"},{"id":37,"name":"西部"}]}' | |
movie_dict = dict([(em['id'],em['name']) for em in json.loads(genre_movie)['genres']]) | |
print(list(map(lambda x:movie_dict.get(x),[80, 9648, 53]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.morphology import square | |
from skimage import measure,morphology | |
import numpy as np | |
def find_square(img,th=0.7,nums=15,min_width=30,max_width=50,dilation_square_with=10): | |
contours = measure.find_contours(img, 0.7) | |
mask_img = np.zeros(img.shape) | |
count = 0 | |
for contour in contours: | |
x_min = int(contour[:,0].min()) | |
x_max = int(contour[:,0].max()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import os | |
from tqdm import tqdm | |
from multiprocessing import Pool | |
import pandas as pd | |
def get_corr_matrix(Subject_id): | |
Subject_id = str(Subject_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
test_str = 'This story appears in the June/July in U.S..' | |
test_str=test_str[0] + re.sub('[A-Z]', '', test_str[1:], count=0, flags=0) |