Motivation
When giving a presentation on STEM disciplines, we usually need to draw a gif of some dynamical systems to express our ideas clearly. However, creating a portable, fluid, and authentic gif is challenging, it is very hard to find suitable parameters for drawing a gif.
Challenge
- No matter how long this process takes, we only have a limited time to watch (usually very short).
- How to define fluidity of an animation (comfortable to watch)?
- Due to the stability of the discretize dynamical system of interest, we can not arbitrarily choose a stepsize for the system.
- What is the relationship between the size of the created gif and fluidity?
Analysis
We define three concept for $i\in\{r,o\}$:
$$ \begin{align} D_i:&=\frac{\Delta_i}{F_i},\label{d}\\ R_i:&=\frac{F_i}{T_i},\\ S_i:&=\frac{R_i}{D_i},\\ v_i:&=D_i R_i, \label{v} \end{align} $$where $r$ and $o$ represent the above quantities is measured in reality and observation respectively, $\Delta_i$ is the total variation, or the total path length of things moving in the image measured by some reasonable metrics, $F_i$ is total number of images, $T_i$ is total time, $D_i$ is resolution (the average difference between two adjacent images in the series), $R_i$ is frame rate, $S_i$ is fluidity or smoothness of a gif, and $v_i$ is the velocity of things in images.
In our creating-a-gif-for-dynamical-systems case, $R_r$ is how many images are calculated per unit real time. Considering
$$ \begin{align*} \dot{\theta}_t&=-L^{\prime}(t,\theta_t),\\ \theta_{t+1} &=\theta_t-\eta L^{\prime}(t,\theta_t), \end{align*} $$where $\eta$ is learning rate. At every time step $t$, an image $\theta_{t}$ is generated, and therefore $R_r=\frac{1}{\eta}$.
In order to guarantee the stability of the dynamical system, we have to increase $R_r$. However, if we save all these easy-to-calculate images into gif it is usually lead to prohibitively large gif file. So, we need to sample some images with compression ratio $k=\frac{F_r}{F_o}$ and store them into gif. To keep the gif authentic (without distortion), we set $l=\frac{T_r}{T_o}$, acceleration ratio, a constant (otherwise the process distorted) and therefore
$$ \begin{align*} k \eta&=\frac{l}{R_o},\\ \end{align*} $$where $R_o$ is the FPS of gif (a constant). According to equations \eqref{d}-\eqref{v}, we have
$$ \begin{align*} S_o&=\frac{R_o}{D_o}=\frac{F^2_o}{T_o\Delta}=\frac{F^2_o}{T_o T_r v_r},\\ F_o&=\frac{R_r T_r}{k}, \end{align*} $$where $\Delta=\Delta_r=\Delta_o$ in this case, $F_o$ is proportional to the size of the gif file. Finally, we get the suitable compression ratio $k$ and corresponding gif size measured by $F_o$
$$ \begin{align*} k&=\frac{\sqrt{T_r}}{\eta\sqrt{S_o T_o v_r}}, \; v_r=|L^{\prime}|,\\ F_o&=\sqrt{S_o T_o T_r v_r}. \end{align*} $$Citation
Cited as:
https://zhaotong94.github.io/blog/hcssdgds/.
Or
@article{zhao2024how,
title = "How to Create a Small and Smooth Dynamic GIF for Dynamical Systems?",
author = "Zhao, Tong",
journal = "zhaotong94.github.io",
year = "2024",
month = "Oct",
url = "https://zhaotong94.github.io/blog/hcssdgds/"}
...