393 lines
185 KiB
Plaintext
393 lines
185 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"### Solution for Assignment 3 of the course \"Introduction to Machine Learning\" at the University of Leoben.\n",
|
|||
|
"##### Author: Fotios Lygerakis\n",
|
|||
|
"##### Semester: SS 2022/2023"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"Create an abstract class “ContinuousDistribution”. The class must contain the following function definitions (not implementations)\n",
|
|||
|
"* Data Import and Export using csv files.\n",
|
|||
|
"* Computation of the mean based on the samples from the csv.\n",
|
|||
|
"* Computation of the standard deviation based on the samples from the csv.\n",
|
|||
|
"* Visualization of the distribution, the raw data or the generated samples.\n",
|
|||
|
"* Generating/Drawing Samples from the distribution.\n"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import abc\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"import pandas as pd\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"from scipy.stats import multivariate_normal\n",
|
|||
|
"from scipy.stats import beta"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 2,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"class ContinuousDistribution(abc.ABC):\n",
|
|||
|
" def __init__(self, name):\n",
|
|||
|
" self.name = name\n",
|
|||
|
"\n",
|
|||
|
" @abc.abstractmethod\n",
|
|||
|
" def import_data(self, filename):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" @abc.abstractmethod\n",
|
|||
|
" def export_data(self, filename):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" @abc.abstractmethod\n",
|
|||
|
" def compute_mean(self):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" @abc.abstractmethod\n",
|
|||
|
" def compute_std(self):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" @abc.abstractmethod\n",
|
|||
|
" def visualize(self):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" @abc.abstractmethod\n",
|
|||
|
" def generate_samples(self, n):\n",
|
|||
|
" pass"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"Implement a class “GaussDistribution”, which implements a multivariate Gaussian distribution (Equation 2.6 in the book).\n",
|
|||
|
"* It is a child class of “ContinousDistribution”.\n",
|
|||
|
"* Implement the functions defined in “ContinousDistribution”.\n",
|
|||
|
"* Implement a constructor that optionally takes the dimension of the multivariate distribution.\n",
|
|||
|
"* Implement a visualization for Multivariate Gaussians up to 3 dimensions.\n",
|
|||
|
"* Find the empirical parameters of the distribution that created the samples in the ‘MGD.csv’ file.\n",
|
|||
|
"* Plot the samples of the ‘MGD.csv’ file and the sample from the learned distribution in two subfigures.\n",
|
|||
|
"* Generate visualizations of one- and two-dimensional Gaussians\n",
|
|||
|
"\n",
|
|||
|
"**The actual mean and covariance matrix of the MGD.csv file are [1, 0, 1] and [[1, 0.5, 0.5], [0.5, 1, 0.5], [0.5, 0.5, 1]] respectively.**\n"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 3,
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"class GaussDistribution(ContinuousDistribution):\n",
|
|||
|
" def __init__(self, name, dim=1, mean=None, cov=None):\n",
|
|||
|
" super().__init__(name)\n",
|
|||
|
" self.dim = dim\n",
|
|||
|
" self.mean = mean\n",
|
|||
|
" self.cov = cov\n",
|
|||
|
" self.data = None\n",
|
|||
|
" self.sampled_data = None\n",
|
|||
|
"\n",
|
|||
|
" def import_data(self, filename):\n",
|
|||
|
" self.data = pd.read_csv(filename)\n",
|
|||
|
"\n",
|
|||
|
" def export_data(self, filename):\n",
|
|||
|
" self.data.to_csv(filename, index=False)\n",
|
|||
|
"\n",
|
|||
|
" def compute_mean(self):\n",
|
|||
|
" return self.data.mean()\n",
|
|||
|
"\n",
|
|||
|
" def compute_std(self):\n",
|
|||
|
" # return the covariance matrix if the distribution is multivariate\n",
|
|||
|
" if self.dim > 1:\n",
|
|||
|
" return self.data.cov()\n",
|
|||
|
" return self.data.std()\n",
|
|||
|
"\n",
|
|||
|
" def visualize(self):\n",
|
|||
|
" # Plot the samples of the ‘MGD.csv’ file and the sample from the learned distribution in two separate sub-figures. add a title to each sub-figure.\n",
|
|||
|
" if self.dim == 1:\n",
|
|||
|
" data = self.sampled_data if self.sampled_data is not None else self.data\n",
|
|||
|
" # plot the samples\n",
|
|||
|
" plt.hist(data['x'], density=True, histtype='stepfilled', alpha=0.2)\n",
|
|||
|
"\n",
|
|||
|
" # create a grid of points\n",
|
|||
|
" x = np.linspace(data['x'].min(), data['x'].max(), 100)\n",
|
|||
|
"\n",
|
|||
|
" # plot the pdf of the distribution\n",
|
|||
|
" plt.plot(x, multivariate_normal.pdf(x, self.mean, self.cov))\n",
|
|||
|
"\n",
|
|||
|
" plt.show()\n",
|
|||
|
" elif self.dim == 2:\n",
|
|||
|
" data = self.sampled_data if self.sampled_data is not None else self.data\n",
|
|||
|
" # create a grid of points\n",
|
|||
|
" x = np.linspace(data['x'].min(), data['x'].max(), 100)\n",
|
|||
|
" y = np.linspace(data['y'].min(), data['y'].max(), 100)\n",
|
|||
|
"\n",
|
|||
|
" # plot the pdf of the distribution\n",
|
|||
|
" X, Y = np.meshgrid(x, y)\n",
|
|||
|
" pos = np.empty(X.shape + (2,))\n",
|
|||
|
" pos[:, :, 0] = X\n",
|
|||
|
" pos[:, :, 1] = Y\n",
|
|||
|
" rv = multivariate_normal(self.mean, self.cov)\n",
|
|||
|
" plt.contourf(X, Y, rv.pdf(pos))\n",
|
|||
|
" # plot the samples\n",
|
|||
|
" plt.scatter(data['x'], data['y'], c='r', marker='o')\n",
|
|||
|
" plt.show()\n",
|
|||
|
" elif self.dim == 3:\n",
|
|||
|
" fig = plt.figure()\n",
|
|||
|
" ax = fig.add_subplot(121, projection='3d')\n",
|
|||
|
" ax.set_title('Original Data')\n",
|
|||
|
" ax.scatter(self.data['x'], self.data['y'], self.data['z'], c='r', marker='o')\n",
|
|||
|
" ax.set_xlabel('X Label')\n",
|
|||
|
" ax.set_ylabel('Y Label')\n",
|
|||
|
" ax.set_zlabel('Z Label')\n",
|
|||
|
" ax = fig.add_subplot(122, projection='3d')\n",
|
|||
|
" ax.set_title('Sampled Data')\n",
|
|||
|
" ax.scatter(self.sampled_data['x'], self.sampled_data['y'], self.sampled_data['z'], c='b', marker='o')\n",
|
|||
|
" ax.set_xlabel('X Label')\n",
|
|||
|
" ax.set_ylabel('Y Label')\n",
|
|||
|
" ax.set_zlabel('Z Label')\n",
|
|||
|
" plt.show()\n",
|
|||
|
"\n",
|
|||
|
" def generate_samples(self, n):\n",
|
|||
|
" # generate samples from the distribution\n",
|
|||
|
" if self.dim == 1:\n",
|
|||
|
" self.sampled_data = pd.DataFrame(np.random.normal(self.mean, self.cov, n), columns=['x'])\n",
|
|||
|
" elif self.dim == 2:\n",
|
|||
|
" self.sampled_data = pd.DataFrame(np.random.multivariate_normal(self.mean, self.cov, n), columns=['x', 'y'])\n",
|
|||
|
" elif self.dim == 3:\n",
|
|||
|
" self.sampled_data = pd.DataFrame(np.random.multivariate_normal(self.mean, self.cov, n), columns=['x', 'y', 'z'])\n",
|
|||
|
"\n",
|
|||
|
" def fit(self):\n",
|
|||
|
" self.mean = self.compute_mean()\n",
|
|||
|
" self.cov = self.compute_std()"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"Find the empirical parameters of the distribution that created the samples in the ‘MGD.csv’ file."
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 4,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": "<Figure size 640x480 with 2 Axes>",
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhkAAAEWCAYAAADLpIXDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAD2fElEQVR4nOydd3gc5dW375nZpt5lVffecMG40YvpEGoKJEAIIS+d8CYkkFCT0FJI+UJCXkogCST0EkzH2GDTbKvYstwky7Ykq9ftO/N8f4xmtCuv+sqWYO7r8gVe7848W+bMeU75HUkIIbCwsLCwsLCwiDHy4V6AhYWFhYWFxZcTy8mwsLCwsLCwGBEsJ8PCwsLCwsJiRLCcDAsLCwsLC4sRwXIyLCwsLCwsLEYEy8mwsLCwsLCwGBEsJ8PCwsLCwsJiRLCcDAsLCwsLC4sRwXIyLCwsLCwsLEYEy8k4BNx1111IkjSk1z755JNIksSePXtiu6gw9uzZgyRJPPnkkyN2DgsLi9GFJEncddddMTvemjVrkCSJNWvWxOyYFmMfy8nog61bt3LppZeSn5+P0+kkLy+PSy65hK1btx7upR0WDCNi/HE6nYwbN47jjz+eX/3qVzQ0NAz52GVlZdx1110j6kxZWMSa0tJSLrzwQiZMmIDL5SI/P59TTjmFP/7xj4d7aaMWY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70ox8BMGnSJNOOGLZmoN+BRWyxIhlReO2115g4cSLHHHNM1H8/9thjmThxIv/9738P+reLLrqIadOm8atf/arPi/ryyy/nP//5D9/+9rdZtmwZH374IWeeeeaA17hr1y4uvPBCrrzySi677DIef/xxLr/8chYvXsycOXMAqKio4OWXX+aiiy5i0qRJ1NXV8de//pXjjjuOsrIy8vLyBny+gWCs5+233+aXv/wlAJ9//jnr16/nG9/4BgUFBezZs4dHHnmE448/nrKyMuLj4zn22GO54YYb+MMf/sBtt93GrFmzAMz/PvnkkyQmJvLDH/6QxMRE3n//fe644w7a29t56KGHYvoeLCwGyoQJE9iwYQNbtmxh7ty5fT73kUceYc6cOZxzzjnYbDZee+01rrnmGjRN49prr4147q5du/jWt77F1VdfzaWXXsqvf/1rzj77bP7yl79w2223cc011wBw3333cfHFF7N9+3ZkuXu/qKoqp512GsuWLePBBx/kzTff5M477yQUCnHPPff0usa6ujqWLVuGJElcd911ZGVlsXr1aq688kra29u56aabAH2DdNJJJ7F3715uuOEG8vLyePrpp4ecKu3Jt7/9bW677TbefvttrrrqKgDeeecdKioquOKKK8jJyWHr1q08+uijbN26lU8++QRJkjj//PPZsWMHzzzzDL/73e/IzMwEMDeKg/kOLGKIsIigtbVVAOLcc8/t83nnnHOOAER7e7sQQog777xTAOKb3/zmQc81/s1g48aNAhA33XRTxPMuv/xyAYg777zTfOyJJ54QgKisrDQfmzBhggDE2rVrzcfq6+uF0+kUt9xyi/mYz+cTqqpGnKOyslI4nU5xzz33RDwGiCeeeKLP9/zBBx8IQDz33HO9PueII44QaWlp5t89Hs9Bz9mwYYMAxFNPPWU+9txzzwlAfPDBBwc9P9oxrr76ahEfHy98Pl+fa7awGCnefvttoSiKUBRFLF++XPz4xz8Wb731lggEAgc9N9pv+NRTTxWTJ0+OeMy4ttevX28+9tZbbwlAxMXFiaqqKvPxv/71rwddM5dddpkAxPXXX28+pmmaOPPMM4XD4RANDQ3m4z1tzZVXXilyc3NFY2NjxJq+8Y1viJSUFPM9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yksLMThcPDGG2/wu9/97qDfcG/X9kCu+aF
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"x 0.984026\n",
|
|||
|
"y 0.008833\n",
|
|||
|
"z 0.860115\n",
|
|||
|
"dtype: float64\n",
|
|||
|
" x y z\n",
|
|||
|
"x 0.957077 0.652484 0.563223\n",
|
|||
|
"y 0.652484 1.420160 0.753830\n",
|
|||
|
"z 0.563223 0.753830 1.255599\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"gd = GaussDistribution('MGD', 3)\n",
|
|||
|
"gd.import_data('MGD.csv')\n",
|
|||
|
"gd.fit()\n",
|
|||
|
"gd.generate_samples(100)\n",
|
|||
|
"gd.visualize()\n",
|
|||
|
"# print the mean and covariance matrix of the distribution\n",
|
|||
|
"print(gd.mean)\n",
|
|||
|
"print(gd.cov)"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"Generate visualizations of one- and two-dimensional Gaussians using the above class."
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 5,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": "<Figure size 640x480 with 1 Axes>",
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAABCGElEQVR4nO3deXhU5cHG4d/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ERERCVgWj8fjMR3iQKqqqoiPj8fpdGoGVhERkQDR1u/vDr+aRkRERGR/VEZERETEKJURERERMUplRERERIzy+WoaEZH2tq7IaTqCz47uEW86gkjQ0JERERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMUplRERERIxSGRERERGjVEZERETEKJURERERMeqgysi8efPIysoiMjKSnJwcVq5c2ab9FixYgMViYezYsQfzsiIiIhKEfC4jCxcuJC8vj2nTprF69Wqys7MZM2YMZWVl+91v69at3HrrrZxwwgkHHVZERESCj89lZPbs2VxzzTVMnDiRAQMGMH/+fKKjo3n22Wf3uY/L5eKyyy5j+vTp9OnT55ACi4iISHAJ82XjpqYmVq1axZQpU1rXWa1WcnNzWbFixT73u+eee0hNTeWqq67i448/PuDrNDY20tjY2PpzVVWVLzFFJBh5PITVOQiv3Y61uQ5rS93u/6zHHR5DS2QirsgkWiKTcEUm4bHZTScWkTbyqYxUVFTgcrlIS0vbY31aWhobN27c6z6ffPIJzzzzDGvWrGnz68ycOZPp06f7Ek1EgonHQ+TOjcRs/5TInd8Rues77JXfY2uubtvuFhsNCYfRkDyQ+uSjqe86kPqUY1RQRPyUT2XEV9XV1VxxxRU8/fTTJCcnt3m/KVOmkJeX1/pzVVUVmZmZHRFRRPyEtamGLsUfE1u0hNjCpYTXOX6xjccSRnNMOu7wGO8jLAq3LRJrSx1hDTuxNezE1rgLq7uZqMqNRF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9nGITjrw/n7CHdGF0qF/ZPOv36EuZRC2pioyl/2BrPeuJKx2u+l4IkFHZURE2sf2r+HJ0d6BqhYbHH8LXLcC+pxkOtlBa0w8nC3nvsr2YVNw2+zEFi3h8FdOI7Yg33Q0kaCiMiIih8bj8Z6O+Wsu7NwCcRkw8R3I/ROER5lOd+isYVRkX8vmse9Ql5KNramKrPcnwn9meK8SEpFDpjIiIgevsQb+PRHe/gO4GuHwM+D3n0DP40wna3eNiYfxwzmvUDHgSu+KZQ/BCxdA7Q6juUSCgcqIiBwcZzE8dwZ8swisYXD6DLhkQUCNDfGVxxbB9pH3UHDSXyA8Gn5YAk+eCMWrTUcTCWgqIyLiu5I18NdTwbEOopPhyndg5A0dM3uqH3L2GwvX/Ae69oOqIvjb2bBpselYIgFLZUREfLPxbXjuTO907in94Zp86JljOlXnSz0SrlkCfU+F5jpYcIn3Xjsi4jOVERFpu8/
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": "<Figure size 640x480 with 1 Axes>",
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAi8AAAGdCAYAAADaPpOnAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAABuhklEQVR4nO3deXxUVZ43/k9dMAkkqYoxlQ0D2XjAAGHtCAgtYTGKG47t04z2CI7SjQ06NjgDtLaALTJMo+0otOg4LfgoP7qnbXCBFmNABCHNsMSwRkMIYMhqSFUSJMHc+v1R3KSqUsutqrucc+v7fr2ioXKTnCRV937uOd9zjsnhcDhACCGEEMIJQe8GEEIIIYQEg8ILIYQQQrhC4YUQQgghXKHwQgghhBCuUHghhBBCCFcovBBCCCGEKxReCCGEEMIVCi+EEEII4UpfvRugNFEUcfHiRcTHx8NkMundHEI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qf87B6LJ+99MjxlWvD+HeH79+mLE8yxrDD1sdIPYjmdbduKFhCLsj8nRuzm6M9oLiueTHs8XG2+K8/JRMnR4RKyweyk2Fn0cvodsXGcdHczSbliS57oYIw4j0RCSugwdXqS9an5h/xKl0VkQTcY7kcpFwYUNRgstrkRB0PRirRfWZ1jxGmKMuDIvBRj1GP5qLgBIFtswrLNW76bohoKL/njv2ic9eJlhxetzjsfXtz9GO/+ywtA9L64Sxct6N0EXRnvh8HZi4/HiobaOgZ2qf4/o81GqfW3eZljx2BNjtGEk6oFRXsSEl2ahv95N0JyRgguFFj5oEUzkkNOOUAOONOvo1S0bIcK9+5rlGVa8hRg
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"gd = GaussDistribution('1D', dim=1, mean=0, cov=1)\n",
|
|||
|
"gd.generate_samples(100)\n",
|
|||
|
"gd.visualize()\n",
|
|||
|
"\n",
|
|||
|
"gd = GaussDistribution('2D', dim=2, mean=[0, 0], cov=[[1, 0], [0, 1]])\n",
|
|||
|
"gd.generate_samples(100)\n",
|
|||
|
"gd.visualize()"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"Implement a class “BetaDistribution” (Equation 2.5 in the book)\n",
|
|||
|
"* It is also a child class of “ContinousDistribution”.\n",
|
|||
|
"* It’s purpose is to generate beta distributed samples and plot the distribution giving the parameters a and b.\n",
|
|||
|
"* The contractor should take the parameters a and b as arguments.\n",
|
|||
|
"* Implement a visualization for Beta distributions, including the mean and the standard deviation lines."
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 6,
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"class BetaDistribution(ContinuousDistribution):\n",
|
|||
|
" def __init__(self, name, a, b):\n",
|
|||
|
" super().__init__(name)\n",
|
|||
|
" self.a = a\n",
|
|||
|
" self.b = b\n",
|
|||
|
" self.data = None\n",
|
|||
|
" self.sampled_data = None\n",
|
|||
|
"\n",
|
|||
|
" def import_data(self, filename):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" def export_data(self, filename):\n",
|
|||
|
" self.sampled_data.to_csv(filename, index=False)\n",
|
|||
|
"\n",
|
|||
|
" def compute_mean(self):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" def compute_std(self):\n",
|
|||
|
" pass\n",
|
|||
|
"\n",
|
|||
|
" def visualize(self):\n",
|
|||
|
" # Plot the distribution of the beta distribution\n",
|
|||
|
" x = np.linspace(0, 1, 100)\n",
|
|||
|
" y = beta.pdf(x, self.a, self.b)\n",
|
|||
|
" plt.plot(x, y)\n",
|
|||
|
" plt.title('Beta Distribution with a = ' + str(self.a) + ' and b = ' + str(self.b))\n",
|
|||
|
" plt.xlabel('x')\n",
|
|||
|
" plt.ylabel('y')\n",
|
|||
|
" plt.show()\n",
|
|||
|
"\n",
|
|||
|
" def generate_samples(self, n):\n",
|
|||
|
" self.sampled_data = pd.DataFrame(np.random.beta(self.a, self.b, n), columns=['x'])"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"source": [
|
|||
|
"Generate visualizations of Beta distributions using the above class."
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 7,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": "<Figure size 640x480 with 1 Axes>",
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAHHCAYAAAB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zGysrLueY6HhwcOHjyIpKSkarcUjRw5stIDPx0cHDBmzBjj1yqVCmPGjMHYsWNx+PBhdOjQoVo13M/Vq1dx7NgxTJkyBZ6ensbjLVq0QK9evbBx48a7rnn55ZfLfN2lSxesW7cOOp0OGo2m3NdRKBTo1KkTdu/eDaCka+X69et488038euvvyI6Ohq9evXCnj170Lx58wca2NmzZ0+EhoaWeS8ajQZxcXEVXqdUKqFUKgGUdK1mZGTAYDCgTZs2lfq5mzJlyl2tmOWpbMvC7VasWIHvvvsOU6ZMqVTrwu0/d1lZWSgoKECXLl3w1VdfISYmBhEREcbvu7m5lalbpVKhXbt2Ze7Xxo0b4e/vjyeffNJ4zMXFBS+99BKmTJlS6fcxfvz4Ml//61//wqJFi7Bx40a0aNHinteNGDECDz300H2fvzJ/34YOHYqhQ4cavx48eDD69OmDrl274oMPPrirO5jkxXBDJteuXbsyA/CeeuoptGrVChMmTMDAgQOhUqlw/vx5ZGZmwsfHp9znuHbt2n1fx2Aw4LPPPsOiRYsQHx9fpk+8om6FysrOzgYAuLu73/Ocjz/+GCNHjkRgYCAiIyPRv39/jBgxAiEhIZV+nTtnYlQkICAArq6uZY6VBsmLFy+aLNwkJCQAABo1anTX95o0aYLNmzcjJyenTG316tUrc17ph3V6evo9ww1QEoJKu7327Nk
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"bd = BetaDistribution('Beta', 2, 5)\n",
|
|||
|
"bd.generate_samples(100)\n",
|
|||
|
"bd.visualize()"
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"kernelspec": {
|
|||
|
"display_name": "Python 3",
|
|||
|
"language": "python",
|
|||
|
"name": "python3"
|
|||
|
},
|
|||
|
"language_info": {
|
|||
|
"codemirror_mode": {
|
|||
|
"name": "ipython",
|
|||
|
"version": 2
|
|||
|
},
|
|||
|
"file_extension": ".py",
|
|||
|
"mimetype": "text/x-python",
|
|||
|
"name": "python",
|
|||
|
"nbconvert_exporter": "python",
|
|||
|
"pygments_lexer": "ipython2",
|
|||
|
"version": "2.7.6"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 0
|
|||
|
}
|