Coffee Chat Brewing AI Knowledge

eng kor

[Paper] Amyloid-β prediction machine learning model using source-based morphometry across neurocognitive disorders (2024)

Momota, Yuki, et al. “Amyloid-β prediction machine learning model using source-based morphometry across neurocognitive disorders.” Scientific Reports 14.1 (2024): 7633.

Paper Link


Points

Objective

  • Investigated MRI-based machine learning models to predict Alzheimer’s disease (AD), with a focus on diverse patient populations.
  • Utilized source-based morphometry (SBM) to assess Amyloid-beta deposition.

Methodology

  • Preprocessed 3D T1 weighted images into voxel-based gray matter (GM) images, then subjected them to SBM.
  • Implemented a support vector machine (SVM) as a classifier.
  • Employed SHapley ADditive exPlanations (SHAP) for model interpretability and accountability.

Results

  • Achieved a final model accuracy of 89.8% when incorporating MR images, cognitive test results, and apolipoprotein E status.
  • Attained an 84.7% accuracy with the model based solely on MR images.


Background

  • AD is a neurodegenerative disorder characterized by the presentce of A$\beta$ plaques, neurofibrillary tangles, and brain atrophy.
  • A$\beta$ is a defining characteristics of AD, but detecting it is not covenient in routine clinical practice.
    • Methods such as position emission tomography (PET), cerebrospinal fluid (CSF) testing, and Blood biomarkers are used for A$\beta$ detection but are not yet applicable in routine clinical practice.
  • MRI-based A$\beta$ prediction may serve as a useful screening tool before definitive diagnosis through the aforementioned methods.


Method

supfig1

Features

Participants and clinical measurements

  • Recruited in Jury 2018 ~ August 2021 from the memory clinic at Keio University Hospital.
  • AD / MCI / HC

Cognitive assessment (9 measures)

  • Global cognitive function: Mimi-mental state examination (MMSE), Clinical dementia rating (CDR), Functional activity questionnaire (FAQ)
  • Memory: Wechsler Memory Scale-Revised (WMS-R) Lgical Memeory immediate recall (LM I) and delayed recall (LM II)
  • Executive function and attention: Word Fluency, Trail Making Test (TMT)
  • Specific cognitive abilities: Japanese version of Alzheimer’s Disease Assessment Scale-Cognitive subscale (ADAS-cog-J), Japanese Adult Reading Test (JART)

Apolipoprotein E (APOE) genotyping

  • Magnetic nanoparticle DNA extraction kit (EX1 DNA Blodd 200 $\mu$L Kit)
  • real-time polymerase chain reaction (PCR)

[18F] Florbetaben (FBB) amyloid-PET imaging

  • [18F] Florbetaben (FBB)

    Florbetaben, a fluorine-18 (18F)-labeled stilbene derivative (formerly known as BAY-949172), trade name NeuraCeq, is a diagnostic radiotracer developed for routine clinical application to visualize β-amyloid plaques in the brain. [reference]


MRI

Acquisition - 3D T1 weighted MR images (T1 WI)

  • MRI scanner: Discovery MR750 3.0 T scanner (GE Healthcare)
  • Coil: 32-channel head coil
  • Imaging parameters: field of view (FOV) 230mm, matrix size 256$\times$256, slice thickness 1.0mm, voxel size 0.9$\times$0.9$\times$1.0mm

