diff --git a/code_tests/test.cpp b/code_tests/test.cpp index c996b75..a7b3457 100644 --- a/code_tests/test.cpp +++ b/code_tests/test.cpp @@ -17,7 +17,7 @@ TEST_CASE("igam function"){ std::cout << "🫟 Splat CodeTests\n"; auto igamtest = [](double a, double x, double req) { - REQUIRE(igam(a,x)== doctest::Approx(req).epsilon(0.00000000000001)); + REQUIRE(igam(a,x)== doctest::Approx(req).epsilon(0.00000000001)); }; { igamtest(0.5, 0.0, 0.0); diff --git a/main.cpp b/main.cpp index 0a50803..194e9fe 100644 --- a/main.cpp +++ b/main.cpp @@ -58,10 +58,10 @@ namespace splat { int main(int argc, const char * argv[]) { - int seed = 13928981231238123; + int seed = 9472161; int blocksgenerated = 1000000; - std::vector> generators = splat::getAllGenerators(1238124); + std::vector> generators = splat::getAllGenerators(seed); for(const std::unique_ptr &generator : generators){ std::cout << generator->getName() << ": \n"; diff --git a/math/incomplete_gamma.cpp b/math/incomplete_gamma.cpp index 5adb8cd..6af1e6c 100644 --- a/math/incomplete_gamma.cpp +++ b/math/incomplete_gamma.cpp @@ -1,113 +1,103 @@ #include "../rng.h" #include "./incomplete_gamma.h" +#include +#define PI 3.1415926535897932384626433832795028841971693993751 -double igam(double a, double x) { - double maxlog = 7.09782712893383996732E2; - double machep = 1.11022302462515654042E-16; - double big = 4.503599627370496e15; - double biginv = 2.22044604925031308085e-16; +// using the power series proves to be very fast and very accurate. +double igam(double s, double z){ - double ans, ax, c, r; + + if( (s<=0 || z<=0)){ + return 0.0; + } + + int rounds = 50; + + double sum = 0; + + for(int k=0; k1.0 && x>a){ - // return 1.0 - igamc(a,x); - // } + // reimann sum the lower incomplete gamma function + double sum = 0; + auto func = [a](double t) { + double ret = std::pow(t, a-1) * std::exp(-t); + if(std::isinf(ret)) ret=0; +// std::cout << std::format("func({}) -> {}", t,ret); + return ret; + }; - ax = a * std::log(x) - x - std::lgamma(a); - if (ax < -maxlog){ - // std::cout << "max log error on incomplete gamma function\n"; - return 0.0; - } + sum+=func(0); + sum+=func(x); + for(int i=1; i machep); - - return ans * ax/a; + return (1/std::tgamma(a))*ans; } - -// regularized left tail of incomplete gamma -// Q(s, x) = \frac{1}{\Gamma(s)} \int_x^\infty t^{s-1} e^{-t} \, dt -double igamc(double a, double x){ - return 1-igam(a,x); - // double maxlog = 7.09782712893383996732E2; - // double machep = 1.11022302462515654042E-16; - // double big = 4.503599627370496e15; - // double biginv = 2.22044604925031308085e-16; - - - // if(x<=0 || a<=0){ - // return 1.0; - // } - - // if( (x < 1.0 ) || ( x < a)){ - // std::cout << "bad\n"; - // return 1.0 - igam(a,x); - // } - - - // double ax = a * std::log(x) - std::lgamma(a); - - // // maxlog? - // if(ax < -maxlog){ - // std::cout << "max log error on incomplete gamma function\n"; - // return 0.0; - // } - - // ax = std::exp(ax); - - // double y = 1.0 - a; - // double z = x + y + 1.0; - // double c = 0.0; - // double pkm2 = 1.0; - // double qkm2 = x; - // double pkm1 = x + 1.0; - // double qkm1 = z * x; - // double ans = pkm1/qkm1; - - // double pk,qk,r,t,yc; - - // t = 1.0; - - // do { - // c+=1.0; - // y+=1.0; - // z+=2.0; - // yc = y*c; - // pk = pkm1 * z - pkm2 * yc; - // qk = qkm1 * z - qkm2 * yc; - // if (qk !=0){ - // r = pk/qk; - // t = std::fabs((ans-r)/r); - // ans = r; - // }else{ - // t = 1.0; - // } - // pkm2 = pkm1; - // pkm1 = pk; - // qkm2 = qkm1; - // qkm1 = qk; - // if(std::fabs(pk) > big){ - // pkm2 *= biginv; - // pkm1 *= biginv; - // qkm2 *= biginv; - // qkm1 *= biginv; - // } - // std::cout << ans << "-\n"; - // } while (t>machep); - - // return ans * ax; -} - diff --git a/randomness_tests/binary_matrix.cpp b/randomness_tests/binary_matrix.cpp index 8932322..01b584e 100644 --- a/randomness_tests/binary_matrix.cpp +++ b/randomness_tests/binary_matrix.cpp @@ -39,11 +39,11 @@ namespace splat { double x2obs = 0; - std::cout << "debug: "<< counts[0] << ","<> &testData); + std::string getName() override; + double runTest(std::vector> &data) override; + }; +} diff --git a/splat b/splat index ac90d3d..c980ec5 100755 Binary files a/splat and b/splat differ diff --git a/splat_test b/splat_test deleted file mode 100755 index d974b4c..0000000 Binary files a/splat_test and /dev/null differ diff --git a/web/public/libs/splat.wasm b/web/public/libs/splat.wasm index 7774031..4b61964 100755 Binary files a/web/public/libs/splat.wasm and b/web/public/libs/splat.wasm differ