Skip to content

Commit 5825882

Browse files
committed
Add rand(::Eigen) to sample determinantal point processes
1 parent d367b83 commit 5825882

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
julia 0.3
22
Combinatorics
3+
Docile
34
Distributions
45
ODE

src/RandomMatrices.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ module RandomMatrices
22
importall Distributions
33
using Combinatorics
44

5+
if VERSION < v"0.4-"
6+
using Docile
7+
end
8+
59
import Base.rand
610

711
#If the GNU Scientific Library is present, turn on additional functionality.
@@ -32,6 +36,9 @@ include("densities/TracyWidom.jl")
3236
# Ginibre
3337
include("Ginibre.jl")
3438

39+
# determinantal point processes
40+
include("dpp.jl")
41+
3542
#Generating matrices of Haar measure
3643
include("Haar.jl")
3744
include("HaarMeasure.jl")

src/dpp.jl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Random samples from determinantal point processes
2+
3+
@doc doc"""
4+
Computes a random sample from the determinantal point process defined by the
5+
spectral factorization object `L`.
6+
7+
Inputs:
8+
9+
`L`: `Eigen` factorization object of an N x N matrix
10+
11+
Output:
12+
13+
`Y`: A `Vector{Int}` with entries in [1:N].
14+
15+
References:
16+
17+
Algorithm 18 of \cite{HKPV05}, as described in Algorithm 1 of \cite{KT12}.
18+
19+
@article{HKPV05,
20+
author = {Hough, J Ben and Krishnapur, Manjunath and Peres, Yuval and Vir\'{a}g, B\'{a}lint},
21+
doi = {10.1214/154957806000000078},
22+
journal = {Probability Surveys},
23+
pages = {206--229},
24+
title = {Determinantal Processes and Independence},
25+
volume = {3},
26+
year = {2005}
27+
archivePrefix = {arXiv},
28+
eprint = {0503110},
29+
}
30+
31+
@article{KT12,
32+
author = {Kulesza, Alex and Taskar, Ben},
33+
doi = {10.1561/2200000044},
34+
journal = {Foundations and Trends in Machine Learning},
35+
number = {2-3},
36+
pages = {123--286},
37+
title = {Determinantal Point Processes for Machine Learning},
38+
volume = {5},
39+
year = {2012},
40+
archivePrefix = {arXiv},
41+
eprint = {1207.6083},
42+
}
43+
""" ->
44+
function rand{S<:Real,T}(L::Base.LinAlg.Eigen{S,T})
45+
N = length(L.values)
46+
J = Int[]
47+
for n=1:N
48+
λ = L.values[n]
49+
rand() < λ/+1) && push!(J, n)
50+
end
51+
52+
V = L.vectors[:, J]
53+
Y = Int[]
54+
nV = size(V, 2)
55+
while true
56+
# Select i from 𝒴=[1:N] (ground set) with probabilities
57+
# Pr(i) = 1/|V| Σ_{v∈V} (v⋅eᵢ)²
58+
59+
#Compute selection probabilities
60+
Pr = zeros(N)
61+
for i=1:N
62+
for j=1:nV #TODO this loop is a bottleneck - why?
63+
Pr[i] += (V[i,j])^2 #ith entry of jth eigenvector
64+
end
65+
Pr[i] /= nV
66+
end
67+
@assert abs(1-sum(Pr)) < N*eps() #Check normalization
68+
69+
#Simple discrete sampler
70+
i, ρ = N, rand()
71+
for j=1:N
72+
if ρ < Pr[j]
73+
i = j
74+
break
75+
else
76+
ρ -= Pr[j]
77+
end
78+
end
79+
push!(Y, i)
80+
nV == 1 && break #Done
81+
#V = V⊥ #an orthonormal basis for the subspace of V ⊥ eᵢ
82+
V[i, :] = 0 #Project out eᵢ
83+
V = full(qrfact!(V)[:Q])[:, 1:nV-1]
84+
nV = size(V, 2)
85+
end
86+
Y
87+
end

0 commit comments

Comments
 (0)