下面是我使用matlab训练好的神经网络模型请将他转化为python代码:function YXfAf = myNeuralNetworkFunctionXMYNEURALNETWORKFUNCTION neural network simulation function Auto-generated by MATLAB 13-Jun-2023 141912 Y = myNeuralNetwork
import numpy as np
def myNeuralNetworkFunction(X): # ===== NEURAL NETWORK CONSTANTS =====
# Input 1
x1_step1_xoffset = np.array([[3], [0]])
x1_step1_gain = np.array([[0.0256410256410256], [0.0293341155764154]])
x1_step1_ymin = -1
# Layer 1
b1 = np.array([[0.45112137680312625054], [-6.1538104568220415302], [7.5962696268251344023]])
IW1_1 = np.array([[1.4506933011474949513, 0.76817456380868365251], [1.6916436136071324459, -5.71371564825072209], [-2.4093150458006453718, -12.968325412425935284]])
# Layer 2
b2 = -1.2849816281640060733
LW2_1 = np.array([1.3930406566918007716, -1.1442966822471660748, 0.55133783902075017558])
# Output 1
y1_step1_ymin = -1
y1_step1_gain = 0.0463284688441047
y1_step1_xoffset = 2
# ===== SIMULATION ========
# Format Input Arguments
isCellX = isinstance(X, list)
if not isCellX:
X = [X]
# Dimensions
TS = len(X) # timesteps
if X:
Q = X[0].shape[0] # samples/series
else:
Q = 0
# Allocate Outputs
Y = []
# Time loop
for ts in range(TS):
# Input 1
Xp1 = np.matmul(x1_step1_gain, np.subtract(X[ts].T, x1_step1_xoffset))
# Layer 1
a1 = np.tanh(np.matmul(IW1_1, Xp1) + np.tile(b1, (1, Q)))
# Layer 2
a2 = np.matmul(LW2_1, a1) + b2
# Output 1
Y.append(np.matmul(y1_step1_gain, np.subtract(a2, y1_step1_ymin)) + y1_step1_xoffset)
Y = np.array(Y)
# Final Delay States
Xf = []
Af = []
# Format Output Arguments
if not isCellX:
Y = np.squeeze(Y)
return Y, Xf, A
原文地址: https://www.cveoy.top/t/topic/g9YP 著作权归作者所有。请勿转载和采集!