MATLAB Codel APP를 사용하여 MATLAB로 작성된 신경망 함수를 C 함수로 변환하려고합니다. 내가 변환 할 때, 나는cell2mat는 MATLAB Coder에서 C 코드 생성을 지원하지 않습니다.
cell2mat로 무엇입니까하는 코드 생성 arrayfun 지원되지 않습니다는
가 어떻게 이러한 기능을 대체 할 수있는 코드 생성을 지원하지 않습니다?
내 코드는 다음과 같습니다. 입력 X
은 1x2500 매트릭스이고 output
은 1x6 매트릭스입니다.
전체 코드는 boneGrwNN
function Y = boneGrwNN(X)
x1_step1.ymin = -1;
% ===== SIMULATION ========
% Format Input Arguments
isCellX = iscell(X);
if ~isCellX, X = {X}; end;
% Dimensions
TS = size(X,2); % timesteps
if ~isempty(X)
Q = size(X{1},1); % samples/series
else
Q = 0;
end
% Allocate Outputs
Y = cell(1,TS);
% Time loop
for ts=1:TS
% Input 1
X{1,ts} = X{1,ts}';
Xp1 = mapminmax_apply(X{1,ts},x1_step1);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);
% Layer 2
a2 = softmax_apply(repmat(b2,1,Q) + LW2_1*a1);
% Output 1
Y{1,ts} = a2;
Y{1,ts} = Y{1,ts}';
end
% Format Output Arguments
if ~isCellX, Y = cell2mat(Y); end
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end
% Competitive Soft Transfer Function
function a = softmax_apply(n,~)
if isa(n,'gpuArray')
a = iSoftmaxApplyGPU(n);
else
a = iSoftmaxApplyCPU(n);
end
end
function a = iSoftmaxApplyCPU(n)
nmax = max(n,[],1);
n = bsxfun(@minus,n,nmax);
numerator = exp(n);
denominator = sum(numerator,1);
denominator(denominator == 0) = 1;
a = bsxfun(@rdivide,numerator,denominator);
end
function a = iSoftmaxApplyGPU(n)
nmax = max(n,[],1);
numerator = arrayfun(@iSoftmaxApplyGPUHelper1,n,nmax);
denominator = sum(numerator,1);
a = arrayfun(@iSoftmaxApplyGPUHelper2,numerator,denominator);
end
function numerator = iSoftmaxApplyGPUHelper1(n,nmax)
numerator = exp(n - nmax);
end
function a = iSoftmaxApplyGPUHelper2(numerator,denominator)
if (denominator == 0)
a = numerator;
else
a = numerator ./ denominator;
end
end
% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end
가 어떻게이 기능에 대한 C 코드를 생성 할 수 있습니다이 링크의 설계 할수있다?
'cell2mat'이 무엇을하는지 이해하고 전달하는 입력을 이해한다면 왜'cell2mat' 자체를 사용하지 않고 수동으로 동작을 복제 할 수 없습니까? – Wolfie