Commits

Aleksey Khudyakov committed 63180b6

Add more tests for digamma

  • Participants
  • Parent commits 4f22aff

Comments (0)

Files changed (3)

File tests/Tests/SpecFunctions.hs

                       (logGammaL p + logGammaL q - logGammaL (p+q))
             | p <- [0.1,0.2 .. 0.9] ++ [2 .. 20]
             , q <- [0.1,0.2 .. 0.9] ++ [2 .. 20]]
-  , testAssertion "digamma is expected to be precise at 1e-14" $
-      digammaTestIntegers 1e-14
-  -- FIXME: Why 1e-8? Is it due to poor precision of logBeta?
+  , testAssertion "digamma is expected to be precise at 1e-14 [integers]"
+      $ digammaTestIntegers 1e-14
+    -- Relative precision is lost when digamma(x) ≈ 0
+  , testAssertion "digamma is expected to be precise at 1e-14"
+      $ and [ eq 1e-12 r (digamma x) | (x,r) <- tableDigamma ]
+    -- FIXME: Why 1e-8? Is it due to poor precision of logBeta?
   , testAssertion "incompleteBeta is expected to be precise at 1e-8 level"
       $ and [ eq 1e-8 (incompleteBeta p q x) ib | (p,q,x,ib) <- tableIncompleteBeta ]
   , testAssertion "choose is expected to precise at 1e-12 level"

File tests/Tests/SpecFunctions/Tables.hs

   , (13.100000000000000, 9.800000000000001, 0.420000000000000, 0.071321857831804780226)
   , (13.100000000000000, 9.800000000000001, 0.920000000000000, 0.99999578339197081611)
   ]
