-
openAI gym 환경 생성 알아보기 (1)python source code 2023. 7. 22. 14:29728x90
spaces 에서 활용할 수 있는 메소드는 여러 종류가 있지만 사용할 알고리즘, 적용 어플리케이션의 특성에 맞게 선정해야 한다.

DQN 지원 특성 
A2C 지원 특성 
PPO 특성 강화학습 환경을 구축하기 위해 여러 자료들, 정보들을 검색해보고 있지만
생각보다 custom 환경 구축에 대한 자료들은 부족하다... 내용도 어렵거니와...
spases 클래스 MultiDiscrete 함수
함수는 이산 환경을 생성할 수 있으며 아래와 같이 각 사이즈, 벡터별 제한 값을 지정할 수 있다.
아래 코드는 테스트를 위한 10개의 샘플 환경을 추출하는 코드이다.
md = spaces.MultiDiscrete([3,4]) print(md[0]) for i in range(10): print(md.sample())코드를 실행하면 환경 상태 값 임의로 10개를 생성하며
MultiDiscrete 함수에서 정의한 값의 범위 내에서 생성되는 것을 확인할 수 있다.
[0 0] [0 3] [2 1] [0 3] [2 0] [0 3] [1 1] [2 3] [1 2] [0 2]특징 중 하나는 아래처럼 환경에 값을 할당하는 것은 불가능하다.
test = JobShopEnvironment() state_1 = test.observation_space # for i in range(10): # print(state_1.sample()) print(state_1[0]) state_1[0][1] = 0 print(state_1[0][1])---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-34-5a6786f7d4cd> in <cell line: 7>() 5 6 print(state_1[0]) ----> 7 state_1[0][1] = 0 8 print(state_1[0][1])TypeError: 'MultiDiscrete' object does not support item assignmentc.f. Discrete 함수는 단일 값에 대한 범위만 지정 가능
Discrete observations are one-hot encoded, e.g. Discrete(3) and value=1 -> [0, 1, 0].https://stable-baselines3.readthedocs.io/en/master/modules/a2c.html
A2C — Stable Baselines3 2.1.0a2 documentation
Warning If you find training unstable or want to match performance of stable-baselines A2C, consider using RMSpropTFLike optimizer from stable_baselines3.common.sb2_compat.rmsprop_tf_like. You can change optimizer with A2C(policy_kwargs=dict(optimizer_clas
stable-baselines3.readthedocs.io
반응형'python source code' 카테고리의 다른 글
np zeros 타입에러 'cannot interpret '2' as a data type' (0) 2023.07.30 openAI gym 환경 생성 알아보기 (2) (0) 2023.07.22 python 멀티프로세싱 pool process 에 대한 정리 (2) 2023.06.20 Streamlit 모듈을 활용한 웹 페이지 디자인 (사이트) (0) 2023.06.09 openAI gym API 관련 예제 (1) 2023.05.29