Pre-processing

  1. Segmentation: Segmented the MR images into different tissue types: gray matter (GM), white matter (WM), and cerebrospinal fluid (CSF) using Statistical Parametric Mapping toolbox CAT12.

  2. Normalization: The Segmented GM images are then normalized to the Montreal Neurological Institute (MNI) template, which is a standard anatomical template commonly used in neuroimaging research.

    Standard anatomical templates are widely used in human neuroimaging processing pipelines to facilitate group level analyses and comparisons across different subjects and populations. The MNI-ICBM152 template is the most commonly used standard template, representing an average of 152 healthy young adult brains. [reference]

  3. Resampling and Smoothing: Resampled the images to an isotropic voxel size of 2$\times$2$\times$2mm3 and smoothed using a 5mm full-width-at-half-maximum Gaussian kernel.
    • This step helps to standardize the voxel size an reduce noise in the images.
  4. Source-based morphometry (SBM): Incorporates independent component analysis (ICA) to automatically decompose the anatomical brain images into independent spatial maps characterizing different modes of anatomical variability accorss all individuals.

    In signal processing, independent component analysis (ICA) is a computational method for separating a multivariate signal into additive subcomponents. This is done by assuming that at most one subcomponent is Gaussian and that the subcomponents are statistically independent from each other. [reference]

    ica

  5. ICA processing: The 3D GM images (91$\times$109$\times$91 voxels) are loaded and converted into a 1D array format (1$\times$902,629) for processing.
    • A brain mask is created to select relevant (208,082) voxels for ICA using FastICA.
    • The number of extracted independent components (ICs) is a hyperparameter that is tuned for subsequent model building.
  6. Spatial Regression: The extracted ICs are used as spatial regressors for each participant’s GM images, with weighting coefficients ($\beta$) determining the effect of each IC on the GM image.

    \[I_{GM}=\beta_1 IC_1 + \beta_2 IC_2 + ... + \beta_K IC_K\]


Machine learning

  • Input features: ICA’s $\beta$-values, demographic characteristics (age and sex), cognitive assessments, APOE genotype
  • Input conduction: The model is trained and tested using various combinations of input features.
    1. All input features together
    2. Each combination of features: brain images alone, brain images + cognitive assessments, etc.
    3. Different combination of diagnoses: AD+HC, AD+MCI+HC
  • Model: Gaussian kernel support vector machine (SVM)
    • Training involves classification using 5-vold cross-validation.
    • Testing is performed over all splits (5 times), ensuring robust evaluation.
  • Interpretability: SHaply Additive exPlanations (SHAP)
    • SHAP values, based on game theory, indicate the influence of features on predictions.
    • Features with large absolute SHAP values have a strong influence on predictions.
    • Clinical features with positive and negative SHAP values were associated with A$\beta$+ and A$\beta$- conditions, respectively


Statistical analysis

Explores relationships between variables, identifying associations with diagnoses, and testing hypotheses in the context of Alzheimer’s disease research.

  • Two-tailed t-test / Chi-square test
    • Two-tailed t-test: used to compare the means of two groups to determine if there is a significant difference between them.
    • Chi-square test: used to test the independence between categorical variables.
  • Relationships among features: Pearson’s correlation analysis for continous variables
    • Measures the strength and direction of linear relationships between pairs of continuous variables.
    • Provides insights into how variables are related to each other.
  • Associations with diagnoses: Analysis of variance (ANOVA)
    • Used to anaylze the difference among group menas in a sample.
    • Useful when there’re more than two groups being compared, as it determines whether there are statistically significant differences among the group means.


Results

118 cases used for the final model building

table1


Model performance

table2 fig1

table3

A$\beta$ positivity prediction

  • The final model: the model trained with brain images + cognition + APOE as input
  • The highest accuracy (89.8%) and AUC (0.888) with brain images + cognition + APOE
  • The lowest accuracy (84.7%) and AUC (0.830) with brain images alone

The final model’s performance for predicting A$\beta$ positivity in each diagnosis

  • The highest accuracy (89.8%) when including all the paticipants
  • The lowest accuarcy (75.9%) based solely on MCI


SBM

table4

addfig2 fig2

7 independent components (ICs) were derived from the final SBM model

  • Each component showed spatially maximally independent GM volum patters.
  • IC 1 showed a significant correlation with cognitive measures an A$\beta$ positivity.
  • Only AD and IC 1 showed a significant association.
  • Other diagnoses were not associated with any ICs.


Discussion

The proposed model predicted A$\beta$ positivity successfully. (accuracy 89.8%, AUC 0.888)

  • With 118 participants’ data consisting of the features: brain MRI, cognitive info., genetic info.
  • Predicted correctly in non-AD subjects, such as those with FTLD syndrome and psychiatric disorders.
  • Among covariants in the final model, IC 1 had the strongest impact realted to A$\beta$ positivity prediction.


