Commit bfb64a70 authored by Jack Poulson's avatar Jack Poulson

Adding support for computing the log-likelihood of a DPP sample using the...

Adding support for computing the log-likelihood of a DPP sample using the (real part of the) diagonal of the factored result.
parent cdec09a5
...@@ -97,6 +97,9 @@ std::vector<Int> SampleNonsymmetricDPP(Int block_size, bool maximum_likelihood, ...@@ -97,6 +97,9 @@ std::vector<Int> SampleNonsymmetricDPP(Int block_size, bool maximum_likelihood,
std::cout << "Sequential time: " << runtime << " seconds." << std::endl; std::cout << "Sequential time: " << runtime << " seconds." << std::endl;
std::cout << "Sequential DPP GFlop/s: " << gflops_per_sec << std::endl; std::cout << "Sequential DPP GFlop/s: " << gflops_per_sec << std::endl;
const ComplexBase<Field> log_likelihood = catamari::DPPLogLikelihood(*matrix);
std::cout << "Sequential DPP log-likelihood: " << log_likelihood << std::endl;
return sample; return sample;
} }
...@@ -129,6 +132,9 @@ std::vector<Int> OpenMPSampleNonsymmetricDPP(Int tile_size, Int block_size, ...@@ -129,6 +132,9 @@ std::vector<Int> OpenMPSampleNonsymmetricDPP(Int tile_size, Int block_size,
std::cout << "OpenMP time: " << runtime << " seconds." << std::endl; std::cout << "OpenMP time: " << runtime << " seconds." << std::endl;
std::cout << "OpenMP DPP GFlop/s: " << gflops_per_sec << std::endl; std::cout << "OpenMP DPP GFlop/s: " << gflops_per_sec << std::endl;
const ComplexBase<Field> log_likelihood = catamari::DPPLogLikelihood(*matrix);
std::cout << "OpenMP DPP log-likelihood: " << log_likelihood << std::endl;
return sample; return sample;
} }
#endif // ifdef CATAMARI_OPENMP #endif // ifdef CATAMARI_OPENMP
......
...@@ -844,6 +844,9 @@ std::vector<Int> SampleDPP(Int block_size, bool maximum_likelihood, ...@@ -844,6 +844,9 @@ std::vector<Int> SampleDPP(Int block_size, bool maximum_likelihood,
std::cout << "Sequential DPP time: " << runtime << " seconds." << std::endl; std::cout << "Sequential DPP time: " << runtime << " seconds." << std::endl;
std::cout << "Sequential DPP GFlop/s: " << gflops_per_sec << std::endl; std::cout << "Sequential DPP GFlop/s: " << gflops_per_sec << std::endl;
const ComplexBase<Field> log_likelihood = catamari::DPPLogLikelihood(*matrix);
std::cout << "Sequential DPP log-likelihood: " << log_likelihood << std::endl;
return sample; return sample;
} }
...@@ -878,6 +881,9 @@ std::vector<Int> OpenMPSampleDPP(Int tile_size, Int block_size, ...@@ -878,6 +881,9 @@ std::vector<Int> OpenMPSampleDPP(Int tile_size, Int block_size,
std::cout << "OpenMP DPP time: " << runtime << " seconds." << std::endl; std::cout << "OpenMP DPP time: " << runtime << " seconds." << std::endl;
std::cout << "OpenMP DPP GFlop/s: " << gflops_per_sec << std::endl; std::cout << "OpenMP DPP GFlop/s: " << gflops_per_sec << std::endl;
const ComplexBase<Field> log_likelihood = catamari::DPPLogLikelihood(*matrix);
std::cout << "OpenMP DPP log-likelihood: " << log_likelihood << std::endl;
return sample; return sample;
} }
#endif // ifdef CATAMARI_OPENMP #endif // ifdef CATAMARI_OPENMP
......
...@@ -637,6 +637,25 @@ std::vector<Int> LowerFactorAndSampleNonsymmetricDPP( ...@@ -637,6 +637,25 @@ std::vector<Int> LowerFactorAndSampleNonsymmetricDPP(
block_size, maximum_likelihood, matrix, generator); block_size, maximum_likelihood, matrix, generator);
} }
template <typename Field>
ComplexBase<Field> DPPLogLikelihood(const BlasMatrixView<Field>& matrix) {
typedef ComplexBase<Field> Real;
const Int matrix_size = matrix.height;
Real log_likelihood = 0;
for (Int i = 0; i < matrix_size; ++i) {
Real entry = quotient::RealPart(matrix(i, i));
if (entry > Real(0)) {
log_likelihood += std::log(entry);
} else if (entry < Real(0)) {
log_likelihood += std::log(-entry);
} else {
std::cerr << "Had an exactly zero diagonal entry of the result."
<< std::endl;
}
}
return log_likelihood;
}
} // namespace catamari } // namespace catamari
#include "catamari/dense_factorizations/openmp-impl.hpp" #include "catamari/dense_factorizations/openmp-impl.hpp"
......
...@@ -109,6 +109,11 @@ std::vector<Int> OpenMPLowerFactorAndSampleNonsymmetricDPP( ...@@ -109,6 +109,11 @@ std::vector<Int> OpenMPLowerFactorAndSampleNonsymmetricDPP(
BlasMatrixView<Field>* matrix, std::mt19937* generator); BlasMatrixView<Field>* matrix, std::mt19937* generator);
#endif // ifdef CATAMARI_OPENMP #endif // ifdef CATAMARI_OPENMP
// Returns the log-likelihood of a general DPP sample based upon the product of
// the (real part of the) diagonal of the factored result.
template <typename Field>
ComplexBase<Field> DPPLogLikelihood(const BlasMatrixView<Field>& matrix);
} // namespace catamari } // namespace catamari
#include "catamari/dense_factorizations-impl.hpp" #include "catamari/dense_factorizations-impl.hpp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment