From 6fa23bed37f57481a01e946641ba89990b5cced3 Mon Sep 17 00:00:00 2001 From: Thomas Colthurst Date: Tue, 13 Aug 2024 19:45:30 +0000 Subject: [PATCH] Fix Skellam out of domain bug; re-enable hospital integration test --- cxx/assets/hospital_dirty.10.csv | 10 ++++++++++ cxx/distributions/skellam.cc | 2 +- cxx/inference.cc | 4 ++++ cxx/integration_tests.sh | 5 +++-- cxx/pclean/pclean.cc | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 cxx/assets/hospital_dirty.10.csv diff --git a/cxx/assets/hospital_dirty.10.csv b/cxx/assets/hospital_dirty.10.csv new file mode 100644 index 0000000..d7c9155 --- /dev/null +++ b/cxx/assets/hospital_dirty.10.csv @@ -0,0 +1,10 @@ +ProviderNumber,HospitalName,Address1,Address2,Address3,City,State,ZipCode,CountyName,PhoneNumber,HospitalType,HospitalOwner,EmergencyService,Condition,MeasureCode,MeasureName,Score,Sample,Stateavg +10018,callahan eye foundation hospital,1720 university blvd,,,birmingham,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-card-2,surgery patients who were taking heart drugs caxxed beta bxockers before coming to the hospitax who were kept on the beta bxockers during the period just before and after their surgery,,,al_scip-card-2 +10018,callahan eye foundation hospital,1720 university blvd,,,birmingham,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-inf-1,surgery patients who were given an antibiotic at the right time (within one hour before surgery) to help prevent infection,,,al_scip-inf-1 +10018,callahan eye foundation hospital,1720 university blvd,,,birmingham,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-inf-2,surgery patients who were given the right kind of antibiotic to help prevent infection,,,al_scip-inf-2 +10018,callahan eye foundation hospital,1720 university blvd,,,birminghxm,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-inf-3,surgery patients whose preventive antibiotics were stopped at the right time (within 24 hours after surgery),,,al_scip-inf-3 +10018,callahan eye foundation hospital,1720 university blvd,,,birmingham,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-inf-4,all heart surgery patients whose blood sugar (blood glucose) is kept under good control in the days right after surgery,,,al_scip-inf-4 +10018,callahan eye foundation hospital,1720 university blvd,,,birmingham,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-inf-6,surgery patients needing hair removed from the surgical area before surgery who had hair removed using a safer method (electric clippers or hair removal cream c not a razor),,,al_scip-inf-6 +10018,callahan eye foundation hospital,1720 university blvd,,,birmingham,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-vte-1,surgery patients whose doctors ordered treatments to prevent blood clots after certain types of surgeries,,,al_scip-vte-1 +10018,callahan eye foundation hospital,1720 university blvd,,,birmingxam,al,35233,jefferson,2053258100,acute care hospitals,voluntary non-profit - private,yes,surgical infection prevention,scip-vte-2,patients who got treatment at the right time (within 24 hours before or after their surgery) to help prevent blood clots after certain types of surgery,,,al_scip-vte-2 +10019,helen keller memorial hospital,1300 south montgomery avenue,,,sheffield,al,35660,jefferson,2563864556,acute care hospitals,government - hospital district or authority,yes,heart attack,ami-1,heart attack patients given aspirin at arrival,97%,33 patients,al_ami-1 diff --git a/cxx/distributions/skellam.cc b/cxx/distributions/skellam.cc index 3235449..3de3055 100644 --- a/cxx/distributions/skellam.cc +++ b/cxx/distributions/skellam.cc @@ -13,7 +13,7 @@ double lognormal_logp(double x, double mean, double stddev) { double Skellam::logp(const int&x) const { return -mu1 - mu2 + (x / 2.0) * std::log(mu1 / mu2) // TODO(thomaswc): Replace this with something more numerically stable. - + std::log(std::cyl_bessel_i(x, 2.0 * std::sqrt(mu1 * mu2))); + + std::log(std::cyl_bessel_i(std::abs(x), 2.0 * std::sqrt(mu1 * mu2))); } int Skellam::sample(std::mt19937* prng) { diff --git a/cxx/inference.cc b/cxx/inference.cc index dcce931..9708b9a 100644 --- a/cxx/inference.cc +++ b/cxx/inference.cc @@ -32,6 +32,8 @@ void inference_irm(std::mt19937* prng, IRM* irm, int iters, int timeout, clock_t t_begin = clock(); double t_total = 0; for (int i = 0; i < iters; ++i) { + printf("Starting iteration %d, model score = %f\n", + i+1, irm->logp_score()); CHECK_TIMEOUT(timeout, t_begin); single_step_irm_inference(prng, irm, t_total, verbose, 10, true); } @@ -42,6 +44,8 @@ void inference_hirm(std::mt19937* prng, HIRM* hirm, int iters, int timeout, clock_t t_begin = clock(); double t_total = 0; for (int i = 0; i < iters; ++i) { + printf("Starting iteration %d, model score = %f\n", + i+1, hirm->logp_score()); CHECK_TIMEOUT(timeout, t_begin); // TRANSITION LATENT VALUES. for (const auto& [rel, nrels] : hirm->base_to_noisy_relations) { diff --git a/cxx/integration_tests.sh b/cxx/integration_tests.sh index 29c03a9..78f3f7f 100755 --- a/cxx/integration_tests.sh +++ b/cxx/integration_tests.sh @@ -6,13 +6,14 @@ set -e set -x # Run integration test suite -bazel build :hirm pclean:pclean tests:test_hirm_animals tests:test_irm_two_relations tests:test_misc +bazel build tests:test_hirm_animals tests:test_irm_two_relations tests:test_misc ./bazel-bin/tests/test_hirm_animals ./bazel-bin/tests/test_irm_two_relations ./bazel-bin/tests/test_misc +bazel build -c opt :hirm pclean:pclean ./bazel-bin/hirm --mode=irm --iters=5 assets/animals.binary ./bazel-bin/hirm --seed=1 --iters=5 assets/animals.unary ./bazel-bin/hirm --iters=5 --load=assets/animals.unary.1.hirm assets/animals.unary #./bazel-bin/pclean/pclean --schema=assets/flights.schema --obs=assets/flights_dirty.100.csv --iters=5 -#./bazel-bin/pclean/pclean --schema=assets/hospitals.schema --obs=assets/hospital_dirty.100.csv --iters=5 +./bazel-bin/pclean/pclean --schema=assets/hospitals.schema --obs=assets/hospital_dirty.10.csv --iters=5 #./bazel-bin/pclean/pclean --schema=assets/rents.schema --obs=assets/rents_dirty.100.csv --iters=5 diff --git a/cxx/pclean/pclean.cc b/cxx/pclean/pclean.cc index 41b8fa4..8c9c5c6 100644 --- a/cxx/pclean/pclean.cc +++ b/cxx/pclean/pclean.cc @@ -95,6 +95,7 @@ int main(int argc, char** argv) { // Save results if (result.count("output") > 0) { std::string out_fn = result["output"].as(); + std::cout << "Savings results to " << out_fn << "\n"; to_txt(out_fn, hirm, encoding); }