diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffa093de..6c632c92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: - x64 test_set: - "estimation" + - "higher_order_estimation" - "higher_order" - "plots" - "basic" diff --git a/Project.toml b/Project.toml index 2d49b87f..c8996ee6 100644 --- a/Project.toml +++ b/Project.toml @@ -70,6 +70,7 @@ MatrixEquations = "^2" NLopt = "0.6, ^1" Optim = "^1" Plots = "^1" +Pigeons = "^0.2" PrecompileTools = "^1" REPL = "^1" Random = "^1" @@ -102,6 +103,7 @@ JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d" Optim = "429524aa-4258-5aef-a3af-852621145aeb" +Pigeons = "0eb8d820-af6a-4919-95ae-11206f830c31" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -109,4 +111,4 @@ Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [targets] -test = ["Aqua", "JET", "CSV", "DataFrames", "DynamicPPL", "MCMCChains", "LineSearches", "Optim", "Test", "Turing", "FiniteDifferences", "Zygote", "Plots", "StatsPlots"] +test = ["Aqua", "JET", "CSV", "DataFrames", "DynamicPPL", "MCMCChains", "LineSearches", "Optim", "Test", "Turing", "Pigeons", "FiniteDifferences", "Zygote", "Plots", "StatsPlots"] diff --git a/test/data/usmodel.csv b/test/data/usmodel.csv new file mode 100644 index 00000000..704e118a --- /dev/null +++ b/test/data/usmodel.csv @@ -0,0 +1,231 @@ +dc,dinve ,dy ,labobs,pinfobs,dw,robs +0.125190343495092,3.74590245809472,-0.346646871942539,2.40599138364354,1.73321288857178,-0.390910855357731,0.209166666666667 +-0.311350549973952,7.8632665246694,1.15161239527572,3.12008510042125,2.48223977335953,0.149491058377834,0.251666666666667 +0.429219445192359,3.03630734680101,1.16038522796237,3.72278058296871,0.760128270556626,1.80411479077715,0.2725 +1.10204814758356,1.05355467484111,1.53376234618327,3.70532905517229,0.883676382216336,0.374201838469659,0.275 +-0.514535875011632,-0.054366832738566,0.247688219858674,3.71684726813908,1.8409541555473,0.628307103489846,0.2875 +0.0960511445626366,-0.410564067900935,0.0739084412649618,2.97850194689238,0.247338225209548,0.964797828024913,0.31 +-0.382119840181304,-5.98467636772344,-1.66438273365395,2.09049185540141,-0.398455006770648,0.398455006770689,0.3175 +1.7562547965365,-2.40616152192817,-0.539529184386311,0.365709158814639,-1.10095087276125,1.10095087276125,0.3175 +-0.0381809032957676,-1.24411612082761,0.83676666115764,-0.440932473002363,-0.576582594719133,1.77420169939067,0.285833333333333 +0.952915189957594,2.92601419881703,-1.31267961165202,-0.0888388694548326,0.0983767910132549,-0.0983767910132656,0.294166666666667 +1.50105472828255,5.8565465387299,3.72752944647471,0.0559662336831934,-0.307749365805066,2.66079910682451,0.300833333333333 +1.44021227274669,9.86864732111715,2.66242880952962,1.8613449412685,0.39374973967865,0.762332500428933,0.313333333333333 +4.76315338667251,7.80250117903879,3.62979390543319,3.26170775836761,2.09024501598964,0.182580091765963,0.33 +-2.9568287628029,-1.84539139398265,2.058564265717,3.91358887387815,1.9059540621623,0.316359616308709,0.359166666666667 +2.16327190545343,-3.77026343348561,1.47994349966473,4.70659391993809,3.6607817602528,-0.417254184937363,0.366666666666667 +-2.50974652162233,-3.57856052816862,1.86293638822508,4.88353991762739,0.61238567427071,0.445825258782982,0.3975 +1.21688658652727,-1.09397220814569,1.94214491685773,4.32712691767745,0.0565131408089226,2.02689554947523,0.425833333333333 +0.610431493283898,-1.29620395693397,-0.023129631364327,4.39869574064284,1.10125846080451,-0.0756084440855744,0.4275 +0.595631179795532,1.78197084111221,0.923349585105143,4.90854911753718,-0.0950384418145323,2.11530917356649,0.416666666666667 +1.62515565444977,1.43990445664903,-0.0666815494147386,3.96348327702958,0.189986646328189,-0.189986646328215,0.436666666666667 +-0.318993889670651,-7.68357054064359,0.327554218218211,3.79748637530838,1.14344052210056,-0.148407436783714,0.470833333333333 +2.9853311740012,6.555164697121,2.88999951632206,4.6646951106124,0.29208364431863,2.63495458569266,0.498333333333333 +0.654750608618315,3.05398252039646,0.952820153383414,5.74498734691275,0,0.956945101615069,0.52 +0.369727760692172,0.700180829241106,0.538329847851514,4.41089669055464,0.186926218594019,1.69992221184427,0.563333333333333 +-0.303738495757159,0.308251212012095,-0.825008405488461,3.14346091194261,0.383751361792806,0.546487904438564,0.514166666666667 +-0.771388492760025,-1.83604089758222,-1.9284216912896,1.52694793053138,0.218627109382386,0.703038401110007,0.393333333333333 +0.184604161746449,-2.33652946899923,-0.84055180936241,0.685806016455445,0.321605030405125,0.591643325922114,0.29 +0.811455305093318,1.66473112516078,-0.186697025815988,-0.0510200591484704,0.0924742361980258,-0.092474236198008,0.2225 +0.576932144730677,3.52508037392226,0.852539362231937,-0.534355056351558,0.179265061451961,0.725718490539784,0.256666666666667 +1.37724385989509,1.66561742841617,1.64573708766568,0.218354868806387,0.281827729761597,0.615039268514487,0.246666666666667 +1.73727018612993,3.08579685685316,2.5216388894263,1.28093757713066,0.480523560472479,0.408371181252143,0.335833333333333 +1.21702814101496,4.2169299862436,1.25665977356471,2.35358463136157,0.41924275327534,0.461820214940111,0.375 +0.559847440552005,2.34409224081927,1.00393866449497,3.81921870729673,0.742782692078903,0.130585304796583,0.485 +0.239131064013975,0.0793325106021996,0.260082683213227,4.69263825896616,1.00647104507132,-0.140664770759884,0.589166666666667 +-0.674629817078255,-1.27636160637712,-0.738394948457312,4.46514247724218,1.00687829505217,0.702565040877836,0.620833333333333 +0.154695641712237,0.933174102883356,0.512520496195066,4.15766958538524,0.577509994556813,1.93308211855084,0.673333333333333 +-0.391066896167047,0.0375058825424048,-0.415640990585189,4.15437407907569,1.27836792468146,-0.455318011029931,0.7025 +1.29266641096888,-0.523860374086951,1.33329583247587,3.95707268877595,0.383406650182216,1.24264543699585,0.731666666666667 +-0.0924196744412598,-0.796952592974748,0.344246290951674,3.66254592573938,1.40344292133512,0.196591213308992,0.733333333333333 +-0.161245780470836,-1.40436076141302,-0.538321163619685,2.71575407190414,0.681911988588446,0.892923708225467,0.75 +0.666621175366686,0.638635102370841,0.627411213239952,2.30817559335992,0.592882189073274,0.185331855132233,0.808333333333334 +0.189812524157333,-1.82673255990676,-1.45102220801482,0.511900531323704,0.00993443275203454,1.52855745119588,0.813333333333333 +-1.59647721231283,-8.74667249546337,-3.08040127876234,-1.37178920220987,1.09663221107303,-1.09663221107304,0.465833333333333 +0.418637603338539,-2.9277410793724,0.327354028454693,-1.86791845273086,0.313925798595571,1.20125470346468,0.235 +0.792714101415072,0.487870888233203,2.00772025516142,-1.32138142370786,0.654107574797402,0.0949595981183506,0.330833333333333 +0.381989134703531,5.33582661868968,1.89195027747485,-0.3466837297197,0.499891841541489,0.981616736972576,0.540833333333333 +1.90670765404735,5.52311048353062,1.51622364168611,0.237782659215213,0.232108421420341,0.500495587786944,0.6425 +1.54748019781727,3.16346472289075,2.22625843468643,1.5174915893445,0,0.727275932907986,0.770833333333333 +1.03888601836798,0.996146604245098,-0.432872323177094,1.05269801260982,0.236389622103284,0.485635175245399,0.894166666666667 +-0.0840638060431616,-1.92543746310577,0.0340328845528575,0.548440562406256,0.418340234564329,1.01025549018335,0.9975 +-0.00726558060227944,2.41284371161083,1.52111080911084,0.0408303535523942,0.435709674004281,1.66963124577892,0.983333333333333 +1.12902437794247,-2.44318375590541,-0.781887187950019,1.14077712442491,0.348158215040373,-0.348158215040364,0.924166666666667 +-0.699488697061895,-3.48296859640629,-0.162716021786991,0.853816226596052,0.380156321734759,0.311887962722629,0.734166666666667 +-0.0755912706160871,-1.31936321193436,-1.65512195343695,-0.134784709974667,0.293630331737438,0.393657597038754,0.574166666666667 +-0.432264100951159,-2.08127199515684,0.236514944153782,-0.833138594130219,0.21729896594338,0.465297541096604,0.500833333333333 +0.94671961854948,1.10056369171392,1.54005165302362,-1.447272343728,0.212119149039314,1.13925276763298,0.433333333333333 +0.231867722777849,1.65409893142217,1.30079325301347,-1.57034377485627,0.310296440790436,0.358602374289205,0.420833333333333 +1.60984095839706,2.75304136543315,1.86469060745196,-0.825505406655282,0.337410695475793,0.327043576391091,0.6 +0.755469055327865,1.52951042395864,1.6234953082627,-0.628525516737966,0.587743085706771,1.37953347416369,0.614166666666667 +1.04535825810768,2.55999233447503,0.717578585387628,-0.253213252728301,0.148719644457929,0.498531806103827,0.651666666666667 +0.375881615681806,0.0265757558824191,0.45957431767215,-0.34332975746679,0.241198688296995,0.401890344732053,0.711666666666667 +0.807952050495317,-1.47945733509604,-0.317507694048118,-1.1308607689603,0.314538397071162,0.324441412805932,0.730833333333333 +0.249057539344847,0.487545239834049,0.812986170892373,-1.26308989288128,0.226040921986348,1.03979876520602,0.741666666666667 +0.457708763954201,3.70071490538822,0.808603271257084,-0.794425988626529,0.197942385158578,0.42901891620096,0.740833333333333 +1.22167778456702,1.65666385001623,1.45426983614084,-0.942665406043204,0.197551347182623,0.425503627880985,0.8325 +0.0427345745158618,2.13673667753181,0.352997846141534,-0.711096838440881,0.745333704857432,0.489249877372476,0.863333333333333 +1.71106043802899,2.69184464206651,1.79635920943849,0.367014179673788,0.29567651809308,-0.295676518093046,0.865833333333333 +1.32088780240753,-0.0315985813364534,0.755169413167096,1.3749607673825,0.258568040814167,0.960959268567663,0.8725 +1.33209022442065,0.929263850764329,0.92484937690881,0.791506900215836,0.3933719720008,0.811461879616605,0.864166666666667 +-0.313577723902199,0.888912605084414,-0.170734634880091,0.85977586885673,0.495161939019351,0.101854759631074,0.894166666666667 +1.59260985030284,3.4946993052146,2.00832398881482,1.653126511908,0.506126088821057,0.0873474631603699,0.993333333333333 +0.752581486153531,2.1901704502383,0.937676503611556,2.0780228722125,0.432428286800324,0.157543925918496,1.01916666666667 +1.38079781930566,2.1474231236009,1.67625647933926,2.14471268615733,0.368537148688564,0.801066827630592,1.01833333333333 +2.11624597668481,2.41369751652351,2.05601746978596,2.44969671196424,0.636185048276428,0.519897191831156,1.04166666666667 +1.31457239966488,2.27031276882315,2.1474273608826,2.8386658124877,0.649666478856759,1.62315862889886,1.13916666666667 +-0.0437709789341056,-0.697561706681654,0.0659646860557359,2.87508445051509,0.840908599851975,0.27642145996057,1.22833333333333 +0.580089313263045,-1.4183398543631,0.371337432584937,2.82516728917369,1.04880220750427,0.604127987616746,1.3525 +-0.0250503382756619,-3.09029022972808,0.502367855014768,2.85668743017135,0.914614461882346,0.172352761808039,1.39083333333333 +0.0863998645534707,-2.69847636152343,0.551218405046939,1.8738144201244,0.454189290234908,1.15442448492753,1.20583333333333 +0.901536358215196,2.02269260500407,-0.368192671766451,1.45204148644029,0.544845391508808,1.03830113015928,0.9975 +-0.036067005149107,0.134124498830403,0.298466667745288,1.8278754141499,0.980810947597099,0.577662154072698,0.973333333333333 +-0.102115650942437,2.79339776395042,0.299893663714784,1.95451900972893,1.10337937060963,-0.077729353890696,1.04333333333333 +1.93120469907205,1.91922978717085,1.64934919063955,1.05194292835472,1.08725710516566,1.92804671190308,1.19666666666667 +1.17216692000295,-0.994498065708484,1.34488852824461,2.01649944497791,1.04326181158747,0.430966362132903,1.495 +1.50478134434434,0.674764757670005,0.270479643860426,1.80729714443765,0.984517003599139,0.947910279041118,1.48583333333333 +-0.32447756323478,2.78147043841241,-0.0542259746338232,1.39975906987803,1.40562171335872,0.490169661102719,1.47916666666667 +0.611787689018058,2.69452948126065,1.11695102400597,1.73019909795039,1.03554702746766,0.363077170006328,1.64166666666667 +0.224381844552795,-0.180085283682587,-0.122044369887135,1.79895787589788,1.28723861781825,0.092093595415303,2.08166666666667 +-0.15600244017736,0.637531508690898,0.191441724216816,1.80089475239208,1.4305082340063,0.379495930355482,2.24583333333333 +0.170294231183732,-2.98363593646593,-0.958862076727655,1.49053185376613,1.29418675821871,0.483637843909705,2.235 +-0.168378339814012,-1.60005692018828,-0.685406487299474,0.77287256205625,1.41819949684074,0.760535921649991,2.14333333333333 +-0.332198226277285,-1.89889171573429,-0.345503029077122,-0.684320091944414,1.36555972658932,-0.0807454788044471,1.97 +0.484330725396717,0.103805404140388,0.316114907955239,-1.65000920913775,0.79528335639325,1.31005756339001,1.67583333333333 +-0.849223977248585,-0.616037354395132,-1.66119100858316,-2.29236260503996,1.2830134128901,-0.453133131420584,1.39166666666667 +0.779733908318917,1.86206781559005,2.17739087173163,-2.66242004628498,1.49216825216483,0.552892794964215,0.964166666666667 +0.176429525146773,3.57352431578028,-0.00678783990133525,-3.01581366648901,1.3036900649479,0.302770185432797,1.14083333333333 +0.209813641807273,1.54946590519603,0.237171000973945,-3.06138510933738,1.00541555559084,0.182717233084411,1.36833333333333 +0.913289518364309,2.20836253713924,-0.281339920395794,-2.35635843635703,0.797799167408586,-0.0134814213059684,1.1875 +-0.305452079379961,2.95125058145442,0.633677505326887,-2.17117576262876,1.55325187596214,1.14440689385804,0.885 +1.35715302497158,1.27213291476562,1.80947746532547,-1.88515430844944,0.59591739791558,0.538310262477884,1.075 +0.909001870907844,0.589379404983248,0.417873406567765,-1.80802009619111,0.966640422200049,0.525924599467532,1.185 +1.33864117535325,4.21105623981151,1.14615638245868,-1.80545672040722,1.32017286313073,0.514741003688906,1.28583333333333 +1.30903892701593,3.42121529607758,1.99276526081144,-1.40693395554325,1.19342446402348,1.67415553364315,1.63416666666667 +-0.184482837171174,0.527384407984556,0.633280441308216,-0.789678028067613,1.53553880831945,-0.132006996681117,1.95416666666667 +-0.27616034250417,-0.61927413729552,-1.04914735496129,-0.678841283001987,1.93045262959055,0.138586696154078,2.64 +-0.729801808639763,-2.20848852717162,0.443845509961648,-0.50293707599144,1.96108899537681,0.0660074419850947,2.49916666666667 +-0.351031405737444,-2.8793163707233,-1.38211344352715,-1.2200151871827,1.89341167371011,0.420741182459347,2.33083333333333 +0.308690238022223,-1.37849792028706,-0.219386958255768,-1.86923117574833,2.32768363975069,0.253104755836544,2.8125 +-0.326784574154658,-1.29083309630565,-1.47382392011093,-2.37207402093583,2.89657915064785,-0.0706454192074997,3.0225 +-2.41406047980945,-5.34166374771797,-0.893328100636609,-4.00898429626125,2.94765260968033,-0.19938804029715,2.33666666666667 +-0.0695735326093541,-5.64304653359247,-1.68865167773401,-6.78927742669629,2.27121189229451,0.40353894440832,1.57583333333333 +0.887962743600269,-1.11291399288302,0.256553071540225,-7.38777956287987,1.51079697777905,0.521203271316676,1.355 +0.867452325660111,1.2079239960249,1.10952390863008,-6.82627387472877,1.84129426623487,-0.131850930304821,1.54 +0.476061147341795,1.09440483473068,0.811257139643089,-6.32375179062433,1.7438993046174,0.21420521529325,1.35333333333333 +1.50419576014883,3.46950232002848,1.74769124489217,-5.14967657995794,1.09943075418935,1.09243781657525,1.20666666666667 +0.23875222685723,1.88749290105028,0.294544003978899,-5.24198281363874,1.06488679460952,0.814363140327244,1.29916666666667 +0.71908078234145,0.581883379886449,-0.00470312037339227,-5.2731452961163,1.35869961778621,1.00671947200276,1.32083333333333 +0.612876752062505,4.31088098112642,0.270216055867877,-5.35688015089181,1.808482920215,0.248144837932677,1.21833333333333 +0.868170999086999,3.67945337223046,0.763368041001854,-5.01331602639664,1.62573830754549,0.139755216326615,1.165 +0.332954624047943,5.39069350396372,1.4760179570178,-3.8583717615582,1.43713056935884,0.543132160259107,1.28916666666667 +0.754423906505394,1.84550053259423,1.28588887145258,-3.82412742007023,1.20960709704114,0.732201488669051,1.455 +0.30714957448123,1.32228341677089,-0.454753001423455,-3.04264136987695,2.15523099764292,-0.486539119141474,1.62833333333333 +0.331021454651477,0.795258492486283,-0.107518363730037,-3.27706176248711,1.47812145986013,1.31926374438048,1.68916666666667 +1.90648611188021,6.83302678941104,3.43265404542467,-1.48912755945565,1.81689588188028,0.00547801376488222,1.82083333333333 +0.0695540932417771,2.65422108930164,0.523474875747638,-1.55508752517517,1.64348889746737,0.146268048286905,2.025 +0.109078744927274,1.55137972534553,0.841241746722517,-1.08373816696428,2.09417118387707,0.315583974028982,2.39583333333333 +0.176087142252925,0.689026637387912,-0.253478971104869,-1.04830252575186,1.74672329679821,1.02826799849204,2.51833333333333 +-0.223523184600538,-1.06104500560622,-0.32557479823106,-1.83556889548561,2.43889365797672,-0.355484967692531,2.545 +0.823953212108108,1.63806465616742,0.260984201530164,-1.32123030858776,2.13170928859383,0.1109942901506,2.73666666666667 +0.162148154893941,-1.41059880655629,-0.223439342796382,-1.33456540178685,1.97967584243823,0.410876242917207,3.39416666666667 +0.270271440997817,-1.64026638258838,-0.106994466072706,-2.02244659556521,2.08695819590496,0.823043452739099,3.76166666666667 +-2.45506627646796,-9.38633690596544,-2.42908482403868,-4.11450889974486,2.18685285693714,0.454810187457052,3.17166666666667 +0.725263246697011,0.447779718695159,-0.581364138675895,-4.68247253795119,2.24457801055737,0.329093453847617,2.45916666666667 +0.691670179703237,2.95860941237575,1.49165889587266,-4.12815215303152,2.73177312906308,-0.0458462240362348,3.96333333333333 +0.087455199362239,0.481814242284287,1.66010977796418,-3.63474885475694,2.5461811454889,0.0694867193839652,4.1425 +-0.52597979805546,0.684579276839344,-1.11288008264535,-3.7997506886847,1.8620010026976,-0.155474947278978,4.445 +-0.0667060690821018,-0.430387424250085,0.864404597089902,-4.8506100805584,1.76426907185547,0.411548981016281,4.39416666666667 +-1.39589608119115,-0.591312594467013,-1.59321072461853,-5.39500658255463,1.80780864212924,-0.328734841989656,3.39666666666667 +0.259209384759004,-3.36588162067889,-1.94892637881469,-6.95436036740711,1.35097406520286,1.22565801122008,3.55666666666667 +-0.210999330841787,-3.89334609373518,0.230702569312029,-6.52555811781468,1.20624439072801,-0.414474617049413,3.62833333333333 +0.626937882375614,-3.98145114804964,-0.669146054121939,-7.01915334588534,1.40259224532642,0.162384921386284,2.75166666666667 +1.53523562744346,-1.39465955897978,-0.214518230372732,-7.7491341974519,1.07207134869514,0.162512233534833,2.32166666666667 +0.751643602632271,0.604436005531454,0.960855168582953,-7.69331559088613,0.818711639690939,0.249185617894485,2.16333333333333 +1.89965651466298,2.38574920515879,1.96989927447646,-6.95037293727017,0.719588994986875,0.03627250240578,2.20083333333333 +1.76884245259595,4.35513998183211,1.6718675180424,-4.89131331890343,1.0186480656893,-0.418045659668098,2.365 +1.19846576693806,4.78515398288937,1.73896193449923,-4.22084608942475,0.752689273057605,0.289762460530745,2.3575 +0.268183757919189,1.51790444212506,1.52187217481821,-3.20150733150422,1.24202757351757,0.0824951014845881,2.42166666666667 +1.27573604704384,3.35555519757702,1.45204840654662,-2.0391951131727,0.859589206549405,0.0137787903259654,2.63916666666667 +0.47772181971709,1.35583713264253,0.700693609718428,-2.29209347146798,0.796357825094951,0.642515920115007,2.8475 +1.00027454935952,1.12308782650445,0.514695395169497,-2.14306919626875,0.633721260057385,0.0780255168290123,2.31666666666667 +1.39618449179193,-0.268256022415699,0.700584498751027,-1.73164730309628,1.11968597431575,0.148829978415919,2.11916666666667 +0.856154666288148,0.58873406885516,0.611478709925677,-1.70767925156122,0.569555629278007,0.267269337773583,1.98083333333333 +1.84278816989831,-1.06842379727604,1.28957416743367,-1.79615064295803,0.413235586754457,0.966096626479142,1.975 +0.0710181743050953,1.58907598146845,0.46937498887371,-1.50970393605189,0.643704007482615,0.986766895011768,2.02583333333333 +0.544178039350697,-0.406613186032558,0.458668530616592,-1.54319272944753,0.515110298137511,0.823597780108453,1.95666666666667 +0.326252498049257,-0.27081756372661,0.121088067991423,-1.97833929505293,0.512470503989349,0.414074840589595,1.73 +1.60527893903395,-0.564336170392977,0.667996503001859,-1.76428598214096,0.577082638577231,0.340956595918969,1.55166666666667 +0.400089733961863,0.399036824619316,0.210244767069867,-1.48404825929714,0.651695382770434,1.03119223024523,1.56666666666667 +-0.00923405229406171,-2.85473580948485,0.306036045002315,-0.597099427250385,0.822833289121228,-0.69454590783228,1.555 +1.38103238669055,1.06341789817995,0.805451617581753,-0.230139524927495,0.543445950840926,0.349986922535658,1.6625 +1.12296850240637,1.28016825044145,0.635879761713795,0.131989467962512,0.742278213849446,0.269108409843377,1.71083333333333 +0.119619758239367,-0.165882686162661,1.48497022417826,0.666162470989661,0.723288742447625,0.526727533975484,1.72916666666667 +1.39303192354464,-0.360525847763881,0.215328369000986,0.298843173317209,0.846886478045672,0.755119440372768,1.66583333333333 +0.632957496726931,1.36183262460486,1.03450145610054,0.82976579991896,0.951390551623099,0.14284529047128,1.78916666666667 +0.662890954428349,-0.509296492154334,0.287225645453646,0.918128346660069,1.11067497633348,0.0912625702449841,1.99583333333333 +1.16974375155604,0.991736088407464,1.08835575485762,1.70847815663251,0.747126528219777,-0.151532152934678,2.1175 +0.147636796945449,0.0894480675246427,0.729802796951617,2.38852503459816,1.12515121604408,-0.887903180681059,2.36083333333333 +0.594718841406348,-0.433412546841907,0.435507733355053,2.58456751489877,0.954440742925922,-0.599620737316234,2.43166666666667 +0.648556418838609,1.21610746067717,0.483145824664803,2.70146258453212,0.706096328815242,-0.000211044852767017,2.27083333333333 +0.371275472319951,-2.05768557449272,0.0307172983364126,2.32402517783675,0.68981474263472,0.707181201385354,2.15333333333333 +0.290621071858197,-0.18308572342292,0.348174213848893,2.3591491406425,1.18900024022039,0.643811660209636,2.0625 +0.0386311423858956,-3.38568166104113,0.0448378415075013,1.55321811579159,1.15781261965919,0.975901119153892,2.06083333333333 +0.543259065299651,-1.57282272332907,-0.223814218084158,0.585872361659085,0.881591584793018,0.661989228190922,2.04 +-0.449797987498187,-3.29228562756691,-1.02958944171655,0.0188529915169511,0.746920163935716,0.124545046308658,1.93583333333333 +-1.0721999274744,-4.15415888591548,-0.72366653829647,-0.984652080396813,1.17880502817185,-0.422453502447395,1.60666666666667 +0.578987771466473,-1.00602481436127,0.444640987769049,-1.43187566420426,0.642468134766361,1.17091488903764,1.46583333333333 +0.186237784950322,-0.66442724341087,0.23835810529124,-1.53413035516479,0.706817128653725,0.449265111453899,1.41083333333333 +-0.094296526365099,-0.948322466532744,0.191069270167077,-1.79484578907977,0.522452473334845,0.517057926699119,1.20416666666667 +1.58045440035426,0.0194601258561136,0.809697596112301,-1.77846641300687,0.602598253534037,1.3431876614001,1.00583333333333 +0.443792178140484,3.12803429844956,0.73500852743723,-1.42356888960887,0.545632523303663,0.262452682090203,0.9425 +0.963756808801122,0.940311070772509,0.707295462775505,-1.40004855556901,0.451468035452685,0.947156162021317,0.814166666666667 +0.961834289805324,2.50744001254387,0.789754758182312,-1.43822664437084,0.517255443086917,-0.121215321477269,0.759166666666667 +-0.152850242722309,0.105435071694586,-0.131793817732842,-1.20198472812643,0.776031730804494,-0.578598300432672,0.76 +0.746927848495943,1.73406107146735,0.274167588954583,-0.481535473952988,0.549186414734049,-0.155485118800142,0.75 +0.735887916916227,1.3123355567017,0.248790458001281,-0.290398853713782,0.429962192140199,-0.0378048268220361,0.765 +0.60315452962783,3.67777137658223,1.05361121647752,-0.0387475382106004,0.527004507861317,-0.136379011154791,0.7475 +0.655235582864236,0.988726763679892,0.774516204829638,0.0187502639078616,0.604650921766581,0.558152877745318,0.803333333333333 +0.619042543161527,2.05768034625504,1.07337788332063,1.08300213465463,0.418867443957627,-0.611731534598141,0.985 +0.692356232170312,0.478613456701055,0.290319051559095,1.34267496415367,0.638285893000212,-0.734857604996176,1.12166666666667 +0.695674209158938,2.18513192502132,0.886988356788493,2.03632003648897,0.465060733945677,0.112975557604306,1.29166666666667 +-0.13629675445776,1.8974539165884,0.135120406197188,2.11518436914457,0.633489256988273,0.132064721144578,1.4525 +0.81057930107437,-0.612951072213264,-0.0302963924410733,1.53247355200392,0.358800531063608,0.211543220323367,1.505 +0.566764029506203,0.729755735170983,0.553798381808406,1.81584340460392,0.4670165101337,0.100092760247856,1.44916666666667 +0.345964234547694,1.30582943777858,0.455169317397576,1.47506426342147,0.479943846980646,0.458149336395959,1.43 +0.644676222993383,1.32063508322921,0.490597779543691,0.821486302600363,0.639577373281419,0.382261522586397,1.34083333333333 +1.11375907158339,2.29193665008899,1.37403448233181,1.25566766650866,0.354035677060871,0.565934012781487,1.31083333333333 +0.438904497893077,1.99307181315166,0.550585560601576,1.81153070016018,0.311284298049053,0.418645950112129,1.32666666666667 +0.664410644718487,0.766504390071532,0.859941188172456,2.39501585510294,0.529722418513767,-0.0762069019746487,1.32 +0.427418927173278,0.676124457374442,0.305518305326473,2.73927007830616,0.637455721560087,-0.00596963569262421,1.31916666666667 +0.277934657334754,1.63262818446404,1.291772942134,3.07773452723876,0.159781385827884,0.557067562033314,1.38083333333333 +1.2943997932079,3.19248604750266,0.97569626721122,3.4851745817619,0.343924004727647,0.633427177970351,1.38333333333333 +0.755759478875461,0.090134152423957,0.455419838506032,3.43281837706047,0.326053167946228,1.42684009263006,1.37666666666667 +0.697280372351372,1.96876920633719,0.875217173331294,3.52019982304159,0.253210857669828,1.55484528383764,1.38 +1.32709997507044,2.26035807575244,0.409786835756336,3.33742357921142,0.16637381786957,1.27371883751282,1.375 +0.88531202752381,0.704141207032023,0.863268913179809,2.99267688766003,0.364015771494142,1.1385166691809,1.38333333333333 +1.06308963239957,2.19016256015749,1.20885323014136,4.13603268696932,0.345159332822398,0.233115719368804,1.215 +0.462499468709495,0.942232527584793,0.468627159773291,3.9523792259597,0.40563830316529,1.3903283366539,1.18333333333333 +1.5732869366758,1.79686529253036,0.555612238267941,3.98699031238579,0.354868527607799,-0.0317664694631681,1.18666666666667 +0.949492130996873,1.11565401095891,0.86610968398179,4.05813225128964,0.346472007972931,0.536713178809926,1.27333333333333 +1.09910107519522,-0.0724456805704108,1.46539379241449,4.0902605206652,0.426583150896764,1.63045140566613,1.32666666666667 +0.122946014964555,0.944866024986311,-1.18051725516216,4.18893530278592,0.895080034395157,2.4924648145834,1.42 +0.417638062299034,1.88643854344883,1.29022726704488,3.76265129151977,0.430017441329778,-0.127674051530086,1.56833333333333 +0.589930840077784,-0.524245043384156,-0.433010731732338,3.06124307383124,0.51399085178172,1.42926910220591,1.63 +0.578441118484307,-0.298732183236552,0.217694988508697,2.8317993364584,0.405126845008397,0.111670170835929,1.61833333333333 +0.161646627345931,-1.78347312066506,-0.376035971588294,2.4519507805187,0.80339200516848,0.876092523896539,1.39833333333333 +-0.172709114345992,-2.88228040821491,0.0107063410557657,1.19438147970055,0.759832841385943,-0.110245569841389,1.08166666666667 +-0.149230347689411,-1.33187658020631,-0.671393919933962,0.206238608853937,0.412830520880281,0.0178951988777101,0.874166666666667 +1.00251695438243,-3.60760800779718,0.0742633694899268,-0.688298432615568,0.501298009956219,0.283579369250905,0.533333333333333 +0.166504093667356,-1.90349573045552,0.583238395877856,-0.832836684820563,0.250676424936813,1.02052713389944,0.433333333333333 +0.711646999732977,-1.61049328681082,0.340853686381706,-0.680085923833474,0.444635933952409,0.463508623871704,0.4375 +0.57708492580656,-0.675429124646257,0.33625691610996,-0.751883550010632,0.318994861044786,0.0281071882430552,0.435 +0.16804908125664,-0.33038731334284,-0.125306365705796,-1.39752979495165,0.487093955721107,-0.210277169959817,0.360833333333333 +-0.0205252293212652,-0.42810961574645,-0.285066330985046,-1.79949697620765,0.711530121738591,0.661175029411204,0.3125 +0.593974742483908,1.97908039708489,0.752780433887438,-1.98259646486827,0.283011466756822,1.07110536496052,0.311666666666667 +0.963100368463358,3.77434088854915,1.45254639128268,-2.47480348336313,0.329327912571209,1.07303229820342,0.254166666666667 +0.477770530240775,2.48717621866388,0.681041328242827,-2.09159392019234,0.352657756486163,0.637122676239891,0.251666666666667 +1.06272365803494,0.843084076624677,1.01716103905153,-1.88739671956142,0.676433680105237,-0.152529403853073,0.250833333333333 +0.134490769038962,3.27115245186013,0.579110626934039,-2.28738981395816,0.786670661654654,0.640072087445695,0.2525 +0.890420982568628,2.16798602005923,0.664565005542386,-1.87907140900137,0.359229290844265,0.983931292021872,0.358333333333333 +0.788226274207716,2.18192499178394,0.614386847994297,-1.76049362247306,0.568063223871995,0.254465931034027,0.4875 diff --git a/test/runtests.jl b/test/runtests.jl index 65eb38bc..dd8b1091 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,6 +19,10 @@ include("functionality_tests.jl") # end +if test_set == "higher_order_estimation" + include("test_higher_order_estimation.jl") +end + if test_set == "estimation" include("test_estimation.jl") end diff --git a/test/test_higher_order_estimation.jl b/test/test_higher_order_estimation.jl new file mode 100644 index 00000000..7c9f0fd6 --- /dev/null +++ b/test/test_higher_order_estimation.jl @@ -0,0 +1,180 @@ +using MacroModelling +import Turing +import Pigeons +import Turing: NUTS, sample, logpdf +import Optim, LineSearches +using Random, CSV, DataFrames, MCMCChains, AxisKeys +import DynamicPPL: logjoint + +include("../models/FS2000.jl") + +# load data +dat = CSV.read("data/FS2000_data.csv", DataFrame) +data = KeyedArray(Array(dat)',Variable = Symbol.("log_".*names(dat)),Time = 1:size(dat)[1]) +data = log.(data) + +# declare observables +observables = sort(Symbol.("log_".*names(dat))) + +# subset observables in data +data = data(observables,:) + + +Turing.@model function FS2000_loglikelihood_function(data, m) + alp ~ Beta(0.356, 0.02, μσ = true) + bet ~ Beta(0.993, 0.002, μσ = true) + gam ~ Normal(0.0085, 0.003) + mst ~ Normal(1.0002, 0.007) + rho ~ Beta(0.129, 0.223, μσ = true) + psi ~ Beta(0.65, 0.05, μσ = true) + del ~ Beta(0.01, 0.005, μσ = true) + z_e_a ~ InverseGamma(0.035449, Inf, μσ = true) + z_e_m ~ InverseGamma(0.008862, Inf, μσ = true) + # println([alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m]) + Turing.@addlogprob! get_loglikelihood(m, [alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m], data, algorithm = :pruned_second_order) +end + + + +pt = @time Pigeons.pigeons(target = Pigeons.TuringLogPotential(FS2000_loglikelihood_function(data, FS2000)), + record = [Pigeons.traces; Pigeons.round_trip; Pigeons.record_default()], + n_chains = 1, + n_rounds = 9, + multithreaded = true) + +samps = MCMCChains.Chains(Pigeons.get_sample(pt)) + + +println(mean(samps).nt.mean) + + +# estimate highly nonlinear model + + +# load data +dat = CSV.read("data/usmodel.csv", DataFrame) +data = KeyedArray(Array(dat)',Variable = Symbol.(strip.(names(dat))), Time = 1:size(dat)[1]) + +# declare observables +observables = [:dy, :dc, :dinve, :labobs, :pinfobs, :dw, :robs] + +# Subsample from 1966Q1 - 2004Q4 +# subset observables in data +data = data(observables,75:230) + + +include("models/Caldara_et_al_2012_estim.jl") + + +get_parameters(Caldara_et_al_2012_estim) +Turing.@model function Caldara_et_al_2012_loglikelihood_function(data, m) + ζ ~ Beta(0.356, 0.02, μσ = true) + β ~ Beta(0.993, 0.002, μσ = true) + ψ ~ Normal(0.5, 0.3) + γ ~ Normal(40, 1) + dȳ ~ Normal(0, 1) + dc̄ ~ Normal(0, 1) + ρ ~ Beta(0.5, 0.25, μσ = true) + λ ~ Beta(0.5, 0.25, μσ = true) + δ ~ Beta(0.01, 0.005, μσ = true) + η ~ InverseGamma(0.1, Inf, μσ = true) + σ̄ ~ InverseGamma(0.021, Inf, μσ = true) + # println([alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m]) + Turing.@addlogprob! get_loglikelihood(m, [dȳ, dc̄, β, ζ, δ, λ, ψ, γ, σ̄, η, ρ], data, algorithm = :pruned_third_order) +end + + +pt = @time Pigeons.pigeons(target = Pigeons.TuringLogPotential(Caldara_et_al_2012_loglikelihood_function(data, Caldara_et_al_2012_estim)), + record = [Pigeons.traces; Pigeons.round_trip; Pigeons.record_default()], + n_chains = 1, + n_rounds = 2, + multithreaded = false) + +samps = MCMCChains.Chains(Pigeons.get_sample(pt)) + + +println(mean(samps).nt.mean) + + +# Random.seed!(30) + +# function calculate_posterior_loglikelihood(parameters) +# alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m = parameters +# log_lik = 0 +# log_lik -= get_loglikelihood(FS2000, parameters, data) +# log_lik -= logpdf(Beta(0.356, 0.02, μσ = true),alp) +# log_lik -= logpdf(Beta(0.993, 0.002, μσ = true),bet) +# log_lik -= logpdf(Normal(0.0085, 0.003),gam) +# log_lik -= logpdf(Normal(1.0002, 0.007),mst) +# log_lik -= logpdf(Beta(0.129, 0.223, μσ = true),rho) +# log_lik -= logpdf(Beta(0.65, 0.05, μσ = true),psi) +# log_lik -= logpdf(Beta(0.01, 0.005, μσ = true),del) +# log_lik -= logpdf(InverseGamma(0.035449, Inf, μσ = true),z_e_a) +# log_lik -= logpdf(InverseGamma(0.008862, Inf, μσ = true),z_e_m) +# return log_lik +# end + +# sol = Optim.optimize(calculate_posterior_loglikelihood, +# [0,0,-10,-10,0,0,0,0,0], [1,1,10,10,1,1,1,100,100] ,FS2000.parameter_values, +# Optim.Fminbox(Optim.LBFGS(linesearch = LineSearches.BackTracking(order = 3))); autodiff = :forward) + +# @testset "Estimation results" begin +# @test isapprox(sol.minimum, -1343.7491257498598, rtol = eps(Float32)) +# @test isapprox(mean(samps).nt.mean, [0.40248024934137033, 0.9905235783816697, 0.004618184988033483, 1.014268215459915, 0.8459140293740781, 0.6851143053372912, 0.0025570276255960107, 0.01373547787288702, 0.003343985776134218], rtol = 1e-2) +# end + + + +# plot_model_estimates(FS2000, data, parameters = sol.minimizer) +# plot_shock_decomposition(FS2000, data) + +# FS2000 = nothing +# m = nothing +# @profview sample(FS2000_loglikelihood, NUTS(), n_samples, progress = true) + + +# chain_NUTS = sample(FS2000_loglikelihood, NUTS(), n_samples, init_params = FS2000.parameter_values, progress = true)#, init_params = FS2000.parameter_values)#init_theta = FS2000.parameter_values) + +# StatsPlots.plot(chain_NUTS) + +# parameter_mean = mean(chain_NUTS) + +# pars = ComponentArray(parameter_mean.nt[2],Axis(parameter_mean.nt[1])) + +# logjoint(FS2000_loglikelihood, pars) + +# function calculate_log_probability(par1, par2, pars_syms, orig_pars, model) +# orig_pars[pars_syms] = [par1, par2] +# logjoint(model, orig_pars) +# end + +# granularity = 32; + +# par1 = :del; +# par2 = :gam; +# par_range1 = collect(range(minimum(chain_NUTS[par1]), stop = maximum(chain_NUTS[par1]), length = granularity)); +# par_range2 = collect(range(minimum(chain_NUTS[par2]), stop = maximum(chain_NUTS[par2]), length = granularity)); + +# p = surface(par_range1, par_range2, +# (x,y) -> calculate_log_probability(x, y, [par1, par2], pars, FS2000_loglikelihood), +# camera=(30, 65), +# colorbar=false, +# color=:inferno); + + +# joint_loglikelihood = [logjoint(FS2000_loglikelihood, ComponentArray(reduce(hcat, get(chain_NUTS, FS2000.parameters)[FS2000.parameters])[s,:], Axis(FS2000.parameters))) for s in 1:length(chain_NUTS)] + +# scatter3d!(vec(collect(chain_NUTS[par1])), +# vec(collect(chain_NUTS[par2])), +# joint_loglikelihood, +# mc = :viridis, +# marker_z = collect(1:length(chain_NUTS)), +# msw = 0, +# legend = false, +# colorbar = false, +# xlabel = string(par1), +# ylabel = string(par2), +# zlabel = "Log probability", +# alpha = 0.5); + +# p