Performance

  1. Informative heterogeneity of features among non-AD participants
    • The performance of the model based only on AD continuum achieved slightly lower (88.4%) than on all cases.
  2. Advantages of SBM
    • The model based on diverse clinical populations may be better suited for application in clinical settings.
      • Patients visiting physicians’ would have various neurocongitive disorders beyond the AD continuum.
    • The proposed model based only on brain images (accuracy 84.7%) may assist for screening of potential candidates for AD-related clinical trials.
    • SBM detects subtle morphological changes and unknown patterns in brain structures associated with ND diseases without relying on existing atlases.
  3. Comparable prediction performance in MCI patiences
    • Surpassed the accuracy of the physician’s clinical diagnosis of AD (75.9% > 70%)


Feature Importance of the model - SHAP

fig3

All ICs demonstrated greater importance compared to demoghrapic and cognitive features such as MMSE. The three most influential features in the model were identified as follows: IC 1, logical memory (LM) I, and LM II.

  • IC 1 exhibited a significantly correlation with A$\beta$ positivity and cognivite measures.
    • Its spacial pattern of the loading coefficients closely resembled the cortical pattern observed in neurodegeneration (ND) in AD, particularly in the parietal lobe.
    • No Medial temporal lobe (MTL) atrophy was observed in any IC, which is the typical AD pattern.
      • This discrepance suggests a potential indication of tau pathodology rather than A$\beta$ pathology.
  • LM scores reflected memory impairments, a cardinal symptom of AD.
  • The presence of APOE -$\epsilon#4 also emerged as a significant factor.

Furthermore, the model revealed distinct associations between IC 1 and A$\beta$ positivity, as well as IC 4 and age.

  • This indicates the model’s ability to discriminate between AD-related ND from normal aging in brain imaging, suggesting that the pathological process of AD is not strictly age-dependent. → Brain atrophy patterns in normal aging processes can be distinguished from those in neurodegeneartive disease.


Limitation

  1. A$\beta$ positivity was determined only by amyloid-PET scan: CSF A$\beta$ would be a more sensitive marker in the pre-clinical status.
  2. a limited number of samples: could be affect accuracy of a machine learning model.
  3. Longitudinal follow-up data might improve model performance, rather than a cross-sectional approach.

[Paper] Tabtransformer: Tabular data modeling using contextual embeddings (2020)

Huang, Xin, et al. “Tabtransformer: Tabular data modeling using contextual embeddings.” arXiv preprint arXiv:2012.06678 (2020).

Paper Link


Points

  • TabTransformer: A cutting-edge tabular data model leveraging contextual embeddings.
  • Pre-trained by innovative two-phase approach for robust feature representation.
  • Showed SOTA performance in both supervised and semi-supervised learning.
  • Handles missing and noisy data robustly, ensuring reliable performance.


Background

The current state-of-the-art (SOTA) mdoels for tabular data primarily consist of tree-based ensemble methods, notably gradient boosted decision trees (GBDT). However, these models exhibit several limitations in comparison to deep learning models:

  • Not suitable for continual learning from streaming data.
  • Ineffective for end-to-end learning of multi-modality of tabular data, such as incorporating image or text features.
  • Not suitable for semi-supervised learning.

On the other had, while multi-layer perceptrons (MLPs) offer the potential for end-to-end learning of image or text encoders, they are constrained by several drawbacks:

  • Lack of interpretability.
  • Vulnerability to missing and noisy data.
  • Limited performance in semi-supervised learning scenarios.
  • Inability to match the performance of tree-based models.


Method

archi

  • The Transformer layers receive only categorical inputs $x_{cat}$.
  • Continuous inputs $x_{cont}$ are concatenated with the outputs of the Transformer modules of the categorical inputs.
  • During the pre-training phase, the Transformer layers undergo training on two different tasks using unlabeled data
    • Only the categorical inputs are utilized for pre-training, with the exclusion of the continuous inputs.

    code1

  • The pre-trained model is fine-tuned alongsidethe MLP head, utilizing labeled data to predict a target $y$.
  • Continuous values are incorporated during the fine-tuning phase by concatenating them with the categorical values.

    code2


Model Architecture

