单变量
单变量取数据
data = load('ex1data1.txt');
X = data(:, 1); y = data(:, 2);
多变量取数据
data = load('ex1data2.txt');
X = data(:, 1:2);
y = data(:, 3);
运行train后弹出
对应的图
比如simulink格式
graphics格式
导出的函数形式
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 30-Jan-2021 09:01:36.
%
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
%
% X = 1xTS cell, 1 inputs over TS timesteps
% Each X{1,ts} = Qx1 matrix, input #1 at timestep ts.
%
% and returns:
% Y = 1xTS cell of 1 outputs over TS timesteps.
% Each Y{1,ts} = Qx1 matrix, output #1 at timestep ts.
%
% where Q is number of samples (or series) and TS is the number of timesteps.%#ok<*RPMT0>% ===== NEURAL NETWORK CONSTANTS =====% Input 1
x1_step1.xoffset = 5.0269;
x1_step1.gain = 0.116440868415997;
x1_step1.ymin = -1;% Layer 1
b1 = [14.042816227217203;10.829822894133768;-7.7236816033501636;4.6630989655237869;-1.6040654273298633;-0.65993667173065473;4.2289667275540159;-9.1592130579667526;12.13654091898813;-15.703978850857604];
IW1_1 = [-13.961737650057232;-14.033143496877679;14.033592553636298;-14.000368259946766;13.989659274275441;-13.927198867729832;11.381031227414059;-18.718887023153201;15.767556263365563;-12.280677436660298];% Layer 2
b2 = 1.0050712872879728;
LW2_1 = [-0.25740959435228478 0.25630456816917047 0.41476156959461874 -0.095876155369502725 -0.24659666733636154 -0.35777296228019673 0.095335365316523368 -0.01948709416037836 -0.044091570515430667 0.69616590295248804];% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 0.0745498123208475;
y1_step1.xoffset = -2.6807;% ===== 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
elseQ = 0;
end% Allocate Outputs
Y = cell(1,TS);% Time loop
for ts=1:TS% Input 1X{1,ts} = X{1,ts}';Xp1 = mapminmax_apply(X{1,ts},x1_step1);% Layer 1a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);% Layer 2a2 = repmat(b2,1,Q) + LW2_1*a1;% Output 1Y{1,ts} = mapminmax_reverse(a2,y1_step1);Y{1,ts} = Y{1,ts}';
end% Final Delay States
Xf = cell(1,0);
Af = cell(2,0);% 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% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end