2016-08-20 4 views
0

私はtheanoで遊び始めているので、簡単な関数を計算して出力をテストしようとしましたが、私がtheanoコンパイルバージョンとnonanoバージョンをテストすると出力ビットは....異なる計算の出力の違い、theano、nonanoano

コード:

import numpy as np 
import theano.tensor as T 
from theano import function 

np.random.seed(1) 
S = np.random.rand(4,3) 
Q = np.random.rand(4,3) 

def MSE(a, b): 
    n = min(a.shape[0], b.shape[0]) 
    fhat = T.dvector('fhat') 
    y = T.dvector('y') 
    mse = ((y - fhat)**2).sum()/n 
    mse_f = function([y, fhat], mse) 
    return mse_f(a,b) 

for row in range(S.shape[0]): 
    print(MSE(S[row], Q[row])) 

for i in range(S.shape[0]): 
    print(((S[i] - Q[i])**2).sum()/S.shape[0]) 

出力:私はこっち探しています何

# from MSE function 
0.0623486922837 
0.0652202301174 
0.151698460419 
0.187325204482 

# non theano output 
0.0467615192128 
0.0489151725881 
0.113773845314 
0.140493903362 

答えて

0
この文の表現で

print(((S[i] - Q[i])**2).sum()/S.shape[0]) 

あなたはS.shape[1]、ないS.shape[0]で割る必要があります。

S = np.random.rand(4,3)を使用してSを作成しました。つまり、Sの形は(4,3)です。つまり、S.shape(4, 3)です。 Sの各行の長さはS.shape[1]です。

+0

ああ...正しいです。でも、今ここで実際に起こっていることについてちょっと混乱しています。 'n'は' S.shape [0] 'と同じ4に等しくなければなりません。OH NO、その時点で行ベクトルになりますので、形状は単純に行。 – UberStuper

+0

答えに追加のコメントを追加しました。それは役に立ちますか? –

+0

yup!わかった。ありがとう! – UberStuper