|
| 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