fig1

  • Each instance $x\equiv \lbrace x_{cat}, x_{cont}\rbrace$ is paired with its corresponding label $y$: $(x, y)$.
  • $x_{cat} \equiv \lbrace x_1, x_2, …, x_m\rbrace$ represents categorical features, with each $x_i$ being a categorical feature $i \in {1, …, m}$.
  • $x_{cat}$ undergoes transformation into column embedding $E_\phi$:

    \[E_\phi(x_{cat}) \equiv \lbrace e_{\phi_1}(x_1), ..., e_{\phi_m}(x_m) \rbrace, \ e_{\phi_i}(x_i) \in \mathbb{R}^d\]
  • The embeddings are fed into the multiple Transformer layers $f_\theta$, producing contextual embeddings:

    \[\{h_1, ..., h_m\}=f_\theta(E_\phi(x_{cat})), \ h\in \mathbb{R}^d\]
  • Contextual embeddings of $x_{cat}$ are concatenated with the $x_{cont} \in \mathbb{R}^c $ to form a vector of dimension $(d\times m+c)$.
  • The vector is passed through an MLP layer $g_\psi$ and a cross-entropy loss $H$ is computed between the predicted output and the target $y$:

    \[L(x, y) \equiv H(g_\psi(f_\theta(E_\phi(x_{cat})), x_{cont}), y)\]


Column Embedding

colemb

  • Each categorical feature $x_i$ has its own embedding lookup table $e_{\phi_i}(.)$.
  • For the $i$th feature with $d_i$ classes, the embedding table $e_{\phi_i}(.)$ contains $(d_1+1)$ embeddings. The additional $d_1+1$th embedding is reserved for representing the missing(masked) values.
  • Each embedding $e_{\phi_i}(j)$ is represented as $[c_{\phi_i}, w_{\phi_{ij}}]$, where:
    • $c_{\phi_i}$ helps distinguish the classes in column $i$ from those in the other columns.
    • $w_{\phi_{ij}}$ distinguishes the class of the feature $j$ within the $i$th column from the other classes within the same column.
  • *The dimension $d$ likely is set to be the same as the hidden dimension $h$ according to the codes.

    code3


Pre-training

The Transformer layers are trained using inputs consisting of categorical values $x_{cat}=\lbrace x_1, x_2, …, x_m\rbrace$ on two pre-training tasks:

  1. Masked language modeling (MLM)
    • Randomly masks $k\%$ features of the input, where $k$ is set to 30 in experiments.
    • Minimizes the cross-entropy loss of a multi-class classifier $g_\psi$, which predicts the original features of the masked features.
  2. Replaced token detection (RTD)
    • Replaces the original feature by a random value of that feature.
    • Minimizes the loss of a binary classifier predicting whether the feature has been replaced.
    • Each column has its own embedding lookup table, necessitating the definition of a separate binary classifier for each column.


Experiments

Settings

Data

  • Models were evaluated on 15 publicly available binary classification datasets sourced from UCI repository, AutoML Challenge, and Kaggle.
  • Each dataset was divided into 5 cross-validation splits.
  • Training:Validation:Testing proportion was set to 65:15:20 (%).
  • The number of categorical features ranged from 2 to136.
  • Semi-supervised and supervised experiments
    • Semi-supervised: Training data consisted of $p$ labeled data points + the remaining unlabeled data, with $p\in (50, 200, 500)$ for 3 different scenarios.
    • Supervised: Fully labeled training data was used.

Setup

  • Hidden dimension: 32
  • The num of layers: 6
  • The num of attention heads: 8
  • MLP layer architecture: $\lbrace 4\times l, \ 2\times l \rbrace$ (where $l$ represents the size of its input).
  • Hyperparamter optimization (HPO) conducted with 20 rounds for each cross-validation split.
  • Metrics: Area under the curve (AUC).
  • Pre-training was exclusively applied in the semi-supervised scenario.
    • It was not found to be significantly beneficial when the entire dataset was labeled.
    • Its benefits were more apparent when there is a large number of unlabeled examples and a few labeled examples, as pre-training provided representations of the data that could not be learned solely from the labeled examples.

Baseline model: An MLP model without Transformers was employed to evaluate the effectiveness of Transformers in comparison.


