Vector Row product vs Matrix产品,计算速度差异很大

时间:2018-02-09 22:33:52

标签: vectorization octave matrix-multiplication

任何人都可以用行*矢量矢量化计算与矩阵来解释我获得的速度差异很大。*矩阵计算?我知道了 行*向量为0.000959158秒 矩阵。*矩阵为0秒 我附加的代码对FV和FM进行了完全相同的计算,然后绘制相同的结果只是为了表明结果是相同的。我期待一些差异但不是0.00009而不是没有。

 %Plots the Fair Skill Score for a binary event 
    % Initialization %
    clear ; close all; clc
    %input parameters
    m = 2; %number of mutually exclusive events
    printf('Running Fair Skill Score ... ');
    f = linspace(0,1,21); %20 real frequencies of event
    p = linspace(0,1,26); %25 probabilities attributed by forecaster

tic
FV = log(m) + f' * log(p) + (1-f') * log(1-p);%fair score formula, calculated as matrix 
toc
[X,Y]= meshgrid(f,p); %set mesh grid for 3D surface plot

tic
FM = log(m) + X .* log(Y) + (1-X) .* log(1-Y);
toc

subplot(1,2,1)
surf(X,Y,FV');%FV is transposed because X and Y are vectors
title (['Fair Skill']);
xlabel(['frequency']);
ylabel("probability forecast");
zlabel("score");
colorbar
subplot(1,2,2)
surf(X,Y,FM)

0 个答案:

没有答案