Skip to content

Instantly share code, notes, and snippets.

@pgr
Last active August 29, 2015 14:20
Show Gist options
  • Save pgr/9b2c4e745a45142eb88b to your computer and use it in GitHub Desktop.
Save pgr/9b2c4e745a45142eb88b to your computer and use it in GitHub Desktop.
TDigest runtime error
problem_data = [0.024397248818809142, 0.024821490199349136, 0.025245503252921613, 0.025669111541194247, 0.026092138196762173, 0.026514405900485264, 0.02693573685938608, 0.02735595278527934, 0.027774874874304224, 0.028192323787531344, 0.028608119632816623, 0.029022081948074964, 0.029434029686147008, 0.029843781201432863, 0.030251154238467307, 0.030655965922611453, 0.031058032801214344, 0.03145717107995413, 0.031853197150891153, 0.03224592831605407, 0.0326351835622022, 0.03302078433876185, 0.03340255533911071, 0.03378032528538202, 0.03415392771695687, 0.03452320178280961, -0.053976188916461755, -0.05399087605774065, -0.05400463975057198, -0.05401747003178825, -0.05402936155927222, -0.05404031321417414, -0.05405032770403158, -0.05405941116679291, -0.054067572775742284, -0.05407482434532018, -0.05408117993783091, -0.05408665547102595, -0.05409126832654974, -0.054095036959232665, -0.05409798050721487, -0.05410011840288313, -0.05410146998460261, -0.054102054109224945, -0.054101888765354295, -0.05410099068735316, -0.05409937497007109, -0.05409705468428014, -0.0540940404928028, -0.054090340267320035, -0.05408595870584916, -0.05408089699906224,
-0.054075152689973885, -0.054068719823353185, -0.05406158928850628, -0.054053749210901815, -0.05404518534446992, -0.05403588146458601, -0.054025819761753, -0.05401498123599729, -0.05400334609199554, -0.05399089413495033, -0.05397760516723364, -0.05396345938581729, -0.0539484377805098, -0.05393252253301836, -0.05391569741685422, -0.05389794819809835, -0.05387926303704283, -0.053859632890721515, -0.053839051916341245, -0.05381751787562197, -0.053795032540051385, -0.053771602097055934, -0.05374723755708631, -0.05372195516161133, -0.05369577674383146, -0.05366872989756285, -0.05364084785791486, -0.05361216919009053, -0.05358273743081125, -0.053552600730506744, -0.05352181149622841, -0.053490426035239895, -0.05345850419923454, -0.05342610902912561, -0.053393306400351795, -0.053360164668637466, -0.05332675431614435, -0.05329314759794887, -0.053259418188777496, -0.05322564082993064, -0.05319189097632424, -0.05315824444357718, -0.05312477705507208, -0.05309156428891648, -0.05305868092473163, -0.053026200690196194, -0.05299419590727313, -0.05296273713804881, -0.0529318928301148, -0.05290172898551353, -0.05287230892544867, -0.05284369319887464,
-0.052815939586726424, -0.05278910312946458, -0.05276323615379093, -0.05273838829848174, -0.05271460653928817, -0.052691935212855874, -0.052670416039618785, -0.05265008814562406, -0.0526309880832482, -0.05261314985076649, -0.05259660491074064, -0.05258138220719176, -0.05256750818152839, -0.052555006787201694, -0.05254389950306236, -0.052534205345396004, -0.05252594087861653, -0.052519120224599015, -0.0525137550706362, -0.05250985467600492, -0.05250742587713129, -0.05250647309134565, -0.052506998319220746, -0.052509001145488794, -0.05251247873853561, -0.05251742584847214, -0.05252383480378614, -0.052531695506579025, -0.052540995426395364, -0.05255171959265469, -0.0525638505856977, -0.05257736852646131, -0.05259225106479936, -0.05260847336646803, -0.052626008098797694, -0.052644825415074946, -0.05266489293766129, -0.052686175739877175, -0.05270863632668267, -0.0527322346141883, -0.052756927908032346, -0.05278267088066311, -0.05280941554756737, -0.052837111242488716, -0.05286570459168193, -0.05289513948725235, -0.05292535705963158, -0.05295629567333258, -0.05298789101830762, -0.053020076345146154, -0.05305278279599679, -0.05308593975901068,
-0.053119475222283635, -0.05315331612736478, -0.05318738872240105, -0.05322161891498774, -0.05325593262479585, -0.05329025613604775, -0.053324516449912006, -0.05335864163688856, -0.05339256118925421, -0.05342620637363766, -0.05345951058379179, -0.05349240969362934, -0.05352484241058591, -0.053556750629371944, -0.05358807978617255, -0.05361877921335102, -0.053648802494708464, -0.05367810782134807, -0.05370665834818879, -0.053734422551168295, -0.05376137453699295, -0.05378749416093133, -0.05381276685632072, -0.05383718327216161, -0.05386073886334796, -0.05388343348172015, -0.05390527096794533, -0.053926258744225436, -0.05394640740782935, -0.05396573032544227, -0.05398424322832232, -0.05400196380825165, -0.05401891131426705, -0.05403510615015333, -0.05405056947268099, -0.05406532279056883, -0.054079387564151135, -0.05409278480572913, -0.05410553468058604, -0.05411765610864579, -0.054129166366756014, -0.05414008069157752, -0.05415041188306352, -0.0541601699085143, -0.054169361507195146, -0.054177989843685916, -0.05418605435448939, -0.054193550884251145, -0.05420047201523573, -0.05420680744552948, -0.054212544367799195, -0.054217667848616376,
-0.05422216120835915, -0.05422600640170615, -0.05422918439873822, -0.05423167556666512, -0.05423346005219535, -0.05423451816456801, -0.05423483075926539, -0.05423437962242525, -0.05423314785597099, -0.0542311202634771, -0.054228283736785954, -0.05422462764339041, -0.054220144214594694, -0.05421482893446361, -0.05420868092956733, -0.05420170335952598, -0.05419390380835472, -0.05418529467660591, -0.05417589352612327, -0.05416572323286224, -0.05415481185140404, -0.05414319228749703, -0.054130901923132003, -0.05411798224229765, -0.054104478457380464, -0.054090439136169184, -0.05407591582942047, -0.05406096269893913, -0.054045636146123455, -0.054029994440923636, -0.05401409735115911, -0.053998005772138806, -0.05398178135652695, -0.05396548614439593, -0.05394918219340693, -0.053932931209058774, -0.05391679417494543, -0.05390083098296273, -0.05388510006340585, -0.053869658014900026, -0.05385455923410829, -0.053839855545161984, -0.053825595828761674, -0.05381182567498778, -0.05379858713204064, -0.053785918599043935, -0.05377385481469344, -0.0537624268694471, -0.05375166221713418, -0.05374158468595351, -0.05373221448883439, -0.053723568233137085,
-0.05371565892967356, -0.053708496001032356, -0.05370208528919511, -0.05369642906243562, -0.05369152602149588, -0.05368737130503674, -0.053683956494364644, -0.05368126961743897, -0.05367929515216816, -0.053678014029006196, -0.05367740363286424, -0.05367743780435598, -0.05367808684039841, -0.053679317494193204, -0.053681092974617324, -0.053683372945054965, -0.053686113545795125, -0.05368926751230042, -0.053692784437567156, -0.05369661113044427, -0.05370069199769283, -0.05370496942574817, -0.05370938416223808, -0.053713875697312445, -0.0537183826448411, -0.05372284312353821, -0.05372719513807195, -0.05373137696021907, -0.05373532751012381, -0.05373898673772051, -0.05374229600437855, -0.05374519846482734, -0.05374763944941765, -0.053749566846773844, -0.05375093148688957, -0.05375168752471691, -0.0537517928242961, -0.053751209343470024, -0.05374990351922363, -0.053747846653684934, -0.05374501530081966, -0.05374139160566925, -0.05373696345162108, -0.05373172431937247, -0.053725672953955826, -0.05371881298436484, -0.053711152543960985, -0.05370270389165696, -0.05369348303386945, -0.053683509347229576, -0.05367280520203577, -0.053661395586430585,
-0.05364930773128015, -0.05363657073573223, -0.053623215193426936, -0.053609272819332233, -0.05359477607717483, -0.05357975780743626, -0.05356425085588286, -0.05354828770259827, -0.053531900091487075, -0.05351511866021824, -0.053497972570578194, -0.053480489139204036, -0.05346269346866895, -0.05344460807889383, -0.05342625258703878, -0.05340764358038648, -0.05338879477855422, -0.0533697173886629, -0.05335042050891611, -0.053330911532400514, -0.05331119655109845, -0.05329128076010569, -0.05327116886204798, -0.053250865471691375, -0.05323037552074156, -0.05320970466282755, -0.05318885967866482, -0.05316784888139208, -0.0531466825220753, -0.053125373195370404, -0.053103936245334785, -0.053082390171375275, -0.05306075703431754, -0.053039062862578895, -0.05301733805842313, -0.05299561780427201, -0.05297394246904401, -0.05295235801448615, -0.05293091640145988, -0.05290967592386972, -0.05288870125338432, -0.05286806305036018, -0.05284783728543944, -0.052828104488554115, -0.0528089489975308, -0.052790458206218506, -0.05277272181205872, -0.05275583106301395, -0.05273987800376856, -0.052724954721114416, -0.052711152588433015, -0.052698561509185664,
-0.05268726915932411, -0.052677360228535336, -0.052668915660236335, -0.05266201189023776, -0.052656720083998715, -0.05265310537239943, -0.05265122608596365, -0.052651132987468305, -0.05265286850288466, -0.052656465950602374, -0.05266194876889596, -0.052669329741601996, -0.05267861031834037, -0.05268978031833466, -0.05270281821054165, -0.05271769177738829, -0.05273435887306968, -0.05275276818008309, -0.05277285996403815, -0.052794566826792455, -0.052817814457969625, -0.05284252238492457, -0.05286860472122699, -0.05289597091374054, -0.05292452648837981, -0.052954173794632166, -0.05298481274893511, -0.053016341577002794, -0.05304865755519797, -0.053081657751046785, -0.05311523976299537, -0.05314930245950678, -0.053183746717596764, -0.05321847616090538, -0.05325339789739965, -0.05328842325679974, -0.053323468527817774, -0.05335845562302776, -0.053393312454646596, -0.05342797287676785, -0.05346237633865125, -0.053496467465931986, -0.05353019564207507, -0.05356351459012843, -0.05359638195482361, -0.053628758885068836, -0.05366060961687564, -0.05369190105675642, -0.053722602365627856, -0.05375268454325208, -0.05378212001324559, -0.053810882208684074,
-0.05383894515832988, -0.05386628307350791, -0.053892869935655195, -0.053918679084569245, -0.053943682807380294, -0.05396785192827354, -0.05399115539898806, -0.054013559890120855, -0.054035029383266125, -0.054055524764022006, -0.05407500346407758, -0.054093419296951446, -0.054110722583778616, -0.05412686047283454, -0.05414177730831046, -0.054155415000213064, -0.05416771339544185, -0.05417861065010006, -0.0541880436030968, -0.054195948151100015, -0.054202259624900745, -0.05420691316725045, -0.05420984411223336, -0.05421098836623629, -0.054210282790578, -0.054207665585859606, -0.05420307667809689, -0.05419645810669359, -0.05418775441431369, -0.05417691303870804, -0.054163884706548766, -0.05414862382932193, -0.054131088901325626, -0.054111242899817245, -0.05408905368734986, -0.05406449439224412, -0.05403754369495977, -0.054008185972214795, -0.05397641134705035, -0.05394221571712336, -0.05390560078532514, -0.05386657409272998, -0.05382514905387207, -0.0537813449943435, -0.05373518719070026, -0.05368670691265778, -0.05363594146755152, -0.05358293424703245, -0.053527734775961566, -0.05347039876346144, -0.05341098815607722, -0.05334957119299326, -0.05328622246324571,
-0.0532210229648653, -0.05315406016587842, -0.05308542806708835, -0.05301522726655245, -0.05294356502566456, -0.05287055533674576, -0.05279631899204011, -0.05272098360582757, -0.05264468344500427, -0.05256755897165171, -0.05248975619382119, -0.05241142596893205, -0.052332723307821204, -0.05225380667929881, -0.05217483731506121, -0.05209597851480867, -0.05201739495141296, -0.05193925197597774, -0.05186171492263338, -0.05178494841290728, -0.05170911565951068, -0.05163437776938374, -0.05156089304584181, -0.0514888162896682, -0.051418298099001, -0.05134948416786547, -0.0512825145832068, -0.05121752312028359, -0.05115463653628716, -0.05109397386205823, -0.05103564569177917, -0.05097975347052739, -0.05092638885185052, -0.05087563334206604, -0.05082755837573078, -0.05078222567766815, -0.050739687694683934, -0.05069998802464424, -0.05066316184286486, -0.050629236325769815, -0.05059823107178491, -0.05057015851944012, -0.05054502436266144, -0.050522827963240285, -0.05050356276047453, -0.05048721667798183, -0.05047377252769106, -0.05046320841102362, -0.05045549811728079, -0.05045061151925806, -0.05044851496611155, -0.05044917167350534, -0.05045254211107193,
-0.05045858438722114, -0.05046725463133525, -0.050478507373390685, -0.05049229592104824, -0.05050857271016659, -0.050527289556517245, -0.05054839776056869, -0.050571848113564036, -0.05059759087720576, -0.05062557576108392, -0.05065575189789582, -0.05068806781650547, -0.05072247141289198, -0.05075890991903644, -0.05079732986979754, -0.05083767706782676, -0.05087989654657471, -0.05092393253144078, -0.050969728399119174, -0.051017226635195034, -0.05106636879004523, -0.05111709543309929, -0.05116934610551679, -0.051223059271338495, -0.051278172267169554, -0.051334621250453974, -0.051392341146400934, -0.05145126559362432, -0.05151132688855833, -0.05157245595280197, -0.051634582395724465, -0.05169763472057586, -0.051761540625992856, -0.05182622733070173, -0.051891621897399084, -0.05195765155588026, -0.052024244025485666, -0.05209132783693486, -0.052158832653618, -0.052226689592413306, -0.05229483154409807, -0.052363193493419675, -0.05243171283889085, -0.05250032971237184, -0.0525689872984996, -0.05263763215402151, -0.05270621452708829, -0.052774688676557345, -0.05284301319135441, -0.05291115130993742, -0.05297907123990225, -0.053046746477765735,
-0.053114156128956334, -0.053181285228037896, -0.05324812501100862, -0.05331467299515607, -0.05338093277012102, -0.05344691359652817, -0.053512629956714075, -0.053578101105721275, -0.05364335062254504, -0.05370840596161423, -0.053773298004483897, -0.05383806061171326, -0.053902730174899716, -0.05396734516883622, -0.05403194570375741, -0.05409657307763745, -0.05416126932850126, -0.054226076786709584, -0.054291037627177484, -0.05435619342148576, -0.054421584689844885, -0.0544872504528716, -0.05455322778313935, -0.054619551356465096, -0.05468625300289721, -0.05475336125737095, -0.054820900910001344, -0.054888892580074955, -0.05495735238598366, -0.05502629175925848, -0.055095717354510264, -0.05516563098299953, -0.0552360295457401, -0.055306904966134836, -0.05537824412214658, -0.055450028778011966, -0.05552223551551093, -0.05559483566480939, -0.055667795234897816, -0.055741074843653246, -0.05581462964755759, -0.0558884092711102, -0.055962357735977915, -0.056036413389931206, -0.05611050883562035, -0.0561845708592511, -0.05625852035922481, -0.05633227227481359, -0.05640573551494679, -0.0564788128871907, -0.05655140102700944, -0.05662339032740056,
-0.05669466491718289, -0.056765102832575756, -0.0568345764785367, -0.056902953283619426, -0.05697009640394109, -0.05703586542820849, -0.05710011708393473, -0.05716270594498132, -0.05722348514056327, -0.05728230706585718, -0.05733902409435338, -0.05739348929209397, -0.05744555713393878, -0.05749508422200034, -0.0575419300063879, -0.05758595750839819, -0.05762703404628803, -0.057665031963760494, -0.057699829361292025, -0.057731310830423245, -0.05775936819113048, -0.05778390123238892, -0.05780481845603123, -0.05782203782399786, -0.05783548750906688, -0.05784510657687513, -0.05785084538249965, -0.05785266553712411, -0.057850539589371794, -0.057844450638142426, -0.05783439194924615, -0.057820366575851254, -0.05780238698275219, -0.05778047467445522, -0.057754659827069794, -0.0577249809239852, -0.05769148439530344, -0.057654224260991586, -0.05761326177770895, -0.05756866508925721, -0.057520508880594644, -0.057468874035349005, -0.05741384729675713, -0.057355520931953695, -0.057293992399525505, -0.05722936402024269, -0.057161742650873024, -0.05709123936098096, -0.057017969112608514, -0.05694205044273117, -0.0568636051483782, -0.05678275797430334,
-0.05669963630308853, -0.05661436984756078, -0.056527090345399524, -0.05643793125580953, -0.056347027458132824, -0.056254514952270886, -0.05616053056078745, -0.056065211632561056, -0.05596869574785552, -0.05587112042467622, -0.05577262282627978, -0.05567333946970472, -0.05557340593519105, -0.05547295657635751, -0.05537212423100585, -0.055271039932422834, -0.055169832621052205, -0.055068628856410375, -0.054967552529121805, -0.05486672457295231, -0.0547662626767209, -0.05466628099597392, -0.0545668898643082, -0.054468195528322196, -0.05437029997835568, -0.05427330092309369, -0.0541772918597584, -0.05408236216752814, -0.0539885972000045, -0.053896078376641336, -0.05380488327305337, -0.05371508571012597, -0.05362675584185115, -0.053539960241818854, -0.0534547619882957, -0.05337122074782701, -0.05328939285730145, -0.05320933140442058, -0.053131086306519026, -0.05305470438768422, -0.0529802294541274, -0.05290770236776076, -0.052837161117938625, -0.05276864089132306, -0.05270217413983744, -0.05263779064667385, -0.052575517590323285, -0.052515379606599646, -0.05245739884863148, -0.05240159504479767, -0.05234798555458565, -0.05229658542235317,
-0.05224740742897682, -0.052200462141372785, -0.05215575795987756, -0.052113301163478336, -0.052073095952884944, -0.05203514449143739, -0.05199944694384479, -0.051966001512753685, -0.051934804473145475, -0.051905850204564806, -0.051879131221182394, -0.05185463819969767, -0.051832360005088556, -0.051812283714217214, -0.05179439463730259, -0.05177867633727215, -0.05176511064700686, -0.0517536776844955, -0.0517443558659155, -0.05173712191665966, -0.05173195088032946, -0.051728816125717385, -0.05172768935180236, -0.0517285405907839, -0.05173133820918225, -0.05173604890703341, -0.05174263771520952, -0.05175106799089667, -0.05176130141126388, -0.05177329796535852, -0.051787015944265075, -0.05180241192956593, -0.0518194407801442, -0.05183805561737058, -0.05185820780871769, -0.051879846949847076, -0.05190292084521566, -0.05192737548725039, -0.05195315503414127, -0.051980201786304775, -0.05200845616157168, -0.05203785666915464, -0.05206833988245313, -0.052099840410754966, -0.052132290869895515, -0.052165621851937606, -0.05219976191802603, -0.052234637686750254, -0.05227017406626191, -0.0523062945820399, -0.052342921728108505, -0.052379977317693206,
-0.05241738283338862, -0.05245505977691374, -0.05249293001853006, -0.05253091614619794, -0.052568941814546376, -0.05504306338386081, -0.05506204981601834, -0.0550819539114258, -0.055102690136180056, -0.05512417229887596, -0.055146313916089915, -0.05516902857714492, -0.05519223030824004, -0.05521583393602761, -0.05523975545072068, -0.05526391236881264, -0.055288224095489856, -0.055312612286816526, -0.05533700121176932, -0.05536131811419705, -0.05538549357477821, -0.05540946187304632, -0.055433161325460854, -0.05545653452732017, -0.055479528450398004, -0.055502094444536514, -0.05552418821551375, -0.05554576980332139, -0.05556680356089544, -0.05558725813333828]
import tdigest
td = tdigest.TDigest()
td.batch_update(problem_data)
'''
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-12-806df86bd090> in <module>()
1 td = tdigest.TDigest()
----> 2 td.batch_update(problem_data)
[...]tdigest.pyc in batch_update(self, values)
66 w = 1
67 for x in values:
---> 68 self.update((x, w))
69 self.compress()
70 return
[...]tdigest.pyc in update(self, (x, w))
107 c_j = S[j]
108
--> 109 q = self._compute_centroid_quantile(c_j)
110 if c_j.count + w > 4 * self.n * self.delta * q * (1 - q):
111 S.pop(j)
[...]tdigest.pyc in _compute_centroid_quantile(self, centroid)
56 denom = self.n
57 cumulative_sum = sum(
---> 58 c_i.count for c_i in self.C.value_slice(-float('Inf'), centroid.mean))
59 return (centroid.count / 2. + cumulative_sum) / denom
60
[...]tdigest.pyc in <genexpr>(***failed resolving arguments***)
56 denom = self.n
57 cumulative_sum = sum(
---> 58 c_i.count for c_i in self.C.value_slice(-float('Inf'), centroid.mean))
59 return (centroid.count / 2. + cumulative_sum) / denom
60
[...]Anaconda\lib\site-packages\bintrees\abctree.pyc in <genexpr>(***failed resolving arguments***)
285 Yields values in ascending key order if reverse is False else in descending key order.
286 """
--> 287 return (v for k, v in self.iter_items(start_key, end_key, reverse=reverse))
288
289 def item_slice(self, start_key, end_key, reverse=False):
cython_trees.pyx in iter_items (bintrees\cython_trees.c:2801)()
cython_trees.pyx in bintrees.cython_trees.NodeStack.push (bintrees\cython_trees.c:1076)()
RuntimeError: Stack overflow in NodeStack.push().
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment