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 r = calc_sumprod(dim, n, a, b)
% sum the corresponding products along the direction dim
%
% expand a or b to n rows/columns along the specified dimension
%
na = size(a, dim);
nb = size(b, dim);
if na == 1
if nb == 1
r = a .* b;
if n > 1
r = r * n;
end
else
... | zzhangumd-smitoolbox | pmodels/gamma/private/calc_sumprod.m | MATLAB | mit | 875 |
function X = invgammad_sample(alpha, beta, n)
%invgammad_sample Samples from an inverse Gamma distribution
%
% X = invgammad_sample(alpha, beta);
% X = invgammad_sample(alpha, beta, n);
%
% draws n samples from an inverse gamma distribution with shape
% parameter alpha and scale parameter beta.
%
% ... | zzhangumd-smitoolbox | pmodels/gamma/invgammad_sample.m | MATLAB | mit | 1,095 |
function C = dird_cov(alpha, d)
%DIRD_COV the covariance matrix of a Dirichlet distribution
%
% C = DIRD_COV(alpha);
% C = DIRD_COV(alpha, d);
%
% Computes the covariance matrix of a dirichlet distribution.
% Here, alpha is either a scalar, or a vector of size d x 1.
%
% Created by Dahua Lin, on Dec 26... | zzhangumd-smitoolbox | pmodels/gamma/dird_cov.m | MATLAB | mit | 1,262 |
function W = wishartd_sample(S, df, n)
% Samples from a Wishart distribution
%
% W = wishartd_sample(d, df);
% draws a sample from a d-dimensional df-degree standard Wishart
% distribution (whose scale matrix is an identity matrix).
%
% The result is returned in form of a d x d matrix.
%
% W = wis... | zzhangumd-smitoolbox | pmodels/gamma/wishartd_sample.m | MATLAB | mit | 3,032 |
function L = dird_logpdf(alpha, X, c)
%DIRD_LOGPDF Evaluates log-pdf of Dirichlet distribution
%
% L = dird_logpdf(alpha, X)
% L = dird_logpdf(alpha, X, 0);
% L = dird_logpdf(alpha, X, c);
%
% Evaluates the log probability density values at given samples
% with respect to given Dirichlet distribution(... | zzhangumd-smitoolbox | pmodels/gamma/dird_logpdf.m | MATLAB | mit | 2,567 |
function L = invgammad_logpdf(alpha, beta, X, c)
%invgammad_logpdf Evaluate log probability density of inverse gamma distribution
%
% log f(x; alpha, beta) =
% - (alpha + 1) * log(x) - beta / x + const
%
% with const = alpha * log(beta) - gammaln(alpha)
%
% L = invgammad_logpdf(alpha, beta, X);
% L = inv... | zzhangumd-smitoolbox | pmodels/gamma/invgammad_logpdf.m | MATLAB | mit | 3,537 |
function opt = mcmc_options(opt, varargin)
% Verify or set MCMC sampling options for smi_mcmc
%
% opt = mcmc_options();
% opt = mcmc_options([]);
% returns the default MCMC sampling option struct.
%
% opt = mcmc_options(opt);
% verify the validity of an MCMC sampling option
%
% opt = mcmc_options([]... | zzhangumd-smitoolbox | pmodels/common/mcmc_options.m | MATLAB | mit | 3,713 |
function r = randpick(n, k)
%RANDPICK Random sample without replacement
%
% r = RANDPICK(n, k);
%
% randomly pick k distinct numbers from 1:n. In the output, r is
% a vector of size 1 x k. (Note that it should have k <= n).
% Note that r is sorted.
%
% History
% -------
% - Created... | zzhangumd-smitoolbox | pmodels/common/randpick.m | MATLAB | mit | 996 |
function R = mcmc_drive(S, opts)
%MCMC_DRIVE Drive the running of an MCMC procedure.
%
% R = MCMC_DRIVE(S, opts);
%
% Drives a MCMC sampling procedure and collects samples.
%
% Input arguments:
% - S0: The SMI state (an instance of class smi_state) that
% has been initialized... | zzhangumd-smitoolbox | pmodels/common/mcmc_drive.m | MATLAB | mit | 2,037 |
function mv = vecmean(X, w)
%VECMEAN Mean(s) of vectors
%
% mv = VECMEAN(X);
% Computes the mean vector of the column vectors in X.
%
% The mean vector of vectors v1, v2, ..., vn is defined as
%
% mv = (v1 + v2 + ... + vn) / n;
%
% Let X be a d x n matrix, with each column rep... | zzhangumd-smitoolbox | pmodels/common/vecmean.m | MATLAB | mit | 1,810 |
function opt = varinfer_options(opt, varargin)
% Verify or set variational inference control options for smi_varinfer
%
% opt = varinfer_options();
% opt = varinfer_options([]);
% returns the default variational inference option struct.
%
% opt = varinfer_options(opt);
% verify the validity of an vari... | zzhangumd-smitoolbox | pmodels/common/varinfer_options.m | MATLAB | mit | 4,197 |
function [V, mv] = vecvar(X, w, mv)
%VECVAR Variances of vector components
%
% V = VECVAR(X);
% computes the variances of the components of vectors in X.
%
% The variance of values v1, v2, ..., vn is defined as
%
% (sum_i (v_i - mv)^2) / n
%
% here, mv is the mean value.
%
% Given a ... | zzhangumd-smitoolbox | pmodels/common/vecvar.m | MATLAB | mit | 3,811 |
classdef genmodel_base
% The base of the classes that implement simple generative model
%
% This is an abstract class that defines the functions to be
% implemented by derived classes.
%
methods(Abstract)
n = query_obs(obj, X);
% Verify the observations... | zzhangumd-smitoolbox | pmodels/common/genmodel_base.m | MATLAB | mit | 910 |
function [C, mv] = veccov(X, w, mv)
%VECCOV Computes the covariance matrix of vectors
%
% C = veccov(X);
% computes the covariance matrix of column vectors in X.
%
% The function computes the sample covariance matrix for sample
% vectors v1, v2, ..., vn, as
%
% C = sum_i (vi - mv)... | zzhangumd-smitoolbox | pmodels/common/veccov.m | MATLAB | mit | 4,372 |
function R = varinfer_drive(S, opts)
% Drive a MCMC sampling procedure based on an SMI program
%
% R = varinfer_drive(S, opts);
%
% Drives a variational inference procedure and collects samples.
%
% Input arguments:
% - S: the SMI state that has been properly initialized.
%
% - opts: ... | zzhangumd-smitoolbox | pmodels/common/varinfer_drive.m | MATLAB | mit | 3,297 |
classdef prior_base
% The base class of prior distributions
%
% Created by Dahua Lin, on Dec 27, 2011
%
methods(Abstract)
n = query_samples(obj, X);
% Verify the validity of input samples and return the number
L = logpdf(obj, X);
% Evaluate... | zzhangumd-smitoolbox | pmodels/common/prior_base.m | MATLAB | mit | 683 |
/********************************************************************
*
* C++ mex implementation of core algorithm of randpick
*
* Created by Dahua Lin, on Aug 10, 2011
*
*******************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <set>
#include <cmath>
usi... | zzhangumd-smitoolbox | pmodels/common/private/randpick_cimp.cpp | C++ | mit | 3,201 |
function P = binoprobs(n, p)
% Compute probability of binomial distribution
%
% P = binoprobs(n, p);
% Compute the probability mass function of binomial distribution.
% In the input, n is a positive integer representing the total
% number of trials, p is the probability of success of each trial.
% ... | zzhangumd-smitoolbox | pmodels/common/binoprobs.m | MATLAB | mit | 1,468 |
function R = rand_label(K, n, op)
% Generates random labeling
%
% R = rand_label(K, n);
% R = rand_label(K, n, 'v');
%
% Generates a 1 x n row vector, with each element being a
% random integer in [1, K].
%
% R = rand_label(K, n, 'b');
%
% Generates a K x n matrix, with each column being a rando... | zzhangumd-smitoolbox | pmodels/common/rand_label.m | MATLAB | mit | 1,409 |
function R = vscatter(X, U, W, op)
% Compute the scatter vector/matrix
%
% R = vscatter(X, U, W, 'v');
% computes the scatter vector defined as follows.
%
% Suppose X is a d x n matrix, U is a d x K matrix, then
% R is a d x K matrix defined by
%
% R(i, k) = sum_j W(k, j) * (X(i, j) - U(i, k)... | zzhangumd-smitoolbox | pmodels/common/vscatter.m | MATLAB | mit | 3,310 |
classdef smi_state
%SMI_STATE the base class of the run-time state of an iterative program
%
% Created by Dahua Lin, on Dec 26, 2011
%
methods(Abstract)
obj = initialize(obj, varargin);
% Initialize the state
obj = update(obj);
% Update cur... | zzhangumd-smitoolbox | pmodels/common/smi_state.m | MATLAB | mit | 525 |
function s = dpmm_merge_samples(M, obs, H, ss, varargin)
%DPMM_MERGE_SAMPLES Merges multiple samples from the same chain into one
%
% s = dpmm_merge_samples(M, obs, H, ss, ...);
%
% merges multiple DPMM samples drawn from a MCMC chain (those
% produced by the method make_output of dpmm class) into a singl... | zzhangumd-smitoolbox | pmodels/dp/dpmm_merge_samples.m | MATLAB | mit | 4,819 |
classdef dpmm_sol
% The class that captures a DPMM solution
%
% Created by Dahua Lin, on Sep 26, 2011
%
%% properties
properties(GetAccess='public', SetAccess='private')
nobs; % the number of observations
iatoms; % the vector of the atom-ind... | zzhangumd-smitoolbox | pmodels/dp/dpmm_sol.m | MATLAB | mit | 14,667 |
function v = logcrp(alpha, M)
% LOGCRP evaluates log-probability of a partition under Chinese Restaurant Process
%
% Given a partition with K clusters, in which the k-th cluster has
% m(k) elements, the log-probability of m is
%
% p(m) = alpha^K * prod_{k=1}^K (m(k) - 1)! *
% Gamma(alpha) / Gam... | zzhangumd-smitoolbox | pmodels/dp/logcrp.m | MATLAB | mit | 2,180 |
function S = dpmm_inherits(atom_ids, max_id, atoms, pricounts, q, T)
%DPMM_INHERITS Creates a struct that captures the inherited atoms for DPMM
%
% S = DPMM_INHERITS(atom_ids, max_id, atoms, pricounts);
% S = DPMM_INHERITS(atom_ids, max_id, atoms, pricounts, q);
% S = DPMM_INHERITS(atom_ids, max_id, atoms, pricou... | zzhangumd-smitoolbox | pmodels/dp/dpmm_inherits.m | MATLAB | mit | 3,046 |
function [x, acc] = crpsim(alpha, n, pricount)
%CRPSIM Simulate a Chinese Restaurant Process (CRP)
%
% x = CRPSIM(alpha, n);
%
% simulates a Chinese Restaurant process to generate a sequence
% of length n.
%
% x = CRPSIM(alpha, n, pricount);
%
% performs the simulation with prior count on the firs... | zzhangumd-smitoolbox | pmodels/dp/crpsim.m | MATLAB | mit | 1,375 |
function s = dpmm_demo(op)
% A program to demonstrate the use of DPMM
%
% s = dpmm_demo; with visualization
% s = dpmm_demo('novis'); no visualization
%
% The function returns the merged sample.
%
% Created by Dahua Lin, on Sep 21, 2011
%
%% parse input
novis = nargin == 1 && strcmpi(op, 'no... | zzhangumd-smitoolbox | pmodels/dp/dpmm_demo.m | MATLAB | mit | 1,578 |
/********************************************************************
*
* crpsim_cimp.cpp
*
* The C++ mex implementation of crpsim (CRP simulation)
*
* Created by Dahua Lin, on Sep 17, 2011
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <... | zzhangumd-smitoolbox | pmodels/dp/private/crpsim_cimp.cpp | C++ | mit | 2,468 |
/********************************************************************
*
* dp_base.h
*
* Basic facilities for DP-based implementation
*
* Created by Dahua Lin, on Sep 17, 2011
*
********************************************************************/
#ifndef DP_BASE_H_
#define DP_BASE_H_
/**
* Draw from a dis... | zzhangumd-smitoolbox | pmodels/dp/private/dp_base.h | C | mit | 668 |
/**********************************************************
*
* dpmm_redraw_labels.cpp
*
* C++ mex implementation of label re-drawing
*
* Created by Dahua Lin, on Sep 24, 2011
*
**********************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include "dp_base.h"
#include <cma... | zzhangumd-smitoolbox | pmodels/dp/private/dpmm_redraw_labels.cpp | C++ | mit | 1,765 |
classdef dpmm < smi_prg
% The class to implement a DP mixture model (DPMM) program
%
% Created by Dahua Lin, on Sep 17, 2011
%
%% Properties
properties(GetAccess='public', SetAccess='private')
amodel; % the underlying atom model (of class genmodel_base)
base... | zzhangumd-smitoolbox | pmodels/dp/dpmm.m | MATLAB | mit | 8,128 |
function write_mps(P, filename, fmt)
% Write an LP or QP optimization problem to MPS file
%
% write_mps(P, filename);
% writes an LP problem to the specified MPS file.
%
% write_mps(P, filename, fmt);
% writes an QP problem to the specified MPS file using specified
% extension.
%
% Note that... | zzhangumd-smitoolbox | optim/adaptor/write_mps.m | MATLAB | mit | 8,634 |
function [x, fval, flag, info] = mstd_solve(P, options)
% Adaptor of MATLAB optimization toolbox to solve the LP/QP problem
%
% x = mstd_solve(P);
% x = mstd_solve(P, options);
%
% Uses linprog/quadprog (in optimization toolbox) to solve the
% LP/QP problem given by the struct P (as constructed in l... | zzhangumd-smitoolbox | optim/adaptor/mstd_solve.m | MATLAB | mit | 2,562 |
function [x, fval, flag, info] = cplex_solve(P, options)
% Adaptor of CPLEX optimizer to solve the LP/QP problem
%
% x = cplex_solve(P);
% x = cplex_solve(P, options);
%
% Uses quadprog (in optimization toolbox) to solve the LP or QP
% problem given by the struct P (as constructed in lp_problem or ... | zzhangumd-smitoolbox | optim/adaptor/cplex_solve.m | MATLAB | mit | 2,366 |
function [x, fval, flag, info] = mosek_solve(P, options)
% The wrapper of MOSEK optimizer for solving LP or QP problem.
%
% x = mosek_solve(P);
% x = mosek_solve(P, options);
%
% [x, fval] = mosek_solve( ... );
% [x, fval, flag] = mosek_solve( ... );
% [x, fval, flag, info] = mosek_solve( ..... | zzhangumd-smitoolbox | optim/adaptor/mosek_solve.m | MATLAB | mit | 2,760 |
function [x, fval, flag, info] = gurobi_solve(P, options)
% Adaptor of GUROBI optimizer to solve the LP/QP problem
%
% x = gurobi_solve(P);
% x = gurobi_solve(P, options);
%
% Uses GUROBI optimizer to solve the LP or QP problem given by the
% struct P (as constructed in lp_problem or qp_problem).
%... | zzhangumd-smitoolbox | optim/adaptor/gurobi_solve.m | MATLAB | mit | 1,757 |
/********************************************************************
*
* qpps.cpp
*
* The C++ mex implementation of qpps.m
*
* Created by Dahua Lin, on Jul 21, 2010
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <algorithm>
using namesp... | zzhangumd-smitoolbox | optim/lpqp/qpps.cpp | C++ | mit | 3,226 |
function [x, lambda] = qplec(H, f, A, b)
% Solves quadratic programming problems with linear equation constraints
%
% x = qplec(H, f, A, b);
% solves the following constrained quadratic programming problem:
%
% minimize (1/2) * x' * H * x + f' * x
% s.t. A * x = b
%
% Suppose ... | zzhangumd-smitoolbox | optim/lpqp/qplec.m | MATLAB | mit | 3,228 |
function S = lp_problem(f, A, b, Aeq, beq, l, u)
%LP_PROBLEM Linear programming problem
%
% A Linear programming problem is formulated as:
%
% minimize f(x) = f' * x;
%
% s.t. bl <= A * x <= bu
% Aeq * x = beq
% l <= x <= u
%
% S = LP_PROBLEM(f, A, b);
% S = LP_PROBLEM(f... | zzhangumd-smitoolbox | optim/lpqp/lp_problem.m | MATLAB | mit | 2,392 |
% The function to solve a simple QP on probability simplex
%
% The problem is formulated as follows:
%
% min (1/2) ||x||^2 - f' * x;
%
% s.t. x >= 0 (element wise), and sum(x) == 1.
%
%
% X = qpps(F);
%
% When F is a vector, it returns the solution vector.
%
% When F is an m x n matrix (m > ... | zzhangumd-smitoolbox | optim/lpqp/qpps.m | MATLAB | mit | 528 |
function [Aeq, beq] = check_lin_eqc(d, Aeq, beq, funname)
% Check the validity of linear equality constraints
%
% [Aeq, beq] = check_lin_eqc(d, Aeq, beq, funname);
%
if ~(isfloat(Aeq) && ndims(Aeq) == 2)
error([funname ':invalidconstr'], ...
'The equality coefficient matrix Aeq should be a numeric matrix... | zzhangumd-smitoolbox | optim/lpqp/private/check_lin_eqc.m | MATLAB | mit | 795 |
function [l, u] = check_bnds(d, l, u, funname)
% Check the validity of range bounds
%
% [l, u] = check_bnds(d, l, u, funcname);
%
if ~isempty(l)
if ~(isfloat(l) && (isscalar(l) || isequal(size(l), [d 1])))
error([funname ':invalidconstr'], ...
'The lower bound should be either a scalar of a d... | zzhangumd-smitoolbox | optim/lpqp/private/check_bnds.m | MATLAB | mit | 729 |
function [A, bl, bu] = check_lin_iec(d, A, b, funname)
% Check the validity of linear inequality constraints
%
% [A, bl, bu] = check_lin_iec(d, A, b, funname);
%
if ~(isfloat(A) && ndims(A) == 2)
error([funname ':invalidconstr'], ...
'The inequality coefficient matrix A should be a numeric matrix.');
end... | zzhangumd-smitoolbox | optim/lpqp/private/check_lin_iec.m | MATLAB | mit | 1,588 |
function S = qp_problem(H, f, A, b, Aeq, beq, l, u)
%QP_PROBLEM Quadratic programming problem
%
% A Linear programming problem is formulated as:
%
% minimize f(x) = (1/2) * x' * H * x + f' * x;
%
% s.t. bl <= A * x <= bu
% Aeq * x = beq
% l <= x <= u
%
% S = QP_PROBLEM(H, ... | zzhangumd-smitoolbox | optim/lpqp/qp_problem.m | MATLAB | mit | 2,648 |
function [x, v, dx, fcnt] = linesearch(f, x0, v0, step, beta, minstep)
% Performs line search as a step in numerical optimization
%
% [x, v, dx, fcnt] = linesearch(f, x, step, beta, minstep);
% performs line search along the direction of step to locate the
% minima.
%
% Inputs:
% - f: t... | zzhangumd-smitoolbox | optim/nonlin/linesearch.m | MATLAB | mit | 1,767 |
function options = smi_optimset(op0, varargin)
% Set optimization options (for SMI optimization functions)
%
% options = smi_optimset(funcname);
%
% Gets the default optimization setting for a smi optimization
% function (such as 'gdfmin', 'bfgsfmin', and 'newtonfmin').
%
% options = smi_optimset(funcna... | zzhangumd-smitoolbox | optim/nonlin/smi_optimset.m | MATLAB | mit | 3,401 |
classdef optim_mon
% The class to represent a optimization monitor
%
% Created by Dahua Lin, on Aug 7, 2010
%
properties(Constant)
NoneLevel = 0;
ProcLevel = 1;
IterLevel = 2;
end
properties(GetAccess='public', SetAccess='privat... | zzhangumd-smitoolbox | optim/nonlin/optim_mon.m | MATLAB | mit | 3,109 |
function [x, info] = bfgsfmin(f, x0, varargin)
% Perform unconstrained minimization using (BFGS) quasi-Newton method
%
% x = bfgsfmin(f, x0, ...);
% solves a (local) minima of f using quasi-Newton method, with
% Broyden-Fletcher-Goldfarb-Shanno (BFGS) updates.
% Here, f is the objective funct... | zzhangumd-smitoolbox | optim/nonlin/bfgsfmin.m | MATLAB | mit | 4,174 |
function [x, info] = gdfmin(f, x0, varargin)
% Perform unconstrained minimization using simple gradient descent
%
% x = gdfmin(f, x0, ...);
% solves a (local) minima of f using standard gradient descent.
% Here, f is the objective function that supports the following
% usage:
%
% ... | zzhangumd-smitoolbox | optim/nonlin/gdfmin.m | MATLAB | mit | 3,319 |
function [g, H] = approx_deriv(f, x, h)
% Compute approximated derivatives by finite difference
%
% g = approx_deriv(f, x);
% g = approx_deriv(f, x, h);
% computes the (approximated) gradient of a function f at x.
% Here, h is the difference at x-value used in the approximation.
% If omitted, it u... | zzhangumd-smitoolbox | optim/nonlin/approx_deriv.m | MATLAB | mit | 2,009 |
function [r1, r2] = check_deriv(f, X, h)
% A function for checking whether derivatives are computed correctly
%
% r1 = check_deriv(f, X);
% r1 = check_deriv(f, X, h);
%
% This statement takes an objective function f and a set of vectors
% in X as input. Here, f should be a function handle that su... | zzhangumd-smitoolbox | optim/nonlin/check_deriv.m | MATLAB | mit | 2,476 |
function [x, info] = newtonfmin(f, x0, varargin)
% Perform unconstrained minimization using Newton's method
%
% x = newtonfmin(f, x0, ...);
% solves a (local) minima of f using standard Newton's method.
% Here, f is the objective function that supports the following
% usage:
%
% [v, g, H]... | zzhangumd-smitoolbox | optim/nonlin/newtonfmin.m | MATLAB | mit | 4,318 |
function [x, flag] = lincg(A, b, x0, tol, max_iter)
%LINCG Solves a linear equation using conjugate gradient
%
% x = LINCG(A, b, x0);
% x = LINCG(A, b, x0, tol);
% x = LINCG(A, b, x0, tol, max_iter);
%
% solves a linear equation A * x = b using conjugate gradient
% method.
%
% Input arguments:
%... | zzhangumd-smitoolbox | optim/nonlin/lincg.m | MATLAB | mit | 3,067 |
function f = comb_objfun(varargin)
%COMB_OBJFUN Linear combination of objective functions
%
% An objective function f is a function that support the following use:
%
% (1) v = f(x);
% (2) [v, g] = f(x); (optional)
% (3) [v, g, H] = f(x); (optional)
%
% Here, x is a feasible solution, and v, g, H are respect... | zzhangumd-smitoolbox | optim/nonlin/comb_objfun.m | MATLAB | mit | 2,953 |
function modules = smi_modules()
% Get modules information of SMI toolbox
%
% smi_modules();
% prints information about modules of SMI toolbox.
%
% modules = smi_modules();
% get a list of module information.
%
% modules is an array of structs, of which each element corresponds
% to a partic... | zzhangumd-smitoolbox | tbman/smi_modules.m | MATLAB | mit | 4,910 |
function smi_build_mex(varargin)
% Re-build all mex files in the toolbox
%
% smi_build_mex;
% smi_build_mex name1 name2 ...
%
%% main
mdls = smi_modules;
bopts = {'-O'};
% get environment
bcslib_home = getenv('BCSLIB_HOME');
if isempty(bcslib_home)
error('smi_build_mex:enverror', ...
'Cannot find... | zzhangumd-smitoolbox | tbman/smi_build_mex.m | MATLAB | mit | 1,404 |
function smi_add_path()
% The function to add smitoolbox to MATLAB search paths
%
% smi_add_path;
%
% Note that this function does not save path permantly. To do so,
% one can call savepath.
%
%% main
mdls = smi_modules;
rdir = fileparts(fileparts(mfilename('fullpath')));
subpaths = ['tbman'; vertcat(mdls.sub... | zzhangumd-smitoolbox | tbman/smi_add_path.m | MATLAB | mit | 427 |
function info = smi_test(module, suitename)
% Performs unit testing for SMI modules
%
% info = smi_test(module, suitename);
% info = smi_test(module, suitenames);
% Runs a test suite or a collection of suites under a module.
%
% Here, module and suitename are both strings, and suitenames
% is a ce... | zzhangumd-smitoolbox | tbman/smi_test.m | MATLAB | mit | 4,978 |
function S = pca_std(X, pd, varargin)
%PCA_STD Standard principal component analysis
%
% S = PCA_STD(X);
% S = PCA_STD(X, pd, ...);
%
% trains a standard principal component analysis model based on
% the data given as columns of X.
%
% Suppose there are n samples in d-dimensional space, then X sh... | zzhangumd-smitoolbox | classics/subspace/pca_std.m | MATLAB | mit | 7,573 |
function W = cov_whiten(C, k, method, v)
% Solves a whitening transform
%
% Given a Gaussian variable X with covariance C = U D U'.
% Let W = D^{-1/2} * U', then WX has covarance I.
% This transform W is called the whitening transform.
%
% W = cov_whiten(C);
% W = cov_whiten(C, []);
% W = cov_wh... | zzhangumd-smitoolbox | classics/subspace/cov_whiten.m | MATLAB | mit | 2,741 |
function ica_demo(method)
% A simple program to demonstrate how ICA is used to decouple noisy signals
%
% ica_demo(method);
%
% You can choose the method of running ICA: 'defl' or 'symm'.
%
% Created by Dahua Lin, on Dec 31, 2011
%% prepare signals
t = (0 : 0.02 : 2 * pi).';
d = length(t);
n = 500;
X1 = bsxfun... | zzhangumd-smitoolbox | classics/subspace/ica_demo.m | MATLAB | mit | 635 |
function [W, H, objv, converged] = nnmf_std(X, r, W0, varargin)
%NNMF_STD Non-Negative Matrix Factorization
%
% [W, H] = NNMF_STD(X, r, W0, ...);
% [W, H, objv, converged] = NNMF_STD( ... );
%
% Perform Non-negative matrix factorization using standard methods.
%
% Let X be an m x n matrix, then the goal... | zzhangumd-smitoolbox | classics/subspace/nnmf_std.m | MATLAB | mit | 9,289 |
function W = ica_fast(X, k, W0, varargin)
%ICA_FAST Fast Independent Component Analysis (Fast ICA)
%
% W = ICA_FAST(X, k);
% W = ICA_FAST(X, k, [], ...);
% W = ICA_FAST(X, k, W0, ...);
%
% Performs Fast ICA on a given set of data.
%
% Input arguments:
% - X: the sample matrix, where each... | zzhangumd-smitoolbox | classics/subspace/ica_fast.m | MATLAB | mit | 7,793 |
function [mu, Sw, Sb] = scattermat(X, K, L, w)
% Compute scatter matrices for labeled Data
%
% [mu, Sw, Sb] = scattermat(X, K, L);
% [mu, Sw, Sb] = scattermat(X, K, L, w);
%
% computes within-class (and between-class) scatter matrices
% from labeled data.
%
% Inputs:
% - X: a d x n mat... | zzhangumd-smitoolbox | classics/subspace/scattermat.m | MATLAB | mit | 2,392 |
function c = fisherlda_binary(X, L, varargin)
%FISHERLDA_BINARY Fisher's Linear Discriminant Analysis on two-classes
%
% c = FISHERLDA_BINARY(X, L ...);
% performs two-class linear discrminant analysis (LDA).
%
% In the input, X is the data matrix, with each column being a
% sample. Let the size of ... | zzhangumd-smitoolbox | classics/subspace/fisherlda_binary.m | MATLAB | mit | 3,478 |
function [T, Tmu] = fisherldax(X, K, L, varargin)
%FISHERLDAX (Generalized) Multi-class Fisher's Linear Discriminant Analysis
%
% T = FISHERLDAX(X, K, L, ...);
% [T, Tmu] = FISHERLDAX(X, K, L, ...);
%
% Performs multi-class Fisher's linear discriminant analysis on
% given Data to derive a discriminant ... | zzhangumd-smitoolbox | classics/subspace/fisherldax.m | MATLAB | mit | 7,604 |
function fisherlda_binary_demo()
% A simple program to demonstrate the use of fisherlda_binary
%
% fisherlda_binary_demo;
%
% Created by Dahua Lin, on Nov 22, 2010
%
% prepare model
mu = randn(2, 2) * 4;
sigma = randn(2, 2);
sigma = sigma * sigma';
% prepare data
n = 2000;
T = chol(sigma, 'lower');
X1 = bsxfun... | zzhangumd-smitoolbox | classics/subspace/fisherlda_binary_demo.m | MATLAB | mit | 998 |
function objf = comb_lossfun(X, Y, K, w, lossfun)
%COMB_LOSSFUN Combined loss function
%
% Generally, the total loss (risk) on a given set of (weighted) samples
% is given by
%
% sum_{i=1}^n w_i loss(theta' * x_i, y_i).
%
% Here, theta is a coefficient vector, x_i is the i-th sample (which
% is associat... | zzhangumd-smitoolbox | classics/regression/comb_lossfun.m | MATLAB | mit | 3,295 |
function f = glinreg_objfun(X, Y, w, rho, rc)
%GLINREG_OBJFUN Generalized linear regression objective function
%
% A generalized linear regression problem is an optimization problem
% formulated as minimizing the following objective
%
% f(theta, theta0) =
% \sum_{i=1}^n + w_i * rho((theta' * x_i + ... | zzhangumd-smitoolbox | classics/regression/glinreg_objfun.m | MATLAB | mit | 3,080 |
function robustlinreg_demo
%ROBUSTLINREG_DEMO Demo of robust linear regression
%
% robustlinreg_demo;
%
% This is a small program that demonstrates the use of robust
% linear regression.
%
% Created by Dahua Lin, on Jan 15, 2012
%
%% prepare data
n = 500;
noise = 0.05;
outlier_fraction = 0.3;
outliers ... | zzhangumd-smitoolbox | classics/regression/robustlinreg_demo.m | MATLAB | mit | 1,489 |
function f = mlogireg_objfun(X, y, w, rc)
%MLOGIREG_OBJFUN Multi-class logistic regression objective function
%
% The objective function for an K-class logistic regression problem is
%
% f(theta) = - sum_i w_i log p_i + (rc/2) * ||theta||^2
%
% Here, if the i-th sample is in the k-th class, then
%
% p_i... | zzhangumd-smitoolbox | classics/regression/mlogireg_objfun.m | MATLAB | mit | 2,856 |
function [theta, theta0] = logireg(X, y, w, rc, initsol, varargin)
%LOGIREG Logistic regression
%
% [theta, theta0] = LOGIREG(X, y);
% [theta, theta0] = LOGIREG(X, y, w);
% [theta, theta0] = LOGIREG(X, y, w, rc, ...);
% [theta, theta0] = LOGIREG(X, y, w, rc, initsol, ...);
%
% Performs logistic regression... | zzhangumd-smitoolbox | classics/regression/logireg.m | MATLAB | mit | 2,751 |
function mlogireg_demo()
%MLOGIREG_DEMO Demo of Multi-class logistic regression
%
% mlogireg_demo;
%
% This is a simple program that demonstrates the use of
% multi-class logistic regression (mlogiregf)
%
% History
% -------
% - Created by Dahua Lin, on Jan 25, 2011
% - Modified by Da... | zzhangumd-smitoolbox | classics/regression/mlogireg_demo.m | MATLAB | mit | 1,622 |
function [v, G] = quadloss(Z, Y)
%QUADLOSS Quadratic loss function
%
% v = QUADLOSS(D);
% v = QUADLOSS(Z, Y);
%
% [v, G] = QUADLOSS(D);
% [v, G] = QUADLOSS(Z, Y);
%
% Evaluates the quadratic loss, defined to be
%
% v = (1/2) * ||z - y||^2.
%
% Input arguments:
% - D: The matri... | zzhangumd-smitoolbox | classics/regression/quadloss.m | MATLAB | mit | 801 |
function [v, g] = logistic_loss(z, y)
%LOGISTIC_LOSS The logistic loss function
%
% v = LOGISTIC_LOSS(z, y);
% [v, g] = LOGISTIC_LOSS(z, y);
%
% Evaluates the logistic loss function, which is defined to be
%
% loss(z, y) = log(1 + exp(-z * y));
%
% Input arguments:
% - z: The line... | zzhangumd-smitoolbox | classics/regression/logistic_loss.m | MATLAB | mit | 729 |
function logireg_demo()
% A simple script to demonstrate the use of logireg
%
% logireg_demo;
%
% Created by Dahua Lin, on Jan 25, 2011
%
%% prepare data
n = 1000;
t = rand() * (2 * pi);
tc = t + pi/2 + randn() * 0.5;
d = 3;
xc = randn() * 10;
yc = randn() * 10;
dir = [cos(tc) sin(tc)] * d;
X0 = gen_data(n, xc ... | zzhangumd-smitoolbox | classics/regression/logireg_demo.m | MATLAB | mit | 1,375 |
function [o1, o2] = llsq(X, y, w, r)
%LLSQ Linear least square problem
%
% The function solves the (weighted) linear least square problem, as
%
% minimize (1/2) * sum_i w_i ||x_i' * a - y_i||^2 + (1/2) * r * ||a||^2
%
% It is well known that the solution to this problem is
%
% optimal a = inv(X' * W * X + ... | zzhangumd-smitoolbox | classics/regression/llsq.m | MATLAB | mit | 3,925 |
function [v, G] = huberloss(Z, Y, r)
%HUBERLOSS Huber loss function
%
% v = HUBERLOSS(E, r);
% v = HUBERLOSS(Z, Y, r);
%
% [v, G] = HUBERLOSS(E, r);
% [v, G] = HUBERLOSS(Z, Y, r);
%
% Evaluates the huber loss function, defined to be
%
% v = (1/2) * e^2, when |e| < r
% = r * e ... | zzhangumd-smitoolbox | classics/regression/huberloss.m | MATLAB | mit | 849 |
function [v, G] = mlogistic_loss(Z, Y)
%MLOGISTIC_LOSS Multi-class Logistic loss function
%
% v = MLOGISTIC_LOSS(Z, Y);
% [v, G] = MLOGISTIC_LOSS(Z, Y);
%
% Evaluates the multi-class logistic loss function, defined as
%
% loss(z, y) = - sum_{k=1}^K (y_k * log(p_k))
%
% with p_k = exp(z_k) / su... | zzhangumd-smitoolbox | classics/regression/mlogistic_loss.m | MATLAB | mit | 1,465 |
function [theta, theta0] = mlogireg(X, y, w, rc, initsol, varargin)
%MLOGIREG Multi-class logistric regression
%
% [theta, theta0] = MLOGIREG(X, y);
% [theta, theta0] = MLOGIREG(X, y, w);
% [theta, theta0] = MLOGIREG(X, y, w, rc, ...);
% [theta, theta0] = MLOGIREG(X, y, w, rc, initsol, ...);
%
% Performs ... | zzhangumd-smitoolbox | classics/regression/mlogireg.m | MATLAB | mit | 3,211 |
function [theta, theta0] = glinreg(X, Y, w, rho, rc, initsol, varargin)
%GLINREG Logistic regression
%
% [theta, theta0] = GLINREG(X, Y, [], rho);
% [theta, theta0] = GLINREG(X, Y, w, rho);
% [theta, theta0] = GLINREG(X, Y, w, rho, rc, ...);
% [theta, theta0] = GLINREG(X, Y, w, rho, rc, initsol, ...);
%
% ... | zzhangumd-smitoolbox | classics/regression/glinreg.m | MATLAB | mit | 2,865 |
function [v, G] = bisquareloss(Z, Y, r)
%BISQUARELOSS Bisquare loss function
%
% v = BISQUARELOSS(E, r);
% v = BISQUARELOSS(Z, Y, r);
%
% [v, G] = BISQUARELOSS(E, r);
% [v, G] = BISQUARELOSS(Z, Y, r);
%
% Evaluates the bisquare loss, defined to be
%
% v = (r^2/6) * min{(1 - (1 - (e/r)^2)^3), 1} ... | zzhangumd-smitoolbox | classics/regression/bisquareloss.m | MATLAB | mit | 893 |
function f = logireg_objfun(X, y, w, rc)
%LOGIREG_OBJFUN Logistic regression objective function
%
% The objective function of logistic regression is given by
%
% f(theta) = - \sum_i w_i ( y_i log(p_i) + (1 - y_i) log(1 - p_i) )
% + (rc / 2) * ||theta||^2
%
% Here, p_i = 1 / (1 + exp(-z_... | zzhangumd-smitoolbox | classics/regression/logireg_objfun.m | MATLAB | mit | 2,968 |
function f = tikregf(c)
%TIKREGF Function handle for regularization
%
% f = TIKREGF(c);
% f = TIKREGF(Q);
%
% Constructs and returns a function handle for Tikhonov
% regularization.
%
% Tikhonov regularization function is generally defined to be
%
% f(x) = (1/2) * x' * Q * x.
%
% Here,... | zzhangumd-smitoolbox | classics/regression/tikregf.m | MATLAB | mit | 2,334 |
function s = kmseeds(data, K, method, varargin)
%KMSEEDS Selecting seeds for clustering
%
% s = KMSEEDS({X}, K, method, ...);
% s = KMSEEDS({X, costfun}, K, method, ...);
% s = KMSEEDS(D, K, method, ...);
%
% Selects K seeds from a set of samples for K-means or K-medoid
% clustering.
%
% Input... | zzhangumd-smitoolbox | classics/cluster/kmseeds.m | MATLAB | mit | 5,501 |
function kmedoid_std_demo(n, K)
% Demo of kmedoid_std in clustering 2D points
%
% kmedoid_std_demo(n, K);
%
% Input arguments:
% - n: The number of sample points
% - K: The number of clusters
%
% Created by Dahua Lin, on Mar 27, 2012
%
%% prepare data
X = rand(2, n);
%% run
cfun = @(i, j) pws... | zzhangumd-smitoolbox | classics/cluster/kmedoid_std_demo.m | MATLAB | mit | 649 |
function kmeans_std_demo(n, K)
% Demo of kmeans_std in clustering 2D points
%
% kmeans_std_demo(n, K);
%
% Input arguments:
% - n: The number of sample points
% - K: The number of clusters
%
% Created by Dahua Lin, on Mar 27, 2012
%
%% prepare data
X = rand(2, n);
%% run
[M, L] = kmeans_std(X... | zzhangumd-smitoolbox | classics/cluster/kmeans_std_demo.m | MATLAB | mit | 580 |
function S = afpsmat(S0, q)
%AFPSMAT Affinity propagation similarity matrix
%
% S = AFPSMAT(S0);
%
% Given an input similarity matrix, it generates a modified matrix
% for the use in affinity propagation.
%
% In particular, it sets the median of the pairwise similarities
% to each diag... | zzhangumd-smitoolbox | classics/cluster/afpsmat.m | MATLAB | mit | 1,266 |
function [M, L] = afpclus(S, varargin)
%AFPCLUS Clustering by Affinity Propagation
%
% [M, L] = AFPCLUS(S, ...);
%
% Performs Affinity propagation to cluster data samples.
%
% Input arguments:
% - S: The similarity matrix, of size n x n.
% Here, n is the number of sa... | zzhangumd-smitoolbox | classics/cluster/afpclus.m | MATLAB | mit | 6,008 |
function afpclus_demo(n, q)
% Demo of afpclus in clustering 2D points
%
% afpclus_demo(n);
% afpclus_demo(n, q);
%
% Input arguments:
% - n: The number of sample points
% - q: The quantile ratio (greater q encourages more centers)
% (default = 0.5)
%
% Created by Dahua Lin, on Mar... | zzhangumd-smitoolbox | classics/cluster/afpclus_demo.m | MATLAB | mit | 736 |
function d = clusvid(L1, L2)
%CLUSVID variation information distance between clusters
%
% d = CLUSVID(L1, L2);
% computes the variation information distance between two
% clusters, which respectively label the same set of samples
% with labels L1 and L2.
%
% In the input L1 and L2 should be ve... | zzhangumd-smitoolbox | classics/cluster/clusvid.m | MATLAB | mit | 1,171 |
function [M, L, info] = kmedoid_std(C, M0, varargin)
%KMEDOID_STD Implements standard K-medoid clustering
%
% [M, L] = KMEDOID_STD(C, M0, ...);
% [M, L] = KMEDOID_STD(C, K, ...);
% [M, L] = KMEDOID_STD({cfun, n}, M0, ...);
% [M, L] = KMEDOID_STD({cfun, n}, K, ...);
%
% performs K-medoid clustering... | zzhangumd-smitoolbox | classics/cluster/kmedoid_std.m | MATLAB | mit | 6,087 |
function S = kmopts(varargin)
%KMOPTS Options for K-means and K-medoid
%
% S = KMOPTS;
%
% returns the default option struct.
%
% S = KMOPTS('name1', value1, 'name2', value2, ...);
%
% constructs an option struct, modifying part of the option values
% using the input values.
%
% S = KMOPTS(S0, '... | zzhangumd-smitoolbox | classics/cluster/kmopts.m | MATLAB | mit | 2,826 |
function [M, L, info] = kmeans_std(X, M0, varargin)
%KMEANS_STD Standard K-means algorithm
%
% [M, L] = KMEANS_STD(X, K, ...);
% [M, L] = KMEANS_STD(X, M0, ...);
% [M, L] = KMEANS_STD({X, w}, K, ...);
% [M, L] = KMEANS_STD({X, w}, M0, ...);
%
% This function implements the standard K-means algorith... | zzhangumd-smitoolbox | classics/cluster/kmeans_std.m | MATLAB | mit | 6,483 |
function K = gausskernel(X, Y, sigma)
%GAUSSKERNEL The Gaussian kernel (radial basis function)
%
% K = GAUSSKERNEL(X, [], sigma);
% K = GAUSSKERNEL(X, Y, sigma);
%
% Evaluates the Gaussian kernel in a pairwise manner.
%
% The Gaussian kernel is defined to be
%
% k(x, y) = exp( - ||x - ... | zzhangumd-smitoolbox | classics/kernels/gausskernel.m | MATLAB | mit | 880 |
function K = polykernel(X, Y, a, b, d)
%POLYKERNEL The polynomial kernel
%
% K = POLYKERNEL(X, [], a, b, d);
% K = POLYKERNEL(X, Y, a, b, d);
%
% Evaluates the polynomial kernel in a pairwise manner.
%
% The polynomial kernel is defined to be
%
% k(x, y) = (a * (x' * y) + b)^d.
%
% ... | zzhangumd-smitoolbox | classics/kernels/polykernel.m | MATLAB | mit | 662 |
function K = sigmoidkernel(X, Y, a, b)
%SIGMOIDKERNEL Sigmoid kernel
%
% K = SIGMOIDKERNEL(X, [], a, b);
% K = SIGMOIDKERNEL(X, Y, a, b);
%
% Evaluates the sigmoid kernel in a pairwise manner.
%
% The polynomial kernel is defined to be
%
% k(x, y) = tanh(a * (x' * y) + b)
%
% Her... | zzhangumd-smitoolbox | classics/kernels/sigmoidkernel.m | MATLAB | mit | 656 |
function invmqkernel(X, Y, a, b)
%INVMQKERNEL The inverse multiquadric kernel
%
% K = INVMQKERNEL(X, [], a, b);
% K = INVMQKERNEL(X, Y, a, b);
%
% Evaluates the inverse multi-quadric kernel in a pairwise manner.
%
% The inverse multi-quadric kernel is defined to be
%
% k(x, y) = 1 / (a... | zzhangumd-smitoolbox | classics/kernels/invmqkernel.m | MATLAB | mit | 853 |
function tf = is_svm_dual_sol(S)
%IS_SVM_PROBLEM Whether the input argument is an SVM dual-solution struct
%
% tf = is_svm_dual_sol(S);
% returns whether S is a valid SVM problem struct.
%
% Created by Dahua Lin, on Jan 17, 2012
%
%% main
tf = isstruct(S) && numel(S) == 1 && isfield(S, 'tag') && ...
strc... | zzhangumd-smitoolbox | classics/svm/is_svm_dual_sol.m | MATLAB | mit | 347 |
function b = svm_dual_offset(S, K, alpha, si)
%SVM_DUAL_OFFSET Solve the offset value for dual SVM training
%
% b = SVM_DUAL_OFFSET(S, K, alpha, si);
%
% solves the offset value b for dual SVM training.
%
% Note that b is fixed to 0 for SVM ranking.
%
% Inputs
% - S: The SVM problem st... | zzhangumd-smitoolbox | classics/svm/svm_dual_offset.m | MATLAB | mit | 2,141 |