Skip to content

Instantly share code, notes, and snippets.

View hlpureboy's full-sized avatar

Allen hlpureboy

  • Beijing
  • 11:43 (UTC +08:00)
View GitHub Profile
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)
@hlpureboy
hlpureboy / huafe_transform.py
Created May 28, 2022 12:54
huafe_transform
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)
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])))
@hlpureboy
hlpureboy / find_square.py
Created September 16, 2021 12:00
find square in image
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())
@hlpureboy
hlpureboy / 200_rois_fc.py
Created August 17, 2021 07:29
corr 200 rois fc
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)
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)