# Penurunan Matematis dan Referensi Tambahan IQL
###### tags: `logbook` `fasttrack` `IQL`
Referensi yang digunakan untuk mengerti lebih lanjut dari IQL yang disebut pada paper referensi utama. Berikut referensi tambahan yang digunakan:
# Penurunan Matematis
## Policy Gradient dan A2C
Fondasi dari persamaan matematis yang diberikan pada IA2C dimulai dari Policy Gradient dan A2C.
PG secara langsung melakukan fitting policy dari sebuah agent dengan model terparameterisasi $\pi_\theta$. Nilai $\theta$ akan terus diupdate sampai policy yang dimiliki agent optimal. Didapatkan persamaan loss-function

Dengan $B=s_t,u_t,s^*_t,r_t$ adalah minibatch yang mengandung experience trajectory dimana $s^*_t = s_{t+1}$ dan $t_B$ adalah last step dalam minibatch. Lalu $R_t =\sum_{\tau=t}^{t_B-1}\gamma^{\tau-t} r_\tau$.
A2C merupakan improvement dari PG dengan menambahkan value regressor $V_\omega$ untuk mengestimasi $E[R^{\pi}_t|s_t=s]$. Pertama, A2C mengurangi bias dari sampled return dengan menambahkan nilai dari last-state sehingga

Setelah itu variansi sampled return dapat dikurangi dengan

dimana $A_t$ dianggap sebagai sampled advantage dan $A^{\pi}(s,u)=Q^\pi(s,u) - V^\pi (s)$. Hasil akhirnya adalah memperoleh persamaan 3 dan 4.

Dari persamaan 4 didapatkan bahwa loss function dipengaruhi oleh selisih antara $R_t$ dengan value regressor $V_\omega(s_t)$. Pertanyaannya bedanya apa ya?
## Independent A2C
Advantage Actor Critic (A2C). Landasan awal:
* Ambil sebuah network $G(V,E)$, intersection i dan j disebut neighbor bila ada edge (jalan) menghubunginya
* Local region disebut $V_i = N_i \cup i$ dengan $N_i$ adalah neighborhood dari intersection i.
* Jarak antar dua agent $d(i,j)$ diukur berdasarkan jumlah minimum edge yang menghubungkan mereka. d(i,i) = 0,d(i,j)=1 untuk $j \in N_i$
* Setiap agent learns its own policy $\pi_{\theta_i}$ & value functionnya $V_{\omega_i}$
* Diasumsikan global state dan reward shared ke semua agent
Centralized A2C updating mudah diekstensikan ke IA2C dengan mengestimasi local return sebagai

