In the file demo_extractor_maze.py, the variables clean_states and clean_inner_states are used in the clean_demonstration_trajectory method of the DemoExtractor class. Here's a breakdown of their differences:
clean_states
Purpose: This list stores the cleaned states from the demonstration trajectory after applying the cleaning process based on the eps_state threshold.
Content: Each element in clean_states represents a state from the demonstration trajectory that has been filtered and retained after the cleaning process.
Usage: These states are used for further processing, such as creating tasks or goals in the environment.
clean_inner_states
Purpose: Similar to clean_states, this list stores the cleaned inner states (often used for simulation resets, especially in environments like Mujoco) from the demonstration trajectory.
Content: Each element in clean_inner_states corresponds to an inner state from the demonstration trajectory that has been filtered and retained after the cleaning process.
Usage: These inner states are typically used for resetting the simulation to specific states, which is useful for tasks like skill learning or replaying trajectories.
Key Differences
Type of States:
clean_states contains the general states from the demonstration.
clean_inner_states contains the inner states, which are often more detailed and used for simulation resets.
Usage Context:
clean_states is used for tasks like goal creation and visualization.
clean_inner_states is used for resetting the environment or simulation to specific states.
Initialization:
Both lists are initialized with the first state from the demonstration trajectory:
Both lists are populated based on the cumulative distance in the goal space. If the cumulative distance exceeds eps_state, the corresponding state and inner state are added to clean_states and clean_inner_states, respectively:
python
if sum_dist > self.eps_state or i + k == len(self.L_states) - 1:
clean_states.append(self.L_states[i+k])
clean_inner_states.append(self.L_inner_states[i+k])
In summary, clean_states and clean_inner_states are both cleaned versions of the demonstration trajectory, but they serve different purposes in the context of the environment and simulation. clean_states is used for general task processing, while clean_inner_states is used for more detailed simulation control, such as resetting the environment.
Certainly! Let's consider a hypothetical example to illustrate how the content of clean_states and clean_inner_states might differ, especially in the context of a MazeEnv (as implied by the code).
Hypothetical Scenario
Imagine a simple 2D maze environment where the state represents the position of the agent in the maze, and the inner state might include additional information like the agent's velocity, orientation, or internal simulation parameters (e.g., joint angles if it were a robot).
Example Data
Suppose the raw demonstration trajectory (L_states and L_inner_states) looks like this:
python
L_states = [
[0.0, 0.0], # Position (x, y) at time step 0
[0.1, 0.1], # Position (x, y) at time step 1
[0.2, 0.2], # Position (x, y) at time step 2
[0.3, 0.3], # Position (x, y) at time step 3
[0.4, 0.4] # Position (x, y) at time step 4
]
L_inner_states = [
{"position": [0.0, 0.0], "velocity": [0.0, 0.0], "orientation": 0.0}, # Inner state at time step 0
{"position": [0.1, 0.1], "velocity": [0.1, 0.1], "orientation": 0.1}, # Inner state at time step 1
{"position": [0.2, 0.2], "velocity": [0.2, 0.2], "orientation": 0.2}, # Inner state at time step 2
{"position": [0.3, 0.3], "velocity": [0.3, 0.3], "orientation": 0.3}, # Inner state at time step 3
{"position": [0.4, 0.4], "velocity": [0.4, 0.4], "orientation": 0.4} # Inner state at time step 4
]
Cleaning Process
Assume eps_state = 0.2, meaning the trajectory will be cleaned if the cumulative distance between states exceeds 0.2. The cleaning process might result in:
python
clean_states = [
[0.0, 0.0], # First state is always included
[0.2, 0.2], # Cumulative distance from [0.0, 0.0] to [0.2, 0.2] is 0.28 (exceeds eps_state)
[0.4, 0.4] # Cumulative distance from [0.2, 0.2] to [0.4, 0.4] is 0.28 (exceeds eps_state)
]
clean_inner_states = [
{"position": [0.0, 0.0], "velocity": [0.0, 0.0], "orientation": 0.0}, # Corresponding inner state
{"position": [0.2, 0.2], "velocity": [0.2, 0.2], "orientation": 0.2}, # Corresponding inner state
{"position": [0.4, 0.4], "velocity": [0.4, 0.4], "orientation": 0.4} # Corresponding inner state
]
Key Differences
clean_states:
Contains only the position information [x, y].
Example: [0.0, 0.0], [0.2, 0.2], [0.4, 0.4].
clean_inner_states:
Contains more detailed information, such as position, velocity, and orientation.
clean_states: Used for high-level tasks like goal creation or visualization. It only needs the position (or other minimal information) to represent the state.
clean_inner_states: Used for resetting the simulation or environment. It requires more detailed information (e.g., velocity, orientation) to ensure the simulation starts exactly as it was during the demonstration.
In summary:
clean_states contains simplified, high-level states (e.g., position).
clean_inner_states contains detailed, low-level states (e.g., position, velocity, orientation) required for precise simulation control.