# Artificial Intelligence to Reshape the Healthcare Ecosystem
## 2 AI Techniques for Healthcare
### Diffusion Models  
Diffusion models are probabilistic generative models. They are effective in generating high-quality output data, typically images [99; 100; 101]. The basic idea of these models is to generate new content by reversing a diffusion process, that is, loss of information due to noise. Gaussian noise distribution is typically used. Due to this intrinsic capability, diffusion models can be useful in medical imaging applications, such as MRI and CT scans. Diffusion models consist of two phases. First, in the _forward diffusion process_, a neural network is trained to introduce noise into the dataset, then this process is reversed. The forward diffusion process gradually adds noise to data over a number of time steps until the original data are indistinguishable from the Gaussian cloud distribution. Let \(x_{0}\) be a sample from the data distribution \(q(x_{0})\). The result of the forward process is a sequence of latent variables \(x_{1},x_{2},\dots,x_{T}\), where \(T\) denotes the total number of steps. Since at each step \(t\) noise is added to the sample, it follows that  
\[q(x_{t}|x_{t-1})=\mathcal{N}(x_{t};\sqrt{1-\beta_{t}}x_{t-1},\beta_{t}\mathbf{ I}) \tag{56}\]  
where \(\beta_{t}\) is a variance schedule that controls the amount of noise added at each step. The full forward process can be written as  
\[q(x_{1:T}|x_{0})=\prod_{t=1}^{T}q(x_{t}|x_{t-1}) \tag{57}\]  
The _reverse diffusion process_ aims to recover the original data from the noise by reversing the forward process. This operation is represented as  
\[p_{\theta}(x_{t-1}|x_{t})=\mathcal{N}(x_{t-1};\mu_{\theta}(x_{t},t),\Sigma_{ \theta}(x_{t},t)) \tag{58}\]  
where \(\mu_{\theta}\) and \(\Sigma_{\theta}\) are the parameters for the model to learn in order to tune the reverse process, that can be expressed as  
\[p_{\theta}(x_{0:T})=p(x_{T})\prod_{t=1}^{T}p_{\theta}(x_{t-1}|x_{t}) \tag{59}\]  
where \(p(x_{T})\) is typically a standard Gaussian distribution. The entire process, sketched in Figure 9, can be modeled as a Markov chain. The model is trained to minimize the difference between the forward and reverse processes. The resulting training objective can be derived as  
\[L_{\text{vlb}}=\mathbb{E}_{q(x_{0:T})}\bigg{[}\log\frac{q(x_{1:T}|x_{0})}{p_{ \theta}(x_{0:T})}\bigg{]} \tag{60}\]  
that can be expressed as the sum of KL divergences between the forward and reverse distributions at each step. The complexity of this operation induced the definition of a simplified training objective, often used, which aims to reduce the noise in the corresponding score. This objective can be expressed as  
\[L_{\text{simple}}=\mathbb{E}_{x_{0}\in\epsilon,t}\Big{[}\|\epsilon-\epsilon_{ \theta}(x_{t},t)\|^{2}\Big{]} \tag{61}\]  
where \(\epsilon\) is the noise added at step \(t\) and \(\epsilon_{\theta}\) is the model prediction of the noise. To generate samples from the model, a noise sample \(x_{T}\sim\mathcal{N}(0,\mathbf{I})\) is used and processed by applying the learned reverse process iteratively:  
\[x_{t-1}\sim p_{\theta}(x_{t-1}|x_{t}) \tag{62}\]  
The process ends when a sample \(x_{0}\) from the learned data distribution is obtained. As mentioned above, diffusion models can generate high-quality medical images, which can be used for different purposes. For example, it is possible to increase the volume and diversity of medical image datasets for training robust machine learning models. They have proved useful for enhancing the clarity and detail of diagnostic images. As a further example, diffusion models can also generate novel molecular structures with desirable properties, aiding in drug discovery [102]. Concerning the implementation of applications in the context of healthcare based on diffusion models, PyTorch and TensorFlow, are extremely popular. However, it is worth mentioning Diffusers [103] and NVIDIA Clara [104]. A notable research example of the use of diffusion models is illustrated in [105].