top of page

The AI Blog

information about the rapid developments of AI to teens, from a teen :).

Most technical information comes from outside sources but summarized into my own words for easier understanding for the readers.

Post: Text
Post: Text

Reinforcement Learning Day 6

  • arimilli5
  • Jul 19, 2023
  • 2 min read

Hey guys! Today I am going to be explaining my custom OpenAI Gym Environment, made for medical diagnosis.


The Explaination:

  1. The code begins by importing the necessary libraries: gym, which provides the OpenAI Gym framework for creating RL environments, and random for generating random numbers.

  2. The class "MedicalDiagnosisEnv" is defined, and it inherits from the gym.Env class, which makes it compatible with the OpenAI Gym.

  3. In the "__init__" method, the environment is initialized. It sets up the possible symptoms and actions that can be taken. For example, "self.symptoms" represents different symptoms, and "self.actions" includes possible actions that can be taken (in this case, "yes," "no," or "unknown").

  4. The observation space is defined using "spaces.MultiBinary", which represents a binary vector for the presence or absence of each symptom.

  5. The action space is defined using "spaces.Discrete", which represents a discrete set of actions (in this case, indices 0, 1, 2 representing "yes," "no," and "unknown").

  6. The initial state of the environment is set with "self.current_symptoms" containing all zeros, representing no symptoms initially. The "self.current_diagnosis" is set to None initially.

  7. The reset method is implemented to reset the environment to its initial state. It randomly chooses a "self.current_diagnosis" from the list of "self.correct_diagnosis", which represents the true diagnosis.

  8. The step method simulates an agent taking an action in the environment. It takes an action as input, which is the index of the action space representing yes, no, or unknown. For each step, the current step count is incremented.

  9. The method checks if the maximum number of steps (self.max_steps) has been reached. If so, it returns the current symptoms, a reward of 0, and a boolean value indicating that the episode is done.

  10. If the maximum steps have not been reached, the method updates the state (self.current_symptoms) based on the chosen action. It sets the corresponding symptom index to 1 to indicate the presence of the symptom.

  11. The method calculates the reward as 1 if the chosen diagnosis matches the true diagnosis (self.current_diagnosis). Otherwise, the reward is 0.

  12. The method sets the "done" flag to True if the diagnosis is correct (reward = 1), indicating that the episode is finished.

  13. The render method is implemented for debugging purposes. It prints the current state of symptoms and the current diagnosis.

Overall, this code creates a simple environment for a medical diagnosis task, where the agent can take actions based on symptoms and receive rewards based on the accuracy of its diagnosis.


 
 
 

Recent Posts

See All

Commentaires


Post: Blog2 Post

©2022 by moondeavors

  • Facebook
  • Instagram
bottom of page