最近在做降低实验复杂度的问题,分析一下需要用的ITR代码,包含Matlab和python代码。
1.引入ITR
由于BCI在输入、转换算法、输出和其他特征方面存在很大差异,因此通常很难进行比较。虽然不同的系统可能会被证明对不同的应用程序最有价值,但一个标准的性能度量将作为跟踪BCI开发的通用基准而有用。通信系统的一个标准度量是比特率,即单位时间内通信的信息量,比特率取决于速度和精度。虽然每个BCI系统的有效性在很大程度上取决于它所应用的应用程序,但比特率为比较不同系统和测量系统内部的改进提供了客观的衡量标准。
2.ITR公式,单位bits/min
其中:
●其中,T表示平均判断时长,M表示类别个数,P表示识别正确率。ITR的单位是bits/min。
●特别需要指出,当正确率P小于1/N时,ITR强制为0。
变量关系如下:
3.ITR函数代码
3.1 matlab代码
function [ itr ] = itr(n, p, t)
% Calculate information transfer rate (ITR) for brain-computer interface
% (BCI) [2]
% function [ itr ] = itr(n, p, t)
%
% Input:
% n : # of targets
% p : Target identification accuracy (0 <= p <= 1)
% t : Averaged time for a selection [s]
%
% Output:
% itr : Information transfer rate [bits/min]
%
% Reference:
% [1] M. Cheng, X. Gao, S. Gao, and D. Xu,
% "Design and Implementation of a Brain-Computer Interface With High
% Transfer Rates",
% IEEE Trans. Biomed. Eng. 49, 1181-1186, 2002.
%
% Masaki Nakanishi, 22-Dec-2017
% Swartz Center for Computational Neuroscience, Institute for Neural
% Computation, University of California San Diego
% E-mail: masaki@sccn.ucsd.edu
if nargin < 3
error('stats:itr:LackOfInput', 'Not enough input arguments.'); end
if p < 0 || 1 < p
error('stats:itr:BadInputValue',...
'Accuracy need to be between 0 and 1.');
elseif p < 1/n
warning('stats:itr:BadInputValue',...
'The ITR might be incorrect because the accuracy < chance level.');
itr = 0;
elseif p == 1
itr = log2(n)*60/t;
else
itr = (log2(n) + p*log2(p) + (1-p)*log2((1-p)/(n-1)))*60/t;
end
3.2 python代码
import math
def itr(n, p, t):
if not all(isinstance(i, (int, float)) for i in [n, p, t]):
raise TypeError("Inputs must be numeric.")
if p < 0 or p > 1:
raise ValueError("Accuracy needs to be between 0 and 1.")
elif p < 1/n:
print("Warning: The ITR might be incorrect because the accuracy < chance level.")
itr = 0
elif p == 1:
itr = math.log2(n) * 60 / t
else:
itr = (math.log2(n) + p*math.log2(p) + (1-p)*math.log2((1-p)/(n-1))) * 60 / t
return itr
注意:MATLAB 中的 nargin
函数在 Python 中没有直接的对应项。在这里,我使用了 all
函数和类型检查来确保输入为数字,以确保与 MATLAB 的 nargin
检查相同的行为。