<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="/SIDM/feed.xml" rel="self" type="application/atom+xml" /><link href="/SIDM/" rel="alternate" type="text/html" /><updated>2023-05-09T17:02:35+00:00</updated><id>/SIDM/feed.xml</id><title type="html">SIDM-Structural Information Decision-Making Framework for Reinforcement Learning</title><subtitle>Repository for SIDM, a novel unsupervised adaptive framework improving policy quality, stability, and sample efficiency in RL scenarios (Deep RL, Hierarchical RL, Multi-Agent RL). Includes code, examples, and pretrained m</subtitle><entry><title type="html">gpt generated notes of learning the hsd3 repository</title><link href="/SIDM/reinforcement-learning/bipedal-robots/hierarchical-skills/2023/05/09/readcodes-hsd3.html" rel="alternate" type="text/html" title="gpt generated notes of learning the hsd3 repository" /><published>2023-05-09T15:58:56+00:00</published><updated>2023-05-09T15:58:56+00:00</updated><id>/SIDM/reinforcement-learning/bipedal-robots/hierarchical-skills/2023/05/09/readcodes-hsd3</id><content type="html" xml:base="/SIDM/reinforcement-learning/bipedal-robots/hierarchical-skills/2023/05/09/readcodes-hsd3.html">&lt;p&gt;this is my gpt generated notes of learning the hsd3 repository.&lt;/p&gt;
&lt;h2 id=&quot;prelude-learn-by-homework-not-gpt-genrated&quot;&gt;Prelude: learn by homework (not GPT genrated)&lt;/h2&gt;
&lt;p&gt;I create a hsd3_learn dir, that contains the commented version of the original code.
I make a try to let gpt4 turn the code into a programming homework (the one in Stanford CSw224 GNN) usng the promtps like&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;act as a Stanford CS TA for RL course who is humourous and good at 引导和启发 students.
Please design a programming home work in a  .py file : provide information and background like the purpose of function, variable meaning, library function usage and syntax etc. in the format comment, ask student to complete the function according to the prompt.
Now i will give you functions or class from real codebase one by one, turn them into the homework.py. 
don’t skip, ensuring every line is the same with the original codes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;you need to make students understand the whole database by home work.
in what order should you transform the code into homework, for better understanding
Considering the complexity of the codebase and the interconnectedness of the various components, a good strategy would be to start with the fundamental building blocks and gradually move towards the more complex functionalities. Here’s a recommended order to transform the code into homework assignments&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;add comment, 
provide information and background like the purpose of function, variable meaning, library function usage and syntax etc. in the format comment,
don’t skip, ensuring every line is the same with the original code&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;after finishing this helpful and interesting tutorial, one should be able to run the hsd3 and have a good understanding of the codebase.&lt;/p&gt;

&lt;p&gt;to my surprise now GPT4 is capable of reading 300+line of code&lt;/p&gt;

&lt;h2 id=&quot;outline&quot;&gt;Outline&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;prompts: you need to make students understand the whole database by home work.
in what order should you transform the code into homework, for better understanding
Considering the complexity of the codebase and the interconnectedness of the various components, a good strategy would be to start with the fundamental building blocks and gradually move towards the more complex functionalities. Here’s a recommended order to transform the code into homework assignments:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Exploring the codebase&lt;/strong&gt;: Before diving into specific files, you could assign a task for students to explore the codebase. Ask them to document the purpose of each directory and file. This will give them a broad understanding of the codebase structure.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Requirements and Setup&lt;/strong&gt;: Students should understand the software dependencies of the project. Assign them to study the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirements.txt&lt;/code&gt; file, install the necessary packages, and set up the project for development.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Configuration Files&lt;/strong&gt;: Start with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config&lt;/code&gt; directory. Understanding these files will provide students with insights into how different parts of the system are set up, such as the agent and environment configurations.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Utilities&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/utils.py&lt;/code&gt; file seems to contain utility functions that are likely used throughout the project. Understanding these will provide a good foundation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt;: Move on to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/models&lt;/code&gt; directory. Understanding the underlying models (e.g., bandits, blocks, traced) is key to comprehending the training process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Agents&lt;/strong&gt;: Next, tackle the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/agents&lt;/code&gt; directory. Each file appears to define a different type of agent, and understanding how these agents are defined and operate is crucial.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Environments&lt;/strong&gt;: Understanding the environment in which the agents operate is also crucial. Students should therefore study the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/envs&lt;/code&gt; directory next.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Replay Buffer and Hash Count&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/replaybuffer.py&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/hashcount.py&lt;/code&gt; files seem to implement important aspects of the agent’s memory and state tracking. These should be covered next.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rendering and Spaces&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/render.py&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/spaces.py&lt;/code&gt; files probably deal with the visualization and the state/action spaces of the environments. Understanding these will help students visualize the agent’s actions and the environment.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Training and Pretraining&lt;/strong&gt;: Finally, students should study the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;train.py&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pretrain.py&lt;/code&gt; scripts, as well as the corresponding scripts in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;learn_hsd3&lt;/code&gt; directory. These scripts will tie together everything the students have learned so far and show them how all these components interact during the training process.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember, each of these steps could itself be broken down into several smaller tasks to make the process more manageable. Also, encourage students to constantly test their understanding by running the code and experimenting with it. This hands-on experience will greatly facilitate their learning process.&lt;/p&gt;
&lt;h2 id=&quot;exploring-the-codebase&quot;&gt;Exploring the codebase&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;prompts: **Exploring the codebase according the given tree . outpuut **: Before diving into specific files, explore the codebase document the purpose of each directory and file. give me a broad understanding of the codebase structure. (explain uncommon names like hucc)
Sure, based on the structure you provided, here’s an overview of the directories and files:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CODE_OF_CONDUCT.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CONTRIBUTING.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LICENSE&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;README.md&lt;/code&gt; are standard files found in many repositories that provide guidance on how to interact with the project.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config&lt;/code&gt;: This directory contains configuration files (in YAML format), which specify parameters for different parts of the system. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;agent&lt;/code&gt; subdirectory contains configurations for different types of agents. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;common.yaml&lt;/code&gt; might contain settings common to all configurations.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hydra&lt;/code&gt;: Hydra is a framework for elegantly configuring complex applications. This directory might contain the setup for hydra and configurations related to it. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;launcher&lt;/code&gt; subdirectory probably contains configurations for launching jobs, for example, on a SLURM cluster.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;format&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nohup.out&lt;/code&gt;: These files could contain output logs or formatting instructions, though without more context it’s hard to say.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc&lt;/code&gt;: This directory seems to be the core of the project, containing several modules and files related to different aspects of the codebase. 
Based on the information and the code snippets you’ve provided, “HUCC” could potentially stand for “Hierarchical Unsupervised Control/Controller” or “&lt;strong&gt;Hierarchical Unsupervised Continuous Control&lt;/strong&gt;” given the context of the research paper “Hierarchical Skills for Efficient Exploration”. The paper proposes a hierarchical skill learning framework for reinforcement learning in continuous control tasks, which could explain the usage of “HUCC”.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;agents&lt;/code&gt;: This module probably contains implementations of different types of learning agents.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;envs&lt;/code&gt;: This module likely contains different environments in which the agents can operate.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hashcount.py&lt;/code&gt;: This might implement a data structure for counting occurrences of different items.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models&lt;/code&gt;: This module may contain different models used by the agents.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render.py&lt;/code&gt;: This file might be responsible for rendering or visualizing the agent’s behavior.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;replaybuffer.py&lt;/code&gt;: This file likely implements a replay buffer, which is a common component in reinforcement learning for storing past experiences.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spaces.py&lt;/code&gt;: This file might define different types of spaces (like action or observation spaces).&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;utils.py&lt;/code&gt;: This file likely contains utility functions used across the codebase.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;learn_hsd3&lt;/code&gt;: This directory might contain scripts and instructions for learning a specific model or task (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hsd3&lt;/code&gt;).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pretrain.py&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;train.py&lt;/code&gt;: These scripts are likely the entry points for pre-training and training the agents.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirements.txt&lt;/code&gt;: This file usually lists the Python dependencies required by the project.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scripts&lt;/code&gt;: This directory might contain auxiliary scripts for tasks like data preprocessing or analysis.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please note that these are educated guesses based on the names and typical structure of machine learning projects. For precise information, you should refer to the project’s documentation or the comments and docstrings in the code.&lt;/p&gt;

