This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Computing marginal log likelihood of data for unknown mean, fixed variance model. | |
Running Demo | |
------------ | |
$ python marg_lik_of_normal.py | |
This will compare numerical and exact methods for calculating marg. lik. | |
By visual inspection, user can see the exact method matches numerical. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' Define invertible, differentiable transform for arrays of positive vals. | |
Utility funcs for transforming positive vals to and from unconstrained real line. | |
This transform is sometimes called the "softplus" transformation. | |
See: https://en.wikipedia.org/wiki/Rectifier_(neural_networks) | |
To run automated tests to verify correctness of this script, do: | |
(Add -v flag for verbose output) | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import itertools | |
def calc_bar_z_K(resp_UK=None, wc_U=None): | |
''' Compute empirical doc-topic probability vector | |
Returns | |
------- | |
barz_K : 1D array, size K | |
barz_K[k] = fraction of tokens in doc explained by topic k |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import autograd.numpy as np | |
from autograd.scipy.special import gammaln, digamma | |
from autograd import grad, hessian | |
from scipy.optimize import fmin_l_bfgs_b | |
def L_theta( | |
theta_d_K=None, | |
N_d_K=None, | |
alpha_K=None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [] = Countdown(start) | |
% Will just count down from provided input number to 1 | |
% Printing each value along the way. | |
% | |
disp('Counting down...'); | |
for i = start:-1:1 | |
pause(0.5); % wait half a second | |
disp(i); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [] = RankOneUpdateTest( D ) | |
nTrial = 1000; | |
invW = randn( 3*D, D); | |
invW = invW'*invW; | |
x = randn(D,1); | |
cholinvW = chol(invW,'upper'); | |
logdetinvW = 2*sum(log(diag(cholinvW))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logp = DMMargLik( Nvec, alphvec ) | |
logZ_lik = sum( gammaln( Nvec+alphvec ) ) - gammaln( sum(Nvec+alphvec) ); | |
logZ_prior = sum( gammaln( alphvec) ) - gammaln( sum( alphvec ) ); | |
logp = logZ_lik - logZ_prior; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Eigen/Dense" | |
#include <iostream> | |
#include <time.h> | |
using namespace Eigen; | |
using namespace std; | |
double diffclock(clock_t clock1,clock_t clock2) | |
{ | |
double diffticks=clock1-clock2; | |
double diffms=(diffticks)/CLOCKS_PER_SEC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Eigen/Dense" | |
#include "mex.h" | |
#include <iostream> | |
using namespace Eigen; | |
using namespace std; | |
typedef Map<MatrixXd> MexMat; | |
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 100; | |
M = 4; | |
sig = .4; | |
% Create evenly spaced pts between 0 and M | |
% X is N x 1 | |
X = linspace( 0, M, N )'; | |
% Calc squared Euclidean distance | |
% between every pair of rows in X |