+tableDigamma :: [(Double,Double)]
+tableDigamma =
+  [(10.0261172557341425, 2.2544954834170942704)
+  , (0.9070101446062873, -0.7415277833790858697)
+  , (3.4679213262860156, 1.0925031389314479036)
+  , (28.5703089405901878, 3.3347652650101657912)
+  , (5.9700184459319399, 1.7006665338476734117)
+  , (20.5303177686997920, 2.9973508205248813319)
+  , (5.6622605630542511, 1.642928044767174578)
+  , (4.4741465342999014, 1.3824198603491073545)
+  , (21.4416006516504787, 3.0418326144933285349)
+  , (47.6946291432301663, 3.8542988022858133412)
+  , (11.2357450115053670, 2.37393979612347783)
+  , (0.3352840110772935, -3.1124447967622668187)
+  , (2.5037441860153118, 0.70499097759044615508)
+  , (0.5241560861477529, -1.8489960634174653631)
+  , (0.1972018552655726, -5.3635382066874583984)
+  , (0.8289440927562556, -0.90024805153750431241)
+  , (2.0717397641759350, 0.46804129690738538461)
+  , (9.1173553049782452, 2.1543380160183835947)
+  , (1.1815938184339669, -0.31262126373727594508)
+  , (7.3600347508772019, 1.9265946441432051373)
+  , (19.7457045917841398, 2.9574003365402394827)
+  , (4.1956416643620571, 1.3101672771843546617)
+  , (7.3868205159465790, 1.9304848277860633399)
+  , (1.2786090750546355, -0.19373178842778396302)
+  , (10.6498308581562604, 2.3178608134278073649)
+  , (10.6750266252851169, 2.3203381265132185796)
+  , (10.6883248506773985, 2.3216431742802630112)
+  , (14.3373372205836365, 2.6275879484098640937)
+  , (3.3932538441985769, 1.0672611106295628591)
+  , (11.4168205413938768, 2.3906538776946248959)
+  , (3.2500957742991048, 1.0170253699094922162)
+  , (2.7573211981404855, 0.82209952378707862319)
+  , (21.8943170241258827, 3.0632163239190455251)
+  , (16.7950471612825254, 2.7910180230044043803)
+  , (9.2578640399661225, 2.1704940538770385317)
+  , (5.3213868642873896, 1.5748408574979932961)
+  , (9.4381079039564071, 2.1908443398518979706)
+  , (13.1568457441413429, 2.538458049596743038)
+  , (10.6478950333943825, 2.3176702242110884811)
+  , (6.4894496431749733, 1.7911554320176725774)
+  , (20.3998669454332315, 2.9908182167188117617)
+  , (3.6989463639934752, 1.1668268193484248041)
+  , (3.4716258279958572, 1.093739186127963503)
+  , (24.7013029455164919, 3.1864775907749920414)
+  , (1.1608524325026863, -0.33982067949719846345)
+  , (1.9482800424522431, 0.38887621950605427701)
+  , (30.4956621109554185, 3.4010990755913690364)
+  , (16.3105956379859052, 2.7608468922073350349)
+  , (10.6908820268137070, 2.321893932871437638)
+  , (3.4369121607821915, 1.082096765647714065)
+  , (2.2914619096171260, 0.59539711305419018572)
+  , (24.1273989930028883, 3.1624816269998854423)
+  , (14.9455957898231535, 2.6705890837495620538)
+  , (32.2002179941400826, 3.4563650137673369578)
+  , (1.7232417075599473, 0.22682264125689591272)
+  , (9.9662376350778192, 2.248195612105357899)
+  , (10.9702870318273966, 2.348920912357223667)
+  , (18.8934063317711676, 2.912115343761407793)
+  , (8.6720493874148570, 2.1013420151521415846)
+  , (20.4905634096258815, 2.9953645521238549954)
+  , (1.4654265058258678, 0.0036653372399428497258)
+  , (15.4401781010745509, 2.7042406258658000517)
+  , (13.6688064138713390, 2.5780909087521290957)
+  , (2.4073661551765566, 0.65668881914974130964)
+  , (0.8108729056729371, -0.94026521559981879328)
+  , (29.5024809785193902, 3.367430902728568487)
+  , (7.5321882978878660, 1.9513375601887517075)
+  , (3.3716588961200955, 1.0598414578703592159)
+  , (2.9310065630306474, 0.89516303667430119351)
+  , (7.2023118361897769, 1.9033764996201536501)
+  , (3.1362387322050900, 0.97520764792577085966)
+  , (6.5709053027851487, 1.8046329737306385788)
+  , (3.7348491113356177, 1.1779005641199546961)
+  , (1.2328105814385013, -0.24823346907893503732)
+  , (7.9098387372709587, 2.0035651569967263264)
+  , (2.8590898311999715, 0.86554629114604875184)
+  , (2.1964374279534344, 0.54225028515290207842)
+  , (3.8933394033155189, 1.2253803767351847398)
+  , (10.7410508007627694, 2.3268008547643752593)
+  , (2.4921048837305193, 0.69927782909414781809)
+  , (2.2101710538553756, 0.55010424351998365999)
+  , (14.0357118427322334, 2.6055587167248708269)
+  , (4.1320729121597584, 1.2929216807716104043)
+  , (0.2766365979680845, -3.8108738889017748086)
+  , (27.9448247140513644, 3.3122329205038494315)
+  , (9.3081256750537182, 2.1762105230057042782)
+  , (1.4222181352589696, -0.038843893649701873028)
+  , (1.5107587188614726, 0.046499571962236106726)
+  , (3.3467578222470555, 1.0512176183500514526)
+  , (12.2373583939228876, 2.463078843442174648)
+  , (0.9385094944630431, -0.68317598609698337864)
+  , (5.8655552400886410, 1.6814385243672138603)
+  , (17.1377048621110468, 2.8118219246156086477)
+  , (4.0502102843199079, 1.2702685434611071802)
+  , (2.2041235084734976, 0.54665320805956596484)
+  , (0.9498749870396368, -0.66283138696545951252)
+  , (5.5020466797149687, 1.6115010556650319895)
+  , (1.8741725410778542, 0.33826100356492339039)
+  , (14.1730624058772161, 2.6156503142962224118)
+  , (1.0704026637921555, -0.46701211139417769802)
+  ]

File tests/Tests/SpecFunctions/gen.py

 """
 
 from mpmath import *
+import random
+
+# Set fixed seed in order to get repeatable results
+random.seed( 279570842 )
 
 def printListLiteral(lines) :
     print "  [" + "\n  , ".join(lines) + "\n  ]"
 
+
 ################################################################
 # Generate header
-print "module Tests.Math.Tables where"
+print "module Tests.SpecFunctions.Tables where"
 print
 
 ################################################################
     [ '(%.15f, %.15f, %.15f, %.20g)' % (p,q,x, betainc(p,q,0,x, regularized=True))
       for (p,q,x) in incompleteBetaArg
       ])
+
+
+################################################################
+## Generate table for digamma
+
+print "tableDigamma :: [(Double,Double)]"
+print "tableDigamma ="
+printListLiteral(
+    [ '(%.16f, %.20g)' % (x, digamma(x)) for x in
+      [ random.expovariate(0.1) for i in xrange(100) ]
+      ]
+    )