pytorch怎麼計算矩陣的相關係數矩陣?

時間 2021-06-05 09:04:40

1樓:半個馮博士

直接搞個輔助庫一勞永逸:

audtorch - audtorch Documentationpip install audtorch

import

torch

from

audtorch.metrics.functionalimport

pearsonr

input

=torch

.rand(3

,5)target

=torch

.rand(3

,5)output

=pearsonr

(input

,target

)print

('Pearson Correlation between input and target is '

.format

(output

[:,0

]))Pearson

Correlation

between

input

andtarget

istensor

([0.4642,-

0.6112,-

0.2255

])相關係數文件:audtorch.metrics.functional - audtorch Documentation

2樓:soup can

自問自答一波吧....剛剛自己編出來了

def corrcoef(x34;""傳入乙個tensor格式的矩陣x(x.shape(m,n)),輸出其相關係數矩陣"""f = (x.shape[0] - 1) / x.

shape[0] # 方差調整係數

x_reducemean = x - torch.mean(x, axis=0numerator = torch.matmul(x_reducemean.

T, x_reducemean) / x.shape[0var_ = x.var(axis=0).

reshape(x.shape[1], 1denominator = torch.sqrt(torch.

matmul(var_, var_.T)) * f

corrcoef = numerator / denominator

範德蒙德矩陣的逆矩陣怎麼計算

目前看到兩種方法 這種是直接伴隨矩陣暴算 Vandermonde 矩陣的逆矩陣公式 這一種是用拉格朗日插值來做的 利用 Lagrange 內插多項式推導 Vandermonde 矩陣的逆矩陣 這裡我要多幾句嘴,因為後一種做法其實和FFT很有關係。考慮乙個係數向量 乘上乙個Vandermode矩陣就是...

有沒有可以計算帶引數矩陣的計算器?

scenery 帶CAS功能的可以,TI 89鈦或者 TI Nspire CAS啦。不過這種計算器個頭比較大,如果考試不允許很容易被監考老師禁止帶入。因為一眼看過去就 與眾不同 我曾經在大學線性代數考試中使用過TI 89 慶幸監考不懂CAS,允許我使用啦! 電卓院亜紀良 計算帶引數的矩陣的計算器不僅...

3相加熱負載電流怎麼計算

Patrick Zhang 建議題主參閱 工業爐設計手冊 第二版 以下簡稱手冊 查閱該書的第14章 電阻爐 第2節是 電熱元件 其中有各種矽碳棒的引數,以及選配要點。我們知道,導電材料的電阻表示式為 這裡的 是電阻率。在手冊的P769有下圖 圖1 矽碳棒在不同溫度下的電阻係數 從圖1中我們看到,矽碳...