所有输入坐标必须具有相同的类型。输入坐标必须为double或single类型。

9次浏览(最近30天)
我创建了一个7x1观察和2x1行动的自定义环境。当我尝试训练DDPG代理时,训练没有开始。取而代之的是一个弹出窗口,显示以下消息:
“无效的设置
所有输入坐标必须具有相同的类型。输入坐标必须为double或single类型。"
有人能帮我一下吗?输入坐标是什么,我要怎么改变它们?
我真的很期待一个答案,谢谢你的帮助!
2的评论
马克斯Figlestahler
马克斯Figlestahler 2021年7月13日
编辑:马克斯Figlestahler 2021年7月14日
嗨KSSV,
我真的不明白“输入”是什么。它们是在代理和环境之间交换的操作和观察,还是我在环境的类定义中定义的所有内容(例如属性)?
也许我还得说我用的是强化学习设计应用。
也许我的环境类定义代码是有帮助的。请注意,辅助函数(ecms、getnewsoc、geresistance、getreward)没有在最后的方法部分中定义。我将它们存储在与这个类定义相同的文件夹中,因为当我在类定义的方法块中定义它们时,无法找到它们。Matlab总是说
"使用rl.env出错。MATLABEnvironment/validateEnvironment (line 42)
计算阶跃函数时出现错误。
引起的:
未定义函数'getresistance'用于'double'类型的输入参数。"
也许这与辅助函数的定义有关?如果是,我如何在方法块中正确定义它们?
谢谢你的帮助!
classdef环境< rl.env.MATLABEnvironment
%ENVIRONMENT:在MATLAB中定义自定义环境的模板。
%%属性(相应设置属性的属性)
属性
T = 1;
Cycle = 0 (6,1);
cyclename =“abc”
Sigma_0 = 0;
Last_ess = 0;
P_batt_10 = 0 (1,10);
结束
属性(常量)
Dr1 = load()“根据dr1”);
Dr2 = load()“dr2”);
%齿轮比
i_gear = (5.354, 3.243, 2.252, 1.636, 1.211, 1.000, 0.865, 0.717, 0.601);
%终传动比
I_final = 3.07;
%质量因数
k_m = (1.32, 1.16, 1.11, 1.08, 1.07, 1.07, 1.07, 1.06, 1.06);
% [W]电机最大功率
P_e = 25000;
% [W]最大电池电量
P_batt_max = 33000;
滚动阻力系数
F_roll = 0.011;
% [kg]车辆质量
M = 1625;
% [kg]额外质量
M_a = 0;
% [m/s^2]重力加速度
G = 9.81;
% [kg/m^3]空气密度在20°C
Rho_air = 1.2;
% [m^2]空气阻力系数乘以面面积
Cda = 0.54;
% [m]车轮半径
R_wheel = 0.32;
% [W]附属于的力量
P_att = 800;
传动系统效率%
Eff_dt = 0.9;
% [J/kg]燃料低热值
H_f = 42.5e+6;
% [kg/J]往复燃料低热值
e_ICE = 2.35294e-8;
电池效率%
Eff_bat = 0.95;
% SOC列表
soc_list = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0);
% [As]电池容量
Q_b = 20*3600;
%[欧姆]电池内阻
R_int = 0.334 / 20;
% [V]在SOC的开路电压从SOC表
V_oc = (37.78, 45.30, 46.01, 46.56, 46.94, 47.38, 48.00, 48.78, 49.68, 50.66, 51.74);
%参考SOC
SOC_ref = 0.55;
最小SOC %
SOC_min = 0.3;
最大SOC %
SOC_max = 0.8;
% [rad/s] ICE速度表(0.10472=2pi/60)
w_ICE_list = 0.10472*[1100, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6300];
% [Nm] ICE转矩列表
t_ICE_list = [0, 30, 50, 70, 90, 110, 130, 150, 170, 190, 210, 230, 250, 270, 290, 310, 330, 350];
% ICE效率映射在w_ICE和t_ICE
eff_ICE_table = 0.01*[
0.01 21.18 26.06 28.71 30.80 32.33 33.35 34.16 34.57 34.16 33.22 32.70 32.21 31.96 31.96 31.96 31.96 31.96
0.01 21.18 26.47 29.72 31.84 33.09 34.16 34.86 35.29 35.00 35.00 34.72 34.02 33.22 32.96 32.33 32.21 32.09
0.01 21.18 26.47 29.72 31.73 32.96 34.02 34.86 35.29 35.29 35.29 35.15 34.72 34.16 33.48 33.22 33.09
0.01 21.18 26.47 29.41 31.61 32.83 34.02 34.86 35.29 35.29 35.29 35.29 35.00 34.57 34.29 34.02 33.48
0.01 20.17 25.67 28.42 30.91 32.33 33.48 34.29 35.00 35.29 35.29 35.29 35.29 34.86 34.29 33.88 32.58 32.21
0.01 20.17 25.29 28.24 30.36 31.84 32.83 33.75 34.29 34.72 34.86 34.72 34.43 33.88 33.22 32.33 31.37 30.25
0.01 20.17 24.20 27.50 29.41 30.80 31.73 32.70 33.35 33.88 33.88 33.35 32.58 32.58 31.84 30.80 30.04 29.72
0.01 18.82 23.53 26.47 28.52 29.72 30.80 31.61 31.73 31.61 31.26 31.37 31.14 31.26 30.47 30.04 29.72 29.72
0.01 18.82 23.21 25.51 27.32 28.52 29.72 30.25 30.36 30.25 30.04 30.04 29.62 29.51 29.41 29.41 29.41
0.01 18.82 21.44 24.20 26.22 27.50 28.62 28.62 28.52 28.52 28.42 28.52 28.71 28.71 28.71 28.71
0.01 18.82 20.17 23.02 24.62 25.67 26.31 26.64 26.64 25.82 25.51 24.55 24.55 24.55 24.55 24.55 24.55
[0.01 18.82 20.17 22.00 23.33 24.20 24.91 25.29 25.67 24.91 24.20 24.20 24.20 24.20 24.20 24.20];
w_ICE和t_ICE的% [kg/s]消耗率图
consrate_ICE_table = cell2mat(struct2cell(load))“consrate_ICE_table”)));
% [rad/s] ICE阻力速度列表
w_ICE_drag_list = 0.10472*[0,1000, 2000, 3000, 4000, 5000, 6000];
% [Nm] ICE阻力扭矩列表
t_ICE_drag_list = (6.3, 6.3, 8.4, 10.7, 13.1, 17.0, 20.7);
% [rad/s]电机转速列表
W_em_list = 0.10472*[0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000];
% [Nm]电机转矩表
T_em_list = 15000 / 40000 *[-260, -230, -200, -170, -140, -110, -80, -50, -20, -11, -5, 0, 5, 10, 20, 50, 80, 110, 140, 170, 200, 230, 260];
%在w_em和t_em的电机效率图
Eff_em_table = 0.01*[
0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 50.0 50.0 50.0 50.0 50.0 50.0 50.0
80.0 80.0 85.0 86.0 82.5 78.7 74.6 71.6 68.8 66.4 64.8
70.0 73.2 77.0 80.0 83.5 86.5 89.4 91.5 90.0 85.0 70.0 50.0 70.0 82.0 90.0 91.6 90.0 87.5 85.5 83.1 81.1 78.8 76.4
80.4 82.2 84.5 86.4 88.3 90.3 91.7 93.0 90.0 83.0 70.0 50.0 70.0 82.0 90.0 92.9 92.3 91.2 89.5 87.5 86.3 85.0 84.0
84.5 86.1 87.8 89.5 91.1 94.2 92.0 87.0 70.0 50.0 70.0 85.0 91.2 94.0 93.1 92.2 90.9 59.5 88.0 88.0 88.0
89.5 89.5 91.0 92.4 93.8 94.5 94.7 93.0 89.0 70.0 50.0 70.0 85.0 91.0 93.4 93.1 92.2 91.0 90.0 90.0 90.0 90.0 90.0
91.5 91.5 91.5 92.8 94.1 94.8 95.3 93.0 88.0 70.0 50.0 70.0 84.0 90.5 93.1 92.8 92.1 91.0 91.0 91.0 91.0
92.8 92.8 92.8 92.8 92.8 94.1 95.0 95.7 92.7 80.0 50.0 70.0 82.0 90.0 92.7 92.4 91.8 91.8 91.8 91.8 91.8
92.6 92.6 92.6 93.8 94.7 95.3 92.0 85.0 70.0 81.0 89.0 92.2 92.0 91.0 91.0 91.0 91.0 91.0
93.2 93.2 93.2 94.3 94.7 92.0 85.0 50.0 70.0 80.0 87.5 91.6 91.0 91.0 91.0 91.0 91.0 91.0
90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5 90.5
93.5 93.5 93.5 93.5 93.8 90.0 82.0 70.0 50.0 70.0 85.6 90.3 90.0 90.0 90.0 90.0 90.0
92.8 92.8 92.8 92.8 92.8 92.8 93.0 90.0 80.0 70.0 50.0 70.0 75.0 85.0 88.0 88.0 88.0 88.0 88.0 88.0 88.0 88.0 88.0
];
结束
属性
%初始化系统状态[v, a, alpha, gear, soc, sigma, t_ICE]'
State = 0 (7,1)
结束
属性(访问=受保护)
初始化内部标志以表示插曲终止
IsDone = false
结束
%%必要的方法
方法
方法创建环境的实例
更改相应的类名和构造函数名
函数this = Environment()
%初始化观察设置
ObservationInfo = rlNumericSpec([71]);
ObservationInfo。Name =“车辆状态”
ObservationInfo。描述='v, a, alpha, gear, soc, sigma, t_ICE'
%初始化操作设置
ActionInfo = rlNumericSpec([21 1],“LowerLimit”0,“UpperLimit”1);
ActionInfo。Name =“车辆行动”
ActionInfo。描述=“λ,σ”
下面一行实现了RL环境的内置函数
this = this@rl.env.MATLABEnvironment(ObservationInfo,ActionInfo);
初始化属性值并预先计算必要的值
% updateActionInfo(这个);
结束
应用系统动力学和模拟环境
%给出一个步骤的动作。
函数[Observation,Reward,IsDone,LoggedSignals] = step(this,Action)
LoggedSignals = [];
v = this.State(1);
a = this.State(2);
alpha = this.State(3);
gear = this.State(4);
soc = this.State(5);
lastsigma = this.State(6);
lastt_ICE = this.State(7);
%计算驱动电阻
[F_w, w_wheel, w_曲柄,t_曲柄]= getreresistance (v, a, alpha,齿轮);
% ecm
lambda = Action(1);%等效系数
sigma = round(Action(2));% ICE开/关
[t_em_opt, fuel_opt, w_ICE, t_ICE, sigmapenalty] = ecms(t_crank, w_crank, lambda, sigma, soc);
%计算新的SOC
[volt, P_em, P_bat, I_b, newsoc] = getnewsoc(soc, t_em_opt, w_crank);
%保存变量
Results.soc (this.t) = soc;
results.F_w(this.t) = F_w;
results. w_曲柄(this.t) = w_曲柄;
results. t_曲柄(this.t) = t_曲柄;
Results.t_em_opt (this.t) = t_em_opt;
results.w_ICE(this.t) = w_ICE;
results.t_ICE(this.t) = t_ICE;
Results.fuel_opt (this.t) = fuel_opt;
Results.volt (this.t) = volt;
results.P_em(this.t) = P_em;
results.P_bat(this.t) = P_bat;
results.I_b(this.t) = I_b;
Results.lambda (this.t) = lambda;
Results.sigma (this.t) = sigma;
文件名=这个。cyclename +“.results.mat”
保存(文件名,“结果”
%计算奖励
Delta_ess = sigma - lastsigma;
如果Delta_ess == 0
这一点。Last_ess =这个。Last_ess + 1;
elseifAbs (delta_ess) == 1
这一点。Last_ess = 0;
结束
K = 10:1:2将旧电池电量推远一步
this.P_batt_10(k) = this.P_batt_10(k-1);
结束
this. p_bat_10 (1) = P_bat;%保存上次电池电量值在数组中
奖励= getreward(sigma, sigmapenalty, w_ICE, t_ICE, delta_ess, this)。last_ess, soc, this.P_batt_10);
如果这一点。T < length(this.cycle.v)
New_t =这个。T + 1;
这一点。= new_t;
IsDone = false;
elseif这一点。T == length(this.cycle.v)
IsDone = true;
结束
V = this.cycle.v(this.t);
A = this.cycle (this.t);
Alpha = this.cycle.alpha(this.t);
齿轮= this.cycle.gear(this.t);
观察值= [v];一个;α;齿轮;newsoc;σ;t_ICE];
这一点。状态=观察;
结束
将环境重置为初始状态并输出初始观察值
函数[InitialObservation, t, cycle, cyclename] = reset(this)
这一点。T = 1;
N = mod(round(1200000*rand(1)),12);
开关n
情况下1
这一点。循环= this.dr1.dr1.dr1_1;
这一点。cyclename =“dr1_1”
情况下2
这一点。循环= this.dr1.dr1.dr1_3;
这一点。cyclename =“dr1_3”
情况下3.
这一点。循环= this.dr1.dr1.dr1_4;
这一点。cyclename =“dr1_4”
情况下4
这一点。循环= this.dr1.dr1.dr1_5;
这一点。cyclename =“dr1_5”
情况下5
这一点。循环= this.dr1.dr1.dr1_6;
这一点。cyclename =“dr1_6”
情况下6
这一点。循环= this.dr1.dr1.dr1_7;
这一点。cyclename =“dr1_7”
情况下7
这一点。循环= this.dr1.dr1.dr1_8;
这一点。cyclename =“dr1_8”
情况下8
这一点。循环= this.dr1.dr1.dr1_9;
这一点。cyclename =“dr1_9”
情况下9
这一点。循环= this.dr1.dr1.dr1_11;
这一点。cyclename =“dr1_11”
情况下10
这一点。循环= this.dr1.dr1.dr1_12;
这一点。cyclename =“dr1_13”
情况下11
这一点。循环= this.dr1.dr1.dr1_13;
这一点。cyclename =“dr1_13”
情况下12
这一点。循环= this.dr1.dr1.dr1_14;
这一点。cyclename =“dr1_14”
结束
V = double(this.cycle.v(1));
A = double(this.cycle.a(1));
Alpha = double(this.cycle.alpha(1));
齿轮= double(this.cycle.gear(1));
soc = double(this.SOC_ref);在每个周期开始时,%随机SOC在0.3和0.8之间
Sigma = double(0);%从ICE开始
t_ICE = double(0);%从ICE开始
这一点。P_batt_10 = double(0 (1,10));
InitialObservation = [v;一个;α;齿轮;soc;σ;t_ICE];
这一点。State = InitialObservation;
这一点。T = 1;
%(可选)使用notifyEnvUpdated通知
%环境已更新(例如更新可视化)
% notifyEnvUpdated(这个);
结束
结束
%%可选方法(设置相应的方法属性)
方法(Access = public)
结束
方法(访问=受保护)
%(可选)每次更新环境时更新可视化
% (notifyEnvUpdated被调用)
%函数envUpdatedCallback(this)
%结束
结束
结束

登录评论。

答案(0)

世界杯预选赛小组名单社区寻宝

在MATLAB Central中找到宝藏,并发现社区如何帮助您!世界杯预选赛小组名单

开始狩猎!

Baidu
map