Last active
August 29, 2015 14:22
-
-
Save xuewei4d/de5492d0320eed561b78 to your computer and use it in GitHub Desktop.
GMM API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"class DensityMixin(object):\n", | |
" def score(self, X):\n", | |
" \"\"\"Return the log liklihood of the model given the data X, #2473, #4062.\"\"\"\n", | |
" return np.sum(self.score_samples(X))\n", | |
" \n", | |
" def density(self, X):\n", | |
" \"\"\"Return the density value of the data\"\"\"\n", | |
" return np.exp(self.score_samples(X))\n", | |
" \n", | |
" \n", | |
"class GaussianMixture(DensityMixin, BaseEstimator):\n", | |
" def __init__(self, n_components=1, covariance_type='diag',\n", | |
" random_state=None, thresh=None, tol=1e-3, min_covar=1e-3,\n", | |
" n_iter=100, n_init=1, params='wmc', init_params='wmc',\n", | |
" verbose=0):\n", | |
" \"\"\"\n", | |
" Comment:\n", | |
" 1. covariance_type=\"full\" would be the usual case\n", | |
" 2. deprecate ``params`` ? #4429\n", | |
" \"\"\"\n", | |
" pass\n", | |
" \n", | |
" def _get_covars(self):\n", | |
" \"\"\"Covariance parameters for each mixture component.\n", | |
" The shape depends on `cvtype`::\n", | |
"\n", | |
" (`n_states`, 'n_features') if 'spherical',\n", | |
" (`n_features`, `n_features`) if 'tied',\n", | |
" (`n_states`, `n_features`) if 'diag',\n", | |
" (`n_states`, `n_features`, `n_features`) if 'full'\n", | |
" \n", | |
" Comment: Change it to be public, #1528\n", | |
" \"\"\"\n", | |
" \n", | |
" \n", | |
" def score_samples(self, X):\n", | |
" \"\"\"Return the per-sample likelihood of the data under the model.\n", | |
"\n", | |
" Compute the log probability of X under the model and\n", | |
" return the posterior distribution (responsibilities) of each\n", | |
" mixture component for each element of X.\n", | |
" \n", | |
" Parameters\n", | |
" ----------\n", | |
" X: array_like, shape (n_samples, n_features)\n", | |
" \n", | |
" Returns\n", | |
" -------\n", | |
" logprob : array_like, shape (n_samples,)\n", | |
" Log probabilities of each data point in X.\n", | |
" \n", | |
" Comment: log likelihood given the data or probability of the data?\n", | |
" what should score in score_sampling mean? I think it is intended for each sample, \n", | |
" it should be the probability of the data, refer to 'likelihood function' in wiki.\n", | |
" So should we just keep using the name score_sample?\n", | |
" \n", | |
" Currently it returns a tuple of log_probability, responsibility\n", | |
" it should return only log_probability #2473\n", | |
" \n", | |
" \"\"\"\n", | |
" pass \n", | |
" \n", | |
"\n", | |
" def score(self, X, y=None):\n", | |
" \"\"\"Compute the log probability under the model.\n", | |
"\n", | |
" Parameters\n", | |
" ----------\n", | |
" X : array_like, shape (n_samples, n_features)\n", | |
" List of n_features-dimensional data points. Each row\n", | |
" corresponds to a single data point.\n", | |
"\n", | |
" Returns\n", | |
" -------\n", | |
" logprob : array_like, shape (n_samples,)\n", | |
" Log probabilities of each data point in X\n", | |
" \n", | |
" Comment: \n", | |
" 1. Move it to the DensityMixin, #2473\n", | |
" 2. It should return one single number, the likelihood of the model given the data\n", | |
" \"\"\"\n", | |
" pass\n", | |
" " | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"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.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment