Rank: 394 based on 289 downloads (last 30 days) and 5 files submitted
photo

Peter Perkins

E-mail
Company/University
The MathWorks, Inc

Personal Profile:

Professional Interests:

 

Watch this Author's files

 

Files Posted by Peter View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
06 Aug 2009 Mersenne Twister Mersenne Twister uniform pseudo-random number generator. Author: Peter Perkins random number, mersenne, statistics, twister, probability, generator 64 5
  • 5.0
5.0 | 3 ratings
18 Jun 2009 Copula Functions Functions accompanying MATLAB News&Notes article "Monte-Carlo Simulation in MATLAB Using Copulas" Author: Peter Perkins copula, probability, statistics, monte carlo 95 10
  • 4.46667
4.5 | 15 ratings
18 Jun 2009 Screenshot smoothhist2D Plot a smoothed histogram of bivariate data Author: Peter Perkins eilers, graphics, plotting, histogram, scatterplot, specialized 90 6
  • 4.2
4.2 | 5 ratings
18 Jun 2009 Random Number Streams "Independent" streams of pseudorandom numbers. Author: Peter Perkins pseudo, statistics, random stream, probability, rngs 15 0
18 Jun 2009 BioMedical EDU Webinar - Statistics and Curve Fitting Code and data used during the BioMedical EDU Webinar given on 10/8/03. Author: Peter Perkins biomedical, demo, statistics, biomedial, edu, probability 25 0
Comments and Ratings on Peter's Files View all
Updated File Comment by Comments Rating
12 Nov 2009 smoothhist2D Plot a smoothed histogram of bivariate data Author: Peter Perkins Hubert, Hubsi

Hey!
Glad I finally found the script, but have some difficulties...
Don't know wheather this is the right place to post questions reagarding this skript, but I'll try:
How can change the axis: I would like to have the point of origin in the lower left corner and not at the upper right one.
Thanks for any suggestions!

24 Aug 2009 smoothhist2D Plot a smoothed histogram of bivariate data Author: Peter Perkins Beaver, Scott

Indeed, excellent file and simple to use.

06 Aug 2009 Mersenne Twister Mersenne Twister uniform pseudo-random number generator. Author: Peter Perkins Tursa, James

To Joe Bunda: The included lcc is a C compiler, not a C++ compiler. You need a C++ compiler to compile twister.cpp. I did a quick look at the code and it looks like it wouldn't take much to convert it to a C routine that lcc would accept.

To Peter Perkins: Do you plan on including a C version in a later update for people without a C++ compiler? If not, would you mind if I made a go at it?

13 Jun 2009 Copula Functions Functions accompanying MATLAB News&Notes article "Monte-Carlo Simulation in MATLAB Using Copulas" Author: Peter Perkins Toljic, Nikola

Very nice.

17 Feb 2009 smoothhist2D Plot a smoothed histogram of bivariate data Author: Peter Perkins Ronchi, Emanuele

Hi, I modified the function so that you con get the histogram and axes out and so that you can enter the edges as well (instead of only the bin numbers)

let me know if there are problems. From my tests it looks ok but didn't try on non uniform grids yet

Emanuele

function [F,ctrs1,ctrs2]=smoothhist2D(X,lambda,nbins,outliercutoff,plottype)
% SMOOTHHIST2D Plot a smoothed histogram of bivariate data.
% [H,X,Y]=SMOOTHHIST2D(X,LAMBDA,NBINS) plots a smoothed histogram of the bivariate
% data in the N-by-2 matrix X. Rows of X correspond to observations. The
% first column of X corresponds to the horizontal axis of the figure, the
% second to the vertical. LAMBDA is a positive scalar smoothing parameter;
% higher values lead to more smoothing, values close to zero lead to a plot
% that is essentially just the raw data. NBINS is a two-element vector
% that determines the number of histogram bins in the horizontal and
% vertical directions.
%
% SMOOTHHIST2D(X,LAMBDA,NBINS,CUTOFF) plots outliers in the data as points
% overlaid on the smoothed histogram. Outliers are defined as points in
% regions where the smoothed density is less than (100*CUTOFF)% of the
% maximum density.
%
% SMOOTHHIST2D(X,LAMBDA,NBINS,[],'surf') plots a smoothed histogram as a
% surface plot. SMOOTHHIST2D ignores the CUTOFF input in this case, and
% the surface plot does not include outliers.
%
% SMOOTHHIST2D(X,LAMBDA,NBINS,CUTOFF,'image') plots the histogram as an
% image plot, the default.
%
% MODIFICATIONS TO THE ORIGINAL FUNCTION:
% 1. you can also enter the histogram edges instead of the bin numbers
% by making NBINS a CELL array. Example (using X defined below)
% 2. Added outputs (histogram and edges)
%
% [h,xg,yg]=smoothhist2D(X,5,{[-5:0.1:10],[0:0.1:15]},.05);
%
% Example:
% X = [mvnrnd([0 5], [3 0; 0 3], 2000);
% mvnrnd([0 8], [1 0; 0 5], 2000);
% mvnrnd([3 5], [5 0; 0 1], 2000)];
% smoothhist2D(X,5,[100, 100],.05);
% smoothhist2D(X,5,[100, 100],[],'surf');
%
% Reference:
% Eilers, P.H.C. and Goeman, J.J (2004) "Enhancing scaterplots with
% smoothed densities", Bioinformatics 20(5):623-628.

