Citra biner
Cara mudah untuk memahami bagaimana sebuah distribusi berkaitan dengan sebuah data frame adalah dengan menghasilkan sampel.
Ukuran citra adalah 2 kali 2 piksel dan probabilitas bernilai 1 untuk klaster ini adalah 0,8; 0,8; 0,2; dan 0,9 untuk piksel yang bersesuaian.
Latihan ini adalah bagian dari kursus
Model Campuran di R
Petunjuk latihan
- Hasilkan 100 citra biner dari klaster satu. Mulailah dengan mensimulasikan masing-masing dari empat piksel sebagai sampel biner.
- Lihatlah citra biner yang dihasilkan.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Create the vector of probabilities
p_cluster_1 <- c(0.8, 0.8, 0.2, 0.9)
# Create the sample for each pixel
pixel_1 <- sample(c(0, ___), ___, replace = TRUE,
prob = c(1-p_cluster_1[___], p_cluster_1[___]))
pixel_2 <- sample(c(0, 1), 100, replace = TRUE,
prob = c(1-p_cluster_1[___], p_cluster_1[___]))
pixel_3 <- sample(c(0, 1), 100, replace = TRUE,
prob = c(1-p_cluster_1[___], p_cluster_1[___]))
pixel_4 <- sample(c(0, 1), 100, replace = TRUE,
prob = c(1-p_cluster_1[___], p_cluster_1[___]))
# Combine the samples
sample_cluster_1 <- cbind(pixel_1, pixel_2, pixel_3, pixel_4)
# Have a look to the sample
head(___)