1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-08 22:21:08 +00:00
ReCo.jl/README.adoc

209 lines
6 KiB
Text
Raw Normal View History

2022-01-13 16:18:35 +00:00
= ReCo.jl
2022-02-08 20:34:06 +00:00
:source-highlighter: highlight.js
:highlightjs-languages: bash, julia, latex
2022-01-13 16:18:35 +00:00
image:https://img.shields.io/badge/code%20style-blue-4495d1.svg[Code Style: Blue, link=https://github.com/invenia/BlueStyle]
2022-01-15 17:55:01 +00:00
**Re**inforcement learning of **co**llective behavior.
2022-01-24 21:07:39 +00:00
== Setup
2022-03-19 22:11:03 +00:00
The following steps from the setup have to be followed every time before running anything in the following sections. An exception is installing the dependencies which has to be done only the first time.
2022-01-24 21:07:39 +00:00
=== Launch Julia
To activate the environment, navigate to the main directory `/ReCo.jl` and then run the following to launch Julia:
2022-02-08 20:34:06 +00:00
[source,bash]
2022-01-24 21:07:39 +00:00
----
cd ReCo.jl
julia --threads auto
----
`auto` automatically sets the number of threads to use. If you want to use a specific number `N` of threads, replace `auto` with `N`.
2022-02-08 20:34:06 +00:00
=== Activating environment
2022-01-24 21:07:39 +00:00
2022-03-19 22:11:03 +00:00
After launching Julia, the package environment has to be activated by running the following in the REPL:
2022-01-24 21:07:39 +00:00
2022-02-08 20:34:06 +00:00
[source,julia]
2022-01-24 21:07:39 +00:00
----
using Pkg
Pkg.activate(".")
----
=== Install/update dependencies
After activating the package environment, run the following to install/update the package dependencies:
2022-01-24 21:07:39 +00:00
2022-02-08 20:34:06 +00:00
[source,julia]
2022-01-24 21:07:39 +00:00
----
Pkg.update()
2022-01-24 21:07:39 +00:00
----
This step has to be done by running the line above for the first time using the package to install its dependencies. Running the line above after the first time will update the installed dependencies which is optional.
2022-02-08 14:09:43 +00:00
=== Import the package
2022-02-08 14:09:43 +00:00
You can import the package by running:
2022-02-08 20:34:06 +00:00
[source,julia]
----
using ReCo
----
This will export the package's functions that are intended to be used by the end user.
2022-02-08 20:34:06 +00:00
== Help mode
To access the documentation of the presented package functions further in this README, run `using ReCo` first. Then, enter the help mode by pressing `?` in the REPL. Now, enter the function's name followed by enter to see its documentation.
2022-02-08 14:09:43 +00:00
== Run a simulation
2022-02-08 14:09:43 +00:00
2022-02-07 16:50:57 +00:00
Initialize a simulation with 100 particles having a self-propulsion velocity of 40.0 and return the relative path to the simulation directory:
2022-02-08 20:34:06 +00:00
[source,julia]
----
sim_dir = init_sim(100, 40.0)
----
Run the simulation:
2022-02-08 20:34:06 +00:00
[source,julia]
----
run_sim(sim_dir, duration=20.0)
----
2022-02-08 20:34:06 +00:00
The values for the number of particles, self-propulsion velocity and simulation duration are used here as an example. For more information about possible values and other optional arguments, see the documentation of `init_sim` or `run_sim`.
2022-01-24 21:07:39 +00:00
2022-02-08 14:09:43 +00:00
== Simulation visualization
2022-02-07 16:50:57 +00:00
2022-02-08 14:09:43 +00:00
=== Animation
2022-02-08 20:34:06 +00:00
To generate an animation of a simulation, run the following:
[source,julia]
----
animate(sim_dir)
----
The function's documentation includes all possible optional arguments and where the output can be found.
2022-02-08 14:09:43 +00:00
=== Snapshot plot
2022-02-08 21:18:44 +00:00
To plot only one snapshot of a simulation, run the following:
2022-02-08 14:09:43 +00:00
2022-02-08 21:18:44 +00:00
[source,julia]
----
plot_snapshot(sim_dir)
----
This will ask for the number of the snapshot to plot out of the total number of snapshots. The function's documentation includes all possible optional arguments and where the output can be found.
2022-02-08 21:18:44 +00:00
== Run a reinforcement learning process
2022-02-07 16:50:57 +00:00
2022-02-07 17:41:34 +00:00
Run a reinforcement learning process and return the environment helper and the the path of the process directory relative to the directory `ReCo.jl`:
2022-02-08 20:34:06 +00:00
[source,julia]
2022-02-07 16:50:57 +00:00
----
2022-02-07 17:41:34 +00:00
env_helper, rl_dir = run_rl(ENVTYPE)
2022-02-07 16:50:57 +00:00
----
`ENVTYPE` has to be replaced by one of the environments named after the file names in the directory `ReCo.jl/RL/Envs`, for example: `LocalCOMEnv`. A short description of an environment is included at the beginning of the corresponding file.
2022-02-07 16:50:57 +00:00
2022-02-08 20:34:06 +00:00
The documentation of `run_rl` includes all possible optional arguments.
=== Q-matrix
2022-01-24 21:07:39 +00:00
2022-02-07 17:41:34 +00:00
`env_helper` has the abstract type `EnvHelper`. To access the Q-matrix, enter the following:
2022-02-08 20:34:06 +00:00
[source,julia]
2022-02-07 17:41:34 +00:00
----
env_helper.shared.agent.policy.learner.approximator.table
----
2022-04-05 01:21:46 +00:00
To generate a LaTeX table with the states and actions combintation names for the Q-matrix, run the following after activating the environment in `ReCo.jl/analysis`:
2022-02-07 17:41:34 +00:00
2022-02-08 20:34:06 +00:00
[source,julia]
2022-02-07 17:41:34 +00:00
----
2022-04-05 01:21:46 +00:00
include("Q_matrix_latex_export.jl")
2022-04-05 01:12:39 +00:00
export_q_matrix(env_helper, FILENAME_WITHOUT_EXTENSION)
2022-02-07 17:41:34 +00:00
----
`FILENAME_WITHOUT_EXTENSION` has to be replaced by the wanted file name without extension of the `.tex` file. The function's documentation explains where the output is placed.
The output file can be used in a LaTeX document:
[source,latex]
----
\input{FILENAME_WITHOUT_EXTENSION}
----
2022-02-08 20:34:06 +00:00
=== Rewards
2022-02-07 17:41:34 +00:00
To access the rewards, run the following:
2022-02-08 20:34:06 +00:00
[source,julia]
2022-02-07 17:41:34 +00:00
----
env_helper.shared.hook.rewards
----
To plot the rewards, run the following:
2022-02-08 20:34:06 +00:00
[source,julia]
2022-02-07 17:41:34 +00:00
----
plot_rewards(rl_dir)
----
The function's documentation explains where the output is placed.
2022-02-08 20:34:06 +00:00
=== Mean kappa
2022-04-05 01:21:46 +00:00
To plot the mean of kappa as the ratio of the eigenvalues of the gyration tensor, run the following after activating the environment in `ReCo.jl/analysis`:
2022-02-07 17:41:34 +00:00
2022-02-08 20:34:06 +00:00
[source,julia]
2022-02-07 17:41:34 +00:00
----
2022-04-05 01:21:46 +00:00
include("mean_kappa.jl")
2022-02-08 22:16:38 +00:00
plot_mean_κ(; rl_dir=rl_dir, n_last_episodes=N_LAST_EPISODES)
2022-02-07 17:41:34 +00:00
----
`N_LAST_EPISODES` is the number of the last episodes of the learning process to average over. The function's documentation explains where the output is placed.
2022-02-07 17:41:34 +00:00
2022-01-24 21:07:39 +00:00
== Run analysis
2022-04-05 01:21:46 +00:00
First, `cd` into and activate the environment in `ReCo.jl/analysis`.
2022-02-08 22:16:38 +00:00
=== Mean squared displacement and random walk
2022-01-24 21:07:39 +00:00
2022-02-08 20:34:06 +00:00
[source,julia]
2022-01-24 21:07:39 +00:00
----
2022-04-05 01:21:46 +00:00
include("mean_squared_displacement.jl")
2022-01-24 21:07:39 +00:00
run_msd_analysis()
run_random_walk()
----
The output is `ReCo.jl/exports/graphics/mean_squared_displacement.pdf` and `ReCo.jl/exports/graphics/random_walk.pdf`.
2022-01-24 21:07:39 +00:00
=== Radial distribution function
2022-02-08 20:34:06 +00:00
[source,julia]
2022-01-24 21:07:39 +00:00
----
2022-04-05 01:21:46 +00:00
include("radial_distribution_function/radial_distribution_function.jl")
2022-01-24 21:07:39 +00:00
run_radial_distribution_analysis()
2022-02-08 14:09:43 +00:00
----
The output is `ReCo.jl/exports/graphics/radial_distribution.pdf` and `ReCo.jl/exports/graphics/radial_distribution_all_vs.pdf`.
2022-02-08 14:09:43 +00:00
=== Reward discount analysis
[source,julia]
----
2022-04-05 01:21:46 +00:00
include("reward_discount_analysis.jl")
run_reward_discount_analysis()
----
The output is `ReCo.jl/exports/graphics/reward_discount_analysis.pdf`.
2022-02-08 14:09:43 +00:00
== Graphics
2022-03-19 22:11:03 +00:00
The directory `ReCo.jl/graphics` has some Julia files that generate graphics related to this package. The function in every file that has to be run to generate the corresponding graphics starts with `plot_` or `gen_`. The output is placed in `ReCo.jl/exports/graphics`.