% Written by Peter Perkins, The MathWorks, Inc.
% Revision: 1.0 Date: 2006/12/12
% This function is not supported by The MathWorks, Inc.
%
% Requires MATLAB R14.

if nargin < 4 || isempty(outliercutoff), outliercutoff = .05; end
if nargin < 5, plottype = 'image'; end

minx = min(X,[],1);
maxx = max(X,[],1);
if ~iscell(nbins) %mode: bins
    edges1 = linspace(minx(1), maxx(1), nbins(1)+1);
    edges2 = linspace(minx(2), maxx(2), nbins(2)+1);
    nbins1=nbins(1);nbins2=nbins(2);
    ctrs1 = edges1(1:end-1) + .5*diff(edges1);
    ctrs2 = edges2(1:end-1) + .5*diff(edges2);
else %mode: edges
    edges1=nbins{1};
    edges2=nbins{2};
    nbins1=length(edges1);
    nbins2=length(edges2);
    ctrs1=edges1;ctrs2=edges2;
end

edges1 = [-Inf edges1(2:end-1) Inf];
edges2 = [-Inf edges2(2:end-1) Inf];

[n,p] = size(X);
bin = zeros(n,2);
% Reverse the columns of H to put the first column of X along the
% horizontal axis, the second along the vertical.
[dum,bin(:,2)] = histc(X(:,1),edges1);
[dum,bin(:,1)] = histc(X(:,2),edges2);

H = accumarray(bin,1,[nbins2,nbins1]) ./ n;
%H = accumarray(bin,1,nbins([2 1])) ./ n;

% Eiler's 1D smooth, twice
G = smooth1D(H,lambda);
F = smooth1D(G',lambda)';
% % An alternative, using filter2. However, lambda means totally different
% % things in this case: for smooth1D, it is a smoothness penalty parameter,
% % while for filter2D, it is a window halfwidth
% F = filter2D(H,lambda);

relF = F./max(F(:));
if outliercutoff > 0
    outliers = (relF(nbins2*(bin(:,2)-1)+bin(:,1)) < outliercutoff);
end

nc = 256;
colormap(hot(nc));
switch plottype
    case 'surf'
        surf(ctrs1,ctrs2,F,'edgealpha',0);
    case 'image'
        image(ctrs1,ctrs2,floor(nc.*relF) + 1);
        hold on
        % plot the outliers
        if outliercutoff > 0
            plot(X(outliers,1),X(outliers,2),'.','MarkerEdgeColor',[.8 .8 .8]);
        end
        % % plot a subsample of the data
        % Xsample = X(randsample(n,n/10),:);
        % plot(Xsample(:,1),Xsample(:,2),'bo');
        hold off
end

%-----------------------------------------------------------------------------
function Z = smooth1D(Y,lambda)
[m,n] = size(Y);
E = eye(m);
D1 = diff(E,1);
D2 = diff(D1,1);
P = lambda.^2 .* D2'*D2 + 2.*lambda .* D1'*D1;
Z = (E + P) \ Y;
% This is a better solution, but takes a bit longer for n and m large
% opts.RECT = true;
% D1 = [diff(E,1); zeros(1,n)];
% D2 = [diff(D1,1); zeros(1,n)];
% Z = linsolve([E; 2.*sqrt(lambda).*D1; lambda.*D2],[Y; zeros(2*m,n)],opts);

%-----------------------------------------------------------------------------
function Z = filter2D(Y,bw)
z = -1:(1/bw):1;
k = .75 * (1 - z.^2); % epanechnikov-like weights
k = k ./ sum(k);
Z = filter2(k'*k,Y);

Top Tags Applied by Peter
probability, statistics, histogram, plotting, scatterplot
Files Tagged by Peter View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
06 Aug 2009 Mersenne Twister Mersenne Twister uniform pseudo-random number generator. Author: Peter Perkins random number, mersenne, statistics, twister, probability, generator 64 5
  • 5.0
5.0 | 3 ratings
18 Jun 2009 Copula Functions Functions accompanying MATLAB News&Notes article "Monte-Carlo Simulation in MATLAB Using Copulas" Author: Peter Perkins copula, probability, statistics, monte carlo 95 10
  • 4.46667
4.5 | 15 ratings
18 Jun 2009 Screenshot smoothhist2D Plot a smoothed histogram of bivariate data Author: Peter Perkins eilers, graphics, plotting, histogram, scatterplot, specialized 90 6
  • 4.2
4.2 | 5 ratings
18 Jun 2009 Random Number Streams "Independent" streams of pseudorandom numbers. Author: Peter Perkins pseudo, statistics, random stream, probability, rngs 15 0
18 Jun 2009 BioMedical EDU Webinar - Statistics and Curve Fitting Code and data used during the BioMedical EDU Webinar given on 10/8/03. Author: Peter Perkins biomedical, demo, statistics, biomedial, edu, probability 25 0
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com