The effectiveness of the Transformer Layers

  1. Performance comparison

    table1

    • Conducted in a supervised learning scenario, comparing TabTransformer to MLP.
    • TabTransformer outperforms the baseline MLP on 14 datasets, achieving an average 1.0% gain in AUC.
  2. t-SNE visualization of contextual embeddings

    fig2

    • Each marker in the plot represents an average of 2D points over the test data points for a certain class.
    • In the t-SNE plot of the last layer of TabTransformer (Left), semantically similar classes are closely grouped, forming clusters in the embedding space.
    • Before passing into the Transformer (Center), the embeddings start to distinguish features with different characteristics.
    • The embeddings of MLP (Right) do not reveal any discernible pattern.
  3. Prediction performance of linear models using the embeddings from different Transformer layers

    fig2

    • Logistic regression models are employed to evaluate the quality of learned embeddings.
    • Each model predicts $y$ using embedding features along with continuous values.
    • Metrics: Cross-validation score in AUC on the test data.
    • Normalization: Each prediction score is normalized by the best score from an end-to-end trained TabTransformer for the corresponding dataset.
    • Features: Embeddings are averaged and processed using maximum pooling instead of concatenation.
    • The effectiveness of the embeddings improves as the Transformer layers progress.


The robustness of TabTransformer

The robustness of TabTransformer was evaluated by assessing its performance on datasets containing noisy data and data with missing values.

fig4_5

  1. Noisy data
    • Method: Values were replaced with randomly generated ones from corresponding columns, introducing noise into datasets.
    • Findings: As the noise increases, TabTransformer demonstrated significantly significantly superior compared to the MLP (see fig. 4).
    • The contextual property of embeddings likely contributes to TabTransformer’s robustness in noisy environments.
  2. Data with missing values
    • Method: Some values artificially made missing, and models were evaluated on these modified datasets.
      • The average learned embeddings over all classes in the corresponding columns were used to handle the embeddings of missing values.
    • Findings: TabTransformer exhibited better stability than MLP in handling missing values (see fig. 5).


Supervised learning

TabTransformer’s performance was compared against four categories of methods:

  • Logistic Regression and GBDT
  • MLP and sparse MLP
  • TabNet model
  • Variational Information Bottleneck (VIB) model

table2

Findings:

  • TabTransformer demonstrated comparable performance with GBDT.
  • It significantly outperformed than recent deep learning models designed for tabular data, including TabNet and VIB.


Semi-supervised learning

TabTransformer was evaluated under the semi-supervised learning scenario and compared against other semi-supervised models, including baseline models:

  • Entropy Regularization (ER)
  • Pseudo Labeling (PL) combined with MLP, TabTransformer, and GBDT
  • MLP (DAE): An unsupervised pre-training method designed for deep models on tabular data, specifically the swap noise Denoising AutoEncoder

table3_4

Method:

  • Pre-trained models (TabTransformer-RTD/MLM and MLP): pre-trained on the unlabeled data and then fine-tuned on labeled data.
  • Semi-supervised learning methods (ER and PL): trained on the mix of labeled and unlabeled training data.

Findings:

  • TabTransformer-RTD/MLM are outperformed all the other models.
  • TabTransformer (ER), TabTransformer (PL) and GBDT (PL) performed worse than the average of all the models.
  • TabTransformer-RTD consistently showed better results when the number of unlabeled data decreased, surpassing TabTransformer-MLM.
    • This could be attributed to the easier pre-training task of a binary classification compared to the multi-class classification of MLM.
  • With only 50 data points, MLM (ER) and MLM (PL) outperformed TabTransformer models.
    • The suggests that the proposed approach allows for informative embeddings but does not enable the weights of the classifier itself to be trained with unlabeled data.
  • Overall, TabTransformer models are promise in extracting useful information from unlabeled data to aid supervised training, and are particularly useful when the size of unlabeled data is large.

Github.io에서 markdown 수식 문법 적용이 안될 때

Github blog 포스트에 수식을 작성했는데, markdown 수식 문법 적용이 되지 않는 문제가 있었습니다. 해결 방법을 기록해두고자 포스팅합니다.

1. _config.yml 파일 수정

markdown process 관련 설정을 확인하여 수정, 없으면 추가합니다. markdown engine을 kramdown으로 설정해야 한다고 합니다.

2. _includes 폴더 내 수식 문법 관련 HTML 파일 작성

일반적으로 github blog 내에는 _include 폴더가 존재합니다. 폴더 내에 수식 문법이 포스트에 적용될 수 있게끔 하기 위한 스크립트를 작성합니다. 아래 내용이 HTML 파일에 작성되면 됩니다.

