I want to know the way to fix the erorr.
The error masage said that make the value finite.
There are four input state variables.
How can I fix it?
function set.State(this,state)
validateattributes(state,{'numeric'},{'finite','real','vector','numel',4},'','State');
this.State = double(state(:));
notifyEnvUpdated(this);
end

댓글 수: 5

Gargi Patil
Gargi Patil 2021년 8월 11일
Hi! Can you share the code for state as it is difficult to determine the cause of the error without knowing its values? You can use the function isfinite to find out which value(s) in state is(are) not finite and fix it accordingly.
Below is the code.
% pendulum throwing ball to target point.
classdef MyEnvironment < rl.env.MATLABEnvironment
properties
m = 1.0; % mass of pendulum
L = 1.0; % length of pendulum
g = 9.8; % gravity
b = 0.01; % Coefficient of friction
MaxForce = 75; % Troque
Ts = 0.04; % time step
Target = 2.5; % target point
RewardForNotFalling = 0; % negative reward
RewardForStrike = 10; % positive reward
PenaltyForFalling = -10; % punishment
State = [0 0 0 0]'; % ovservation angular, angular velocity, ball's distance, troque
end
properties(Access = protected)
IsDone = false
end
methods
function this = MyEnvironment()
ObservationInfo = rlNumericSpec([4 1]);
ObservationInfo.Name = 'States';
ObservationInfo.Description = 'theta,w,ball_gosa,u';
ActionInfo = rlNumericSpec([1 1],'LowerLimit',30,'UpperLimit',75);
ActionInfo.Name = 'Action';
ObservationInfo.Description = 'F';
this = this@rl.env.MATLABEnvironment(ObservationInfo,ActionInfo);
updateActionInfo(this);
end
function [Observation,Reward,IsDone,LoggedSignals] = step(this,Action)
LoggedSignals = [];
Force = getForce(this,Action);
theta = this.State(1);
w = this.State(2);
IsDone = false;
R = 0;
% pendulum dynamics by eulur method
q2 = w - (this.g/this.L) *theta*this.Ts- this.b * this.Ts-Force*this.Ts;
q1 = theta + w * this.Ts;
% ball dynamics
ball_x = this.L * sin(q1);
ball_y = -this.L * cos(q1);
ball_time = sqrt(2*abs(ball_y)/9.8);
ball_reach = ball_x +abs(q2).*ball_time;
ball_gosa = ball_reach-this.Target;
q3 = ball_gosa;
% condition of reward
if 0 < q3 && q3 < 0.5
IsDone = true;
R = this.RewardForStrike;
else
R = this.RewardForNotFalling;
end
Observation = [q1 q2 q3 Force]';
this.State = Observation;
this.IsDone = IsDone;
Reward = getReward(this,R);
notifyEnvUpdated(this);
end
function InitialObservation = reset(this)
theta0 = 0;
w0 = 0;
ball_gosa0 = 0;
u0 = 0;
InitialObservation = [theta0 w0 ball_gosa0 u0]';
this.State = InitialObservation;
notifyEnvUpdated(this);
end
end
methods
function force = getForce(~,action)
force = action;
end
function updateActionInfo(this)
this.ActionInfo= this.ActionInfo;
end
% Reward function
function Reward = getReward(this,R)
if this.IsDone==1
Reward = R + this.RewardForStrike;
else
Reward = R + this.PenaltyForFalling;
end
end
function set.State(this,state)
validateattributes(state,{'numeric'},{'finite','real','vector','numel',4},'','State');
this.State = double(state(:));
notifyEnvUpdated(this);
end
function set.MaxForce(this,val)
validateattributes(val,{'numeric'},{'finite','real','positive','scalar'},'','MaxForce');
this.MaxForce = val;
end
function set.Ts(this,val)
validateattributes(val,{'numeric'},{'finite','real','positive','scalar'},'','Ts');
this.Ts = val;
end
function set.RewardForNotFalling(this,val)
validateattributes(val,{'numeric'},{'real','finite','scalar'},'','RewardForNotFalling');
this.RewardForNotFalling = val;
end
function set.PenaltyForFalling(this,val)
validateattributes(val,{'numeric'},{'real','finite','scalar'},'','PenaltyForFalling');
this.PenaltyForFalling = val;
end
function set.RewardForStrike(this,val)
validateattributes(val,{'numeric'},{'real','finite','scalar'},'','RewardForStrike');
this.RewardForStrike = val;
end
function set.L(this,val)
validateattributes(val,{'numeric'},{'finite','real','positive','scalar'},'','L');
this.L = val;
end
function set.m(this,val)
validateattributes(val,{'numeric'},{'finite','real','positive','scalar'},'','m');
this.m = val;
end
end
methods (Access = protected)
% (optional) update visualization everytime the environment is updated
% (notifyEnvUpdated is called)
function envUpdatedCallback(this)
plot(this.State)
hold on
XLimMode = 'auto';
YLimMode = 'auto';
end
end
end
Gargi Patil
Gargi Patil 2021년 8월 12일
Hi! Can you kindly share the workflow or the parameter values that throw this error?
ryunosuke tazawa
ryunosuke tazawa 2021년 8월 13일
Sorry for the late reply. This error has been fixed. However, the result of learning is not good.
Gargi Patil
Gargi Patil 2021년 8월 13일
Hi, a new question can be created for further queries about the results of the learning.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Reinforcement Learning Toolbox에 대해 자세히 알아보기

질문:

2021년 8월 8일

댓글:

2021년 8월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by