&lt;h2 id=&quot;utilities&quot;&gt;&lt;strong&gt;Utilities&lt;/strong&gt;:&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/utils.py&lt;/code&gt; file seems to contain utility functions that are likely used throughout the project. Understanding these will provide a good foundation.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Optimizers in PyTorch&lt;/strong&gt;:
 PyTorch provides several optimization algorithms that you can use to train your models. 
 These are implemented in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.optim&lt;/code&gt; module. To create an optimizer, you need to 
 pass the parameters of the model that the optimizer should update, and the learning rate.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Signal handling in Python&lt;/strong&gt;:
 Python’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;signal&lt;/code&gt; module provides mechanisms to handle various types of system signals, 
 including the SIGUSR1 signal. You can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;signal&lt;/code&gt; function from this module to register 
 a handler function that will be called when a specific signal is received.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Tensor indexing in PyTorch&lt;/strong&gt;:
 PyTorch provides several ways to index tensors. The simplest way is to use square brackets and 
 indices. However, if you want to perform more complex indexing, you can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index_select&lt;/code&gt; 
 or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gather&lt;/code&gt; methods. You will need to use one of these methods in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dim_select&lt;/code&gt; function.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Sorting strings naturally&lt;/strong&gt;:
 Python’s built-in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sorted&lt;/code&gt; function sorts strings lexicographically, which might not be what 
 you want if your strings contain numbers. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sorted_nicely&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sorted_nicely_sep&lt;/code&gt; functions 
 should sort strings in a way that humans would expect, e.g., “2” should come before “10”.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Recursive functions&lt;/strong&gt;:
 A recursive function is a function that calls itself during its execution. This allows the function 
 to be written in a more readable and elegant manner, at the expense of potentially higher memory usage. 
 You will need to write a recursive function to handle the potentially nested optimizers in the 
 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make_optim&lt;/code&gt; function.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;models&quot;&gt;&lt;strong&gt;Models&lt;/strong&gt;:&lt;/h2&gt;
&lt;p&gt;Move on to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/models&lt;/code&gt; directory. Understanding the underlying models (e.g., bandits, blocks, traced) is key to comprehending the training process.
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bandits&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blocks&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;traced&lt;/code&gt; files are all part of the codebase for a reinforcement learning system. They are grouped under the “models” directory because they collectively provide the components necessary for defining various aspects of the models used in reinforcement learning.&lt;/p&gt;

&lt;p&gt;Here’s an overview of what each of these components does:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bandits 老虎机:&lt;/strong&gt; In the context of reinforcement learning, a bandit is a type of problem where an agent must choose between a set of actions, each with an uncertain reward. The goal of the agent is to find the action with the highest expected reward. The term comes from the idea of a gambler at a row of slot machines (sometimes known as “one-armed bandits”) who has to decide which machines to play, how many times to play each machine, and in which order to play them, to maximize their return. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bandits.py&lt;/code&gt; file likely contains code for various bandit algorithms.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Blocks 预定义的GNN模块:&lt;/strong&gt; Blocks usually refer to pre-defined building blocks that can be used to construct neural networks. In this context, each “block” is a specific arrangement of layers in a neural network. Blocks can be combined and stacked to create complex network architectures. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blocks.py&lt;/code&gt; file probably contains code defining these building blocks.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Traced 模型跟踪:&lt;/strong&gt; The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;traced.py&lt;/code&gt; file likely contains code related to the tracing functionality provided by PyTorch’s JIT (Just-In-Time) compiler. Tracing allows you to convert your PyTorch model into a form that can be more efficiently executed in C++, while also allowing the model to be saved and loaded in different environments. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TracedModule&lt;/code&gt; class, which you provided in the code snippet, is an example of this. It wraps a given PyTorch module and provides tracing functionality to it.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Why are they under the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models&lt;/code&gt; directory?&lt;/p&gt;

&lt;p&gt;In machine learning projects, it’s common to organize code into directories based on their role in the system. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models&lt;/code&gt; directory typically contains all code related to model definition, training, and inference. Since bandit algorithms, network building blocks, and model tracing are all directly related to models, it makes sense to place them in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models&lt;/code&gt; directory. This organization helps other developers and researchers understand and navigate the codebase.&lt;/p&gt;

&lt;h3 id=&quot;bandit&quot;&gt;bandit&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;prompts: again, turn it into homework&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Homework: Multi-Armed Bandit Algorithms in Reinforcement Learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The goal of this assignment is to understand the concept of multi-armed bandit problems and various strategies for solving them using reinforcement learning techniques.&lt;/p&gt;

&lt;p&gt;The provided code defines a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bandit&lt;/code&gt; class and several subclasses, each of which implements a different strategy for solving the multi-armed bandit problem:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UniformBandit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EpsGreedyBandit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UCBBandit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DiscountedUCBBandit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SlidingWindowUCBBandit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Agent57Bandit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ThompsonBandit&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your task is to complete the following:&lt;/p&gt;

&lt;h4 id=&quot;task-1-understanding-bandit-strategies&quot;&gt;Task 1: Understanding Bandit Strategies&lt;/h4&gt;

&lt;p&gt;For each of the seven bandit strategies, provide a brief description of how the strategy works, and under what circumstances it might be a good choice. Use resources like textbooks, lecture notes, or online resources to aid your understanding.&lt;/p&gt;