inlineMathdisplayMath 항목에서 각각의 수식 문법 기호를 설정할 수 있습니다. 위 예시의 displayMath 와 같이 리스트 내에 여러 기호를 설정할 수 있습니다. 위 예시에 따르면 수식을 $$ 로 감싸거나, \\[ \\] 사이에 입력하면 display style로 작성할 수 있게 됩니다.

*\\[ \\] 말고 \[ \] 로 문법을 설정하여 포스트에 적용하면, [ ] 괄호를 사용한 일반 텍스트까지 수식으로 처리되는 경우가 있었습니다.

Inline과 Display style

수식 입력 방식에는 inline style과 display style이 있습니다.

  • Inline style: 줄 바꿈 없이, 문장 내에서 수식을 표기하는 방법

  • Display style: 수식을 블록으로 생성해 표기하는 방법

    $2$ plus $3$ is $5$: $$2+3=5$$
    

    $2$ plus $3$ is $5$: \[2+3=5\]


3. 2에서 작성한 HTML 스크립트를 포스트에 적용

위에서 작성한 스크립트를 실제 포스팅 시 적용하기 위해 layout에 관련한 HTML 파일을 수정합니다. _layout 폴더에 있는 HTML 파일 중 적합한 파일을 찾아 포스트의 내용 부분에 새로 작성한 HTML 파일의 내용을 가져와 적용합니다. 저는 ‘default.html’ 파일 중 content가 입력되는 부분을 찾아 수정했습니다. 아래 예시와 같습니다.

"content" 블록 내 { content } 의 위치에 작성한 포스트의 본문이 보여집니다. include file.html 은 ‘file.html’의 내용을 가져온다는 뜻입니다. 따라서 해당 블록 내에 ‘math.html’에서 작성한 수식 문법 사항을 적용하겠다는 의미의 코드가 됩니다.

위 코드를 아래와 같이 수정하면 수식 문법 적용 여부를 포스팅 시 설정해 줄 수 있는데요,

page.use_mathtrue 이면 ‘math.html’ 내용을 적용한다는 의미의 코드입니다. 여기서 page 는 각 포스트를 의미합니다. page.use_math 을 설정하기 위해서는 매 포스트 작성 시 Front Matter에 use_math: true 를 추가해주면 됩니다.

수식이 필요 없거나, 수식을 적용하기 싫은 포스트에는 use_math 를 추가하지 않거나 false 로 설정하면 됩니다.


Reference

https://junia3.github.io/blog/markdown
https://an-seunghwan.github.io/github.io/mathjax-error/

When mathematical expression syntax isn't applying on GitHub Pages

I wrote a math expression in a GitHub blog post, but there was an issue with applying markdown syntax. I’m posting this to document the solution that I applied.

1. Modify the _config.yml file

Check and modify the markdown-related settings in the _config.yml file like below. If they don’t exist, add them like below. It’s recommended to set the markdown engine to kramdown.

2. Write a HTML file of math expression syntax within the _includes folder

Generally, GitHub blogs contain an _include folder. Write a script within this folder to enable math expression syntax to be applied to posts. Let’s assume creating a html file named ‘math’

You can set each math syntax mark for the inlineMath and displayMath. Similar to the displayMath item in the above code, you can specifiy multiple marks in the list. Following the example, if you wrap the formula in $$ or \\[ and \\], the math style will be displayed as the display style.

*When setting the syntax as \[ and \] instead of \\[ \\], there might be instances where ordinary text enclosed within square brackets is also treated as part of the math expression.

Inline and Display style

The inline style and the display style are two styles of math expression.

  • Inline style: Representing math expression within a sentence without line breaks

  • Display style: Generating math expression as blocks for representation

    $2$ plus $3$ is $5$: $$2+3=5$$
    

    $2$ plus $3$ is $5$: \[2+3=5\]


3. Apply the HTML script created in 2. to the post

To apply the script created above to an actual post, you’ll need to modify the HTML file related to the layout. Find an appropriate file in the _layout folder and incorporate the content of the html file into the section where the post’s content is inserted. For example, I found and modified the ‘default.html’ file like the example below:

