# Graphs and Data

## :chart\_with\_upwards\_trend: Session, Trial, and Experiment Graphs

As shown in [Lab Organization](https://slm-lab.gitbook.io/slm-lab/master/using-slm-lab/lab-organization), SLM Lab is organized into the hierarchy of Session, Trial and Experiment, with each higher level being a collection of its lower level. The graphs produced by each level, along with their moving average, are shown in the table below.

All the examples in this page is generated from an experiment using the spec file [slm\_lab/spec/experimental/a2c/a2c\_nstep\_n\_search.json](https://github.com/kengz/SLM-Lab/blob/master/slm_lab/spec/experimental/a2c/a2c_nstep_n_search.json), which is used to answer the question:

> What values of n of A2C n-step returns provide the fastest, most stable solution, if the other variables are held constant?

|                                                                                                                                          Graph                                                                                                                                          |                                                                                                                                          MA Graph                                                                                                                                         |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6MbpSMpj39Fcq7Enq%2F-Lu6jWHrA6OhfYda7E8T%2Fa2c_nstep_breakout_t5_s0_session_graph_train_mean_returns_vs_frames.png?alt=media\&token=6aae3ba0-b0ec-48ff-bac9-093888f615ce) | ![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6MbpSMpj39Fcq7Enq%2F-Lu6gqe-BKvGvkNTs0Ae%2Fa2c_nstep_breakout_t5_s0_session_graph_eval_mean_returns_ma_vs_frames.png?alt=media\&token=53ab31ee-be26-45f9-8044-b7b2741f9dcd) |
|       ![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6MbpSMpj39Fcq7Enq%2F-Lu6k5keuOfZh9SgmAe5%2Fa2c_nstep_breakout_t5_trial_graph_mean_returns_vs_frames.png?alt=media\&token=2ace5173-fc19-428d-ab61-6008d5b79a3a)      |      ![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6MbpSMpj39Fcq7Enq%2F-Lu6gx7yP9NzGaU9cMm4%2Fa2c_nstep_breakout_t5_trial_graph_mean_returns_ma_vs_frames.png?alt=media\&token=555473e0-2383-42ce-a371-bc40ba362653)      |
|     ![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6MbpSMpj39Fcq7Enq%2F-Lu6mzbUPjqTxHg28wwS%2Fa2c_nstep_breakout_multi_trial_graph_mean_returns_vs_frames.png?alt=media\&token=e3549ed1-2cd8-4a18-a822-76d97ec88fe9)     |     ![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6MbpSMpj39Fcq7Enq%2F-Lu6mwBP6qWf9j1yiXxA%2Fa2c_nstep_breakout_multi_trial_graph_mean_returns_ma_vs_frames.png?alt=media\&token=f94aa595-5b0a-40ea-bb26-c26f18929629)    |

The first row shows the Session graphs. Session is the lowest level, running a single agent with an environment, with the total rewards checkpointed at specified frequency. It is common to smoothen the graph by taking the moving average with a window of 100 checkpoints.

The second row shows the Trial graphs. Trial is a collection of Sessions, and the Trial graph takes the Sessions' mean and plotting an error envelop using standard deviation. This is the most commonly seen deep RL graph as it helps visualize the averaged performance of an instance of a run, repeated over with multiple random seeds.

The last row shows the Experiment (multi trial) graph. An Experiment is a collection of Trials with varying hyperparameters designed to study a hypothesis, and this graph simply overlays the Trial graphs in the experiment for comparison.

## Experiment Variable Graph

Apart from the multi-trial graph, there is another experiment graph which plots **the final performance metrics vs. experiment variables** – the varied hyperparameter values. This helps us see the relationship between the metrics and the experiment variables more clearly. Continuing with the examples above, the experiment variable graph of these trials are plotted below (to view it, download and zoom the graph):&#x20;

![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6nKYVHGmH_UpPQ2Fe%2F-Lu6nMrMuDx4fPBC3jFW%2Fa2c_nstep_breakout_experiment_graph.png?alt=media\&token=5c22b279-21f2-4773-b053-3becc7218f7f)

The color of each dot represent the overall performance of the trial, the darker shade the better. Although only one variable (n of n-step) is shown here, if we have multiple variables in an experiment, this graph will contain more columns of subplots corresponding to the experiment variables.

## Experiment Dataframe

In fact, the experiment variable graph is plotted from the experiment dataframe, saved with suffix `experiment_df.csv`. An example of this is shown below:

![](https://306139625-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LterKThgiKKTvsbx4WI%2F-Lu6q5SKBeisg9riyMMp%2F-Lu6qvomx2w_X52hDE0a%2Fexperiment%20df.png?alt=media\&token=7621bd9b-d4f6-4f1a-bf74-c4407fb338ce)

This dataframe is another useful piece of output data; it sorts best-trials-first by their performance metric, so it can easily be used to read and find the best-performing trial. The experiment dataframe first lists the trial index, then the experiment variables, and finally a set of predefined metrics.

## Advanced Usage

More graphs are available in the `data/{spec_name}_{timestamp}/graph/` data folder produced from a run, including graphs of loss values, learning rate, etc. These are for more advanced users.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://slm-lab.gitbook.io/slm-lab/master/analyzing-results/session-graph.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