&lt;h4 id=&quot;task-2-implement-new-bandit-strategy&quot;&gt;Task 2: Implement New Bandit Strategy&lt;/h4&gt;

&lt;p&gt;Create a new class, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YourBandit&lt;/code&gt;, that inherits from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bandit&lt;/code&gt; class and implements a different strategy for the multi-armed bandit problem. Explain why you chose this strategy and in which circumstances it could be superior to the existing ones.&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;YourBandit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Bandit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;action_space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gym&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;action_space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# TODO: Add any initialization code here
&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# TODO: Update estimates of action values
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sample_action&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# TODO: Decide on an action to take
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;best_action&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# TODO: Return the current best action
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;dist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# TODO: Return the current distribution over actions
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;task-3-test-your-bandit-strategy&quot;&gt;Task 3: Test Your Bandit Strategy&lt;/h4&gt;

&lt;p&gt;Test your bandit strategy on a multi-armed bandit problem of your choice. Compare its performance to the performance of the other bandit strategies. You can use the gym environment for creating the multi-armed bandit problem.&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# TODO: Code for testing bandit strategies
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;task-4-discussion&quot;&gt;Task 4: Discussion&lt;/h4&gt;

&lt;p&gt;Discuss the results of your experiments. Did your bandit strategy perform as expected? Why or why not? How did the different bandit strategies compare?&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Submit your completed assignment as a Python script or Jupyter notebook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;You may find the PyTorch documentation helpful, particularly the sections on distributions (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.distributions&lt;/code&gt;) and operations (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.nn.functional&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gym&lt;/code&gt; library is used for the action spaces. Be sure to understand how it works before proceeding with the assignment.&lt;/li&gt;
  &lt;li&gt;For &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Task 3&lt;/code&gt;, remember to average results over multiple runs to get reliable comparisons. The bandit problem has inherent randomness, so a single run may not be representative.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;blocks&quot;&gt;blocks&lt;/h3&gt;

&lt;p&gt;The provided code is a skeleton of some classes and functions that are commonly used in the domain of Reinforcement Learning (RL), particularly in policy gradient methods and model-based RL. These classes are typically used for different types of network architectures and the implementation of different types of policy and value functions.&lt;/p&gt;

&lt;p&gt;Please note that without the full implementation details, I can only provide a high-level summary of the potential purpose of each class and function.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TransformedDistribution&lt;/code&gt;: This class could be a subclass of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D.TransformedDistribution&lt;/code&gt;, a PyTorch class that creates a distribution by applying a sequence of transformations to a base distribution.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TransformDistribution&lt;/code&gt;: Likely a custom class to define a distribution transformed according to some specific rule. It’s a subclass of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nn.Module&lt;/code&gt;, suggesting that it might be a part of a neural network model.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GaussianFromEmbedding&lt;/code&gt;: This class might be used to generate a Gaussian distribution from an embedding vector, often used in policy networks where the output is a continuous action.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GaussianFromMulogstd&lt;/code&gt;: This class is probably used to generate a Gaussian distribution from a mean and log standard deviation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CategoricalFromEmbedding&lt;/code&gt;: This class might be used to create a categorical distribution from an embedding vector, often used in policy networks where the output is a discrete action.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MHGaussianFromEmbedding&lt;/code&gt;: This class could be used for generating a multivariate Gaussian distribution from an embedding. The “MH” prefix might refer to “Metropolis-Hastings”, a famous algorithm in sampling.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EmbedDiscreteSkill&lt;/code&gt;: This could be a class to create an embedding for a discrete skill, often used in hierarchical RL where an agent learns to perform a variety of “skills”.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SplitTaskInput&lt;/code&gt;: A class that might be used to split task input into several parts.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EinsumBilinear&lt;/code&gt;: This class might be an extension of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nn.Bilinear&lt;/code&gt; layer that utilizes Einstein summation convention for a specific operation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SkipNetwork&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SkipDoubleNetwork&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BilinearSkipNetwork&lt;/code&gt;: These classes likely represent different types of neural network architectures with skip connections, which provide shortcuts between layers to help gradient flow during backpropagation and mitigate the vanishing gradient problem.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GroupedLinear&lt;/code&gt;: This class might represent a linear layer where inputs are grouped and each group is processed separately.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Expandtasksubgoal&lt;/code&gt;: Likely a class to process task and subgoal information in an RL context, possibly for a hierarchical RL setup.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FlattenSpace&lt;/code&gt;: This class might take a complex state or action space and flatten it into a simpler space, which can be useful for preprocessing complex environments.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Parallel&lt;/code&gt;: This class might be used to apply the same operation to multiple inputs in parallel.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SqueezeLastDim&lt;/code&gt;: This class might remove the last dimension of the input, a common operation in tensor manipulation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shorthand&lt;/code&gt;: This function is likely a helper function to create a shorthand notation for something. Without more context, it’s hard to say exactly what it does.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FactoryType&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Factory&lt;/code&gt;: These are related to the Factory design pattern, which is used to create objects without specifying the exact class of object that will be created. This can make code more flexible, modular, and scalable.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make_model&lt;/code&gt;: This function probably creates an instance of a model. Without more context, it’s hard to say exactly what kind of model it creates.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember that these are general descriptions based on typical use cases in reinforcement learning and the names of classes and functions. The actual implementation in your code may differ. It’s always best to refer to the specific documentation or comments provided with the code.&lt;/p&gt;

&lt;h3 id=&quot;traced&quot;&gt;traced&lt;/h3&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TracedModule&lt;/code&gt; class in the provided code is a subclass of PyTorch’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nn.Module&lt;/code&gt;. It’s used to convert a PyTorch model into TorchScript via tracing, which is a way to create a serializable and optimizable version of your model.&lt;/p&gt;

&lt;p&gt;The main advantage of TorchScript is that it allows you to serialize your models, so you can save them to disk and load them in another environment (e.g., in a server doing inference). It also allows you to optimize your models and run them in a high-performance, strongly typed language.&lt;/p&gt;

&lt;p&gt;Here is what each part of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TracedModule&lt;/code&gt; class does:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__init__&lt;/code&gt;: This is the constructor method that gets called when you create an instance of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TracedModule&lt;/code&gt;. It takes as input an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nn.Module&lt;/code&gt; object &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;m&lt;/code&gt;, initializes the parent &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nn.Module&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super().__init__()&lt;/code&gt; and assigns the input module to the instance variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self.m&lt;/code&gt;. It also sets &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self._traced&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;None&lt;/code&gt;. This variable will later hold the traced version of the model.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forward&lt;/code&gt;: This method is called when you pass input data through the module. If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self._traced&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;None&lt;/code&gt; (meaning the model has not yet been traced), it uses the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;trace&lt;/code&gt; function from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.jit&lt;/code&gt; to trace the model &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self.m&lt;/code&gt; with the input data &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inp&lt;/code&gt; and assigns the traced model to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self._traced&lt;/code&gt;. Then it applies the traced model to the input data and returns the result.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forward&lt;/code&gt; method ensures that the model is only traced the first time &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forward&lt;/code&gt; is called, and the traced model is reused for subsequent calls. This allows you to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TracedModule&lt;/code&gt; just like any other PyTorch module, but under the hood it automatically converts the model to TorchScript the first time it’s run.&lt;/p&gt;

&lt;p&gt;Keep in mind that tracing has limitations: it can’t handle models with control flow (like if statements or loops) that depend on input data or model parameters, because it only captures the operations performed with the example input data it’s given. If your model has such control flow, you should use scripting instead of tracing.&lt;/p&gt;

&lt;p&gt;Also note that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forward&lt;/code&gt; method traces the model every time it’s run if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self._traced&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;None&lt;/code&gt;. In a multi-threaded environment, this could potentially result in the model being traced multiple times simultaneously. You might want to add thread-safety measures if you’re using this in a multi-threaded context.&lt;/p&gt;

&lt;h2 id=&quot;agents&quot;&gt;&lt;strong&gt;Agents&lt;/strong&gt;:&lt;/h2&gt;
&lt;p&gt;Next, tackle the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/agents&lt;/code&gt; directory. Each file appears to define a different type of agent, and understanding how these agents are defined and operate is crucial.&lt;/p&gt;

&lt;h3 id=&quot;hsd3&quot;&gt;hsd3&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;prompts( it changes the code): 
add comment, 
provide information and background like the purpose of function, variable meaning, library function usage and syntax etc. in the format comment,
don’t skip, ensuring every line is the same with the original codes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This completes the _update_hi method which is responsible for updating the high-level policy. The method performs updates on the Q-function, the policy, and the temperature parameter. These updates are done based on the policy gradient approach. The logs of the losses are then returned. The target network is also updated after each iteration to maintain stability in learning&lt;/p&gt;

&lt;h4 id=&quot;hitolointerface&quot;&gt;HiToLoInterface&lt;/h4&gt;

&lt;p&gt;In this code, HiToLo refers to a &lt;strong&gt;Hi&lt;/strong&gt;gh-Level &lt;strong&gt;to&lt;/strong&gt; &lt;strong&gt;Lo&lt;/strong&gt;w-Level interface. It represents an interface between high-level and low-level sub-agents, likely within a Hierarchical Reinforcement Learning (HRL) context.&lt;/p&gt;

&lt;p&gt;HRL is a type of reinforcement learning architecture that allows for learning and decision-making at various levels of abstraction. It typically involves high-level policies (or sub-agents) making more abstract, strategic decisions, and low-level policies carrying out the specific actions to achieve those strategic goals.&lt;/p&gt;

&lt;p&gt;In this case, the HiToLoInterface class seems to be handling the translation between the high-level and low-level sub-agents, including parsing information from the high-level agent and translating it into a form that the low-level agent can use, and vice versa.&lt;/p&gt;

&lt;p&gt;Here is the explanation of the Python code snippet you’ve provided:&lt;/p&gt;

&lt;p&gt;This script defines a class &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HiToLoInterface&lt;/code&gt; which is a part of a Hierarchical Reinforcement Learning (HRL) system. The class represents the interface between a high-level and a low-level policy.&lt;/p&gt;

&lt;p&gt;The main role of this class is to manage the transition between high-level policies (which decide on abstract goals) and low-level policies (which execute specific actions to achieve these goals).&lt;/p&gt;

&lt;p&gt;Key methods and elements of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HiToLoInterface&lt;/code&gt; class:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__init__(self, env, cfg: DictConfig)&lt;/code&gt;: The constructor of the class that takes in the environment and a configuration dictionary as arguments. It prepares all the necessary variables, configurations, and spaces based on the input configuration. It also sets up goal spaces and task maps.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parse_lo_info(cfg)&lt;/code&gt;: This static method loads low-level information from a provided configuration. It returns subsets and task maps.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;action_mask_hi(self)&lt;/code&gt;: This method generates a mask for high-level actions based on subsets of features in the goal space.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gs_obs(self, obs)&lt;/code&gt;: This method returns the goal space observations from the overall observations.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translate(self, gs_obs, task, subgoal, delta_gs_obs=None)&lt;/code&gt;: This method translates the goal space observations, task and subgoal into the low-level policy’s action space.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;update_bp_subgoal(self, gs_obs, next_gs_obs, action_hi)&lt;/code&gt;: This method updates the backprojected subgoal based on the current and next goal space observations, and the high-level action.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;observation_lo(self, o_obs, action_hi)&lt;/code&gt;: This method constructs a low-level observation from the overall observation and the high-level action.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dist_lo(self, gs_obs, task, subgoal)&lt;/code&gt;: This method calculates the distance between the projected current state and the subgoal in the low-level policy’s action space.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reward_lo(self, gs_obs, next_gs_obs, task, subgoal)&lt;/code&gt;: This method calculates a potential-based reward for the low-level policy.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log_goal_spaces(self)&lt;/code&gt;: This method logs the information about the goal spaces.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This class heavily relies on PyTorch and the gym library for handling tensors and constructing spaces, respectively. It also uses some custom classes like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CtrlgsPreTrainingEnv&lt;/code&gt; for certain operations.&lt;/p&gt;

&lt;h2 id=&quot;environments&quot;&gt;&lt;strong&gt;Environments&lt;/strong&gt;:&lt;/h2&gt;
&lt;p&gt;Understanding the environment in which the agents operate is also crucial. Students should therefore study the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/envs&lt;/code&gt; directory next.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;add comment in a code review paradigm: provide information and background like the purpose of function, variable meaning, library function usage and syntax etc. in the format comment,
make sure every line is the same with the original codes. 
when i say continue, directly generate the continuous upcomming content.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Replay Buffer and Hash Count&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/replaybuffer.py&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/hashcount.py&lt;/code&gt; files seem to implement important aspects of the agent’s memory and state tracking. These should be covered next.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Rendering and Spaces&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/render.py&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hucc/spaces.py&lt;/code&gt; files probably deal with the visualization and the state/action spaces of the environments. Understanding these will help students visualize the agent’s actions and the environment.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;configure&quot;&gt;configure&lt;/h2&gt;

&lt;p&gt;Hydra is a powerful open-source library for developing applications that have complex configurations. It simplifies the handling of configurations for Python applications, allowing you to manage and organize your configurations efficiently. Hydra uses a structured configuration approach which enables easier configuration management and validation.&lt;/p&gt;

&lt;h3 id=&quot;commonyml&quot;&gt;common.yml&lt;/h3&gt;
&lt;p&gt;Here is a brief introduction of some Hydra syntax and functionalities shown in the configuration file:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hydra.run.dir&lt;/code&gt;: This parameter defines the directory in which the application will be run. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.&lt;/code&gt; signifies that the application will run in the current directory.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hydra.sweep.dir&lt;/code&gt;: This is used when running sweep jobs (multiple runs of the application with different configurations). The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${now:%Y}&lt;/code&gt;-style syntax is used to interpolate the current date and time into the directory path. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${oc.env:USER}&lt;/code&gt; syntax retrieves the current user’s name from the environment variables.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;slurm&lt;/code&gt;: This section is specific to running the application on a Slurm workload manager, typically found on high-performance computing clusters. Parameters like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;partition&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cpus_per_task&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gpus_per_task&lt;/code&gt;, etc., define the resources requested for the Slurm job.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;seed&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;device&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log_level&lt;/code&gt;: These parameters specify the random seed, the device to use for computation (CPU or GPU), and the logging level for the application, respectively.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;visdom&lt;/code&gt;: Visdom is a visualization tool for PyTorch. Parameters under this key configure the Visdom server.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;checkpoint_path&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keep_all_checkpoints&lt;/code&gt;: These parameters define where to save the model checkpoints and whether to keep all checkpoints or just the most recent one.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;env&lt;/code&gt;: This section configures the training and evaluation environments.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval&lt;/code&gt;: This section contains parameters related to the evaluation of the model, such as the interval between evaluations and the metrics to compute.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;video&lt;/code&gt;: This section contains parameters for recording videos of the training and evaluation sessions.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hydra uses the YAML syntax for its configuration files. YAML is a human-readable data serialization standard that’s ideal for configuration files and data exchange between languages with different data structures. In the provided YAML file, keys and values are separated by a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:&lt;/code&gt; and nested parameters are represented by indentation.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${...}&lt;/code&gt; syntax in Hydra is used for interpolation, where the value of one config parameter is used in another. For example, in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${env.args}&lt;/code&gt;, the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;env.args&lt;/code&gt; will be inserted in place of the entire &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${env.args}&lt;/code&gt; string.&lt;/p&gt;

&lt;p&gt;Finally, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; in YAML signifies the absence of a value or that the value is not applicable in this context.&lt;/p&gt;

&lt;p&gt;For a more comprehensive understanding, the official Hydra documentation is a great resource: https://hydra.cc/docs/intro/.&lt;/p&gt;

&lt;h3 id=&quot;humanoidyml&quot;&gt;humanoid.yml&lt;/h3&gt;

&lt;h4 id=&quot;hsd3-1&quot;&gt;hsd3&lt;/h4&gt;
&lt;p&gt;Here’s a brief explanation of the parameters in the YAML configuration file:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaults&lt;/code&gt;: This field includes references to other configuration files, essentially saying “include the settings defined in these files as a starting point”. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;- common&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;- agent: hsd3&lt;/code&gt; lines mean that the configuration defined in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;common.yaml&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hsd3.yaml&lt;/code&gt; files (under the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;agent&lt;/code&gt; directory) are loaded as defaults. If the same parameter is defined in this configuration file and in one of the default configuration files, the value in this configuration file will be used.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max_steps&lt;/code&gt;: This is the maximum number of training steps.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;robot&lt;/code&gt;: Specifies the type of robot to be used in the environment.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;goal_space&lt;/code&gt;: Specifies the goal space (or the representation of the goals) for the task.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subsets&lt;/code&gt;: This could be a parameter to specify which subsets of the data to use.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;action_interval&lt;/code&gt;: The number of environment steps between two actions.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eps&lt;/code&gt;: This is typically a parameter related to the exploration strategy (epsilon-greedy, for instance), where a random action is selected with probability &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eps&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto_adapt&lt;/code&gt;: Flag for automatic adaptation of the configuration based on the environment.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval&lt;/code&gt;: This section configures the evaluation of the model, such as the interval between evaluations and the metrics to compute.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;video&lt;/code&gt;: This parameter controls the video recording of the training and evaluation sessions. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; means no video recording.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;visdom.offline&lt;/code&gt;: This parameter decides whether to use the offline mode of visdom for visualization.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;env&lt;/code&gt;: This section configures the training and evaluation environments.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;agent&lt;/code&gt;: This section contains parameters specific to the agent, such as the batch size, replay buffer size, number of updates, goal space, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;model&lt;/code&gt;: This section defines the models to be used for the different components of the agent.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;optim&lt;/code&gt;: This section specifies the optimizers to be used for training the different components of the agent, along with their learning rates.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the provided YAML file, keys and values are separated by a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:&lt;/code&gt; and nested parameters are represented by indentation. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${...}&lt;/code&gt; syntax in Hydra is used for interpolation, where the value of one config parameter is used in another. For example, in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${robot}&lt;/code&gt;, the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;robot&lt;/code&gt; will be inserted in place of the entire &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${robot}&lt;/code&gt; string.&lt;/p&gt;

&lt;h4 id=&quot;pretrain&quot;&gt;pretrain&lt;/h4&gt;

&lt;p&gt;Sure, here’s a brief explanation of the additional parameters in this YAML configuration file:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;horizon&lt;/code&gt;: This could refer to the planning horizon, which is the number of steps into the future the agent should consider when making decisions.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;idle_steps&lt;/code&gt;: This might be the number of initial steps for which the agent takes no action.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;features&lt;/code&gt;: This specifies the type of features to be used for the task.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature_dims&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature_rank&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature_rank_max&lt;/code&gt;: These parameters could be related to feature selection or dimensionality reduction.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ctrl_eps&lt;/code&gt;: This could be a parameter for controlling the agent’s exploration strategy.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;precision&lt;/code&gt;: This could be related to the precision of the goal representation or the precision with which the agent should achieve its goals.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max_new_tasks&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;task_weighting&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;downrank&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lp_new_task&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lp_eps&lt;/code&gt;: These parameters appear to be related to the task generation and selection process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval_mode&lt;/code&gt;: This could be a mode for the evaluation process. In this case, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reachability&lt;/code&gt; could mean that the agent is evaluated based on its ability to reach different goals.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;combine_after_steps&lt;/code&gt;: This might be the number of steps after which certain operations (like merging of tasks or updates) should be performed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backprop_fallover&lt;/code&gt;: This flag could control whether to use a specific technique (like fallover) during backpropagation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;estimate_joint_spaces&lt;/code&gt;: This could be a flag for estimating the joint spaces of the robot. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; means this option is not used.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init_model_from&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;checkpoint_path&lt;/code&gt;: These parameters could be used to initialize the agent’s model from a checkpoint.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;distributed&lt;/code&gt;: This section configures the distributed training setup, like the number of actors and learners and the path for storing rendezvous files.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;agent.flatten_obs&lt;/code&gt;: This parameter could decide whether to flatten the observation before feeding it into the agent’s model.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;agent.per_task_alpha&lt;/code&gt;: This could be a flag for using a different &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha&lt;/code&gt; parameter (which usually controls the trade-off between exploration and exploitation) for each task.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;model.reachability&lt;/code&gt;: This could specify the model to be used for estimating the reachability of different goals.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${...}&lt;/code&gt; syntax in Hydra is used for interpolation, where the value of one config parameter is used in another. For example, in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${robot}&lt;/code&gt;, the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;robot&lt;/code&gt; will be inserted in place of the entire &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${robot}&lt;/code&gt; string.&lt;/p&gt;

&lt;p&gt;Remember, these explanations are based on general machine learning concepts and some educated guesses. The actual meaning of the parameters could be different and could be understood by reading the documentation or the code of the specific project.&lt;/p&gt;

&lt;h2 id=&quot;train--pretrain&quot;&gt;Train &amp;amp; pretrain&lt;/h2&gt;

&lt;p&gt;use GPT to add comment is the most common use.&lt;/p&gt;

&lt;p&gt;here we explore usage of using GPT-4 to learn codes&lt;/p&gt;

&lt;h3 id=&quot;copy-in-blank-pretrainpy&quot;&gt;copy in blank pretrain.py&lt;/h3&gt;

&lt;p&gt;generate comment and the hide code, ask user to copy and paste according to the prompt.&lt;/p&gt;

&lt;h3 id=&quot;trainpy&quot;&gt;train.py&lt;/h3&gt;</content><author><name></name></author><category term="reinforcement-learning" /><category term="bipedal-robots" /><category term="hierarchical-skills" /><summary type="html">this is my gpt generated notes of learning the hsd3 repository. Prelude: learn by homework (not GPT genrated) I create a hsd3_learn dir, that contains the commented version of the original code. I make a try to let gpt4 turn the code into a programming homework (the one in Stanford CSw224 GNN) usng the promtps like</summary></entry><entry><title type="html">Hierarchical Skill Learning for Bipedal Robots: Concepts and Examples</title><link href="/SIDM/reinforcement-learning/bipedal-robots/hierarchical-skills/2023/05/08/hsd3-readpaper.html" rel="alternate" type="text/html" title="Hierarchical Skill Learning for Bipedal Robots: Concepts and Examples" /><published>2023-05-08T14:58:56+00:00</published><updated>2023-05-08T14:58:56+00:00</updated><id>/SIDM/reinforcement-learning/bipedal-robots/hierarchical-skills/2023/05/08/hsd3-readpaper</id><content type="html" xml:base="/SIDM/reinforcement-learning/bipedal-robots/hierarchical-skills/2023/05/08/hsd3-readpaper.html">&lt;h2 id=&quot;concepts&quot;&gt;Concepts&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Pretrained skills (预训练技能, yùxùnliàn jìnéng):&lt;/strong&gt; In reinforcement learning, pretrained skills refer to abilities or behaviors that an agent has already learned before tackling a new task. These skills can be acquired through prior training on related tasks or through unsupervised learning. For example, a bipedal robot may have pretrained skills for walking, jumping, or balancing that can be used in various new tasks.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Balance between generality and specificity (通用性与特异性的平衡, tōngyòngxìng yǔ tèyìxìng de píng héng):&lt;/strong&gt; This refers to the trade-off between designing skills that are broadly applicable across many tasks (generality) and skills that are tailored to a specific task (specificity). For instance, a general skill for a robot could be walking, while a specific skill might be walking on a tightrope. General skills can be useful for many tasks, but may require more fine-tuning for optimal performance. Specific skills can lead to faster learning, but are limited in their applicability.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Continuous control (连续控制, liánxù kòngzhì):&lt;/strong&gt; Continuous control is a type of reinforcement learning problem where the agent’s actions are continuous rather than discrete. For example, a robot’s joint angles or motor torques are continuous variables. Continuous control is often more challenging than discrete control due to the infinite number of possible actions.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Locomotion (运动, yùndòng):&lt;/strong&gt; In the context of robotics and reinforcement learning, locomotion refers to the ability of an agent, like a bipedal robot, to move from one place to another. Locomotion skills can include walking, running, jumping, or crawling.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Sparse-reward (稀疏奖励, xīshū jiǎnglì):&lt;/strong&gt; Sparse-reward refers to reinforcement learning tasks where the agent receives feedback (rewards or penalties) infrequently. This can make it difficult for the agent to learn, as it has to explore the environment extensively to discover which actions lead to rewards. For example, a robot trying to find a hidden object in a room might only receive a reward once it successfully locates the object, without any intermediate feedback.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The paper presents a hierarchical skill learning framework that allows the agent to learn skills of varying complexity without prior knowledge of the task. This framework helps the agent effectively balance generality and specificity, leading to better performance in diverse, sparse-reward tasks for bipedal robots.&lt;/p&gt;

&lt;h3 id=&quot;advanced-concepts&quot;&gt;advanced concepts&lt;/h3&gt;
&lt;p&gt;Imagine a bipedal robot learning to navigate through a complex environment filled with obstacles. The robot needs to learn various skills, such as walking, turning, and climbing, to efficiently explore and complete tasks in the environment.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Skill policy (技能策略, jìnéng cèlüè):&lt;/strong&gt; Individual skill policies control specific aspects of the robot’s behavior. For example, one skill policy might control the movement of the left leg, while another controls the right leg.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Shared policy (共享策略, gòngxiǎng cèlüè):&lt;/strong&gt; The shared policy is used to represent multiple skills or behaviors with a single policy. In this example, the shared policy could represent both the left and right leg movements, as well as more complex behaviors like turning or climbing.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hierarchy of skills (技能层次, jìnéng céngcì):&lt;/strong&gt; Skills are organized into a hierarchy based on their complexity. In this case, simpler skills like moving individual legs form the lower levels of the hierarchy, while more complex skills like turning and climbing are at higher levels.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-level control signal (高级控制信号, gāojí kòngzhì xìnhào):&lt;/strong&gt; The high-level control signal is provided by a higher-level policy that guides the robot’s overall behavior. In our example, the high-level control signal might instruct the robot to move towards a specific target or avoid an obstacle, which then influences the low-level skill policies, such as leg movements and turning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Robot configuration (机器人配置, jīqìrén pèizhì):&lt;/strong&gt; The robot’s configuration refers to its current state, including positions, orientations, and joint angles. In this scenario, the robot’s configuration might include the positions of its legs, torso, and other body parts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;method&quot;&gt;method&lt;/h2&gt;

&lt;h3 id=&quot;personal-gpt4s-notes&quot;&gt;personal (GPT4’s) notes&lt;/h3&gt;

&lt;p&gt;The authors propose an approach that first acquires low-level policies capable of carrying out a useful set of skills in an unsupervised manner, meaning without reward signals from the main tasks of interest. These skills are then used in a hierarchical reinforcement learning setting.&lt;/p&gt;

&lt;p&gt;The pre-training environment consists only of the robot, while in downstream tasks, additional objects may be present. These objects could be fixed (e.g., obstacles) or only indirectly controllable (such as a ball).&lt;/p&gt;

&lt;h4 id=&quot;low-level-skills-and-goal-spaces&quot;&gt;Low-Level Skills and Goal Spaces&lt;/h4&gt;

&lt;p&gt;The usefulness of a skill policy comes from providing additional structure for effective exploration. To provide benefits across a wide range of tasks, skills need to support both fast, directed exploration (e.g., locomotion) and precise movements (e.g., lift the left foot while bending down). The authors propose short-horizon, goal-directed low-level policies trained to achieve target configurations of robot-level state features, such as the position or orientation of its torso or relative limb positions.&lt;/p&gt;

&lt;p&gt;This approach allows defining a hierarchy of skills by controlling single features and their combinations, resulting in varying amounts of control exposed to high-level policies. Each skill is trained to reach goals in a goal space defined over a set of features, yielding policies without task-specific rewards. These policies rely solely on state features related to the specific robot and the prescribed hierarchy of goal spaces.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A feature, in the context of this work, refers to a specific property or characteristic of the robot’s state. State features can include the position, orientation, or relative limb positions of the robot. These features help describe the current situation or configuration of the robot in the environment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;In this approach, low-level policies are trained to achieve target configurations of robot-level state features, such as reaching a certain position or orientation. The authors define a hierarchy of skills by controlling single features and their combinations, which results in different levels of control exposed to high-level policies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;A goal space is defined over a set of features. In this case, the goal space represents a collection of possible goals that can be achieved by manipulating these specific features. For instance, a goal space could be defined over the position and orientation features, meaning that the goals within this space would be related to reaching different positions and orientations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;These low-level policies (skills) do not rely on task-specific rewards; instead, they are trained based on the state features of the robot and the prescribed hierarchy of goal spaces. By focusing on state features and goal spaces, the approach enables the robot to learn a variety of skills that can be useful across a wide range of tasks. The high-level policy then selects and combines these low-level skills to accomplish the specific tasks it is given.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;high-level-policy-and-task-specific-features&quot;&gt;High-Level Policy and Task-Specific Features&lt;/h4&gt;

&lt;p&gt;On downstream tasks, high-level policies operate with a combinatorial action space. State spaces are enriched with task-specific features containing information regarding additional objects in the downstream task. This enriched state space is only available to the high-level policy. The high-level policy is modeled hierarchically with two policies that prescribe a goal space and a goal, respectively.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;“Prescribe” here means that the high-level policy determines or selects the goal space and goal to be used by the low-level policies. It chooses the appropriate goal space and goal based on the current state and the task requirements.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;Action space refers to the set of all possible actions that an agent (in this case, the robot) can take in a given environment. In the context of this work, “operate with a combinatorial action space” means that the high-level policy chooses a combination of low-level skills (goal space) and goals from the available options. This allows the high-level policy to create diverse and complex actions by combining the skills and goals it has access to.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;ol&gt;
    &lt;li&gt;The high-level policy can be seen as a decision-making mechanism that directs the low-level policies (skills) to achieve specific tasks. It is modeled hierarchically, with two components: one that selects a goal space (which skill to use) and another that selects a specific goal within that goal space. By doing so, the high-level policy can dynamically switch between different skills and goals as needed for the given task, while the low-level policies focus on executing the chosen skill to reach the desired goal. The high-level policy’s primary function is to adapt and combine the low-level skills in a way that allows the robot to effectively perform various tasks.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;temporal-abstraction-and-hsd-3&quot;&gt;Temporal Abstraction and HSD-3&lt;/h4&gt;

&lt;p&gt;With a task- and state-dependent policy, it is possible to not only select the required set of skills for a given environment but also switch between them within an episode. In this three-level hierarchy, the higher-level policy explores the hierarchy of goal spaces and dynamically trades off between generality and specificity. Temporal abstraction is obtained by selecting new high-level actions at regular intervals but with a reduced frequency compared to low-level actions. The resulting learning algorithm is called HSD-3, emphasizing the three different levels of control obtained after the hierarchical skill discovery phase.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Switch between them within an episode” refers to the ability of the high-level policy to change the selected skill and goal as needed during a single episode of the task being performed. An episode typically refers to a single run or attempt at solving a task, starting from an initial state and ending when the task is completed or a termination condition is met. By switching between different skills and goals during an episode, the high-level policy can adapt to changing requirements of the task and environment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Temporal abstraction” is a concept in hierarchical reinforcement learning where decisions can be made at different time scales. In the context of this work, it means that the high-level policy selects new actions (which skill to use and which goal to pursue) at a slower frequency compared to the low-level policies. This allows the high-level policy to make long-term decisions while the low-level policies focus on the shorter-term execution of those decisions. By having different levels of control operating at different time scales, the system can achieve more efficient learning and better performance in complex tasks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;formulization&quot;&gt;formulization&lt;/h3&gt;
&lt;p&gt;In the original text, the following mathematical symbols are used:&lt;/p&gt;
&lt;div&gt;

1. $$\left\{\pi_F^{\text {lo }}: \mathcal{S}^{\mathrm{p}} \times \mathcal{G}^F \rightarrow A\right\}_{F \in \mathcal{F}}$$: This notation represents a set of low-level goal-directed skill policies ($\pi_F^{\text {lo }}$) for each feature set $F$ in the collection of feature sets $\mathcal{F}$. Each policy takes as input the proprioceptive observations ($\mathcal{S}^{\mathrm{p}}$) and a goal ($\mathcal{G}^F$) from the goal space associated with the specific feature set $F$. The policy outputs an action ($A$) to be executed by the robot.

2. $\pi^{\mathrm{f}}: S \rightarrow \mathcal{F}$: This notation defines the high-level policy that takes the current state ($S$) as input and selects a goal space from the collection of goal spaces ($\mathcal{F}$). The output is a specific feature set $F$ that the policy determines to be the most appropriate for the current state.

3. $\pi^{\mathrm{g}}: S \times \mathcal{F} \rightarrow \mathcal{G}^F$: This notation defines the second part of the high-level policy that takes the current state ($S$) and the selected feature set $F$ as input and outputs a specific goal ($g$) from the goal space associated with that feature set ($\mathcal{G}^F$).

These mathematical symbols help to define the structure of the high-level and low-level policies and their relationships in a concise manner. They indicate the inputs and outputs of each policy and demonstrate how the policies interact in the hierarchical reinforcement learning framework.

&lt;/div&gt;

&lt;h2 id=&quot;related-work&quot;&gt;related work&lt;/h2&gt;
&lt;p&gt;在这部分中，作者回顾了与层次化强化学习相关的工作。下面是对这部分内容的梳理和分类：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;经典规划系统中的宏观操作符和抽象
    &lt;ul&gt;
      &lt;li&gt;该部分讨论了经典规划系统中宏观操作符和抽象对层次化强化学习的影响。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;层次化强化学习方法
    &lt;ul&gt;
      &lt;li&gt;介绍了层次化强化学习方法的发展历程，以及为现代神经网络基础学习系统带来的主要优势，如改进的探索能力。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;低级策略（选项；技能）的获取
    &lt;ul&gt;
      &lt;li&gt;回顾了从随机游走、互信息目标、代理或专家轨迹数据集、运动捕捉数据以及专用预训练任务中发现低级原语的各种方法。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;通用性和特异性的权衡
    &lt;ul&gt;
      &lt;li&gt;讨论了低级技能在实践中如何在通用性（广泛适用性）和特异性（特定任务的益处）之间产生权衡。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;选项发现和层次化强化学习的先前工作
    &lt;ul&gt;
      &lt;li&gt;通过测试环境的选择，例如传统的网格迷宫导航任务和类似的模拟机器人导航问题，说明了先前工作在解决通用性和特异性权衡方面的偏向性。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;非导航环境的技能获取
    &lt;ul&gt;
      &lt;li&gt;介绍了针对非导航环境的技能获取方法，如使用定制的预训练任务或领域内运动捕捉数据。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;与现有工作的对比
    &lt;ul&gt;
      &lt;li&gt;与现有方法相比，本文关注于在不借助额外监督或预训练任务设计的情况下学习低级技能，不强制要求针对特定行为类型的固定权衡。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;通过梳理和分类这些内容，您可以更好地理解文献回顾部分，并重点关注每个部分的核心内容。&lt;/p&gt;

&lt;!-- Parse the Latex divs with Katex--&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  $(&quot;script[type='math/tex']&quot;).replaceWith(
    function(){
      var tex = $(this).text();
      return katex.renderToString(tex, {displayMode: false});
  });
  
  $(&quot;script[type='math/tex; mode=display']&quot;).replaceWith(
    function(){
      var tex = $(this).text();
      return katex.renderToString(tex.replace(/%.*/g, ''), {displayMode: true});
  });
&lt;/script&gt;</content><author><name></name></author><category term="reinforcement-learning" /><category term="bipedal-robots" /><category term="hierarchical-skills" /><summary type="html">Concepts Pretrained skills (预训练技能, yùxùnliàn jìnéng): In reinforcement learning, pretrained skills refer to abilities or behaviors that an agent has already learned before tackling a new task. These skills can be acquired through prior training on related tasks or through unsupervised learning. For example, a bipedal robot may have pretrained skills for walking, jumping, or balancing that can be used in various new tasks.</summary></entry><entry><title type="html">Building GitHub Pages with RVM, Jekyll, and GitHub Actions Workflow</title><link href="/SIDM/jekyll/github-pages/rvm/github-actions/2023/05/07/welcome-to-jekyll.html" rel="alternate" type="text/html" title="Building GitHub Pages with RVM, Jekyll, and GitHub Actions Workflow" /><published>2023-05-07T09:34:56+00:00</published><updated>2023-05-07T09:34:56+00:00</updated><id>/SIDM/jekyll/github-pages/rvm/github-actions/2023/05/07/welcome-to-jekyll</id><content type="html" xml:base="/SIDM/jekyll/github-pages/rvm/github-actions/2023/05/07/welcome-to-jekyll.html">&lt;p&gt;In this post, we will go through the process of building a GitHub Pages site using RVM, Jekyll, and a GitHub Actions Workflow. We’ll cover key concepts, step-by-step instructions, and address the bugs encountered during the process.&lt;/p&gt;

&lt;h2 id=&quot;key-concepts&quot;&gt;Key Concepts&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;RVM (Ruby Version Manager): A command-line tool for installing, managing, and working with multiple Ruby environments.
Jekyll: A static site generator built with Ruby, used for creating GitHub Pages sites.&lt;/li&gt;
  &lt;li&gt;GitHub Actions: A CI/CD platform integrated with GitHub, allowing you to automate workflows for building, testing, and deploying projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;step-by-step-guide&quot;&gt;Step-by-Step Guide&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Install RVM: Follow the installation instructions for RVM on the official RVM website.&lt;/li&gt;
  &lt;li&gt;Install Ruby: Use RVM to install the desired version of Ruby. For example, to install Ruby 2.7.4, run rvm install 2.7.4 in your terminal.&lt;/li&gt;
  &lt;li&gt;Set up Jekyll: Install Jekyll by running gem install jekyll bundler.
Create a new Jekyll site: Run jekyll new my-site to create a new Jekyll site in the my-site directory. Replace my-site with your desired directory name.&lt;/li&gt;
  &lt;li&gt;Build and serve the site locally: Navigate to the site directory and run bundle exec jekyll serve. Your site should be available at http://localhost:4000.&lt;/li&gt;
  &lt;li&gt;Create a GitHub repository: Create a new GitHub repository and push your Jekyll site to the main branch.&lt;/li&gt;
  &lt;li&gt;Set up GitHub Pages: In your repository settings, enable GitHub Pages by selecting the main branch as the source.&lt;/li&gt;
  &lt;li&gt;Create a GitHub Actions Workflow (this is automatically down following the official tutorial): In your repository, create a .github/workflows/main.yml file and set up the workflow to build and deploy your site. Here’s a sample workflow:
  ```yaml
  on:
 push:
   branches: [ “main” ]
 pull_request:
   branches: [ “main” ]&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;jobs:
    build:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  runs-on: ubuntu-latest

  steps:
  - uses: actions/checkout@v3
  - name: Set up Ruby
    uses: ruby/setup-ruby@v1
    with:
      ruby-version: 2.7.4
  - name: Install dependencies
    run: bundle install
  - name: Build the site
    run: bundle exec jekyll build
  - name: Deploy to GitHub Pages
    uses: peaceiris/actions-gh-pages@v3
    with:
      github_token: $
      publish_dir: ./_site   ``` 8. Commit and push: Commit and push the changes to the main branch. Your site will be built and deployed using the GitHub Actions Workflow.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;bugs-encountered&quot;&gt;Bugs Encountered&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;CSS not loading: The CSS files were not loading correctly due to an incorrect baseurl. This was fixed by updating the head.html file to include /SIDM in the stylesheet link.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Missing navigation links: The navigation menu was not displaying the desired links. This was resolved by adding the site.baseurl in the header.html file, which fixed the navigation links. (remember add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--- layout title ---&lt;/code&gt;)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><category term="jekyll" /><category term="github-pages" /><category term="rvm" /><category term="github-actions" /><summary type="html">In this post, we will go through the process of building a GitHub Pages site using RVM, Jekyll, and a GitHub Actions Workflow. We’ll cover key concepts, step-by-step instructions, and address the bugs encountered during the process.</summary></entry></feed>