value gradient $\nabla L(\omega_i)$ konsisten karena $R_t$ disampling dari stationary policy yang sama $\pi_{\theta^-}$.
Untuk memperoleh policy gradient $\nabla L(\theta_i)$, $V_{\omega_i}$ digunakan sebagai estimasi dari dampak marginal $\pi_{\theta_i}$ pada future return.
Global information sharing is infeasible in real time ATSC due to delay/latency -->they assume communications is limited to each local region.
Local policy dan value regressor mengambil $s_{t,V_i} :=(s_{t,j})_{j \in V_i}$. Recall kembali bahwa $V_i$ itu adalah local region dari intersection i dimana menginclude neighborhood dari i termasuk i. Berarti state yang diambil adalah state saat t dengan j dari
# Referensi Tambahan
* G. Tesauro, “Extending Q-learning to general adaptive multi-agent systems,” in Proc. Adv. Neural Inf. Process. Syst., 2004, pp. 871–878.
* M. Tan, “Multi-agent reinforcement learning: Independent vs. cooperative agents,” in Proc. 10th Int. Conf. Mach. Learn., Jun. 1993, pp. 330–337.
* J. Foerster et al. (Feb. 2017). “Stabilising experience replay for deep multi-agent reinforcement learning.” [Online]. Available: https://arxiv.org/abs/1702.08887
* M. A. Wiering, J. Van Veenen, J. Vreeken, and A. Koopman, “Intelligent traffic light control,” Ph.D. dissertation, Dept. Inst. Inf. Comput. Sci., Utrecht Univ., Utrecht, The Netherlands, 2004.
* M. A. Wiering, “Multi-agent reinforcement learning for traffic light control,” in Proc. 17th Int. Conf. Mach. Learn. (ICML), Jun. 2000, pp. 1151–1158
## Referensi 1. [1](https://proceedings.neurips.cc/paper/2003/file/e71e5cd119bbc5797164fb0cd7fd94a4-Paper.pdf)
## Referensi 2. [2](https://web.media.mit.edu/~cynthiab/Readings/tan-MAS-reinfLearn.pdf)
Fokus ke sini dahulu karena ini langsung di cite sebagai referensi untuk IQL
### Abstract & Other Base Informations
* The paper tries to answer the question: Given same numbers of RL Agents, will cooperative ones outperform independent ones (don't communicate during learning)?
* Key results:
* Independent agents as benchmark, the cooperative are studied in sharing sensation, sharign episodes, and sharing learned policies
* additional sensation helps but must be used efficiently
* sharing learned policies or episodes among agents speeds up learning at the cost of communication
* Agents can communicate instantatenous information, communicate episodes that are sequences of triples experienced by agents, communicate learned decision policies.
* Case study 2 focuses on sharing learned policies and episodes. It shows that in these cases cooperation speeds up learning but does not affect asymptotic performance
* Main contribution of this paper: if cooperation is done intelligently each agent can benet from other agents instantaneous information episodic experience and learned know ledge
### Sharing Policies or Episodes
Disebutkan bahwa sharing policies bisa mempercepat proses learning namun mereka mencapai level performansi yang sama seperti independent agents. cooperative agents can speed up learning measured by the average number of steps in training even though they will eventually reach the same asymptotic performance as independent agents. Opsi sharing policies:
* menggunakan policy yang sama
* terjadi echange of policies dalam frekuensi yang bervariasi
* Ada opsi sharing episode(how?), exchange antar peer atau exchange antara master dengan peer.
One simple way of cooperating is that all agent use the same decision policy -> it shows that more agents using the same policy converged quicker than independent ones.
If agents perform the same task their decision policies during learning can differ because they may have explored the different parts of a state space. Two hunters can complement each other by exchanging their policies and use what the other agent had already learned for its own benefit.
* Hmmm, berarti kalau misalkan dua agent, ketika kondisi yang dihadapi tiap agent berbeda, proses learning bisa lebih cepat karena tiap agent saling melengkapi.
* tapi harus performing the same task, dalam konteks ini tasknya adalah apa? memilih lampu hijau ke jalan yang mana biar tidak macet.
Instead of sharing learned knowledge such as a policy agents can share their episodes. An episode is a sequence of sensation action reward triples experienced by an agent. I used the following episode exchanging:
* when a hunter captured a prey the hunter transferred its entire solution episode to the other hunter
* The other hunter then mentally replayed the episode forward to update its own policy. As a result two hunters doubled their learning experience.
In addition to the exibility of assimilating
episodes, exchanging episodes can be used by heterogeneous reinforcementlearning agents as long as they can interpret episodes eg hunters can have different visual field depths. To demonstrate this point I let two hunters learn from an expert hunter that always moves towards the prey using the shortest path. This result
demonstrates another benefit of learning in a cooperative society where novices can learn quickly from experts by examples
* Sayangnya hal ini sulit diterapkan ke Traffic Control karena kondisi lalu lintas yang dihadapi agent bisa saja berbeda, kalauppun sama, banyak variasinya
* Butuh Agent pengatur lalu lintas yang jago,tapi yang jago itu maksudnya apa? Harus sudah terlatih dahulu
* Atau untuk 1 agent dilatih sendiri (sudah jadi), terus pas jalan online bareng agent 2, agent 2 belajar dari agent 1 sehingga mempercepat proses learningnya.
### Final Result & Remarks

## Referensi 3. [3](https://arxiv.org/pdf/1702.08887.pdf)
Sedikit ragu untuk memasukkan materinya karena membahas tentang experience replay yang hanya digunakan untk DRL (Deep Reinforcement Learning)
## Referensi 4. [4](https://www.researchgate.net/publication/2942266_Intelligent_Traffic_Light_Control)
## Referensi 5. [5](http://www.dcsc.tudelft.nl/~sc4081/2018/assign/pap/Reinforcement_Learning.pdf)