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 |
|---|---|---|---|---|---|
/********************************************************************
*
* fast_median_cimp.cpp
*
* The C++ mex implementation for fast_median.m
*
* Created by Dahua Lin, on Nov 11, 2010
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <bcsli... | zzhangumd-smitoolbox | base/data/private/fast_median_cimp.cpp | C++ | mit | 2,308 |
/********************************************************************
*
* aggreg_percol_cimp.cpp
*
* The C++ mex implementation of aggreg.m
*
* Created by Dahua Lin, on Feb 26, 2012
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <limits>
... | zzhangumd-smitoolbox | base/data/private/aggreg_percol_cimp.cpp | C++ | mit | 4,650 |
/********************************************************************
*
* intcount_cimp.cpp
*
* The C++ mex implementation of integer counting
*
* Created by Dahua Lin, on May 26, 2010
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
using namespace... | zzhangumd-smitoolbox | base/data/private/intcount_cimp.cpp | C++ | mit | 3,155 |
/********************************************************************
*
* wmedian_cimp.cpp
*
* The implementation of the core part of wmedian
*
* Created by Dahua Lin, on Sep 28, 2010
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
using namespace ... | zzhangumd-smitoolbox | base/data/private/wmedian_cimp.cpp | C++ | mit | 2,166 |
/********************************************************************
*
* aggreg_cimp.cpp
*
* The C++ mex implementation of aggreg.m
*
* Created by Dahua Lin, on Nov 10, 2010
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <limits>
using n... | zzhangumd-smitoolbox | base/data/private/aggreg_cimp.cpp | C++ | mit | 6,018 |
%VALUESEG divides a vector of numeric values into constant-value segments
%
% [sp, ep] = valueseg(x);
% divides the numeric/logical/char vector x into segments, such that
% the elements in each segments have the same value.
%
% In the output, sp and ep are row vectors of size m, where m is
... | zzhangumd-smitoolbox | base/data/valueseg.m | MATLAB | mit | 738 |
function [H, varargout] = uniformhist(X, hsiz, rgn)
% Generate histogram over uniform bins
%
% [H, C] = uniformhist(X, n, [a, b]);
%
% generates a histogram over uniform bins for one-dimensional
% data. Here, X is a matrix comprised of observed values.
%
% The interval [a, b] is divid... | zzhangumd-smitoolbox | base/data/uniformhist.m | MATLAB | mit | 3,955 |
% Merge several sorted sequences into one
%
% vc = merge_sorted(v1, v2, ...);
%
% merge the sorted vectors v1, v2, ..., into a sorted vector vc.
% Here, v1, v2, ... are all numeric vectors of the same class.
%
% History
% -------
% - Created by Dahua Lin, on Mar 28, 2011
% | zzhangumd-smitoolbox | base/data/merge_sorted.m | MATLAB | mit | 298 |
function d = fnsdim(A)
% Get the first non-singleton dimension of an array
%
% d = fnsdim(A);
% gets the first non-singleton dimension of the array A.
%
% Created by Dahua Lin, on Sep 13, 2010
%
%% main
nd = ndims(A);
if nd == 2
if size(A, 1) > 1
d = 1;
else
d = 2... | zzhangumd-smitoolbox | base/utils/fnsdim.m | MATLAB | mit | 439 |
function S = parlist(varargin)
% Parses a name/value pair list
%
% S = parlist('name1', value1, 'name2', value2, ...)
% parses a name/value list and return the results as a struct S.
%
% S is a struct with S.name1 = value1, S.name2 = value2, ...
%
% Note that the value names should be valid variable... | zzhangumd-smitoolbox | base/utils/parlist.m | MATLAB | mit | 1,650 |
function h = impline(a, b, c, rgn, varargin)
%IMPLINE Draw a line given by implicit equation
%
% impline(a, b, c, [], ...);
% impline(a, b, c, rgn, ...);
%
% Draws a 2D line within a range.
% The line is given by the following implicit equation.
%
% a x + b y + c = 0
%
% In the input, r... | zzhangumd-smitoolbox | base/utils/impline.m | MATLAB | mit | 1,405 |
function V = pwcc(f, X, Y)
% Perform pairwise computation between columns
%
% V = pwcc(f, X, Y);
% applies the function f to columns in X and Y pairwisely.
%
% f should be a function that can support the following syntax:
%
% v = f(A, B);
%
% where A and B have the same number of co... | zzhangumd-smitoolbox | base/utils/pwcc.m | MATLAB | mit | 1,520 |
function clsname = fresult_class(a, b, c)
% determine the class of the floating point computation result
%
% clsname = fresult_class(a, b);
% determines the result class of a * b
%
% clsname = fresult_class(a, b, c);
% determines the result class of a * b * c
%
% Created by Dahua Lin, on Aug 14, 2011
... | zzhangumd-smitoolbox | base/utils/fresult_class.m | MATLAB | mit | 972 |
function P = cartprod(nums, op)
%CARTPROD Gets the cartesian product of number arrays
%
% P = cartprod([n1, n2, ..., nK]);
% computes the Cartesian product {1:n1} x {1:n2} x ... x {1:nK},
% the results are returned by P, which is a K x (n1 x n2 x ... x nK)
% array, with each column representin... | zzhangumd-smitoolbox | base/utils/cartprod.m | MATLAB | mit | 4,046 |
function devcheck(title, x1, x2, tol)
% Check whether two arrays are close enough, if not raise a warning
%
% devcheck(title, x1, x2, tol);
%
assert(isfloat(x1));
assert(isfloat(x2));
assert(isequal(size(x1), size(x2)));
maxdev = max(abs(x1(:) - x2(:)));
if maxdev > tol
warning('devcheck:largedev', ...
... | zzhangumd-smitoolbox | base/utils/devcheck.m | MATLAB | mit | 411 |
function s = strjoin(strs, delim)
% Join multiple strings with a specified delimiter
%
% s = strjoin(strs, delim);
% joins multiple strings in strs, which is a cell array, into
% a string, using delim as the delimiter.
%
% If delim is omitted, it uses '' as delim, which means to
% simply con... | zzhangumd-smitoolbox | base/utils/strjoin.m | MATLAB | mit | 978 |
function sch = trainsch(n, n0, gr, rstream)
% Makes a training schedule
%
% sch = trainsch(n, n0, gr);
% sch = trainsch(n, n0, gr, rstream);
%
% In the practice of modeling training, it is sometimes more
% efficient to train a model in several stages. Starting from
% a small random subset to trai... | zzhangumd-smitoolbox | base/utils/trainsch.m | MATLAB | mit | 2,637 |
classdef tsuite_pdmat
% The test suite for pdmat_* functions
%
% Created by Dahua Lin, on Aug 25, 2011
% Modified by Dahua Lin, on Sep 3, 2011
%% Properties
properties
types = {'s', 'd', 'f'};
dims = [1 2 5];
nums = [1 3];
end
%% Test c... | zzhangumd-smitoolbox | base/tests/tsuite_pdmat.m | MATLAB | mit | 15,233 |
function Sr = pdmat_plus(S1, S2, c1, c2)
% Compute the sum or linear combination of two matrices
%
% Sr = pdmat_plus(S1, S2);
% computes the sum of the matrix in S1 and that in S2, and returns
% the resultant matrix in a pdmat struct.
%
% Sr = pdmat_plus(S1, S2, c1, c2);
% computes the linear comb... | zzhangumd-smitoolbox | base/pdmat/pdmat_plus.m | MATLAB | mit | 4,742 |
function S = pdmat(a1, a2, a3)
% Constructs a struct representing a (semi)-positive definite matrix
%
% A pdmat struct can represent a (semi)positive definite matrix
% in three different forms, each form has a single-char tag to
% identify it.
%
% - 's': scalar-form:
% use a scalar to represent a ma... | zzhangumd-smitoolbox | base/pdmat/pdmat.m | MATLAB | mit | 4,430 |
function V = pdmat_diag(S)
% Get the diagonal entries of the matrices
%
% V = pdmat_diag(S);
%
% returns the diagonal entries of each matrices packed in S
% as columns of V.
%
% Created by Dahua Lin, on Sep 1, 2010
%
switch S.ty
case 's'
if S.d == 1
V = S.v;
else
... | zzhangumd-smitoolbox | base/pdmat/pdmat_diag.m | MATLAB | mit | 799 |
function S = rand_pdmat(ty, d, n, evrgn)
% Generates a random pdmat struct
%
% S = rand_pdmat(ty, d, n, [a, b]);
% generates a random pdmat struct.
%
% Input arguments:
% - ty: The type of matrix form ('s', 'd', or 'ty')
% - d: the dimension (a matrix has size d x d)
% - n:... | zzhangumd-smitoolbox | base/pdmat/rand_pdmat.m | MATLAB | mit | 1,708 |
function dv = pdmat_dot(A, B)
% Computes the inner product between positive definite matrices
%
% dv = pdmat_dot(A);
% dv = pdmat_dot(A, B);
%
% Computes the inner product (tr(A' * B)) between A and B.
%
% The following cases are supported:
% - A.n == 1 && B.n == 1: return dv as a scalar
% ... | zzhangumd-smitoolbox | base/pdmat/pdmat_dot.m | MATLAB | mit | 3,095 |
function R = pdmat_pick(S, i)
% Get a subset from a pack of positive definite matrices
%
% R = pdmat_pick(S, i);
% returns a pdmat struct that is comprised of the i-th matrix
% in S of the same form.
%
% i can also be a index vector or logical vector, in which case,
% R may contain multiple ma... | zzhangumd-smitoolbox | base/pdmat/pdmat_pick.m | MATLAB | mit | 653 |
function R = pdmat_pwquad(S, X, Y)
% computes pairwise quadratic forms w.r.t. positive definite matrices
%
% R = pdmat_pwquad(S, X);
% R = pdmat_pwquad(S, X, Y);
%
% Here, S must be comprised of exactly one matrix (S.n == 1).
%
% Suppose the size of X is S.d x m and that of Y is S.d x n. T... | zzhangumd-smitoolbox | base/pdmat/pdmat_pwquad.m | MATLAB | mit | 1,644 |
function Y = pdmat_lsolve(S, X)
% Solves linear equation solution w.r.t positive definite matrices
%
% Y = pdmat_lsolve(S, X);
%
% Returns the result Y as pdmat_mvmul(inv(S), X), with the
% calculation implemented in a more efficient way.
%
% Created by Dahua Lin, on Aug 25, 2010
%
%% verify inp... | zzhangumd-smitoolbox | base/pdmat/pdmat_lsolve.m | MATLAB | mit | 1,648 |
function Sr = pdmat_scale(S, c)
% Compute a scalar-product of a positive definite matrix
%
% Sr = pdmat_scale(S, c);
% returns Sr, whose matrix is the scalar product of c and
% that in S.
%
% c can be a scalar, or a row vector.
%
% Created by Dahua Lin, on Aug 25, 2010
%
%% verify input
if ~(isf... | zzhangumd-smitoolbox | base/pdmat/pdmat_scale.m | MATLAB | mit | 1,382 |
function r = pdmat_lndet(S)
% Compute log-determinant of positive definite matrices
%
% r = pdmat_lndet(S);
% computes the log-determinant of positive definite matrices
% contained in S.
%
% r is a scalar (if S.n == 1) or a row vector of size 1 x S.n,
% with r(i) corresponding to the i-th matr... | zzhangumd-smitoolbox | base/pdmat/pdmat_lndet.m | MATLAB | mit | 1,053 |
function R = pdmat_quad(S, X, Y)
% computes quadratic form with respect to positive definite matrices
%
% R = pdmat_quad(S, X);
% R = pdmat_quad(S, X, Y);
%
% Supposes there are m matrices contained in S, and X and Y
% are matrices of the same size S.d x n.
%
% Then R is a matrix of size m ... | zzhangumd-smitoolbox | base/pdmat/pdmat_quad.m | MATLAB | mit | 1,718 |
function Y = pdmat_mvmul(S, X)
% Compute product of positive-definite matrix and vectors
%
% Y = pdmat_mvmul(S, X)
% compute the product of the positive definite matrix (matrices)
% and the columns of X.
%
% Several cases are supports (let ns = S.n and nx = size(X, 2))
% - ns == 1 && nx == 1:... | zzhangumd-smitoolbox | base/pdmat/pdmat_mvmul.m | MATLAB | mit | 2,005 |
function tf = is_pdmat(S)
% Tests whether an argument is a pdmat struct
%
% tf = is_pdmat(S);
% performs a quick check, and returns whether S is a pdmat struct.
%
% Created by Dahua Lin, on Aug 25, 2010
%
tf = isstruct(S) && isscalar(S) && isfield(S, 'tag') && ...
ischar(S.tag) && strcmp(S.tag, 'pdmat');
... | zzhangumd-smitoolbox | base/pdmat/is_pdmat.m | MATLAB | mit | 321 |
function Y = pdmat_choltrans(S, X)
% Transform vectors using the result of Cholesky factorization
%
% Y = pdmat_choltrans(S, X);
%
% Here, S should contain only one matrix (denoted by A).
% Let L be a lower-triangular matrix such that A = L * L'.
% Then this function returns Y = L * X, which is com... | zzhangumd-smitoolbox | base/pdmat/pdmat_choltrans.m | MATLAB | mit | 1,186 |
function M = pdmat_fullform(S, i)
% Gets the full matrix form of a matrix packed in pdmat
%
% M = pdmat_fullform(S);
% Gets the full matrix representation of the matrix represented
% by a pdmat struct S.
%
% Here, S should contain only one matrix (i.e. S.n == 1)
%
% M = pdmat_fullform(S, i);
% ... | zzhangumd-smitoolbox | base/pdmat/pdmat_fullform.m | MATLAB | mit | 1,173 |
function R = pdmat_inv(S)
% Compute the inverse of the positive definite matrices
%
% R = pdmat_inv(S);
% return the inverse of the positive definite matrices in S.
% The inverse is represented in the same form as in S.
%
% Created by Dahua Lin, on Aug 25, 2010
%
%% main
R.tag = S.tag;
R.ty = S.ty;
R.d... | zzhangumd-smitoolbox | base/pdmat/pdmat_inv.m | MATLAB | mit | 868 |
function A = l2mat(K, L, w, op)
%L2MAT Assignment matrix from labels
%
% A = L2MAT(K, L, w);
%
% Constructs an assignment matrix A based on a label vector L, such
% that
%
% If L is a row vector, then A is a K x n matrix, with
%
% A(L(i), i) = w(i).
%
% If L is a column vec... | zzhangumd-smitoolbox | base/matrix/l2mat.m | MATLAB | mit | 2,624 |
/********************************************************************
*
* smallmat.h
*
* The common header shared by all small matrix computation routines
*
* Created by Dahua Lin, on June 8, 2010
*
********************************************************************/
#include <mex.h>
#include <cmath>
#ifn... | zzhangumd-smitoolbox | base/matrix/smallmat.h | C++ | mit | 6,725 |
function B = exelem(A, nr, nc)
% Construct a new matrix by expanding its elements into sub-matrices
%
% B = exelem(A, nr, nc);
% creates a new matrix B by expanding each element in matrix A
% into a sub-matrix of size nr x nc.
%
% Let A is a matrix of size m x n, then in the output, B is a
... | zzhangumd-smitoolbox | base/matrix/exelem.m | MATLAB | mit | 1,566 |
function B = adddiag(A, a)
% Add values to the diagonal of a matrix
%
% B = adddiag(A, a);
% add values in a to the diagonal entries of A, and returns the
% result.
%
% Here, A should be a square matrix (say of size n x n), and
% a can be a scalar or a vector of length n.
%
%% veri... | zzhangumd-smitoolbox | base/matrix/adddiag.m | MATLAB | mit | 854 |
/********************************************************************
*
* det2x2.cpp
*
* The C++ mex implementation of trace of 2x2 matrices
*
* Created by Dahua Lin, on Jun 8, 2010
*
********************************************************************/
#include "smallmat.h"
template<typename T>
inline m... | zzhangumd-smitoolbox | base/matrix/trace2x2.cpp | C++ | mit | 2,400 |
% Cholesky decomposition of 2x2 matrices using fast implementation
%
% R = chol2x2(A);
% computes the cholesky decomposition of each matrix in A using a
% fast implementation. The result is a lower triangle matrix L
% such that A = L * L'.
%
% Every matrix in A should be positive definite.
%
... | zzhangumd-smitoolbox | base/matrix/chol2x2.m | MATLAB | mit | 913 |
function B = rmdiag(A, op)
% Remove the diagonal entries of a square matrix
%
% B = rmdiag(A);
% B = rmdiag(A, 'r');
%
% Let A be an n x n matrix, then B will be an (n-1) x n matrix,
% constructed by removing the diagonal entries, anf lifting
% the entries which are below the diagonal.
%
%... | zzhangumd-smitoolbox | base/matrix/rmdiag.m | MATLAB | mit | 1,768 |
function Y = mvsum(As, X, W, op)
% Compute the (weighted) sum of matrix products
%
% Y = mvsum(As, X, W);
% Y = mvsum(As, X, W, op);
% compute the (weighted sum) of products between matrices and
% vectors, respectively given by As and X, according to the
% formulas below:
%
% When ... | zzhangumd-smitoolbox | base/matrix/mvsum.m | MATLAB | mit | 3,020 |
/********************************************************************
*
* mtimes_sm2v2.cpp
*
* The C++ mex function for multiplication between a 2 x 2 symmetric
* matrix and a generic 2 x n matrix.
*
* Created by Dahua Lin, on June 18, 2010
*
****************************************************************... | zzhangumd-smitoolbox | base/matrix/mtimes_sm2v2.cpp | C++ | mit | 2,716 |
/********************************************************************
*
* inv2x2.cpp
*
* The C++ mex implementation of inverse of 2x2 matrices
*
* Created by Dahua Lin, on Jun 8, 2010
*
********************************************************************/
#include "smallmat.h"
template<typename T>
inline... | zzhangumd-smitoolbox | base/matrix/inv2x2.cpp | C++ | mit | 2,426 |
/********************************************************************
*
* inv2x2.cpp
*
* The C++ mex implementation of inverse of 2x2 matrices
*
* Created by Dahua Lin, on Jun 8, 2010
*
********************************************************************/
#include "smallmat.h"
template<typename T>
inline... | zzhangumd-smitoolbox | base/matrix/polarm2x2.cpp | C++ | mit | 2,444 |
% Compute the determinant of 2x2 matrices using fast implementation
%
% R = det2x2(A);
% computes the determinant of each matrix in A using a fast
% implementation.
%
% A can be in either of the following forms:
% - 2 x 2 matrix
% - 2 x 2 x n array, with each page being a matrix
% ... | zzhangumd-smitoolbox | base/matrix/det2x2.m | MATLAB | mit | 748 |
% Matrix square root of 2x2 positive definite matrices using fast
% implementation
%
% R = sqrtm2x2(A);
% computes the cholesky decomposition of each matrix in A using a
% fast implementation. The result is a lower triangle matrix.
% Every matrix in A should be positive definite.
%
% A can b... | zzhangumd-smitoolbox | base/matrix/sqrtm2x2.m | MATLAB | mit | 895 |
function R = tilemat(Ms)
% Tile multiple matrices to form a single large one
%
% R = tilemat(Ms);
% Creates a big matrix by tiling the matrices given in Ms.
%
% In the input, Ms can be either of the following form:
% - an array of size p x q x m x n, where M(:,:,i,j) gives a
% sub-m... | zzhangumd-smitoolbox | base/matrix/tilemat.m | MATLAB | mit | 1,782 |
% Compute the inverse of 2x2 matrices using fast implementation
%
% R = inv2x2(A);
% computes the inverse of each matrix in A using a fast
% implementation.
%
% A can be in either of the following forms:
% - 2 x 2 matrix
% - 2 x 2 x n array, with each page being a matrix
% - 4 x n ... | zzhangumd-smitoolbox | base/matrix/inv2x2.m | MATLAB | mit | 746 |
% Generates a vector by repeating numbers
%
% x = repnum(ns);
% generates a vector x, whose length is sum(ns), by repeating i for
% ns(i) times.
%
% For example, repnum([3 3 4]) generates a vector of length 10 as
% [1 1 1 2 2 2 3 3 3 3].
%
% The result of repnum can be used as indices fo... | zzhangumd-smitoolbox | base/matrix/repnum.m | MATLAB | mit | 875 |
% Compute the trace of 2x2 matrices using fast implementation
%
% R = trace2x2(A);
% computes the trace of each matrix in A using a fast
% implementation.
%
% A can be in either of the following forms:
% - 2 x 2 matrix
% - 2 x 2 x n array, with each page being a matrix
% - 4 x n ma... | zzhangumd-smitoolbox | base/matrix/trace2x2.m | MATLAB | mit | 639 |
function R = makediag(v)
% Construct (multiple) diagonal matrices from diagonal elements
%
% R = makediag(v);
% Suppose v is a matrix of size d x n, then it creates a d x d x n
% array, such that R(:,:,i) is diag(v(:,i)) for each i from 1 to n.
%
% Created by Dahua Lin, on April 14, 2010
%
%% main
if ~... | zzhangumd-smitoolbox | base/matrix/makediag.m | MATLAB | mit | 645 |
/********************************************************************
*
* inv2x2.cpp
*
* The C++ mex implementation of inverse of 2x2 matrices
*
* Created by Dahua Lin, on Jun 8, 2010
*
********************************************************************/
#include "smallmat.h"
template<typename T>
inline... | zzhangumd-smitoolbox | base/matrix/chol2x2.cpp | C++ | mit | 2,437 |
function v = lndet(C)
% Computes the logarithm of determinant of a positive definite matrix
%
% v = lndet(C);
% returns the log-determinant of the positive definite matrix C.
%
% Remarks
% -------
% This implementation directly computes the log-determinant of
% C based on Cholesky decomposition,... | zzhangumd-smitoolbox | base/matrix/lndet.m | MATLAB | mit | 514 |
/********************************************************************
*
* det2x2.cpp
*
* The C++ mex implementation of determinant of 2x2 matrices
*
* Created by Dahua Lin, on Jun 8, 2010
*
********************************************************************/
#include "smallmat.h"
template<typename T>
in... | zzhangumd-smitoolbox | base/matrix/det2x2.cpp | C++ | mit | 2,384 |
function M = binotable(n)
% Generate a table of binomial coefficients
%
% M = binotable(n);
% generates a table M of size (n+1) x (n+1), where
% when i >= j, M(i, j) = nchoose(i-1, j-1), and
% when i < j, M(i, j) = 0.
%
% M is a lower triangle matrix.
%
% History
% -------
% - Creat... | zzhangumd-smitoolbox | base/matrix/binotable.m | MATLAB | mit | 733 |
/********************************************************************
*
* sqrtm2x2.cpp
*
* The C++ mex implementation of matrix square root of 2x2 matrices
*
* Created by Dahua Lin, on Jun 10, 2010
*
********************************************************************/
#include "smallmat.h"
template<typen... | zzhangumd-smitoolbox | base/matrix/sqrtm2x2.cpp | C++ | mit | 2,459 |
/********************************************************************
*
* repnum_cimp.cpp
*
* The C++ mex implementation for repnum
*
* Created by Dahua Lin, on June 6, 2010
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <bcslib/array/arra... | zzhangumd-smitoolbox | base/matrix/repnum.cpp | C++ | mit | 5,217 |
function C = mmsum(As, Bs, W, op)
% Compute the (weighted) sum of matrix products
%
% C = mmsum(As, Bs, W);
% C = mmsum(As, Bs, W, op);
% compute the (weighted sum) of products between the matrices in
% As and Bs, according to the following formula.
%
% When op = 'NN':
% C = \s... | zzhangumd-smitoolbox | base/matrix/mmsum.m | MATLAB | mit | 5,608 |
function test_mat2x2c(varargin)
% Test the correctness of implementation of 2 x 2 matric computation
%
% test_mat2x2c item1 item2 ...
%
% item is the name of the computation to be tested, which can be
% either of the following values:
% 'inv': matrix inverse
% 'det': matrix determinant
% 't... | zzhangumd-smitoolbox | base/matrix/test_mat2x2c.m | MATLAB | mit | 5,605 |
function Y = mmvmult(A, X)
%MMVMULT Performs multiple matrix-vector multiplication
%
% Y = mmvmult(A, X);
% performs multiple matrix-vector multiplication.
% Here, A should be an array of size p x q x n, and X of size q x n,
% then Y is of size p x n, such that
%
% Y(:,i) = A(:,:,i... | zzhangumd-smitoolbox | base/matrix/mmvmult.m | MATLAB | mit | 1,536 |
function A = constmat(m, n, v)
% Create a matrix whose entries are fixed to a constant value
%
% A = constmat(m, n, v);
% creates a matrix of size m x n, whose entries are fixed to
% a constant value v.
%
% The class of matrix A is is the same as the class of v,
% which can be either numeric ... | zzhangumd-smitoolbox | base/matrix/constmat.m | MATLAB | mit | 904 |
% Derive the polar representation of a 2 x 2 positive definite matrix
%
% R = polarm2x2(A);
% computes the polar representation of a 2x2 positive matrix A.
% Each polar representation is a column vector with three
% entries [a; b; theta], such that
%
% A = R * diag([a b]) * R',
%
% ... | zzhangumd-smitoolbox | base/matrix/polarm2x2.m | MATLAB | mit | 983 |
function R = rotmat2(t)
% Gets the rotation matrix given radius values
%
% R = rotmat2(t)
% Returns the rotation matrix [cos(t) -sin(t); sin(t) cos(t)].
% If t contains m elements, then R is a 2 x 2 x m array, with
% R(:,;,i) corresponding to t(i).
%
% History
% -------
% - Created by Dah... | zzhangumd-smitoolbox | base/matrix/rotmat2.m | MATLAB | mit | 645 |
function M = spdiag(v1, v2)
% Creates a sparse diagonal matrix
%
% M = spdiag(dv);
% creates a diagonal matrix with the diagonal elements given by dv.
% Suppose dv is a vector of length n, then M is an n x n matrix,
% with M(i,i) equaling dv(i).
%
% M = spdiag(n, v);
% creates an n x n diago... | zzhangumd-smitoolbox | base/matrix/spdiag.m | MATLAB | mit | 924 |
function C = mat2_by_polar(a, b, theta)
% Create 2x2 positive definite matrices from the polar representation
%
% C = mat2_by_polar(a, b, theta);
% creates a 2 x 2 positive definite matrix as
%
% C = R * diag([a b]) * R'.
%
% Here, R is a rotation matrix given by R = rotmat2(theta).
%
... | zzhangumd-smitoolbox | base/matrix/mat2_by_polar.m | MATLAB | mit | 1,437 |
/********************************************************************
*
* smi_graph_mex.h
*
* The mex interface for SMI graphs
*
* Created by Dahua Lin, on Oct 28, 2011
*
********************************************************************/
#include <bcslib/matlab/bcs_mex.h>
#include <bcslib/graph/gedgelist... | zzhangumd-smitoolbox | graph/clib/smi_graph_mex.h | C++ | mit | 2,027 |
function X = gsembed(g, w, d, k0)
% Spectral embedding of a graph
%
% X = gsembed(g, w, d);
% computes the d-dimensional embedded coordinates of a graph,
% which correspond to the d smallest eigenvalues of the Laplacian
% matrix.
%
% w is the edge weights, which can be either a scalar or a
% ... | zzhangumd-smitoolbox | graph/spectral/gsembed.m | MATLAB | mit | 842 |
function laplacesm1d_demo(x0, sigma, w)
% A function to demo 1D Laplacian smoothing
%
% laplacesm1d_demo(x0, noise_mag, mker);
%
% Inputs:
% x0: the sequence of values (not corruped by noise)
% sigma: the standard deviation of noise
% w: the neighboring link weights (size 1 x... | zzhangumd-smitoolbox | graph/spectral/laplacesm1d_demo.m | MATLAB | mit | 1,398 |
function x = laplacesm(G, w, a, y)
% Performs Laplacian smooth based on a Gaussian MRF
%
% The problem formulation is to minimize the following objective
% function with respect to X:
%
% (1/2) * sum_e w_e ||X(:,e_i) - X(:,e_j)||^2
% + (1/2) * sum_i (1/2) * a_i ||X(:,i) - Y(:,i)||^2.
%
% x = laplace... | zzhangumd-smitoolbox | graph/spectral/laplacesm.m | MATLAB | mit | 1,801 |
function L = laplacemat(varargin)
% Compute the Laplacian matrix of a graph
%
% L = laplacemat(g);
% L = laplacemat(g, w);
% L = laplacemat(g, w, a);
%
% Computes the (regularized) Laplacian matrix for graph G.
%
% Suppose A is the affinity matrix of G, and d is the vector
% of weighted degrees... | zzhangumd-smitoolbox | graph/spectral/laplacemat.m | MATLAB | mit | 3,788 |
function [x, energy] = minenergy_graphcut(g, w, cp, cn)
%MINENERGY_GRAPHCUT Energy minimization via Graph-cut
%
% [x, energy] = MINENERGY_GRAPHCUT(g, w, cp, cn);
%
% Solves the following energy minimization problem using minimum
% graph cut algorithm.
%
% minimize E(L) = sum_{i in V} cp(i) * I(x... | zzhangumd-smitoolbox | graph/flows/minenergy_graphcut.m | MATLAB | mit | 2,222 |
function [L, cutv] = kolmogorov_mincut(g, caps, src_cap, snk_cap)
%KOLMOGOROV_MINCUT Kolmogorov's Mincut Algorithm
%
% [L, cutv] = KOLMOGOROV_MINCUT(g, caps, src_cap, snk_cap);
% [L, cutv] = KOLMOGOROV_MINCUT(g, caps, tcap);
%
%
% Solve the mincut of a weighted graph, using Kolmogorov's mincut
% algorit... | zzhangumd-smitoolbox | graph/flows/kolmogorov_mincut.m | MATLAB | mit | 2,895 |
/**********************************************************
*
* kolmogorov_mincut_cimp.cpp
*
* A C++ mex wrapper of Kolmogorov's mincut implementation
* (based on maxflow v3.01)
*
* Created by Dahua Lin, on Jan 29, 2012
*
**********************************************************/
#include <mex.h>
#include... | zzhangumd-smitoolbox | graph/flows/private/kolmogorov_mincut_cimp.cpp | C++ | mit | 5,915 |
/*
This is a re-package of the files in maxflow-v3.01 which was
implemented by Vladimir Kolmogorov.
This software library implements the maxflow algorithm
described in
"An Experimental Comparison of Min-Cut/Max-Flow Algorithms for Energy Minimization in Vision."
Yuri Boykov and Vladimir Kol... | zzhangumd-smitoolbox | graph/flows/private/kolmogorov_maxflow.h | C++ | mit | 45,944 |
function W = gr_wmat(g, w)
% Compute the edge-weight matrix from a graph
%
% W = gr_wmat(g);
% W = gr_wmat(g, w);
%
% returns an n x n weight (sparse) matrix W, given by
%
% W(u, v) = w_e if e = (u, v) is an edge of g
% = 0 otherwise.
%
% If w is omitted, it creates a l... | zzhangumd-smitoolbox | graph/common/gr_wmat.m | MATLAB | mit | 2,239 |
function gr_dump(g)
% Dump the information of a graph
%
% gr_dump(g);
%
% Created by Dahua Lin, on Oct 28, 2011
%
%% verify input
if ~is_gr(g)
error('gr_dump:invalidarg', 'The input argument is not a valid graph struct.');
end
%% main
if g.dty == 'd'
dtname = 'Directed';
else
dtname = 'Undirected';
e... | zzhangumd-smitoolbox | graph/common/gr_dump.m | MATLAB | mit | 1,116 |
function C = gr_neighbors(G, vs)
% GR_NEIGHBORS Gets the neighbors of nodes
%
% C = GR_NEIGHBORS(G);
% Gets the neighbors of nodes of a graph and returns them as a cell
% array.
%
% Suppose G has n nodes, then C is a cell array of size n x 1,
% such that C{i} is a row vector of its neighbor n... | zzhangumd-smitoolbox | graph/common/gr_neighbors.m | MATLAB | mit | 931 |
function G = make_gr_bnd(nbs)
% Make a degree-bounded graph struct
%
% The degree-bounded graph struct is a compact representation of
% a directed graph whose (outgoing) degree is upper bounded by K.
%
% The struct contains the following fields:
% - tag: a string: 'gr-bnd'
% - n: the number of ... | zzhangumd-smitoolbox | graph/common/make_gr_bnd.m | MATLAB | mit | 1,199 |
function [h, coords] = gr_plot(g, coords, varargin)
% Plot a graph
%
% h = gr_plot(g, 2, ...);
% h = gr_plot(g, 3, ...);
% h = gr_plot(g, coords, ...);
% plots the graph g.
%
% In input, g is a graph struct produced by make_gr
%
% coords is an n x 2 or n x 3 array that gives the coordinates of ... | zzhangumd-smitoolbox | graph/common/gr_plot.m | MATLAB | mit | 2,207 |
function tf = is_gr(g)
% Tests whether the input argument is a valid graph struct
%
% tf = is_gr(g);
%
% Tests whether the input argument g is a valid graph struct
% produced by make_gr.
%
% Created by Dahua Lin, on Oct 28, 2011
%
%% main
tf = isstruct(g) && isscalar(g) && isfield(g, 'tag') && strcmp(... | zzhangumd-smitoolbox | graph/common/is_gr.m | MATLAB | mit | 334 |
function g = gr_nbs(g)
% Add the neighborhood system to a graph
%
% g = gr_nbs(g);
%
% This function creates or updates the neighborhood system for g.
%
% Created by Dahua Lin, on Nov 30, 2011
%
if ~is_gr(g)
error('gr_nbs:invalidarg', 'g should be a graph struct.');
end
[g.o_nbs, g.o_eds, g.o_degs, g.o_o... | zzhangumd-smitoolbox | graph/common/gr_nbs.m | MATLAB | mit | 364 |
function tf = is_gr_bnd(g)
% Tests whether G is a degree-bounded graph struct
%
% tf = is_gr_bnd(g);
% returns whether g is a valid degree-bounded graph struct.
%
% Created by Dahua Lin, on Nov 30, 2011
%
%% main
tf = isstruct(g) && isscalar(g) && isfield(g, 'tag') && strcmp(g.tag, 'gr-bnd'); | zzhangumd-smitoolbox | graph/common/is_gr_bnd.m | MATLAB | mit | 304 |
function [Gs, ws, Ws] = gr_sym(G, w, option)
% Make an undirected graph from a directed one via symmetrization
%
% Gs = gr_sym(G, [], 'max');
% Gs = gr_sym(G, [], 'min');
%
% Make an undirected graph Gs from a directed graph G through
% symmetrization. If the 2nd argument is 'max', then the edge
% ... | zzhangumd-smitoolbox | graph/common/gr_sym.m | MATLAB | mit | 2,982 |
function [G, varargout] = gr_local(siz, rgn)
% Create a degree-bounded graph with links between local neighbors
%
% G = gr_local(n, r);
%
% Creates a locally connected graph over one-dimensional
% grid. Here, n is the number of nodes, and r is the local range.
% In this graph, each node is connected... | zzhangumd-smitoolbox | graph/common/gr_local.m | MATLAB | mit | 3,626 |
function [g, w] = gr_from_wmat(W, dt, op)
% Construct a graph struct from an edge-weight matrix
%
% [g, w] = gr_from_wmat(W, 'u');
% [g, w] = gr_from_wmat(W, 'd');
% [g, w] = gr_from_wmat(W, 'u', 'nbs');
% [g, w] = gr_from_wmat(W, 'd', 'nbs');
%
% Constructs a graph g from W, the edge weight matrix.
% ... | zzhangumd-smitoolbox | graph/common/gr_from_wmat.m | MATLAB | mit | 1,611 |
function [G, V] = knng(D, op, K, thres)
% Construct K-nearest-neighbor graph
%
% [G, V] = knng(D, 'min', K);
% [G, V] = knng(D, 'max', K);
% [G, V] = knng(D, 'min', K, thres);
% [G, V] = knng(D, 'max', K, thres);
%
% constructs a K-nearest-neighbor graph given the
% pairwise distances/similar... | zzhangumd-smitoolbox | graph/common/knng.m | MATLAB | mit | 2,956 |
function G = gr_bnd2inclist(G0)
% Convert a degree-bounded graph struct to a incidence list struct
%
% G = gr_bnd2inclist(G0);
%
% converts a degree-bounded graph struct G0 to a directed graph
% struct with neighborhood system.
%
% Note that if G0 is associated with a weight matrix W, the
% co... | zzhangumd-smitoolbox | graph/common/gr_bnd2inclist.m | MATLAB | mit | 686 |
/********************************************************************
*
* gr_nbs_cimp.cpp
*
* The C++ mex implementation of part of make_gr functionality
*
* Created by Dahua Lin, on Oct 28, 2011
*
********************************************************************/
#include "../../clib/smi_graph_mex.h"
... | zzhangumd-smitoolbox | graph/common/private/gr_nbs_cimp.cpp | C++ | mit | 1,564 |
function g = make_gr(dty, n, s, t, op)
% Makes a graph with given edges
%
% g = make_gr('d', n, s, t);
%
% makes a directed graph with given edges.
%
% Here, n is the number of nodes, s is the source nodes, t is
% the target nodes. s and t should be vectors of the same size.
%
% g = make_gr('u', n... | zzhangumd-smitoolbox | graph/common/make_gr.m | MATLAB | mit | 2,380 |
function ccs = gr_conncomps(G)
%GR_CONNCOMPS Connected components of undirected graph
%
% ccs = GR_CONNCOMPS(G);
%
% Finds connected components of the graph G.
%
% G should be an undirected graph struct (with neighbor system).
%
% ccs is a 1 x K cell array (K is the number of components), and
% ... | zzhangumd-smitoolbox | graph/algs/gr_conncomps.m | MATLAB | mit | 683 |
function edges = gr_prim(G, w, rv, msk, max_size, max_w)
%GR_PRIM Prim's Minimum Spanning Tree Algorithm
%
% edges = GR_PRIM(G, w, rv);
% edges = GR_PRIM(G, w, rv, msk);
% edges = GR_PRIM(G, w, rv, msk, max_size);
% edges = GR_PRIM(G, w, rv, msk, max_size, max_w);
%
% Use Prim's algorithm to find a minimu... | zzhangumd-smitoolbox | graph/algs/gr_prim.m | MATLAB | mit | 3,347 |
function [vs, ds] = gr_flood(G, s, msk)
%GR_FLOOD Breadth-first flooding
%
% [vs, ds] = GR_FLOOD(G, s);
% [vs, ds] = GR_FLOOD(G, s, msk);
%
% Performs a breadth-first traversal from specified sources (with
% in allowable region)
%
% Input arguments:
% - G: The graph (with neighbor sys... | zzhangumd-smitoolbox | graph/algs/gr_flood.m | MATLAB | mit | 1,653 |
/***************************************************************
*
* gr_is_connected_cimp.cpp
*
* The C++ mex implementation of gr_is_connected_cimp
*
* Created by Dahua Lin, on Jan 26, 2012
*
***************************************************************/
#include "../../clib/smi_graph_mex.h"
#include <bc... | zzhangumd-smitoolbox | graph/algs/private/gr_is_connected_cimp.cpp | C++ | mit | 1,055 |
/***************************************************************
*
* gr_conncomps_cimp.cpp
*
* The C++ mex implementation of gr_conncomps_cimp
*
* Created by Dahua Lin, on Jan 26, 2012
*
***************************************************************/
#include "../../clib/smi_graph_mex.h"
#include <bcslib/g... | zzhangumd-smitoolbox | graph/algs/private/gr_conncomps_cimp.cpp | C++ | mit | 1,913 |
/***************************************************************
*
* gr_dijkstra_cimp.cpp
*
* The C++ mex implementation of gr_dijkstra_cimp
*
* Created by Dahua Lin, on Jan 26, 2012
*
***************************************************************/
#include "../../clib/smi_graph_mex.h"
#include <bcslib/gra... | zzhangumd-smitoolbox | graph/algs/private/gr_dijkstra_cimp.cpp | C++ | mit | 4,019 |
/***************************************************************
*
* gr_flood_cimp.cpp
*
* The C++ mex implementation of gr_dijkstra_cimp
*
* Created by Dahua Lin, on Jan 26, 2012
*
***************************************************************/
#include "../../clib/smi_graph_mex.h"
#include <bcslib/array... | zzhangumd-smitoolbox | graph/algs/private/gr_flood_cimp.cpp | C++ | mit | 3,827 |
/***************************************************************
*
* gr_kruskal_cimp.cpp
*
* The C++ mex implementation of gr_dijkstra_cimp
*
* Created by Dahua Lin, on Jan 26, 2012
*
***************************************************************/
#include "../../clib/smi_graph_mex.h"
#include <bcslib/grap... | zzhangumd-smitoolbox | graph/algs/private/gr_kruskal_cimp.cpp | C++ | mit | 4,091 |
/***************************************************************
*
* gr_prim_cimp.cpp
*
* The C++ mex implementation of gr_prim_cimp
*
* Created by Dahua Lin, on Jan 26, 2012
*
***************************************************************/
#include "../../clib/smi_graph_mex.h"
#include <bcslib/graph/graph... | zzhangumd-smitoolbox | graph/algs/private/gr_prim_cimp.cpp | C++ | mit | 3,301 |
function [lens, vs, preds] = gr_dijkstra(G, w, s)
%GR_DIJKSTRA Single-source shortest paths
%
% [vs, lens] = GR_DIJKSTRA(G, w, s);
% [vs, lens, preds] = GR_DIJKSTRA(G, w, s);
%
% Find the shortest paths to all vertices of the graph from
% specific source using Dijkstra's algorithm.
%
% Input arg... | zzhangumd-smitoolbox | graph/algs/gr_dijkstra.m | MATLAB | mit | 2,250 |