使用基于python的neurora进行表征相似性分析(RSA)

发现了一款用于表征分析的Python API,还是挺方便的,这里简单介绍一下进行表征相似性分析的使用方法。

官方文档见https://neurora.github.io/documentation/index.html

下载

pip install neurora

表征相似性分析的知识可见:

https://zhuanlan.zhihu.com/p/363691154?utm_id=0

一、得到矩阵不相似性矩阵(Representational Dissimilarity Matrix,RDM)

这里随意创建了一个矩阵,使用了neurora里面的对人类行为分析构造RDM的函数,当然也可以选别的构造RDM的函数。

import neurora.rdm_cal as rc
import neurora.rsa_plot
import neurora.rdm_corr
import torch
import torchvision as tv
import numpy as np
# 构造数据
bhv_data = np.random.randn(5,5,4) #  the number of conidtions, the number of subjects, the number of trials
'''
Calculate the subject-result or average-result.

The method to calculate the dissimilarities.
If method='correlation', the dissimilarity is calculated by 
Pearson Correlation. If method='euclidean', the dissimilarity 
is calculated by Euclidean Distance, the results will be 
normalized. If method='mahalanobis', the dissimilarity is 
calculated by Mahalanobis Distance, the results will be 
normalized.

Calculate the absolute value of Pearson r or not.
'''
# 得到RDM矩阵
rdm = rc.bhvRDM(bhv_data, sub_opt=0, method='correlation', abs=False)
print(rdm.shape)
# 绘制图
neurora.rsa_plot.plot_rdm(rdm, lim=[0, 1], rescale=False, conditions=None, cmap=None)
# 绘制带数值的图
neurora.rsa_plot.plot_rdm_withvalue(rdm, lim=[0, 1], value_fontsize=10, conditions=None, con_fontsize=12, cmap='rainbow')

绘制出的两张图如下:

二、进行RSA分析

这里随机创建两个数据,对他们的RDM进行相关性检验

bhv_data1 = np.random.randn(5,5,4) #  the number of conidtions, the number of subjects, the number of trials
bhv_data2 = np.random.randn(5,5,4) #  the number of conidtions, the number of subjects, the number of trials
rdm1 = rc.bhvRDM(bhv_data1, sub_opt=0, method='correlation', abs=False)
rdm2 = rc.bhvRDM(bhv_data2, sub_opt=0, method='correlation', abs=False)

# 使用pearson,当然也可以用spearman等,如rdm_correlation_spearman
spearman_result = neurora.rdm_corr.rdm_correlation_pearson(rdm1, rdm2, rescale=False, permutation=False, iter=5000)
print(spearman_result)

输出内容为皮尔森检验的r值和p值

[0.00366008 0.99199368]

p>0.05,说明不相关,这两个数据都是随机生成的,不相关很正常。

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值