From 70bcc864da1d66d156f2c215a9d1d3cfb7add52f Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Thu, 18 Oct 2018 16:08:10 -0500 Subject: [PATCH 01/25] Removed unecessary use of pow that causes NaN gradient values. --- PhysTools/likelihood/likelihood.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index cca2367..3a0f3d0 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -571,7 +571,10 @@ namespace likelihood{ // Use Taylor approx. log(1 + x) = x - x^2/2 with error roughly x^3/3 // Since |x| < 10^-4, |x|^3 < 10^-12, relative error less than 10^-8 - return x-pow(x,2.0)/2.0+pow(x,3.0)/3.0-pow(x,4.0)/4.0; + T x2 = x*x; + T x3 = x2*x; + T x4 = x3*x; + return x-x2/2.0+x3/3.0-x4/4.0; }; template @@ -593,7 +596,10 @@ namespace likelihood{ // Use Taylor approx. log(1 + x) = x - x^2/2 with error roughly x^3/3 // Since |x| < 10^-4, |x|^3 < 10^-12, relative error less than 10^-8 - return -x-pow(x,2.0)/2.0-pow(x,3.0)/3.0-pow(x,4.0)/4.0; + T x2 = x*x; + T x3 = x2*x; + T x4 = x3*x; + return -x-x2/2.0-x3/3.0-x4/4.0; }; template @@ -1011,7 +1017,7 @@ namespace likelihood{ } } - T alpha = pow(w_sum, T(2))/w2_sum; + T alpha = w_sum*w_sum/w2_sum; T beta = w_sum/w2_sum; T L = gammaPriorPoissonLikelihood()(k, alpha, beta); @@ -1042,7 +1048,7 @@ namespace likelihood{ } const T & mu = w_sum; - T mu2 = pow(mu, T(2)); + T mu2 = mu*mu; const T & sigma2 = w2_sum; T beta = (mu + sqrt(mu2+sigma2*4.0))/(sigma2*2); @@ -1450,7 +1456,7 @@ namespace likelihood{ for(const RawEvent& e : ((entryStoringBin)*expIt)){ w = weighter(e); assert(w >= 0); - w2 = pow(w, DataType(2.0)); + w2 = w * w; assert(w2 >= 0); assert(e.num_events > 0); n_events += e.num_events; @@ -1531,7 +1537,7 @@ namespace likelihood{ for(const RawEvent& e : ((entryStoringBin)*it)) { w = weighter(e); assert(w >= 0); - w2 = pow(w, DataType(2.0)); + w2 = w*w; assert(w2 >= 0); assert(e.num_events > 0); n_events += e.num_events; From d4e8748415263a5dea0b8d4d9742b398483759e0 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Mon, 4 Feb 2019 17:40:27 -0600 Subject: [PATCH 02/25] No need for SAY variants. --- PhysTools/likelihood/likelihood.h | 53 ++----------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 3a0f3d0..bc49db0 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -995,7 +995,7 @@ namespace likelihood{ } }; - struct bayesianSAYLikelihood { + struct SAYLikelihood { template T operator()(double k, T const & w_sum, T const & w2_sum) const { if(w_sum <= 0 || w2_sum < 0) { @@ -1017,7 +1017,7 @@ namespace likelihood{ } } - T alpha = w_sum*w_sum/w2_sum; + T alpha = w_sum*w_sum/w2_sum + one; T beta = w_sum/w2_sum; T L = gammaPriorPoissonLikelihood()(k, alpha, beta); @@ -1025,55 +1025,6 @@ namespace likelihood{ } }; - struct frequentistSAYLikelihood { - template - T operator()(double k, T const & w_sum, T const & w2_sum) const { - if(w_sum <= 0 || w2_sum < 0) { - return(k==0?0:-std::numeric_limits::max()); - } - - if(w2_sum == 0) { - return poissonLikelihood()(k, w_sum, w2_sum); - } - - T one(1); - T zero(0); - if(w_sum == zero) { - if(k == 0) { - return zero; - } - else { - return T(-std::numeric_limits::infinity()); - } - } - - const T & mu = w_sum; - T mu2 = mu*mu; - const T & sigma2 = w2_sum; - - T beta = (mu + sqrt(mu2+sigma2*4.0))/(sigma2*2); - T alpha = (mu*sqrt(mu2+sigma2*4.0)/sigma2 + mu2/sigma2 + 2.0) / 2.0; - T L = gammaPriorPoissonLikelihood()(k, alpha, beta); - - return L; - } - }; - - struct SAYLikelihood { - const bool is_frequentist; - SAYLikelihood():is_frequentist(false) {} - SAYLikelihood(bool is_frequentist):is_frequentist(is_frequentist) {} - bayesianSAYLikelihood bayesian; - frequentistSAYLikelihood frequentist; - template - T operator()(double k, T const & w_sum, T const & w2_sum) const { - if(is_frequentist) - return frequentist(k, w_sum, w2_sum); - else - return bayesian(k, w_sum, w2_sum); - } - }; - //A bin type for keeping events in their histogram bins template From bc660e69b4b449f6988ab2cafd13fe1389bd2835 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Sun, 17 Feb 2019 10:20:24 -0600 Subject: [PATCH 03/25] PowerPrior --- PhysTools/likelihood/likelihood.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index bc49db0..46e6682 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -2129,6 +2129,36 @@ namespace likelihood{ } }; + struct PowerPrior{ + private: + double power, min, max, lnorm; + public: + PowerPrior(double power=0.0, double min=-std::numeric_limits::infinity(), + double max=std::numeric_limits::infinity()): + power(power), min(min), max(max) { + assert(min >= 0.0); + if(min == 0) { + assert(power >= 0.0); + } + else if(std::isfinite(max) && std::isfinite(min)) { + lnorm = log((std::pow(min, power+1.0) - std::pow(max, power+1.0))/(power+1.0)); + } + else if(std::isfinite(min) && power < 1.0) { + lnorm = log(std::pow(min, power+1.0)/(power+1.0)); + } + else { + lnorm = 0.0; + } + } + + template + DataType operator()(DataType x) const{ + if(xmax) + return(DataType(-std::numeric_limits::infinity())); + return power*log(x) - lnorm; + } + }; + struct GaussianPrior{ private: double mean; From 7c2bc414638a1e343bcad5bd4739c7923127b646 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Sun, 17 Feb 2019 10:26:03 -0600 Subject: [PATCH 04/25] setSeed for likelihood --- PhysTools/likelihood/likelihood.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 46e6682..4e1bc83 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -1362,6 +1362,11 @@ namespace likelihood{ return(parameterSeeds); } + void setSeed(const std::vector& newSeed) { + assert(newSeed.size() == parameterSeeds.size()); + parametersSeeds = newSeed; + } + void setObservation(const HistogramsType& newObs){ observation=newObs; } From 60f222aa740b9d7d470f42dd6e1c6560f1e8e21d Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Thu, 21 Feb 2019 09:16:33 -0600 Subject: [PATCH 05/25] Fix typo --- PhysTools/likelihood/likelihood.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 4e1bc83..d0455d4 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -1364,7 +1364,7 @@ namespace likelihood{ void setSeed(const std::vector& newSeed) { assert(newSeed.size() == parameterSeeds.size()); - parametersSeeds = newSeed; + parameterSeeds = newSeed; } void setObservation(const HistogramsType& newObs){ From 594fc9d48d252903638f0b695a214640d0e5692a Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Fri, 8 Mar 2019 11:21:27 -0600 Subject: [PATCH 06/25] Fixed 2dguassian --- PhysTools/likelihood/likelihood.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index d0455d4..a8316d6 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -2142,8 +2142,8 @@ namespace likelihood{ double max=std::numeric_limits::infinity()): power(power), min(min), max(max) { assert(min >= 0.0); - if(min == 0) { - assert(power >= 0.0); + if(min == 0 and power <= 0) { + lnorm = 0.0; } else if(std::isfinite(max) && std::isfinite(min)) { lnorm = log((std::pow(min, power+1.0) - std::pow(max, power+1.0))/(power+1.0)); @@ -2214,7 +2214,7 @@ namespace likelihood{ Gaussian2DPrior(double mean0, double mean1, double stddev0, double stddev1, double correlation): mean0(mean0),mean1(mean1),stddev0(stddev0),stddev1(stddev1),correlation(correlation), lnorm(log(boost::math::constants::one_div_two_pi()/(stddev0*stddev1*sqrt(1.0-correlation*correlation)))), - prefactor(-1.0/(2.0*sqrt(1.0-correlation*correlation))){ + prefactor(-1.0/(2.0*(1.0-correlation*correlation))){ if(std::isinf(stddev0) || std::isinf(stddev0) || std::isnan(stddev0) || std::isnan(stddev1) || std::isnan(correlation)) { lnorm = 0.0; prefactor = 0.0; From 7d9e132eea25c04b700387e08729aec39b48b504 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Fri, 15 Mar 2019 09:56:23 -0500 Subject: [PATCH 07/25] PowerPrior should work for power==0 and x==0. --- PhysTools/likelihood/likelihood.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index a8316d6..f7cfb25 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -2142,7 +2142,7 @@ namespace likelihood{ double max=std::numeric_limits::infinity()): power(power), min(min), max(max) { assert(min >= 0.0); - if(min == 0 and power <= 0) { + if(min == 0.0 and power <= 0.0) { lnorm = 0.0; } else if(std::isfinite(max) && std::isfinite(min)) { @@ -2160,6 +2160,8 @@ namespace likelihood{ DataType operator()(DataType x) const{ if(xmax) return(DataType(-std::numeric_limits::infinity())); + else if(power == 0.0) + return 0.0; return power*log(x) - lnorm; } }; From dbe1c0ca89ccb709d818389b2261f4b55e98dbf0 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Fri, 17 Jan 2020 12:39:42 -0600 Subject: [PATCH 08/25] Future proofing for newer compilers. --- PhysTools/dynamic_histogram.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PhysTools/dynamic_histogram.h b/PhysTools/dynamic_histogram.h index 4e57d45..8a956ae 100644 --- a/PhysTools/dynamic_histogram.h +++ b/PhysTools/dynamic_histogram.h @@ -569,7 +569,7 @@ class histogram : public histogramBase : public histogramBase Date: Sun, 24 Jan 2021 12:14:26 -0500 Subject: [PATCH 09/25] Add uncertainty modification --- PhysTools/likelihood/likelihood.h | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index f7cfb25..2cf3434 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -1025,6 +1025,86 @@ namespace likelihood{ } }; + struct SAYLikelihoodConstUncertaintyMod { + double sigma; + double sigma2; + SAYLikelihoodConstUncertaintyMod(double sigma):sigma(sigma),sigma2(sigma*sigma){} + void SetSigma(double sigma) { + this->sigma = sigma; + this->sigma2 = sigma*sigma; + } + double GetSigma() { + return this->sigma; + } + template + T operator()(double k, T const & w_sum, T const & w2_sum) const { + T new_sigma2 = w2_sum + this->sigma2; + if(w_sum <= 0 || new_sigma2 < 0) { + return(k==0?0:-std::numeric_limits::max()); + } + + if(new_sigma2 == 0) { + return poissonLikelihood()(k, w_sum, new_sigma2); + } + + T one(1); + T zero(0); + if(w_sum == zero) { + if(k == 0) { + return zero; + } + else { + return T(-std::numeric_limits::infinity()); + } + } + + T alpha = w_sum*w_sum/new_sigma2 + one; + T beta = w_sum/new_sigma2; + T L = gammaPriorPoissonLikelihood()(k, alpha, beta); + + return L; + } + }; + + struct SAYLikelihoodRelativeUncertaintyMod { + double sigma_over_mu; + SAYLikelihoodRelativeUncertaintyMod(double sigma_over_mu):sigma_over_mu(sigma_over_mu){} + void SetSigmaOverMu(double sigma_over_mu) { + this->sigma_over_mu = sigma_over_mu; + } + double GetSigmaOverMu() { + return this->sigma_over_mu; + } + template + T operator()(double k, T const & w_sum, T const & w2_sum) const { + T new_sigma2 = w2_sum + pow(this->sigma_over_mu*w_sum, 2); + if(w_sum <= 0 || new_sigma2 < 0) { + return(k==0?0:-std::numeric_limits::max()); + } + + if(new_sigma2 == 0) { + return poissonLikelihood()(k, w_sum, new_sigma2); + } + + T one(1); + T zero(0); + if(w_sum == zero) { + if(k == 0) { + return zero; + } + else { + return T(-std::numeric_limits::infinity()); + } + } + + T alpha = w_sum*w_sum/new_sigma2 + one; + T beta = w_sum/new_sigma2; + T L = gammaPriorPoissonLikelihood()(k, alpha, beta); + + return L; + } + }; + //A bin type for keeping events in their histogram bins template From 20609042d84f2932b29021fb861dd2d064b2dce5 Mon Sep 17 00:00:00 2001 From: Ben Smithers Date: Thu, 23 Jun 2022 10:10:26 -0500 Subject: [PATCH 10/25] added Gaussian arbitrary-dimensional prior --- PhysTools/likelihood/likelihood.h | 127 ++++++++++++++++++++++++++++++ test/gaussian_nd.test.cpp | 51 ++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 test/gaussian_nd.test.cpp diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 2cf3434..2354eb9 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -22,6 +22,13 @@ #include #include +#include +#include +#include +#include +#include +// #define BOOST_UBLAS_TYPE_CHECK 0 + #include "../lbfgsb/lbfgsb.h" #include "../histogram.h" @@ -31,6 +38,9 @@ #include "../autodiff.h" #include "../ThreadPool.h" + +namespace ublas = boost::numeric::ublas; + namespace phys_tools{ ///Tools for performing binned maximum likelihood fits namespace likelihood{ @@ -2328,6 +2338,123 @@ namespace likelihood{ } }; + + double CalcDeterminant(ublas::matrix m){ + /* + http://www.richelbilderbeek.nl/CppUblasMatrixExample7.htm + + This calculates the determinant for an arbitrary ublas matrix! Matrix `m` needs to be square + */ + assert(m.size1() == m.size2() && "Can only calculate the determinant of square matrices"); + ublas::permutation_matrix pivots(m.size1() ); + + const int is_singular = ublas::lu_factorize(m, pivots); + + if (is_singular) return 0.0; + + double d = 1.0; + const std::size_t sz = pivots.size(); + for (std::size_t i=0; i != sz; ++i) + { + if (pivots(i) != i) + { + d *= -1.0; + } + d *= m(i,i); + } + return d; + } + + template + bool InvertMatrix (const ublas::matrix& input, ublas::matrix& inverse) { + /* + Using code snippet from https://stackoverflow.com/questions/17240624/matrix-inversion-in-boost + + Assigns inverse to provided matrix 'inverse' + returns True if successful, False if failed + */ + + typedef ublas::permutation_matrix pmatrix; + ublas::matrix A(input); + // create a permutation matrix for the LU-factorization + pmatrix pm(A.size1()); + + // perform LU-factorization + int res = ublas::lu_factorize(A,pm); + if( res != 0 ) + return false; + + // create identity matrix of "inverse" + inverse.assign(ublas::identity_matrix(A.size1())); + // backsubstitute to get the inverse + ublas::lu_substitute(A, pm, inverse); + return true; + } + + template + struct GaussianNDPrior{ + /* + This is a generalization of the `Gaussian2DPrior` class + */ + private: + // these are matrices rather than vectors, makes it easier! + ublas::vector *means = new ublas::vector(_size); + ublas::vector *stddevs = new ublas::vector(_size); + + double determinant; + double lnorm; + public: + ublas::matrix *correlations = new ublas::matrix(_size, _size); + ublas::matrix *inverse = new ublas::matrix(_size, _size); + + + GaussianNDPrior(std::vector& _means, std::vector& _stddevs, std::vector>& _correlations){ + /* + We need to calculate the determinant of this 2D matrix, and we need to verify the lengths of these arrays are the right shape! + See: https://en.wikipedia.org/wiki/Covariance_matrix#Covariance_matrix_as_a_parameter_of_a_distribution + + We pre-calcualte the determinant and inverse since they're relevant later. Then we calculate the log-likelihood that a sample of values (x) is drawn from this distribution + */ + + for (unsigned int i = 0 ; i< _size; i++){ + (*stddevs)(i) = _stddevs[i]; + (*means)(i) = _means[i]; + for (unsigned int j=0; j<_size; j++){ + (*correlations)(i,j) = _correlations[i][j]; + } + } + + determinant = CalcDeterminant(*correlations); + bool success = InvertMatrix(*correlations, *inverse); + if (!success){ + throw std::invalid_argument("Correlations matrix was un-invertible!"); + } + + lnorm = log(sqrt(pow(boost::math::constants::one_div_two_pi(),static_cast(_size))/determinant)); + } + + template + DataType operator()(std::vector _x){ + /* + This calculates the log likelihood of measuring _x given this correlated prior + */ + if(_x.size()!= _size){ + throw std::invalid_argument("Vector should be same size as priors"); + } + + ublas::vector divvy(_size); + + for (size_t i=0;i<_size;i++){ + divvy(i) = ((*means)(i) - _x[i])/ (*stddevs)(i); + } + + auto first = ublas::prod(*inverse, divvy); + auto final = ublas::inner_prod(divvy, first); + return lnorm - 0.5*final; + + } + }; + struct ZigZagPrior{ private: double point; diff --git a/test/gaussian_nd.test.cpp b/test/gaussian_nd.test.cpp new file mode 100644 index 0000000..76b6929 --- /dev/null +++ b/test/gaussian_nd.test.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include + + +bool double_compare(double x, double y){ + double diff = std::abs(x-y); + double eps=(1e-6); + return (diff> corr{{1, alpha}, + {alpha, 1}}; + std::vector means{0.0, 0.0}; + std::vector sigmas{1.0, 1.0}; + + const size_t n_vals = static_cast(2); + + GaussianNDPrior<2> testprio(means, sigmas, corr); + Gaussian2DPrior otherprio(means[0], means[1], sigmas[0], sigmas[1], alpha); + + std::vector test_values = {0,0.5,1.0,1.5,2.0,2.5}; + + for (unsigned int i=0; i this_test = {test_values[i], test_values[j]}; + auto result = testprio(this_test); + auto other = otherprio(test_values[i], test_values[j]); + bool are_equal = double_compare(result, other); + if (!are_equal){ + throw std::runtime_error("Test failed!"); + } + + } + } + return 0; + +} \ No newline at end of file From 9ef0732c0d043da8776e6586b76871e22560be4e Mon Sep 17 00:00:00 2001 From: Ben Smithers Date: Thu, 23 Jun 2022 10:35:28 -0500 Subject: [PATCH 11/25] added reference output for gaussian nd prior --- test/gaussian_nd.output.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/gaussian_nd.output.txt diff --git a/test/gaussian_nd.output.txt b/test/gaussian_nd.output.txt new file mode 100644 index 0000000..e69de29 From 10f9663fb3ca7f343da9a3fab6d58a74e17ab8eb Mon Sep 17 00:00:00 2001 From: Ben Smithers Date: Thu, 23 Jun 2022 16:18:09 -0500 Subject: [PATCH 12/25] moved ublas alias into likelihood namespace --- PhysTools/likelihood/likelihood.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 2354eb9..2b7e4d8 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -38,13 +38,12 @@ #include "../autodiff.h" #include "../ThreadPool.h" - -namespace ublas = boost::numeric::ublas; - namespace phys_tools{ ///Tools for performing binned maximum likelihood fits namespace likelihood{ + namespace ublas = boost::numeric::ublas; + //some useful type traits template struct remove_reference_wrapper{ using type=T; }; From 51683cb1bbf62672e47bb99f13ca6c6e546e3173 Mon Sep 17 00:00:00 2001 From: Ben Smithers Date: Thu, 23 Jun 2022 16:51:16 -0500 Subject: [PATCH 13/25] made the ublas objects shared_ptrs, all private --- PhysTools/likelihood/likelihood.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 2b7e4d8..fa64d25 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -2397,16 +2397,15 @@ namespace likelihood{ */ private: // these are matrices rather than vectors, makes it easier! - ublas::vector *means = new ublas::vector(_size); - ublas::vector *stddevs = new ublas::vector(_size); + std::shared_ptr> means = std::make_shared>( ublas::vector(_size)); + std::shared_ptr> stddevs = std::make_shared>( ublas::vector(_size)); + std::shared_ptr> correlations = std::make_shared>( ublas::matrix(_size, _size)); + std::shared_ptr> inverse = std::make_shared>( ublas::matrix(_size, _size)); double determinant; double lnorm; public: - ublas::matrix *correlations = new ublas::matrix(_size, _size); - ublas::matrix *inverse = new ublas::matrix(_size, _size); - GaussianNDPrior(std::vector& _means, std::vector& _stddevs, std::vector>& _correlations){ /* We need to calculate the determinant of this 2D matrix, and we need to verify the lengths of these arrays are the right shape! From 1e87f1ce3704783ad5fb63114d6a1725312fbaba Mon Sep 17 00:00:00 2001 From: alexwenym Date: Thu, 10 Oct 2024 16:21:48 -0400 Subject: [PATCH 14/25] updated likelihood file --- PhysTools/likelihood/likelihood.h | 62 ++++++++++++++++--------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index fa64d25..2d0713b 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -2040,7 +2040,7 @@ namespace likelihood{ lastBestDiscreteIndex=dn; } } - //std::cout << " llh: " << bestLLH << std::endl; + std::cout << bestLLH << std::endl; return(bestLLH); } @@ -2338,32 +2338,6 @@ namespace likelihood{ }; - double CalcDeterminant(ublas::matrix m){ - /* - http://www.richelbilderbeek.nl/CppUblasMatrixExample7.htm - - This calculates the determinant for an arbitrary ublas matrix! Matrix `m` needs to be square - */ - assert(m.size1() == m.size2() && "Can only calculate the determinant of square matrices"); - ublas::permutation_matrix pivots(m.size1() ); - - const int is_singular = ublas::lu_factorize(m, pivots); - - if (is_singular) return 0.0; - - double d = 1.0; - const std::size_t sz = pivots.size(); - for (std::size_t i=0; i != sz; ++i) - { - if (pivots(i) != i) - { - d *= -1.0; - } - d *= m(i,i); - } - return d; - } - template bool InvertMatrix (const ublas::matrix& input, ublas::matrix& inverse) { /* @@ -2422,7 +2396,31 @@ namespace likelihood{ } } - determinant = CalcDeterminant(*correlations); + /* + http://www.richelbilderbeek.nl/CppUblasMatrixExample7.htm + + This calculates the determinant for an arbitrary ublas matrix! Matrix `m` needs to be square + */ + ublas::matrix m = *correlations; + assert(m.size1() == m.size2() && "Can only calculate the determinant of square matrices"); + ublas::permutation_matrix pivots(m.size1() ); + + const int is_singular = ublas::lu_factorize(m, pivots); + + double determinant = 1.0; + if (is_singular) determinant = 0.0; + else { + const std::size_t sz = pivots.size(); + for (std::size_t i=0; i != sz; ++i) + { + if (pivots(i) != i) + { + determinant *= -1.0; + } + determinant *= m(i,i); + } + } + bool success = InvertMatrix(*correlations, *inverse); if (!success){ throw std::invalid_argument("Correlations matrix was un-invertible!"); @@ -2431,8 +2429,12 @@ namespace likelihood{ lnorm = log(sqrt(pow(boost::math::constants::one_div_two_pi(),static_cast(_size))/determinant)); } - template - DataType operator()(std::vector _x){ + + template + DataType operator()(DataType const & arg0, ARGS const & ... args){ + + std::vector _x { arg0, args... }; + /* This calculates the log likelihood of measuring _x given this correlated prior */ From 83c47840175341eba75a50c38c85160a2486b0da Mon Sep 17 00:00:00 2001 From: Lukas Hennig Date: Tue, 3 Dec 2024 10:57:27 -0500 Subject: [PATCH 15/25] Fixed bug in compilation by putting LDFLAGS at the end --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4abd5c6..f99c5e8 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ all: $(STAT_PRODUCT) $(DYN_PRODUCT) $(DYN_PRODUCT) : $(OBJS) @echo Linking $(DYN_PRODUCT) - @$(CXX) $(LDFLAGS) $(DYN_OPT) -shared $(OBJS) -o $(DYN_PRODUCT) + @$(CXX) $(DYN_OPT) -shared $(OBJS) -o $(DYN_PRODUCT) $(LDFLAGS) $(STAT_PRODUCT) : $(OBJS) @echo Linking $(STAT_PRODUCT) @$(AR) -rcs $(STAT_PRODUCT) $(OBJS) From 55aa0a4a13d548eb33b0cdbe84c74f4b09405ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=2E=20Arg=C3=BCelles=20Delgado?= Date: Tue, 27 May 2025 22:07:40 -0600 Subject: [PATCH 16/25] fixed missing header --- PhysTools/bin_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/PhysTools/bin_types.h b/PhysTools/bin_types.h index c1b7a82..96732c3 100644 --- a/PhysTools/bin_types.h +++ b/PhysTools/bin_types.h @@ -4,6 +4,7 @@ #ifndef PHYSTOOLS_BIN_TYPES_H #define PHYSTOOLS_BIN_TYPES_H +#include #include "PhysTools/hdf5_serialization.h" #include "PhysTools/histogram.h" From 090b06f130da365f7a3c7d65157c40a51f6a9876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=2E=20Arg=C3=BCelles=20Delgado?= Date: Wed, 28 May 2025 10:18:06 -0600 Subject: [PATCH 17/25] fixed issues with exception handling to be compatible with apple silicon --- PhysTools/likelihood/likelihood.h | 54 ++++++++++++---------------- PhysTools/residuals.h | 59 ++++++++++++++++--------------- 2 files changed, 53 insertions(+), 60 deletions(-) diff --git a/PhysTools/likelihood/likelihood.h b/PhysTools/likelihood/likelihood.h index 2d0713b..b0dcab9 100644 --- a/PhysTools/likelihood/likelihood.h +++ b/PhysTools/likelihood/likelihood.h @@ -8,10 +8,25 @@ #include #include -#ifdef __APPLE__ +#if defined(__x86_64__) || defined(_M_X64) #include -#elif __linux__ - #include + #define ENABLE_FLOAT_EXCEPTIONS() \ + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | \ + _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | \ + _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW) + #define DISABLE_FLOAT_EXCEPTIONS() \ + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( \ + _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | \ + _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)) +#elif defined(__linux__) + #include + #define ENABLE_FLOAT_EXCEPTIONS() \ + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + #define DISABLE_FLOAT_EXCEPTIONS() \ + fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) +#else + #define ENABLE_FLOAT_EXCEPTIONS() + #define DISABLE_FLOAT_EXCEPTIONS() #endif #include @@ -729,13 +744,7 @@ namespace likelihood{ struct thorstenLikelihood { template T operator()(double k, const std::vector& raw_w, int n_events) const { -#ifdef __APPLE__ - //_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW); - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW); -#elif __linux__ - //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); -#endif + ENABLE_FLOAT_EXCEPTIONS(); double log_percentage = log(0.99); @@ -851,22 +860,14 @@ namespace likelihood{ return accumulate(terms.begin(), terms.end()); -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)); -#elif __linux__ - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + DISABLE_FLOAT_EXCEPTIONS(); } }; /* struct thorstenLikelihood { template T operator()(double k, const std::vector& raw_w, int n_events) const { -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW); -#elif __linux__ - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + ENABLE_FLOAT_EXCEPTIONS(); unsigned int count = 1; std::vector kmc; @@ -942,20 +943,11 @@ namespace likelihood{ L += lf; //std::cout << "L += " << lf << std::endl; //std::cout << "L = " << L << std::endl; - -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)); -#elif __linux__ - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + DISABLE_FLOAT_EXCEPTIONS(); return L; } else { -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)); -#elif __linux__ - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + DISABLE_FLOAT_EXCEPTIONS(); return T(0); } } diff --git a/PhysTools/residuals.h b/PhysTools/residuals.h index b5ed16f..5c6413e 100644 --- a/PhysTools/residuals.h +++ b/PhysTools/residuals.h @@ -6,11 +6,28 @@ #include #include #include -#ifdef __APPLE__ + +#if defined(__x86_64__) || defined(_M_X64) #include -#elif __linux__ - #include + #define ENABLE_FLOAT_EXCEPTIONS() \ + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | \ + _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | \ + _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW) + #define DISABLE_FLOAT_EXCEPTIONS() \ + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( \ + _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | \ + _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)) +#elif defined(__linux__) + #include + #define ENABLE_FLOAT_EXCEPTIONS() \ + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + #define DISABLE_FLOAT_EXCEPTIONS() \ + fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) +#else + #define ENABLE_FLOAT_EXCEPTIONS() + #define DISABLE_FLOAT_EXCEPTIONS() #endif + #include #include #include @@ -115,11 +132,7 @@ struct almost_equal > { template struct residual_computer { void operator()(std::vectorconst& z, std::vectorconst& n, std::vectorconst& s, std::vectorconst& m, std::vector& res) { -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW); -#elif __linux__ - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + ENABLE_FLOAT_EXCEPTIONS(); //std::cout << std::setprecision(16); std::cout << "residual_computer" << std::endl; // Useful things to precompute @@ -316,11 +329,7 @@ struct residual_computer { // Clean up the nasty stuff we defined #undef c -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)); -#elif __linux__ - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + DISABLE_FLOAT_EXCEPTIONS(); //return c; } }; @@ -342,7 +351,7 @@ template struct contour_integral_bignum { using big_type=boost::multiprecision::number >; big_type operator()(std::vectorconst& z, std::vectorconst& n, std::vectorconst& s, std::vectorconst& m) { - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); + ENABLE_FLOAT_EXCEPTIONS(); const unsigned int M = m.size(); const unsigned int max_m = *std::max_element(m.begin(), m.end()); std::vector big_z(z.begin(), z.end()); @@ -361,7 +370,7 @@ struct contour_integral_bignum { // residual_sum += c(k,0); //} //#undef c - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); + DISABLE_FLOAT_EXCEPTIONS(); return residual_sum; } }; @@ -383,7 +392,7 @@ struct contour_integral_bignum > { using result_type=phys_tools::autodiff::FD; using big_type=phys_tools::autodiff::FD > >; big_type operator()(std::vectorconst& z, std::vectorconst& n, std::vectorconst& s, std::vectorconst& m) { - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); + ENABLE_FLOAT_EXCEPTIONS(); const unsigned int M = m.size(); const unsigned int max_m = *std::max_element(m.begin(), m.end()); std::vector big_z(z.begin(), z.end()); @@ -402,7 +411,7 @@ struct contour_integral_bignum > { // residual_sum += c(k,0); //} //#undef c - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); + DISABLE_FLOAT_EXCEPTIONS(); return residual_sum; } }; @@ -473,7 +482,7 @@ template struct thorsten_fast { typedef typename make_big_type<16, T>::big_type big_type; big_type operator()(std::vectorconst& w, std::vectorconst& s, unsigned int D) { - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); + ENABLE_FLOAT_EXCEPTIONS(); unsigned int M = s.size(); //const unsigned int max_m = *std::max_element(m.begin(), m.end()); @@ -545,7 +554,7 @@ struct thorsten_fast { std::cout << "result:" << result << std::endl; //T result = static_cast(big_result); - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); + DISABLE_FLOAT_EXCEPTIONS(); return result; } }; @@ -554,11 +563,7 @@ struct thorsten_fast { template struct contour_integral { T operator()(std::vectorconst& z, std::vectorconst& n, std::vectorconst& s, std::vectorconst& m) { -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW); -#elif __linux__ - feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + ENABLE_FLOAT_EXCEPTIONS(); const unsigned int M = m.size(); const unsigned int max_m = *std::max_element(m.begin(), m.end()); std::vector c; @@ -571,11 +576,7 @@ struct contour_integral { residual_sum += c(k,0); } #undef c -#ifdef __APPLE__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~( _MM_MASK_DIV_ZERO | _MM_MASK_INVALID | _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW)); -#elif __linux__ - fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW); -#endif + DISABLE_FLOAT_EXCEPTIONS(); return residual_sum; } }; From cc1fc9e58bfe7745a101908f29d860f56807795d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=2E=20Arg=C3=BCelles=20Delgado?= Date: Wed, 28 May 2025 11:07:25 -0600 Subject: [PATCH 18/25] made the library c++17 compatible --- PhysTools/autodiff.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/PhysTools/autodiff.h b/PhysTools/autodiff.h index 7009c5b..7857559 100644 --- a/PhysTools/autodiff.h +++ b/PhysTools/autodiff.h @@ -793,8 +793,9 @@ namespace autodiff{ T te(e); result.v=pow(b.v,te); const unsigned int n=detail::dimensionExtractor::nVars(result); + T scale = std::pow(b.v, te - T(1)) * e; std::transform(result.g,result.g+n,result.g, - std::bind2nd(std::multiplies(),pow(b.v,te-T(1))*e)); + [scale](T x) {return x*scale;}); return(result); } @@ -807,8 +808,9 @@ namespace autodiff{ T tb(b); result.v=pow(tb,e.v); const unsigned int n=detail::dimensionExtractor::nVars(result); + T scale = result.v*std::log(tb); std::transform(result.g,result.g+n,result.g, - std::bind2nd(std::multiplies(),result.v*log(tb))); + [scale](T x) {return x*scale;}); return(result); } @@ -1074,7 +1076,7 @@ namespace autodiff{ result.v=-result.v; const unsigned int n=detail::dimensionExtractor::nVars(result); std::transform(result.g,result.g+n,result.g, - std::bind2nd(std::multiplies(),T(-1))); + [](T x) {return -x;}); } return(result); } @@ -1088,7 +1090,7 @@ namespace autodiff{ result.v=-result.v; const unsigned int n=detail::dimensionExtractor::nVars(result); std::transform(result.g,result.g+n,result.g, - std::bind2nd(std::multiplies(),T(-1))); + [](T x) {return -x;}); } return(result); } From 23d13e059822ccff052e56fe6bf6beed05adc203 Mon Sep 17 00:00:00 2001 From: "Carlos A. Arguelles Delgado" Date: Fri, 6 Jun 2025 14:57:15 -0400 Subject: [PATCH 19/25] Create README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..128b93f --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# LeptonWeighter +Weights injected neutrino final states to neutrino fluxes. + +Author: C. Weaver + +Contributors: A. Schneider, C. Arg\"uelles From 5aea98e46c67f639ef080f946c25c277f34c7a1c Mon Sep 17 00:00:00 2001 From: "Carlos A. Arguelles Delgado" Date: Fri, 6 Jun 2025 14:57:48 -0400 Subject: [PATCH 20/25] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 128b93f..8883db3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# LeptonWeighter -Weights injected neutrino final states to neutrino fluxes. +# PhysTools +Bin-likelihood and histogram tools Author: C. Weaver From 170b42ea3c993158a1c28966948d5bfbeece7f92 Mon Sep 17 00:00:00 2001 From: "Carlos A. Arguelles Delgado" Date: Fri, 6 Jun 2025 18:23:11 -0400 Subject: [PATCH 21/25] Update README.md --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8883db3..d93f0d8 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,23 @@ Bin-likelihood and histogram tools Author: C. Weaver -Contributors: A. Schneider, C. Arg\"uelles +Contributors: A. Schneider, C. Argüelles + +# Installation + +``` +./configure --prefix=$INSTALLATION_PATH +``` + +for most users `$INSTALLATION_PATH=/usr/local/` or their preferred installation directory. If the configuration use + +``` +./configure --help +``` + +to see the available flags to specify specific libraries. + + + + + From 91d9bb61be641e87f0f287256761a87df030ab7a Mon Sep 17 00:00:00 2001 From: Alex Wen Date: Tue, 17 Jun 2025 14:36:36 -0400 Subject: [PATCH 22/25] Update configure --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 4d73fa0..e87fafc 100755 --- a/configure +++ b/configure @@ -325,7 +325,7 @@ PREFIX=$PREFIX # General Settings VERSION=${VERSION} -CXXFLAGS= -std=c++11 -O2 -g -fPIC +CXXFLAGS= -std=c++14 -O3 -g -fPIC # Libraries CXXFLAGS+=${BOOST_CFLAGS} ${HDF5_CFLAGS} From 07d833a0aef6eb08fd33df6cb2149315f5504872 Mon Sep 17 00:00:00 2001 From: alexwenym Date: Fri, 20 Jun 2025 15:29:08 -0400 Subject: [PATCH 23/25] add .pc file --- Makefile | 1 + configure | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Makefile b/Makefile index f99c5e8..772a7c2 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ install : cp $(LBFGSB_HEADERS) $(PREFIX)/include/$(NAME)/lbfgsb/ mkdir -p $(PREFIX)/include/$(NAME)/likelihood cp $(LIKELIHOOD_HEADERS) $(PREFIX)/include/$(NAME)/likelihood/ + cp phystools.pc $(PREFIX)/lib/pkgconfig/ docs : doxygen diff --git a/configure b/configure index e87fafc..fb2cadb 100755 --- a/configure +++ b/configure @@ -311,6 +311,19 @@ if [ ! -d ./build/ ]; then mkdir build; fi +echo ' +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: PhysTools +Description: Likelihood tools. +URL: https://github.com/icecube/PhysTools +Version: 0.0.1 +Requires: gsl >= 1.15 hdf5 >= 1.8 boost >= 1.65 +Libs: -L${libdir}/lib -lPhysTools +Cflags: -I${includedir}/PhysTools +' >> phystools.pc + echo "Generating config.mk..." echo "# Compiler CC=$CC From 0fd7dfc8ec6b608439c0dc2abdedf6cafc485ca6 Mon Sep 17 00:00:00 2001 From: alexwenym Date: Fri, 20 Jun 2025 15:37:25 -0400 Subject: [PATCH 24/25] makefile update --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 772a7c2..0203628 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ install : cp $(LBFGSB_HEADERS) $(PREFIX)/include/$(NAME)/lbfgsb/ mkdir -p $(PREFIX)/include/$(NAME)/likelihood cp $(LIKELIHOOD_HEADERS) $(PREFIX)/include/$(NAME)/likelihood/ - cp phystools.pc $(PREFIX)/lib/pkgconfig/ + cp $(BASEDIR)/phystools.pc $(PREFIX)/lib/pkgconfig/ docs : doxygen From 8ce44a75c145d35fcdacf2a0d9d8633586a51ed0 Mon Sep 17 00:00:00 2001 From: alexwenym Date: Fri, 20 Jun 2025 16:01:45 -0400 Subject: [PATCH 25/25] fix configure --- configure | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure b/configure index fb2cadb..528620d 100755 --- a/configure +++ b/configure @@ -311,6 +311,9 @@ if [ ! -d ./build/ ]; then mkdir build; fi +echo "Generating pkg-config file..." +echo "prefix=$PREFIX" > phystools.pc + echo ' libdir=${prefix}/lib includedir=${prefix}/include @@ -319,7 +322,7 @@ Name: PhysTools Description: Likelihood tools. URL: https://github.com/icecube/PhysTools Version: 0.0.1 -Requires: gsl >= 1.15 hdf5 >= 1.8 boost >= 1.65 +Requires: gsl >= 1.15 hdf5 >= 1.8 Libs: -L${libdir}/lib -lPhysTools Cflags: -I${includedir}/PhysTools ' >> phystools.pc