Compute the density function of a PageRank random variable

In the random $\alpha$ PageRank model, we replace the deterministic parameter $\alpha$ with a random parameter $A$. For the paper, we assume that $A$ has a $\mathrm{Beta}$ density. In this example, we'll show the density functions for the PageRank elements themselves in the model. Recall that when we substitute $A$ in the PageRank equation

so that

then the vector $x(A)$ has a random variable as each element. It is the density functions of these random variables that this experiment displays.

Contents

Setup the experiment

This experiment should be run from the rapr/experiments/datastats directory

cwd = pwd;
dirtail = 'experiments/density';
if strcmp(cwd(end-length(dirtail)+1:end),dirtail) == 0
    warning('rapr:dir','%s should be executed from rapr/%s\n',mfilename,dirtail);
end
addpath('../../matlab'); % ensure we have the RAPr codes available

We'll load a small graph, so we have a tractable number of density functions to plot.

load('../../data/example-small.mat');
n=size(P,1);

The Beta distribution

In this experimnt, we'll use the beta distribution. Using the RAPr functions, creating an instance of this distribution for our problem is simple.

a=2; b=16; l=0; r=1;
d=alphadist('beta',a,b,l,r);
eA=d.mf(1); eA=eA(end); % compute the expected value of the Beta variable.

For fun, let's plot the density function. Unfortunately, this isn't a built-in RAPr function for the alphadist structure yet. Maybe it's a good one to add since Matlab has the beta built in, and we have to do this strange conversion from our (a,b) to Matlab's (b+1,a+1) parameters.

figure(1); fplot(@(x) betapdf(x,b+1,a+1)*(r-l)+l, [0 1]);
title(sprintf('Density of Beta(%i,%i) on [%i,%i]\n', a,b,l,r));
set(gca,'YTick',[]); box off; pbaspect([4 1 1]);

Compute PageRank at the Gauss points

To compute the density functions, we will first solve for the PageRank vector at each of the Gauss quadrature points. Then, using Barycentric Lagrange interpolation, we'll form an interpolant for the PageRank vector as a function of $\alpha$. With our interpolant, we will sample PageRank vectors based on a Beta distribution and use a kernel density estimation to generate the density functions.

% choose a value for the number of GQ points, the small graph is 6x6, so
% the polynomial should be of degree
N=18;

% compute pagerank at each quadrature point and also compute the PageRank
% vector of the exected value.
[ex stdx xw X] = gqrapr(P,N,d,'direct');
xeA = inoutpr(P,eA);

% construct the interpolant for each node and evaluate the interpolant at
% each of the beta samples. run the resulting samples into a kernel density
% estimator to approximate the pdf.
s=rand('state');rand('state',0); % ensure consistent results
nsamples = 10000; betasamples = d.rnd(nsamples);rand('state',s);
for k=1:length(ex)
    % interpolate and evaluate at betasamples
    prsamples = barylag([xw(:,1) X(k,:)'], betasamples);
    [f(:,k),xi(:,k)] = ksdensity(prsamples); % estimate the density
end
solved pagerank(a=0.8500) in   134 multiplies to 9.358972e-13 tolerance

Plot the PDFs

figure(1); clf; xlims=[0 max(max(xi))]; ylims=[0 max(max(f))+1];tp={'fontsize',16};
for i=1:length(ex),
    subplot(6,1,i); plot(xi(:,i),f(:,i),'k-'); xlim(xlims); ylim(ylims); axis off;
    line([xeA(i),xeA(i)],[-1 ylims(2)],'Marker','o','Color',[0.5 0.5 1]);
    line([ex(i),ex(i)],[-1 ylims(2)],'Marker','*','Color',[1 0.5 0.5]);
    line(xlims, [0 0],'Color',[0 0 0]); text(-0.01,mean(ylims),sprintf('x_%i',i),tp{:});
    if i==6, h=text(0,-8,'0',tp{:});h=text(0.5,-8,'0.5',tp{:});end,pbaspect([8 1 1]);
end
set(gcf,'Color',[1 1 1]); print(gcf,'pagerank-pdfs.eps','-depsc2');