code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
function tf = gr_is_connected(G) %GR_IS_CONNECTED Test graph connectivity % % tf = GR_IS_CONNECTED(G); % Returns whether G is a connected graph. Here, G should be % an undirected graph. % % Created by Dahua Lin, on Jan 25, 2012 % %% verify input arguments if ~(is_gr(G) && isequal(G.dty, 'u') && G.has_n...
zzhangumd-smitoolbox
graph/algs/gr_is_connected.m
MATLAB
mit
482
function [edges, ccs] = gr_kruskal(G, w, K) %GR_KRUSKAL Kruskal's Algorithm for minimum spanning tree/forest % % edges = GR_KRUSKAL(G, w); % edges = GR_KRUSKAL(G, w, K); % % Finds the minimum spanning tree/forest of the given graph G. % % Input arguments: % - G: The input graph, which shoul...
zzhangumd-smitoolbox
graph/algs/gr_kruskal.m
MATLAB
mit
2,226
function [Q, H] = hmm_infer(Pi, T, LL) %HMM_INFER HMM E-step inference % % Q = HMM_INFER(Pi, T, LL); % % Infers the (posterior) marginal distributions of all states in % an Hidden Markov Model. % % Suppose there are K distinct state values, and n steps along % the chain. % % Input argu...
zzhangumd-smitoolbox
pmodels/markov/hmm_infer.m
MATLAB
mit
1,412
function [x, v] = chain_viterbi(A, B, w) %CHAIN_VITERBI Viterbi algorithm on a Hidden Markov chain % % [x, v] = CHAIN_VITERBI(A, B); % [x, v] = CHAIN_VITERBI(A, B, w); % % Performs the Viterbi algorithm along a chain that finds a sequence % of states that maximizes the following objective % % ...
zzhangumd-smitoolbox
pmodels/markov/chain_viterbi.m
MATLAB
mit
2,134
function [x, v] = hmm_decode(Pi, T, LL) %HMM_DECODE Find the most probable state sequence for HMM % % [x, v] = HMM_DECODE(Pi, T, LL); % % Finds the state sequence based on an Hidden Markov Model using % viterbi algorithm. % % Suppose there are K states and n nodes of the chain. % % Input argu...
zzhangumd-smitoolbox
pmodels/markov/hmm_decode.m
MATLAB
mit
1,613
function [Alpha, Lc] = hmm_forward(Pi, T, LL) %HMM_FORWARD HMM Forward recursion % % [Alpha, Lp] = HMM_FORWARD(Pi, T, LL); % % Performs forward recursion to evaluate the alpha values for % Hidden Markov Model based inference. % % Input arguments: % - Pi: The initial distribution of state...
zzhangumd-smitoolbox
pmodels/markov/hmm_forward.m
MATLAB
mit
1,692
function Beta = hmm_backward(T, LL, Lc) %HMM_BACKWARD HMM Backward recursion % % Beta = HMM_BACKWARD(T, LL, Lc); % % Performs forward recursion to evaluate the alpha values for % Hidden Markov Model based inference. % % Input arguments: % - T: The transition probability matrix [K x K] %...
zzhangumd-smitoolbox
pmodels/markov/hmm_backward.m
MATLAB
mit
1,467
/********************************************************** * * chain_viterbi_cimp.cpp * * The C++ mex implementation of chain_viterbi * * Created by Dahua Lin, on Feb 1, 2012 * **********************************************************/ #include <bcslib/matlab/bcs_mex.h> #include <cmath> using namespace ...
zzhangumd-smitoolbox
pmodels/markov/private/chain_viterbi_cimp.cpp
C++
mit
5,153
/********************************************************** * * chain_bp_cimp.cpp * * The C++ mex implementation of chain_bp * * Created by Dahua Lin, on Feb 1, 2012 * **********************************************************/ #include <bcslib/matlab/bcs_mex.h> #include <cmath> using namespace bcs; using ...
zzhangumd-smitoolbox
pmodels/markov/private/chain_bp_cimp.cpp
C++
mit
5,691
/******************************************************************** * * hmm_backward_cimp.cpp * * The C++ mex implementation of hmm_backward * * Created by Dahua Lin, on Feb 1, 2012 * ********************************************************************/ #include <bcslib/matlab/bcs_mex.h> #include <cmath> ...
zzhangumd-smitoolbox
pmodels/markov/private/hmm_backward_cimp.cpp
C++
mit
2,472
/******************************************************************** * * hmm_forward_cimp.cpp * * The C++ mex implementation of hmm_forward * * Created by Dahua Lin, on Feb 1, 2012 * ********************************************************************/ #include <bcslib/matlab/bcs_mex.h> #include <cmath> u...
zzhangumd-smitoolbox
pmodels/markov/private/hmm_forward_cimp.cpp
C++
mit
2,548
function T = markov_tpm(K, seqs, w, pri_c) %MARKOV_TPM Estimation of Markov Transition Probability Matrix % % T = MARKOV_TPM(K, seqs); % T = MARKOV_TPM(K, seqs, w); % T = MARKOV_TPM(K, seqs, [], pri_c); % T = MARKOV_TPM(K, seqs, w, pri_c); % % Estimates the transition probability from observed sequences %...
zzhangumd-smitoolbox
pmodels/markov/markov_tpm.m
MATLAB
mit
3,184
function [mu, fmsg, bmsg] = chain_bp(LA, LB) %CHAIN_BP Discrete Belief Propagation along a chain % % [mu, fmsg, bmsg] = CHAIN_BP(LA, LB); % % Performs belief propagation along a chain based on the following % Markov model % % p(x) = (1/Z) * % prod_{i=1}^n a_i(x_i) * % pro...
zzhangumd-smitoolbox
pmodels/markov/chain_bp.m
MATLAB
mit
1,959
function v = ddentropy(P) % Compute the entropy of discrete distribution % % v = ddentropy(P); % computes the entropies of the discrete distributions represented % by columns of P. % % If P is a vector (row or column), it returns the entropy of % the discrete distribution whose probab...
zzhangumd-smitoolbox
pmodels/ddistr/ddentropy.m
MATLAB
mit
776
function v = ddkldiv(P, Q) % Compute Kullback Leibler divergence % % v = ddkldiv(P, Q); % computes the Kullback Leibler divergence between the discrete % distributions represented by the columns of P and Q. % % If P and Q are both vectors, then it returns the K-L divergence % between t...
zzhangumd-smitoolbox
pmodels/ddistr/ddkldiv.m
MATLAB
mit
844
function [P, H] = ddestimate(V, w, c0) %DDESTIMATE Estimates discrete distribution(s) % % P = ddestimate(V); % P = ddestimate(V, w); % % performs maximum likelihood estimation of discrete distribution(s) % given (weighted) observations. % % Input arguments: % - V: the observed histograms,...
zzhangumd-smitoolbox
pmodels/ddistr/ddestimate.m
MATLAB
mit
3,142
function Y = nrmexp(X, dim) % Compute normalized exponentiation % % Y = nrmexp(X); % Y = nrmexp(X, dim); % computes normalized exponentiation along the specified dimension. % If dim is omitted, the normalization is performed along the % first non-singleton dimension. % % Given a ve...
zzhangumd-smitoolbox
pmodels/ddistr/nrmexp.m
MATLAB
mit
1,404
function Q = ddposterior(pri, lik, op) %DDPOSTERIOR Compute posterior discrete distribution % % Q = DDPOSTERIOR(pri, lik); % Q = DDPOSTERIOR(pri, loglik, 'LL'); % % Compute posterior discrete distributions, given prior and % likelihood (or log-likelihood). % % Suppose there are K classes and n (ob...
zzhangumd-smitoolbox
pmodels/ddistr/ddposterior.m
MATLAB
mit
2,391
/******************************************************************** * * ddsample_cimp.cpp * * The C++ mex implementation for ddsample: sampling from * discrete distributions * * Created by Dahua Lin, on Nov 7, 2010 * ********************************************************************/ #include <bcslib/...
zzhangumd-smitoolbox
pmodels/ddistr/private/ddsample_cimp.cpp
C++
mit
2,934
function X = ddsample(P, n) % Draw samples from discrete distribution(s) % % X = ddsample(P, n); % draw n samples from each of the discrete distributions in P. % % Let P be an K x m matrix, then P represents m distinct discrete % distributions over K classes. % % The output X will be an n x m...
zzhangumd-smitoolbox
pmodels/ddistr/ddsample.m
MATLAB
mit
848
classdef tsuite_wishartd % Test suite for wishartd and wishart_sample % % Created by Dahua Lin, on Sep 3, 2011 % %% Properties properties dims = [1 2 3 5]; types = {'s', 'd', 'f'}; deg = 8.5; end %% Test cases methods ...
zzhangumd-smitoolbox
pmodels/tests/tsuite_wishartd.m
MATLAB
mit
4,967
classdef tsuite_ppca % A test suite for PPCA functions % % Created by Dahua Lin, on Dec 27, 2011 % %% properties properties dims = {[2 1], [5, 3], [10, 4]}; end %% Test cases methods function test_basics(obj) ru...
zzhangumd-smitoolbox
pmodels/tests/tsuite_ppca.m
MATLAB
mit
6,035
classdef tsuite_dirichletd % Test suite for dirichlet distribution functions % % History % ------- % - Create by Dahua Lin, on Sep 1, 2011 % - Modified by Dahua Lin, on Sep 3, 2011 % %% Properties properties dims = [2 5]; nu...
zzhangumd-smitoolbox
pmodels/tests/tsuite_dirichletd.m
MATLAB
mit
4,972
classdef tsuite_gammad % Test suite for gamma distribution functions % % History % ------- % - Create by Dahua Lin, on Sep 1, 2011 % - Modified by Dahua Lin, on Sep 3, 2011 % %% Properties properties dims = { [1 1 1], [1 1 3], [1 3 ...
zzhangumd-smitoolbox
pmodels/tests/tsuite_gammad.m
MATLAB
mit
4,188
classdef tsuite_vscatter % A test suite for vscatter function % % Created by Dahua Lin, on Sep 28, 2011 % %% Test cases methods function test_scatter_vec(obj) %#ok<MANU> tsuite_vscatter.run_multi(@tsuite_vscatter.do_test_scatter_vec); end ...
zzhangumd-smitoolbox
pmodels/tests/tsuite_vscatter.m
MATLAB
mit
2,938
classdef tsuite_invgammad % Test suite for inverse gamma distribution functions % % History % ------- % - Create by Dahua Lin, on Sep 1, 2011 % - Modified by Dahua Lin, on Sep 3, 2011 % %% Properties properties dims = { [1 1 1], [1 ...
zzhangumd-smitoolbox
pmodels/tests/tsuite_invgammad.m
MATLAB
mit
4,280
classdef tsuite_gaussd % A test suite for gaussd class % % History % ------- % - Created by Dahua Lin, on Jun 19, 2010 % - Modified by Dahua Lin, on Aug 17, 2011 % - Modified by Dahua Lin, on Aug 25, 2011 % - Modified by Dahua Lin, on Sep 3, 2011 % ...
zzhangumd-smitoolbox
pmodels/tests/tsuite_gaussd.m
MATLAB
mit
15,274
classdef tsuite_gauss_models % The test suite for various Gauss based generative models % % Created by Dahua Lin, on Dec 13, 2011 % %% configurations properties Jx_forms = {'s', 'd', 'f'}; dims = {1, 2, 5, [3, 2]}; Ks = [1, 3]; end %% main test...
zzhangumd-smitoolbox
pmodels/tests/tsuite_gauss_models.m
MATLAB
mit
7,206
function [W, idf] = tf_idf_weight(C, op) %TF_IDF_WEIGHT Computes TF-IDF Weights % % W = TF_IDF_WEIGHT(C); % % calculates the TF-IDF weights for each pair of word and document % in a corpus. % % Input arguments: % - C: The word-count table of the corpus. Suppose there % ...
zzhangumd-smitoolbox
pmodels/topics/tf_idf_weight.m
MATLAB
mit
1,539
function LL = topic_loglik(Beta, C, Q) %TOPIC_LOGLIK Document log-likelihood for Topic model % % LL = TOPIC_LOGLIK(Beta, C, Q); % % Evaluates the log-likelihood of each document based on a % topic model. % % Suppose there are K topics, n documents and V words in the % vocabulary. % % ...
zzhangumd-smitoolbox
pmodels/topics/topic_loglik.m
MATLAB
mit
1,632
function topiclda_demo() %TOPICLDA_DEMO A simple program to demo the use of LDA % % R = TOPICLDA_DEMO; % %% Configuration V = 50; % the number of words in the vocabulary K = 3; % the number of topics n0 = 500; % the number of training documents n1 = 1000; % the number of testing documents nw = 1000; %...
zzhangumd-smitoolbox
pmodels/topics/topiclda_demo.m
MATLAB
mit
2,694
function [sol, objVs] = topiclda_em_update(C, w, eta, sol, eiters, objVs) %TOPICLDA_EM_UPDATE Performs E-M update of a Topic-LDA solution % % [sol, objVs] = TOPICLDA_EM_UPDATE(C, w, eta, sol, eiters); % % Performs E-M update for Topic-LDA estimation. % % Input arguments: % - C: The word-count...
zzhangumd-smitoolbox
pmodels/topics/topiclda_em_update.m
MATLAB
mit
2,092
/********************************************************** * * topic_loglik_cimp.cpp * * C++ mex implementation of topic_loglik * * Created by Dahua Lin, on Feb 18, 2012 * **********************************************************/ #include <bcslib/matlab/bcs_mex.h> #include "specfuncs.h" #include "corpus....
zzhangumd-smitoolbox
pmodels/topics/private/topic_loglik_cimp.cpp
C++
mit
2,866
// The header file for the class Corpus #ifndef SMI_CORPUS_H #define SMI_CORPUS_H namespace smi { struct Doc { Doc() : nwords(0), words(0), counts(0) {} int nwords; const int32_t *words; const double *counts; }; class Corpus { public: // I and J are zero-based indices ...
zzhangumd-smitoolbox
pmodels/topics/private/corpus.h
C++
mit
1,846
/********************************************************** * * topiclda_varinfer_cimp.cpp * * C++ mex implementation of topiclda_varinfer * * Created by Dahua Lin, on Feb 5, 2012 * **********************************************************/ #include <bcslib/matlab/bcs_mex.h> #include "specfuncs.h" #includ...
zzhangumd-smitoolbox
pmodels/topics/private/topiclda_varinfer_cimp.cpp
C++
mit
10,797
// Some special function codes #ifndef SMI_SPECFUNCS_H #define SMI_SPECFUNCS_H #include <cmath> namespace smi { double gammaln(double x) { const double M_lnSqrt2PI = 0.91893853320467274178; const double s0 = 76.18009172947146; const double s1 = -86.50532032941677...
zzhangumd-smitoolbox
pmodels/topics/private/specfuncs.h
C++
mit
2,055
function v = topiclda_ppx(Beta, C, Gamma) %TOPICLDA_PPX Evaluation of Perplexity for Topic LDA % % v = topiclda_ppx(Beta, C, Gamma); % % Evaluates the perplexity over a corpus for a Topic LDA model. % % Input arguments: % - Beta: The word-distributions of topics % - C: The w...
zzhangumd-smitoolbox
pmodels/topics/topiclda_ppx.m
MATLAB
mit
679
classdef topiclda_em < smi_state % Topic Latent Dirichlet allocation E-M algorithm state % % Created by Dahua Lin, on Feb 18, 2012 % %% properties properties(GetAccess='public', SetAccess='private') vsize; % the size of vocabulary (V) prico...
zzhangumd-smitoolbox
pmodels/topics/topiclda_em.m
MATLAB
mit
7,733
function [Gamma, W, objVs, cvg] = topiclda_varinfer(Beta, alpha, C, w, Gamma, maxIter, tol) %TOPICLDA_VARINFER Variational Inference Step of Latent Dirichlet Allocation % % [Gamma, W] = TOPICLDA_VARINFER(Beta, alpha, C, w, Gamma, maxIter, tol); % [Gamma, W, objVs] = TOPICLDA_VARINFER( ... ); % [Gamma, W, objVs, c...
zzhangumd-smitoolbox
pmodels/topics/topiclda_varinfer.m
MATLAB
mit
3,818
function v = topic_ppx(Beta, C, Q) %TOPIC_PPX Corpus Perplexity for Topic model % % v = TOPIC_PPX(Beta, C, Q); % % Evaluates the perplexity of a topic model on a corpus. % % Suppose there are K topics, n documents and V words in the % vocabulary. % % Input arguments: % - Beta: ...
zzhangumd-smitoolbox
pmodels/topics/topic_ppx.m
MATLAB
mit
856
classdef gauss_lingen < genmodel_base % The class that implements a linear Gaussian generative model % % The linear Gaussian generative model, with parameter u, is % formulated as % % x ~ N(A * u, Cx), or x ~ N(u, Cx) if A is identity. % % Here, let d be the dimension o...
zzhangumd-smitoolbox
pmodels/gauss/gauss_lingen.m
MATLAB
mit
13,623
function X = ppca_ft(M, Z) % Performs forward transform w.r.t. PPCA model % % X = ppca_ft(M, Z); % Transforms the latent vectors in Z to the observed space, with % respect to the PPCA model M, as % % x <- W * z. % % Here, Z should be a q x n matrix, and X is a d x n matrix. % % Created by Da...
zzhangumd-smitoolbox
pmodels/gauss/ppca_ft.m
MATLAB
mit
559
function M = ppca_model(B, s, se, mu) % Constructs a Probabilistic PCA model struct % % M = ppca_model(B, s, se); % M = ppca_model(B, s, se, mu); % % constructs a PPCA model strict. % % Input arguments: % % - B: the basis matrix. The size of U is d x q, where % d is the ob...
zzhangumd-smitoolbox
pmodels/gauss/ppca_model.m
MATLAB
mit
2,119
function M = ppca_mle(X, w, q, varargin) % Performs Maximum Likelihood estimation of PPCA from data % % M = ppca_mle(X, [], q, ...); % M = ppca_mle(X, w, q, ...); % % performs Maximum Likelihood estimation of the PPCA % model from data. % % Input arguments: % - X: The data matrix of size ...
zzhangumd-smitoolbox
pmodels/gauss/ppca_mle.m
MATLAB
mit
4,833
function gaussd_ellipse(G, r, n, varargin) % Draws an Ellipse to represent a Gaussian model % % gaussd_ellipse(G, r, n, ...); % % Input arguments: % - G: A gaussd struct to represent the Gaussian model(s) % - r: the relative radius % - n: the number of points on each ellipse %...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_ellipse.m
MATLAB
mit
1,349
function C = ppca_cov(M) % Get the covariance matrix of a PPCA model % % C = ppca_cov(M); % computes the equivalent covariance matrix of the input PPCA model. % % Created by Dahua Lin, on Dec 27, 2011 % %% verify input if ~is_ppca(M) error('ppca_cov:invalidarg', 'M should be a PPCA struct.'); end %% mai...
zzhangumd-smitoolbox
pmodels/gauss/ppca_cov.m
MATLAB
mit
368
function [ca, cb] = gaussd_const(G) % Calculate two useful constants of Gaussian distributions % % ca = gaussd_const(G); % [ca, cb] = gaussd_const(G); % % This function calculates two useful constants for Gaussian % pdf evaluation. % % ca = mu' * h = mu' * inv(C) * mu = h' * inv(J) * h % cb ...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_const.m
MATLAB
mit
1,453
function R = gaussd_mapest(G, S) % Performs MAP estimation w.r.t. Gaussian prior % % R = gaussd_mapest(G, S); % % Performs MAP estimation with the Gaussian prior G, and the % updates to the canonical param of the prior. % % Input arguments: % - G: the Gaussian prior (G.ty == 'c' && ...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_mapest.m
MATLAB
mit
694
function W = ppca_W(M) % Get the factor matrix W of a PPCA model % % W = ppca_W(M); % computes the factor matrix of the input PPCA model. % % Created by Dahua Lin, on Dec 27, 2011 % %% main W = bsxfun(@times, M.B, M.s);
zzhangumd-smitoolbox
pmodels/gauss/ppca_W.m
MATLAB
mit
232
classdef ppca_gm < genmodel_base % The class implementing PPCA as a genmodel_base subclass % % Created by Dahua Lin, on Nov 6, 2011 % properties(GetAccess='public', SetAccess='private') dim; % the observed space dimension ldim; % the latent space dimens...
zzhangumd-smitoolbox
pmodels/gauss/ppca_gm.m
MATLAB
mit
3,960
classdef gausspri < prior_base % Gaussian prior distribution % % This class wrap a gaussd object to prior_base interface % % Created by Dahua Lin, on Dec 27, 2011 % properties(GetAccess='public', SetAccess='private') dim; % the space dimension gdistr; %...
zzhangumd-smitoolbox
pmodels/gauss/gausspri.m
MATLAB
mit
3,707
function G = agmrf(W, a, y) % Constructs an attractive Gaussian MRF % % An attractive Gaussian MRF is defined to be a Gaussian model, as % % p(x) = exp(E(x)) / Z, % % with % % E(x) = 1/2 * sum_{(i,j) \in E} W(i,j) (x(i) - x(j))^2 % + 1/2 * a (x(i) - y(i))^2 % % This can be written in a matr...
zzhangumd-smitoolbox
pmodels/gauss/agmrf.m
MATLAB
mit
1,790
function v = gaussd_entropy(C, op) % Compute the entropy of a Gaussian distribution % % v = gaussd_entropy(C); % v = gaussd_entropy(C, 'm'); % % computes the entropy of Gaussian distribution(s) based on % its covariance matrix. % % C should be a pdmat struct. v will be a scalar (if C.n == 1), % ...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_entropy.m
MATLAB
mit
1,712
function tf = is_gaussd(G) % Tests whether the input argument is a gaussd struct. % % tf = is_gaussd(G); % % Created by Dahua Lin, on Dec 5, 2011 % tf = isstruct(G) && isscalar(G) && isfield(G, 'tag') && ... strcmp(G.tag, 'gaussd');
zzhangumd-smitoolbox
pmodels/gauss/is_gaussd.m
MATLAB
mit
241
classdef gaussgm < genmodel_base % The class to implement a basic Gaussian generative model % % x ~ N(mu, Sigma); % % Two parameters: % - mu: the mean vector % - Sigma: the covariance % % They together are encapsulated in a gaussd struct. % %% propert...
zzhangumd-smitoolbox
pmodels/gauss/gaussgm.m
MATLAB
mit
4,988
function X = ppca_sample(M, n) % Draws n samples from a PPCA model % % X = ppca_sample(M, n); % draws n samples from a PPCA model M. % % Created by Dahua Lin, on Dec 27, 2011 % %% verify input if ~is_ppca(M) error('ppca_sample:invalidarg', 'M should be a ppca struct.'); end if nargin < 2 n = 1; else...
zzhangumd-smitoolbox
pmodels/gauss/ppca_sample.m
MATLAB
mit
544
function D = gaussd_sqmahdist(G, X, ca) % Evaluate the squared Mahalanobis distances to Gaussian centers % % D = gaussd_sqmahdist(G, X); % D = gaussd_sqmahdist(G, X, ca) % % computes the Gaussian Mahalanobis distance to the centers of % Gaussian distribution in G. % % Given a Gaussian distributio...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_sqmahdist.m
MATLAB
mit
4,523
function Z = ppca_bt(M, X) % Performs backward transform w.r.t. PPCA model % % X = ppca_ft(M, Z); % Transforms the observed vectors in X to the latent space, with % respect to the PPCA model M, as % % Here, X should be a d x n matrix, and Z is a q x n matrix. % % Created by Dahua Lin, on Dec 27, 2...
zzhangumd-smitoolbox
pmodels/gauss/ppca_bt.m
MATLAB
mit
545
function J = ppca_icov(M) % Get the inverse covariance matrix of a PPCA model % % J = ppca_icov(M); % computes the inverse covariance matrix of the input PPCA model. % % Created by Dahua Lin, on Dec 27, 2011 % %% verify input if ~is_ppca(M) error('ppca_cov:invalidarg', 'M should be a PPCA struct.'); end ...
zzhangumd-smitoolbox
pmodels/gauss/ppca_icov.m
MATLAB
mit
449
function dists = ppca_sqmahdist(M, X) % Compute squared Mahalanobis distances to the center of PPCA model % % dists = ppca_sqmahdist(M, X); % computes the squared Mahalanobis distances from the samples % in X to the center of the PPCA model M, which is defined by % % (x - mu)' * inv(C) * (x - m...
zzhangumd-smitoolbox
pmodels/gauss/ppca_sqmahdist.m
MATLAB
mit
981
classdef gmrf_blk_gibbs % The class that implements a block gibbs sampler for Gaussian MRF % % Created by Dahua Lin, on Dec 9, 2011 % %% properties properties(GetAccess='public', SetAccess='private') gmrf; % the underlying gaussian model blocks;...
zzhangumd-smitoolbox
pmodels/gauss/gmrf_blk_gibbs.m
MATLAB
mit
5,279
function X = ellip_slice_sample(x0, llikfun, V, intv, n) %ELLIP_SLICE_SAMPLE Elliptical Slice Sampling % % x = ELLIP_SLICE_SAMPLE(x0, llikfun, v); % % Draws the next sample from the posterior formulated as below % % x ~ N(x | 0, Sigma) * llik( x ); % % Here, Sigma is the prior covariance matri...
zzhangumd-smitoolbox
pmodels/gauss/ellip_slice_sample.m
MATLAB
mit
3,413
function tf = is_ppca(M) % Tests whether the input argument is a PPCA model struct % % tf = is_ppca(M); % % Created by Dahua Lin, on Dec 27, 2011 % %% main tf = isstruct(M) && numel(M) == 1 && isfield(M, 'tag') && ... strcmp(M.tag, 'ppca');
zzhangumd-smitoolbox
pmodels/gauss/is_ppca.m
MATLAB
mit
251
function Gpos = gaussd_conjupdate(Gpri, S) % Computes the posterior Gaussian distribution via conjuate update % % Gpos = gaussd_conjupdate(Gpri, S); % % Estimates the posterior distribution via conjugate updates on % a given priro. % % Input arguments: % - G: the Gaussian prior (G.ty...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_conjupdate.m
MATLAB
mit
1,251
function G = gaussd_mle(X, W, cform, tie_cov) % Performs Maximum likelihood estimation of Gaussian distributions % % G = gaussd_mle(X); % G = gaussd_mle(X, W); % G = gaussd_mle(X, W, cform); % G = gaussd_mle(X, W, cform, tie_cov); % % performs maximum likelihood estimation of Gaussian models based on % ...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_mle.m
MATLAB
mit
4,342
function LP = gaussd_logpdf(G, X, ca_cb) % Evaluate the log-pdf of Gaussian models % % LP = gaussd_logpdf(G, X); % LP = gaussd_logpdf(G, X, {ca, cb}) % % computes the log-pdf of the samples given as columns of X, % with respect to the Gaussian distributions in G. % % Inputs: % - G: ...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_logpdf.m
MATLAB
mit
1,385
function G = gaussd(op, param1, param2) % Constructs a Gauss distribution struct % % G = gaussd('m', mu, C); % % constructs a Gaussian distribution struct with mean and % covariance. % % Suppose you are to construct a struct G comprised of n % Gaussian distributions on a d-dimensional space....
zzhangumd-smitoolbox
pmodels/gauss/gaussd.m
MATLAB
mit
6,026
function demo_gmrf_sample(imsiz, w, n, intv) % Demos the use of Gaussian MRF sampling % % demo_gmrf_sample(imsiz, w, n, intv); % % demonstrates the sampling of images from a Gaussian MRF. % % Input: % - imsiz: the image size, in form of [height, width] % - w: the weights of ...
zzhangumd-smitoolbox
pmodels/gauss/demo_gmrf_sample.m
MATLAB
mit
1,764
function L = ppca_logpdf(M, X) % Evaluate log pdf values at given samples % % L = ppca_logpdf(M, X); % evaluates the log proability density values at the samples given % by X, with respect to the PPCA model. % % Suppose X has n columns (each column is sample), then L % is a vector of size 1 x...
zzhangumd-smitoolbox
pmodels/gauss/ppca_logpdf.m
MATLAB
mit
459
function Gs = gaussd_sub(G, idx) % Get a subset of Gaussian models % % Gs = gaussd_sub(G, idx); % Get a subset of Gaussian models (specified by the index or % index vector idx). % % Created by Dahua Lin, on Dec 20, 2011 % %% main if G.ty == 'm' mu = G.mu(:, idx); Gs.tag = G.tag; Gs.ty...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_sub.m
MATLAB
mit
729
function X = gaussd_sample(G, n, Z) % Samples from (multivariate) Gaussian distributions % % X = gaussd_sample(G); % X = gaussd_sample(G, n); % Draws n samples from a Gaussian distribution G whose mean and % covariance are respectively given by mu and C. % % Input arguments: % - G: a...
zzhangumd-smitoolbox
pmodels/gauss/gaussd_sample.m
MATLAB
mit
2,827
function v = fmm_em_objective(pri, LL, w, c0, s) %FMM_EM_OBJECTIVE Evaluate the objective of an FMM-EM solution % % v = FMM_EM_OBJECTIVE(pri, LL, w, c0, s); % % Evaluates the objective function value for EM-estimation of % a finite mixture model. % % Created by Dahua Lin, on Feb 3, 2012 % %% main if ~i...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_em_objective.m
MATLAB
mit
924
function S = fmm_init(pri, gm, X, w, method, arg) %FMM_INIT Initialize an FMM solution % % S = FMM_INIT(pri, gm, X, w, 'params', A); % % Initializes a finite mixture model solution with initial % parameters (given by A). % % Other inputs: % - pri: The prior object % - gm: The ...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_init.m
MATLAB
mit
2,910
classdef fmm_std < smi_state % The class that implements standard finite mixture model % % History % ------- % - Created by Dahua Lin, on Sep 27, 2011 % - Modified by Dahua Lin, on Dec 26, 2011 % %% Properties % configurations properties(GetAcc...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_std.m
MATLAB
mit
7,521
function R = glmm_demo(method, K) % A script to demo the inference over mixture of Gaussian linear models % % R = glmm_demo(method, K); % % Input arguments: % - method: either of the following strings % - 'em': expectation-maximization % - 'gibbs': Gibb...
zzhangumd-smitoolbox
pmodels/mixmodel/glmm_demo.m
MATLAB
mit
2,687
function [S, L] = fmm_em_update(pri, gm, X, w, c0, S, L) %FMM_EM_UPDATE Expectation-Maximization Update for Finite Mixture Model % % [S, L] = FMM_EM_UPDATE(pri, gm, X, w, S, L); % % Updates finite mixture model solution as an E-M iteration. % % Input arguments: % - pri: The prior object % ...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_em_update.m
MATLAB
mit
1,182
function s = fmm_merge_samples(pri, gm, c0, X, w, ss) %FMM_MERGE_SAMPLES Merge multiple FMM solutions into a single one % % s = FMM_MERGE_SAMPLES(pri, gm, X, w, ss); % % Creates a single FMM that best represents all input FMM samples. % % Input arguments: % - pri: the prior object % -...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_merge_samples.m
MATLAB
mit
1,261
function params = fmm_est_params(pri, gm, X, w, Z) % Estimate mixture model given sample assignment % % params = fmm_est_params(pri, gm, X, w, Z); % % Estimates component model parameters given sample assignment. % % Input arguments: % - gm: the generative model of observations % - pri: ...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_est_params.m
MATLAB
mit
1,193
function R = gmm_demo(cf, op) % A script to demo the inference over Gaussian mixture model % % R = gmm_demo(cf); % R = gmm_demo(cf); % % Runs a Gaussian mixture model demo using the specified covariance % matrix form, which can be either 's' (scale form), % 'd' (diagonal form), or 'f' (full matri...
zzhangumd-smitoolbox
pmodels/mixmodel/gmm_demo.m
MATLAB
mit
2,542
function [S, L] = fmm_gibbs_update(pri, gm, X, w, c0, S, L) %FMM_GIBBS_UPDATE Gibbs Sampling Update for Finite Mixture Model % % [S, L] = FMM_GIBBS_UPDATE(pri, gm, X, w, S, L); % % Updates finite mixture model solution as an E-M iteration. % % Input arguments: % - pri: The prior object % ...
zzhangumd-smitoolbox
pmodels/mixmodel/fmm_gibbs_update.m
MATLAB
mit
1,415
function [R, state] = gmm_fit(X, w, K, varargin) %GMM_FIT Fits a Gaussian Mixture Model % % R = gmm_fit(X, [], K, ...); % R = gmm_fit(X, w, K, ...); % % [R, state] = gmm_fit( ... ); % % Fits a Gaussian mixture model to a (weighted) set of data. % % Suppose there are n samples on a d dimensional space....
zzhangumd-smitoolbox
pmodels/mixmodel/gmm_fit.m
MATLAB
mit
6,333
function gsm_demo(method) % A simple demo of Gaussian scale mixture fitting % % gsm_demo(method); % % Here method can be either 'ip' or 'em'. % % Created by Dahua Lin, on Nov 2, 2011 % %% configure model K = 4; sigma = [1, 4, 12, 36].'; p = [0.4, 0.2, 0.25, 0.15].'; ext = 100; %% generate data n = 1e5; z = dd...
zzhangumd-smitoolbox
pmodels/mixmodel/gsm_demo.m
MATLAB
mit
1,051
function [p, s, converged] = gsm_fit(x, w, K, varargin) % Fits a Gaussian scale mixture to data % % The pdf of a Gaussian scale mixture (GSM) model is formulated as % % f(x) = \sum_{k=1}^K p_k/sqrt(2 *pi * s_k^2) * % exp(- x^2 / (2 * s_k^2) ); % % Here, p_1, ..., p_K are the prior w...
zzhangumd-smitoolbox
pmodels/mixmodel/gsm_fit.m
MATLAB
mit
9,730
function mixppca_demo(n, K) % A program to demonstrate the use of mixture of PPCA % % mixppca_demo(n, K); % % Here, n is the number of sample points, K is the number of % mixture components to be used % % By default n = 50000, and K = 8; % % Created by Dahua Lin, on Nov 6, 2011 % %% get input if...
zzhangumd-smitoolbox
pmodels/mixmodel/mixppca_demo.m
MATLAB
mit
1,099
function c = invgammad_const(alpha, beta) % Compute the constant term for gamma distribution logpdf % % c = invgammad_const(alpha, beta); % % Evaluates the following constant term for the evaluation of % inverse gamma distribution logpdf: % % c = - (alpha log(beta) + gammaln(alpha)) % % Th...
zzhangumd-smitoolbox
pmodels/gamma/invgammad_const.m
MATLAB
mit
811
function L = gammad_logpdf(alpha, beta, X, c) %GAMMAD_LOGPDF Evaluate log probability density of gamma distribution % % log f(x; alpha, beta) = % (alpha - 1) log(x) - x / beta + const % % with const = - (alpha log(beta) + gammaln(alpha)) % % L = gammad_logpdf(alpha, beta, X); % L = gammad_logpdf(alpha, b...
zzhangumd-smitoolbox
pmodels/gamma/gammad_logpdf.m
MATLAB
mit
3,474
function v = dird_entropy(alpha, d) %DIRD_ENTROPY Evaluates the entropy of Dirichlet distribution % % v = dird_entropy(alpha, d); % % Evaluates the entropy of Dirichlet distribution(s). % % Here, alpha should be a matrix of size d x n, and in the output, % the size of v is 1 x n. Particularly...
zzhangumd-smitoolbox
pmodels/gamma/dird_entropy.m
MATLAB
mit
1,029
function [alpha, objv] = dird_mle(X, w, alpha0, varargin) %DIRD_MLE Maximum-likelihood Estimation of Dirichlet Distribution % % [alpha, objv] = DIRD_MLE(X, w, alpha0); % [alpha, objv] = DIRD_MLE(X, w, alpha0, ...); % % Performs maximum-likelihood estimation of Dirichlet distribution. % % Input arguments...
zzhangumd-smitoolbox
pmodels/gamma/dird_mle.m
MATLAB
mit
5,728
function L = wishartd_logpdf(Sigma, df, V, c, op) %WISHARTD_LOGPDF Evaluates the log pdf of Wishart distribution % % L = wishartd_logpdf(Sigma, df, V); % L = wishartd_logpdf(Sigma, df, V, 0); % L = wishartd_logpdf(Sigma, df, V, c); % % Evaluates the log pdf at the matrices given in V, w.r.t. the % Wis...
zzhangumd-smitoolbox
pmodels/gamma/wishartd_logpdf.m
MATLAB
mit
2,266
function h = visdird3(alpha, form) % Visualize a Dirichlet distribution with K == 3 % % visdird3(alpha); % visdird3(alpha, 'image'); % visdird3(alpha, 'mesh'); % % visualizes a Dirichlet distribution with K = 3 as a colored % image or mesh. (image by default); % % alpha is either a scalar or a ...
zzhangumd-smitoolbox
pmodels/gamma/visdird3.m
MATLAB
mit
2,091
function c = wishartd_const(J, df) % Compute the constant term for Wishart distribution log-pdf % % c = wishartd_const(J, df); % % Evaluates the constant term for Wishart distribution log-pdf % or inverse Wishart distribution log-pdf. % % Inputs: % - J: inverse scale matrix in form of p...
zzhangumd-smitoolbox
pmodels/gamma/wishartd_const.m
MATLAB
mit
974
function v = gammad_entropy(alpha, beta) % Compute the entropy for gamma distribution % % v = gammad_entropy(alpha, beta); % % Evaluates the entropy of gamma distribution. % % The sizes of alpha and beta should be compatible in the bsxfun % sense. % % If either size(alpha, 1) > 1 or size(beta,...
zzhangumd-smitoolbox
pmodels/gamma/gammad_entropy.m
MATLAB
mit
665
function X = dird_sample(alpha, n) %DIRD_SAMPLE Samples from a Dirichlet distribution % % X = dird_sample(alpha); % X = dird_sample(alpha, n); % X = dird_sample(alpha, [d, n]); % % Draws n samples from a Dirichlet distribution over the % (d-1)-dimensional probability simplex, whose parameter % ...
zzhangumd-smitoolbox
pmodels/gamma/dird_sample.m
MATLAB
mit
1,818
function X = gammad_sample(alpha, beta, n) %GAMMAD_SAMPLE Samples from a Gamma distribution % % X = gammad_sample(alpha, beta); % X = gammad_sample(alpha, beta, n); % % draws n samples from a gamma distribution with shape parameter % alpha and scale parameter beta. % % Input arguments: % - ...
zzhangumd-smitoolbox
pmodels/gamma/gammad_sample.m
MATLAB
mit
2,351
function L = invwishartd_logpdf(Phi, df, V, c) %INVWISHARTD_LOGPDF Evaluates the log pdf of Inverse Wishart distribution % % L = invwishartd_logpdf(Phi, df, V); % L = invwishartd_logpdf(Phi, df, V, 0); % L = invwishartd_logpdf(Phi, df, V, c); % % Evaluates the log pdf at the matrices given in V, w.r.t. the ...
zzhangumd-smitoolbox
pmodels/gamma/invwishartd_logpdf.m
MATLAB
mit
1,822
function v = invgammad_entropy(alpha, beta) % Compute the entropy for inverse gamma distribution % % v = invgammad_entropy(alpha, beta); % % Evaluates the entropy of inverse gamma distribution. % % The sizes of alpha and beta should be compatible in the bsxfun % sense. % % If either size(alpha...
zzhangumd-smitoolbox
pmodels/gamma/invgammad_entropy.m
MATLAB
mit
687
function v = mvbetaln(alpha, d) %MVBETALN Logarithm of multivariate beta function % % A multivariate beta function is defined to be % % f(a) = prod(gamma(a)) / gamma(sum(a)). % % % v = mvbetaln(alpha); % % Evaluates the logarithm of multivariate beta function. % % Here, alpha should be a ma...
zzhangumd-smitoolbox
pmodels/gamma/mvbetaln.m
MATLAB
mit
1,478
function V = mvgammaln(d, X) % Evaluate Multivariate Log-Gamma function % % In math, the multivariate gamma function with dim d, is defined by % % Gamma_d(x) = pi^(d * (d-1) / 4) % * prod_{j=1}^d Gamma(x + (1 - j)/2) % % In particular, when d == 1, Gamma_d(x) = Gamma(x) % % Then, i...
zzhangumd-smitoolbox
pmodels/gamma/mvgammaln.m
MATLAB
mit
1,496
function c = gammad_const(alpha, beta) % Compute the constant term for gamma distribution logpdf % % c = gammad_const(alpha, beta); % % Evaluates the following constant term for the evaluation of % gamma distribution logpdf: % % c = - (alpha log(beta) + gammaln(alpha)) % % The sizes of alp...
zzhangumd-smitoolbox
pmodels/gamma/gammad_const.m
MATLAB
mit
802
/******************************************************************** * * wishartd_sample_cimp.cpp * * The C++ mex implementation for pieces * * Created by Dahua Lin, on Mar 22, 2011 * ********************************************************************/ #include <bcslib/matlab/bcs_mex.h> #include <cmath> ...
zzhangumd-smitoolbox
pmodels/gamma/private/wishartd_sample_cimp.cpp
C++
mit
2,226