{"id":36519,"date":"2024-11-01T09:49:11","date_gmt":"2024-11-01T09:49:11","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36519"},"modified":"2024-11-01T11:52:52","modified_gmt":"2024-11-01T11:52:52","slug":"deep-learning-pytorch-course-gaussian-mixture-model","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36519\/","title":{"rendered":"Deep Learning PyTorch Course, Gaussian Mixture Model"},"content":{"rendered":"<p><body><\/p>\n<h2>1. What is a Gaussian Mixture Model (GMM)?<\/h2>\n<p>\n        A Gaussian Mixture Model (GMM) is a statistical model that assumes the data is composed of a mixture of several Gaussian distributions.<br \/>\n        GMM is widely used in various fields such as clustering, density estimation, and bioinformatics.<br \/>\n        Each Gaussian distribution is defined by a mean and variance, representing a specific cluster of the data.\n    <\/p>\n<h2>2. Key Components of GMM<\/h2>\n<ul>\n<li><strong>Number of Clusters<\/strong>: Represents the number of Gaussian distributions.<\/li>\n<li><strong>Mean<\/strong>: Represents the center of each cluster.<\/li>\n<li><strong>Covariance Matrix<\/strong>: Represents the spread of each cluster&#8217;s distribution.<\/li>\n<li><strong>Mixing Coefficient<\/strong>: Represents the proportion of each cluster in the overall data.<\/li>\n<\/ul>\n<h2>3. Mathematical Background of GMM<\/h2>\n<p>\n        GMM is expressed by the following formula:<br \/>\n        <br \/>\n<code>P(x) = \u03a3\u2096 \u03c0\u2096 * N(x | \u03bc\u2096, \u03a3\u2096)<\/code><br \/>\n<br \/>\n        Where:<\/p>\n<ul>\n<li><code>P(x)<\/code>: Probability of the data point <code>x<\/code><\/li>\n<li><code>\u03c0\u2096<\/code>: Mixing coefficient of each cluster<\/li>\n<li><code>N(x | \u03bc\u2096, \u03a3\u2096)<\/code>: Gaussian distribution with mean <code>\u03bc\u2096<\/code> and variance <code>\u03a3\u2096<\/code><\/li>\n<\/ul>\n<h2>4. Implementing GMM with PyTorch<\/h2>\n<p>\n        This section covers the process of implementing GMM using PyTorch.<br \/>\n        PyTorch is a popular machine learning library for deep learning.\n    <\/p>\n<h3>4.1. Installing Required Libraries<\/h3>\n<pre><code>!pip install torch matplotlib numpy<\/code><\/pre>\n<h3>4.2. Generating Data<\/h3>\n<p>\n        First, let&#8217;s generate example data.<br \/>\n        Here, we will create two-dimensional data points and divide them into three clusters.\n    <\/p>\n<pre><code>\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Set random seed for reproducibility\nnp.random.seed(42)\n\n# Generate sample data for 3 clusters\nmean1 = [0, 0]\nmean2 = [5, 5]\nmean3 = [5, 0]\ncov = [[1, 0], [0, 1]]  # covariance matrix\n\ncluster1 = np.random.multivariate_normal(mean1, cov, 100)\ncluster2 = np.random.multivariate_normal(mean2, cov, 100)\ncluster3 = np.random.multivariate_normal(mean3, cov, 100)\n\n# Combine clusters to create dataset\ndata = np.vstack((cluster1, cluster2, cluster3))\n\n# Plot the data\nplt.scatter(data[:, 0], data[:, 1], s=30)\nplt.title('Generated Data for GMM')\nplt.xlabel('X-axis')\nplt.ylabel('Y-axis')\nplt.show()\n    <\/code><\/pre>\n<h3>4.3. Defining the Gaussian Mixture Model Class<\/h3>\n<p>\n        We define the necessary classes and methods for implementing GMM.\n    <\/p>\n<pre><code>\nimport torch\n\nclass GaussianMixtureModel:\n    def __init__(self, n_components, n_iterations=100):\n        self.n_components = n_components\n        self.n_iterations = n_iterations\n        self.means = None\n        self.covariances = None\n        self.weights = None\n\n    def fit(self, X):\n        n_samples, n_features = X.shape\n\n        # Initialize parameters\n        self.means = X[np.random.choice(n_samples, self.n_components, replace=False)]\n        self.covariances = [np.eye(n_features)] * self.n_components\n        self.weights = np.ones(self.n_components) \/ self.n_components\n\n        # EM algorithm\n        for _ in range(self.n_iterations):\n            # E-step\n            responsibilities = self._e_step(X)\n            \n            # M-step\n            self._m_step(X, responsibilities)\n\n    def _e_step(self, X):\n        likelihood = np.zeros((X.shape[0], self.n_components))\n        for k in range(self.n_components):\n            likelihood[:, k] = self.weights[k] * self._multivariate_gaussian(X, self.means[k], self.covariances[k])\n        total_likelihood = np.sum(likelihood, axis=1)[:, np.newaxis]\n        return likelihood \/ total_likelihood\n\n    def _m_step(self, X, responsibilities):\n        n_samples = X.shape[0]\n        for k in range(self.n_components):\n            N_k = np.sum(responsibilities[:, k])\n            self.means[k] = (1 \/ N_k) * np.sum(responsibilities[:, k, np.newaxis] * X, axis=0)\n            self.covariances[k] = (1 \/ N_k) * np.dot((responsibilities[:, k, np.newaxis] * (X - self.means[k])).T, (X - self.means[k]))\n            self.weights[k] = N_k \/ n_samples\n\n    def _multivariate_gaussian(self, X, mean, cov):\n        d = mean.shape[0]\n        diff = X - mean\n        return (1 \/ np.sqrt((2 * np.pi) ** d * np.linalg.det(cov))) * np.exp(-0.5 * np.sum(np.dot(diff, np.linalg.inv(cov)) * diff, axis=1))\n\n    def predict(self, X):\n        responsibilities = self._e_step(X)\n        return np.argmax(responsibilities, axis=1)\n    <\/code><\/pre>\n<h3>4.4. Training the Model and Making Predictions<\/h3>\n<p>\n        We will train the model using the defined <code>GaussianMixtureModel<\/code> class and predict the clusters.\n    <\/p>\n<pre><code>\n# Create GMM instance and fit to the data\ngmm = GaussianMixtureModel(n_components=3, n_iterations=100)\ngmm.fit(data)\n\n# Predict clusters\npredictions = gmm.predict(data)\n\n# Plot the data and the predicted clusters\nplt.scatter(data[:, 0], data[:, 1], c=predictions, s=30, cmap='viridis')\nplt.title('GMM Clustering Result')\nplt.xlabel('X-axis')\nplt.ylabel('Y-axis')\nplt.show()\n    <\/code><\/pre>\n<h2>5. Advantages and Disadvantages of GMM<\/h2>\n<p>\n        GMM has the advantage of effectively modeling various cluster shapes, but the learning speed may decrease as the complexity of the model and the dimensionality of the data increase.<br \/>\n        Additionally, since results can vary depending on initialization, it is important to try multiple initializations.\n    <\/p>\n<h2>6. Conclusion<\/h2>\n<p>\n        GMM is a powerful clustering technique used in various fields.<br \/>\n        We explored how to implement GMM using PyTorch and it is essential to understand the necessary mathematical background at each step.<br \/>\n        We hope to conduct more in-depth research on the various applications and extensions of GMM in the future.\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. What is a Gaussian Mixture Model (GMM)? A Gaussian Mixture Model (GMM) is a statistical model that assumes the data is composed of a mixture of several Gaussian distributions. GMM is widely used in various fields such as clustering, density estimation, and bioinformatics. Each Gaussian distribution is defined by a mean and variance, representing &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36519\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Gaussian Mixture Model&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[149],"tags":[],"class_list":["post-36519","post","type-post","status-publish","format-standard","hentry","category-pytorch-study"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deep Learning PyTorch Course, Gaussian Mixture Model - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36519\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deep Learning PyTorch Course, Gaussian Mixture Model - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"1. What is a Gaussian Mixture Model (GMM)? A Gaussian Mixture Model (GMM) is a statistical model that assumes the data is composed of a mixture of several Gaussian distributions. GMM is widely used in various fields such as clustering, density estimation, and bioinformatics. Each Gaussian distribution is defined by a mean and variance, representing &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Gaussian Mixture Model&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36519\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:49:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:52+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36519\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36519\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Gaussian Mixture Model\",\"datePublished\":\"2024-11-01T09:49:11+00:00\",\"dateModified\":\"2024-11-01T11:52:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36519\/\"},\"wordCount\":319,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36519\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36519\/\",\"name\":\"Deep Learning PyTorch Course, Gaussian Mixture Model - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:49:11+00:00\",\"dateModified\":\"2024-11-01T11:52:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36519\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36519\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36519\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Gaussian Mixture Model\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deep Learning PyTorch Course, Gaussian Mixture Model - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/36519\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Gaussian Mixture Model - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"1. What is a Gaussian Mixture Model (GMM)? A Gaussian Mixture Model (GMM) is a statistical model that assumes the data is composed of a mixture of several Gaussian distributions. GMM is widely used in various fields such as clustering, density estimation, and bioinformatics. Each Gaussian distribution is defined by a mean and variance, representing &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Gaussian Mixture Model\"","og_url":"https:\/\/atmokpo.com\/w\/36519\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:49:11+00:00","article_modified_time":"2024-11-01T11:52:52+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36519\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36519\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Gaussian Mixture Model","datePublished":"2024-11-01T09:49:11+00:00","dateModified":"2024-11-01T11:52:52+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36519\/"},"wordCount":319,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36519\/","url":"https:\/\/atmokpo.com\/w\/36519\/","name":"Deep Learning PyTorch Course, Gaussian Mixture Model - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:49:11+00:00","dateModified":"2024-11-01T11:52:52+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36519\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36519\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36519\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Gaussian Mixture Model"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36519"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36519\/revisions"}],"predecessor-version":[{"id":36520,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36519\/revisions\/36520"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}