{ content } displalys the main body of the post. include file.html means it includes the content of ‘file.html’. Therefore, within this block, it signifies applying the math syntax written in ‘math.html’

You can modify the code and adjust if applying the math syntax or not,

The code page.use_math being true indicates that the content of ‘math.html’ will be applied. Here, page refers to the each page. To set page.use_math, simply add use_math: true to the Front Matter of each post.

For posts where math expressions are not needed or you prefer not to apply them, simply omit the use_math tag or set it to false


Reference

https://junia3.github.io/blog/markdown
https://an-seunghwan.github.io/github.io/mathjax-error/

Docker CMDs

Image

Search for an Image

docker search [OPTIONS] IMAGE_NAME
  • --automated=false Show only automated builds
  • --no-trunc=false Show all results
  • -s=n --stars=n Show only images with at least n stars
  • e.g.,
    docker search --stars=100 mysql
    

Download an Image

docker pull [OPTIONS] IMAGE_NAME[:TAG_NAME]
  • -a Download all versions of the image
  • TAG_NAME Specify the version to download, if not specified, the latest version is downloaded
  • e.g.
    docker pull ubuntu:22.04
    

List Images

docker images [OPTIONS] [REPOSITORY]
  • -a --all Show all images
  • --digests Show digests
  • -q --quiet Show only image IDs
  • *To list containers: docker ps

Inspect Image Details

docker image inspect IMAGE_ID
  • You can enter part of the ID instead of the full ID.

Delete an Image

docker rmi [OPTION] IMAGE_NAME:TAG_NAME
  • -f Force delete the image of a running container, but in practice, it only untagged and does not actually delete the image or container.
  • Delete multiple images at once:
    docker rmi IMAGE_NAME_1 IMAGE_NAME_2 ...
    
  • Stop all running containers of a specific image and then delete the image:
    docker rm -f $(docker ps -a --filter ancestor=IMAGE_NAME)
    docker rmi IMAGE_NAME
    

Save and Load Images

docker save -o DIRECTORY IMAGE_NAME
  • -o (output) Specify the directory to save the image
docker load -i DIRECTORY
  • -i Specify the directory of the image to load (input), the image in that directory is loaded.

Tag an Image

docker tag IMAGE_NAME:TAG NEW_NAME:NEW_TAG
  • Allows you to reference an existing image with a new name and tag.
  • e.g.,
    docker tag ubuntu:22.04 abcd:0.1
    


Container

List Containers

docker ps [OPTION]
  • Lists running containers.
  • -a Show all containers, including those that have stopped.

Inspect Container Details

docker inspect CONTAINER_NAME

Run a Container from an Image

docker run [OPTIONS] IMAGE_NAME
  • --name CONTAINER_NAME Set the container name
  • --rm Delete the container after the run command is executed. One-time use of the container
  • -it Keep passing terminal input to the container
    • -i Keep stdin open even if not attached
    • -t Allocate a pseudo-TTY, use TTY mode to write commands to the shell
  • -d Run the container in the background. When this option is specified, the container ID is output.
  • -e Add environment variables. Use as many as you need to add.
    • e.g.,
      docker run -e APP_ENV=production APP2_ENV=dev ubuntu:22.04 env
      
  • -p HOST_PORT:CONTAINER_PORT Bind a specific port of the container connected to the host to the port of the host. Usually used to expose the web server port to the outside.
  • -w DIR Change the working directory
  • -v HOST_DIR:CONTAINER_DIR Mount a specific directory of the host to the container
    • e.g.,
      docker run -v volume:/data ubuntu:22.04
      
    • Mount the current working directory to the container
      docker run -v `pwd`:/opt ubuntu:22.04
      
  • -u USER_ID Access the container with a specific user ID. The account must be added when building the image.

Execute Commands in a Running Container

docker exec CONTAINER_ID or NAME CMD
  • -it Run the shell in the container environment,

Difference between run and exec

  • run: Run a container from an image
  • exec: Run commands in an already running container

Stop a Container

docker stop CONTAINER_ID/NAME
  • Stop a running container (Graceful shutdown)
docker kill CONTAINER_ID/NAME
  • Force stop a running container

Restart a Container

docker start CONTAINER_ID/NAME
  • Restart a stopped container
docker restart CONTAINER_ID/NAME
  • Stop and then restart the container