GSA: remove tags for older Dynare versions

time-shift
Sébastien Villemot 2011-03-17 15:32:22 +01:00
parent fe4dbbfe0e
commit 753aa48a49
116 changed files with 0 additions and 16490 deletions

Binary file not shown.

View File

@ -1,512 +0,0 @@
function VECTOR = LPTAU(I, N)
%
% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN
% KELDYSH INSTITUTE OF APPLIED MATHEMATICS
% RUSSIAN ACADEMY OF SCIENCES
%
% QUASIRANDOM SEQUENCE GENERATORS
% -------------------------------
%
% 28.11.1991
%
% NOTE TO THE USER BY the NEA Data Bank:
% This quasi random number generator has been made available to
% you on condition that its identity is preserved when used
% in computer programs. If its use leads to scientific publication
% of results you should cite it in the references, in addition
% no commercial use should be made unless agreed upon with the
% main author (Prof. I.M. Sobol')
%
% ABSTRACT
% ........
%
% POINTS BELONGING TO LP-TAU SEQUENCES UNIFORMLY DISTRIBUTED IN THE
% N-DIMENSIONAL UNIT CUBE ARE OFTEN USED IN NUMERICAL MATHEMATICS:
%
% - AS NODES FOR MULTIDIMENSIONAL INTEGRATION;
% - AS SEARCHING POINTS IN GLOBAL OPTIMIZATION;
% - AS TRIAL POINTS IN MULTI-CRITERIA DECISION MAKING;
% - AS QUASIRANDOM POINTS FOR QUASI-MONTECARLO ALGORITHMS;
% - ETC.
%
% THIS SUBROUTINE CONTAINS THE ALGORITHM FOR FAST GENERATION OF
% LP-TAU SEQUENCES THAT ARE SUITABLE FOR MULTI-PROCESSOR COMPUTATIONS.
% THE DIMENSIONS N.LE.51, THE NUMBER OF POINTS N.LT.2**30.
% THE PROGRAMMING LANGUAGE IS FORTRAN-77. THIS SUBROUTINE IS AVAILABLE
% ALSO IN %-LANGUAGE.
% THE REPORT DESCRIBING THE ALGORITHM CONTAINS THE DESCRIPTION OF THE
% ALGORITHM AND CERTAIN IMPORTANT PROPERTIES OF LP-TAU SEQUENCES AND
% THEIR GENERALIZATIONS ARE DISCUSSED.
%
% REFERENCE:
% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN
% KELDYSH INSTITUTE OF APPLIED MATHEMATICS
% RUSSIAN ACADEMY OF SCIENCES
%
% QUASIRANDOM SEQUENCE GENERATORS
% MOSCOW 1992, IPM ZAK. NO.30 (100 COPIES)
%
% ------------------------------------------------------------------------
%
% INPUT PARAMETERS:
%
% I - NUMBER OF THE POINT (I=(0,2**30-1)),
% N - DIMENSION OF THE POINT (0<N<52);
%
% OUTPUT PARAMETER:
%
% VECTOR(N) - N-VECTOR CONTAINING THE CARTESIAN CO-ORDINATES OF
% THE I-TH POINT.
%
%
% TO CALL THE SUBROUTINE WRITE:
%
% CALL LPTAU(I,N,VECTOR)
% WHERE I, N: INTEGER CAPABLE OF STORING 2**30 (INTEGER*4 ON IBM
% OR OTHER 32 BIT/WORD MACHINES)
% VECTOR: DOUBLE PRECISION ARRAY WHOSE LENGTH < 52.
%
% INTEGER QP
% QP = QUANTITY POWER
%
% PARAMETER (MAXDIM=51, QP=30, MAXNUM=2**30-1)
MAXDIM=51; QP=30; MAXNUM=2^30-1;
%
% THE DIMENSION OF THE POINT CANNOT EXCEED MAXDIM
% THE TOTAL NUMBER OF GENERATED POINTS CANNOT EXCEED 2**QP
% MAXNUM=2**30-1 // 1073741823
%
% DOUBLE PRECISION VECTOR(N)
% INTEGER I,N
%
% INTEGER PRVNUM,PRVDIM
% INTEGER DIRECT(MAXDIM,QP), MASKV(MAXDIM)
% DOUBLE PRECISION SCALE
%
% Translated into MATLAB by M. Ratto
VECTOR=zeros(1,N);
SCALE =9.31322574615478516E-10;
persistent PRVNUM PRVDIM MASKV DIRECT
if isempty(PRVNUM), PRVNUM=-2; end,
if isempty(PRVDIM), PRVDIM=0; end,
if isempty(DIRECT), ...
DIRECT(1:MAXDIM,1)=[
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912]';
DIRECT(1:MAXDIM,2)=[
805306368, 268435456, 805306368, 268435456, 805306368, ...
268435456, 805306368, 268435456, 268435456, 805306368, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
805306368, 805306368, 268435456, 805306368, 268435456, ...
805306368, 268435456, 805306368, 268435456, 268435456, ...
805306368, 268435456, 805306368, 268435456, 805306368, ...
268435456, 805306368, 805306368, 268435456, 805306368, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
805306368, 268435456, 805306368, 805306368, 268435456, ...
805306368]';
DIRECT(1:MAXDIM,3)=[
939524096, 939524096, 134217728, 671088640, 402653184, ...
402653184, 671088640, 134217728, 671088640, 402653184, ...
939524096, 134217728, 671088640, 939524096, 134217728, ...
671088640, 134217728, 939524096, 939524096, 402653184, ...
402653184, 134217728, 671088640, 402653184, 671088640, ...
402653184, 402653184, 671088640, 134217728, 134217728, ...
939524096, 939524096, 939524096, 939524096, 134217728, ...
671088640, 402653184, 402653184, 671088640, 134217728, ...
671088640, 402653184, 939524096, 134217728, 671088640, ...
939524096, 134217728, 671088640, 134217728, 939524096, ...
939524096]';
DIRECT(1:MAXDIM,4)=[
1006632960, 67108864, 603979776, 1006632960, 335544320, ...
469762048, 872415232, 738197504, 469762048, 872415232, ...
1006632960, 67108864, 872415232, 469762048, 469762048, ...
469762048, 1006632960, 335544320, 872415232, 603979776, ...
201326592, 67108864, 335544320, 67108864, 201326592, ...
738197504, 1006632960, 738197504, 603979776, 335544320, ...
738197504, 67108864, 1006632960, 67108864, 603979776, ...
1006632960, 335544320, 469762048, 872415232, 738197504, ...
469762048, 872415232, 1006632960, 67108864, 872415232, ...
469762048, 469762048, 469762048, 1006632960, 335544320, ...
872415232]';
DIRECT(1:MAXDIM,5)=[
1040187392, 637534208, 1040187392, 838860800, 167772160, ...
234881024, 167772160, 1040187392, 436207616, 33554432, ...
570425344, 1040187392, 503316480, 838860800, 973078528, ...
167772160, 234881024, 436207616, 771751936, 100663296, ...
234881024, 905969664, 771751936, 33554432, 838860800, ...
973078528, 905969664, 33554432, 301989888, 838860800, ...
100663296, 234881024, 1040187392, 637534208, 1040187392, ...
838860800, 167772160, 234881024, 167772160, 1040187392, ...
436207616, 33554432, 570425344, 1040187392, 503316480, ...
838860800, 973078528, 167772160, 234881024, 436207616, ...
771751936]';
DIRECT(1:MAXDIM,6)=[
1056964608, 352321536, 50331648, 419430400, 956301312, ...
889192448, 620756992, 117440512, 956301312, 922746880, ...
822083584, 218103808, 587202560, 385875968, 452984832, ...
218103808, 184549376, 285212672, 150994944, 956301312, ...
352321536, 654311424, 553648128, 352321536, 788529152, ...
956301312, 587202560, 251658240, 218103808, 721420288, ...
251658240, 1056964608, 520093696, 889192448, 587202560, ...
956301312, 419430400, 352321536, 83886080, 654311424, ...
419430400, 385875968, 285212672, 754974720, 50331648, ...
922746880, 989855744, 754974720, 721420288, 822083584, ...
687865856]';
DIRECT(1:MAXDIM,7)=[
1065353216, 1065353216, 578813952, 25165824, 125829120, ...
964689920, 327155712, 310378496, 360710144, 360710144, ...
159383552, 444596224, 947912704, 662700032, 444596224, ...
528482304, 578813952, 578813952, 75497472, 1065353216, ...
92274688, 511705088, 897581056, 847249408, 662700032, ...
931135488, 411041792, 713031680, 696254464, 528482304, ...
209715200, 578813952, 1065353216, 1065353216, 578813952, ...
25165824, 125829120, 964689920, 327155712, 310378496, ...
360710144, 360710144, 159383552, 444596224, 947912704, ...
662700032, 444596224, 528482304, 578813952, 578813952, ...
75497472]';
DIRECT(1:MAXDIM,8)=[
1069547520, 4194304, 826277888, 624951296, 616562688, ...
801112064, 952107008, 406847488, 398458880, 331350016, ...
356515840, 46137344, 1010827264, 1069547520, 734003200, ...
113246208, 490733568, 633339904, 910163968, 801112064, ...
893386752, 851443712, 801112064, 918552576, 742391808, ...
499122176, 62914560, 264241152, 708837376, 717225984, ...
759169024, 499122176, 272629760, 423624704, 155189248, ...
239075328, 205520896, 943718400, 373293056, 457179136, ...
406847488, 71303168, 473956352, 54525952, 624951296, ...
104857600, 1019215872, 901775360, 213909504, 281018368, ...
851443712]';
DIRECT(1:MAXDIM,9)=[
1071644672, 543162368, 190840832, 329252864, 853540864, ...
132120576, 778043392, 73400320, 178257920, 522190848, ...
639631360, 534773760, 991952896, 333447168, 48234496, ...
1059061760, 761266176, 673185792, 220200960, 396361728, ...
362807296, 815792128, 819986432, 346030080, 39845888, ...
752877568, 387973120, 643825664, 291504128, 274726912, ...
568328192, 526385152, 673185792, 98566144, 396361728, ...
727711744, 1042284544, 106954752, 299892736, 912261120, ...
44040192, 895483904, 333447168, 551550976, 467664896, ...
618659840, 606076928, 274726912, 245366784, 446693376, ...
421527552]';
DIRECT(1:MAXDIM,10)=[
1072693248, 273678336, 644874240, 753926144, 495976448, ...
869269504, 355467264, 57671680, 816840704, 961544192, ...
804257792, 495976448, 347078656, 426770432, 1066401792, ...
372244480, 84934656, 208666624, 313524224, 598736896, ...
487587840, 965738496, 1011875840, 296747008, 393216000, ...
523239424, 720371712, 823132160, 128974848, 407896064, ...
747634688, 850395136, 873463808, 504365056, 481296384, ...
686817280, 592445440, 995098624, 498073600, 969932800, ...
586153984, 1039138816, 814743552, 523239424, 294649856, ...
305135616, 506462208, 11534336, 449839104, 619708416, ...
479199232]';
DIRECT(1:MAXDIM,11)=[
1073217536, 947388416, 1070071808, 977797120, 365428736, ...
702021632, 461897728, 829947904, 425197568, 634912768, ...
437780480, 582483968, 792199168, 315097088, 611844096, ...
667418624, 166199296, 513277952, 187170816, 1036517376, ...
25690112, 201850880, 443023360, 990380032, 63438848, ...
211288064, 983040000, 1069023232, 421003264, 742916096, ...
487063552, 363331584, 973602816, 286785536, 171442176, ...
669515776, 110624768, 383254528, 289931264, 352845824, ...
878182400, 655884288, 836239360, 765984768, 549978112, ...
655884288, 85458944, 591921152, 563609600, 277348352, ...
919076864]';
DIRECT(1:MAXDIM,12)=[
1073479680, 71565312, 2359296, 891551744, 158597120, ...
383516672, 1019478016, 947126272, 621019136, 714866688, ...
738459648, 265027584, 468975616, 131858432, 504627200, ...
581173248, 266600448, 865861632, 658243584, 546045952, ...
521404416, 304873472, 1060896768, 163840000, 305922048, ...
257163264, 50069504, 773062656, 59506688, 779354112, ...
165937152, 587988992, 486801408, 160694272, 90439680, ...
423362560, 536608768, 614203392, 56885248, 999030784, ...
10747904, 764674048, 25952256, 989069312, 352583680, ...
799801344, 261357568, 873201664, 40108032, 769392640, ...
254541824]';
DIRECT(1:MAXDIM,13)=[
1073610752, 644218880, 538836992, 455475200, 1062600704, ...
139329536, 205651968, 905052160, 797048832, 452329472, ...
973471744, 627703808, 614072320, 803078144, 637403136, ...
835059712, 949878784, 662044672, 767950848, 426901504, ...
448659456, 23986176, 1016201216, 524943360, 525991936, ...
618790912, 781058048, 761659392, 458096640, 226361344, ...
950665216, 952500224, 516030464, 337510400, 496107520, ...
830865408, 944111616, 636354560, 978452480, 921567232, ...
533594112, 7471104, 678035456, 471203840, 1065746432, ...
575275008, 996540416, 909246464, 879362048, 637927424, ...
25821184]';
DIRECT(1:MAXDIM,14)=[
1073676288, 357892096, 808648704, 2424832, 2555904, ...
624230400, 69271552, 456851456, 1052966912, 600637440, ...
487260160, 794624000, 386727936, 467599360, 798031872, ...
630652928, 340983808, 493944832, 37945344, 264175616, ...
263520256, 833421312, 235077632, 464846848, 534839296, ...
992411648, 10813440, 367067136, 116457472, 115015680, ...
928710656, 619773952, 813760512, 1043398656, 967770112, ...
912850944, 72155136, 1009057792, 668532736, 462356480, ...
267321344, 795803648, 635764736, 574160896, 1003421696, ...
181075968, 56688640, 388562944, 190906368, 657915904, ...
474939392]';
DIRECT(1:MAXDIM,15)=[
1073709056, 1073709056, 137003008, 547782656, 545095680, ...
26836992, 34701312, 354385920, 925663232, 656965632, ...
327581696, 894795776, 110067712, 1038057472, 209354752, ...
596541440, 42631168, 471433216, 52527104, 666861568, ...
706707456, 674070528, 824410112, 305496064, 136282112, ...
847740928, 531464192, 222920704, 379289600, 507740160, ...
11894784, 1053392896, 129990656, 557547520, 666468352, ...
1061912576, 576684032, 1041334272, 380469248, 114196480, ...
133070848, 517046272, 129990656, 790396928, 563773440, ...
388333568, 661749760, 446791680, 737378304, 229998592, ...
348225536]';
DIRECT(1:MAXDIM,16)=[
1073725440, 16384, 605372416, 275234816, 817971200, ...
603963392, 555335680, 721534976, 997801984, 1028767744, ...
407060480, 375275520, 256688128, 1021165568, 303349760, ...
1022476288, 234143744, 106708992, 732971008, 733954048, ...
789889024, 879575040, 764657664, 762658816, 1010843648, ...
941080576, 827932672, 98942976, 1051738112, 624934912, ...
993280000, 134070272, 201375744, 567558144, 882163712, ...
649084928, 356564992, 489439232, 637091840, 60637184, ...
199278592, 815677440, 927678464, 94519296, 419184640, ...
933838848, 426655744, 911130624, 171393024, 561332224, ...
471613440]';
DIRECT(1:MAXDIM,17)=[
1073733632, 536895488, 1043685376, 679944192, 417505280, ...
301981696, 832561152, 210542592, 167501824, 1071341568, ...
229302272, 970661888, 732176384, 576659456, 402464768, ...
451584000, 368467968, 928260096, 933847040, 29319168, ...
582934528, 772612096, 330014720, 647323648, 174071808, ...
1008689152, 295919616, 353869824, 177774592, 580198400, ...
381837312, 638574592, 637558784, 679370752, 504012800, ...
747118592, 429973504, 1032609792, 932667392, 583360512, ...
969498624, 1056333824, 660955136, 247488512, 153509888, ...
242180096, 205840384, 797499392, 824565760, 234348544, ...
842326016]';
DIRECT(1:MAXDIM,18)=[
1073737728, 268455936, 52785152, 1020628992, 345018368, ...
452972544, 704442368, 255987712, 750759936, 697692160, ...
196677632, 764604416, 485625856, 522022912, 680620032, ...
362270720, 838103040, 83972096, 629133312, 46108672, ...
867561472, 725422080, 184504320, 751112192, 191918080, ...
306425856, 507310080, 30453760, 281858048, 604000256, ...
208662528, 319557632, 318779392, 476139520, 863719424, ...
567062528, 521179136, 712790016, 610299904, 293687296, ...
1023086592, 549089280, 1065242624, 707751936, 363024384, ...
16674816, 197136384, 1037561856, 195112960, 372707328, ...
992751616]';
DIRECT(1:MAXDIM,19)=[
1073739776, 939554816, 580732928, 854333440, 172619776, ...
511694848, 936142848, 518199296, 593348608, 225527808, ...
900982784, 180279296, 168904704, 62814208, 754485248, ...
730691584, 1005996032, 411174912, 249866240, 641669120, ...
1008719872, 749066240, 860993536, 94177280, 432564224, ...
226355200, 925784064, 995657728, 967731200, 436226048, ...
913799168, 549894144, 964696064, 843315200, 445863936, ...
1047422976, 548947968, 492066816, 953870336, 1002653696, ...
861440000, 385636352, 325253120, 187353088, 653584384, ...
1008269312, 748693504, 1013016576, 55814144, 255170560, ...
260708352]';
DIRECT(1:MAXDIM,20)=[
1073740800, 67126272, 829514752, 423777280, 968297472, ...
205511680, 147076096, 926669824, 202300416, 118395904, ...
381332480, 1002738688, 743042048, 292551680, 584567808, ...
284339200, 183936000, 616762368, 435221504, 159376384, ...
907322368, 595696640, 247497728, 553735168, 826051584, ...
564454400, 446024704, 214236160, 33661952, 251685888, ...
660327424, 284244992, 859868160, 722502656, 622844928, ...
324342784, 682374144, 400579584, 405353472, 605187072, ...
840682496, 212956160, 157891584, 193201152, 437990400, ...
573578240, 368053248, 580197376, 937905152, 565527552, ...
89064448]';
DIRECT(1:MAXDIM,21)=[
1073741312, 637560320, 189496832, 27474432, 129338880, ...
908054016, 641870336, 186375680, 302677504, 763663872, ...
103878144, 325187072, 858254848, 922041856, 261924352, ...
954978816, 292822528, 849512960, 210311680, 933232128, ...
691981824, 155417088, 627070464, 416795136, 182081024, ...
513433088, 848658944, 515770880, 627273216, 629169664, ...
414566912, 147450368, 698353152, 244844032, 226578944, ...
1020087808, 886978048, 389697024, 1007004160, 839646720, ...
621924864, 549962240, 609583616, 735976960, 87342592, ...
1058542080, 163066368, 307997184, 876471808, 794280448, ...
675386880]';
DIRECT(1:MAXDIM,22)=[
1073741568, 352343296, 644236032, 636735232, 615860480, ...
959444224, 287380736, 1007410432, 890187008, 399480576, ...
520092928, 643311360, 816901376, 695310080, 1019229440, ...
77034240, 733295872, 1035127552, 986582784, 332381952, ...
334852352, 364956416, 596672256, 800381696, 480316672, ...
574863104, 647347968, 702910208, 499965184, 364968704, ...
120862976, 1023256320, 995114240, 13951232, 32520448, ...
702127360, 45176064, 444945664, 237860096, 152839936, ...
530633984, 429135616, 267272448, 884808960, 933712640, ...
61605632, 174335744, 564911360, 302327552, 650589440, ...
450649344]';
DIRECT(1:MAXDIM,23)=[
1073741696, 1065385856, 1073734272, 331949184, 842310784, ...
799537536, 965852032, 369351808, 662886016, 86119808, ...
865109888, 299633792, 422735488, 181087360, 174252416, ...
1041212544, 840196224, 750314368, 391053440, 903306880, ...
742365312, 236995200, 42492800, 946000512, 771692416, ...
897405824, 613803136, 924258688, 808338304, 1038125440, ...
683814272, 177186176, 766008960, 704549248, 194555008, ...
306383744, 496592512, 416020864, 655186816, 1032204928, ...
694773632, 577910144, 45797760, 910332544, 536014976, ...
675946368, 987635840, 788223872, 353993856, 96313472, ...
85248640]';
DIRECT(1:MAXDIM,24)=[
1073741760, 4210752, 12608, 744788544, 494377792, ...
115601344, 769248448, 990895808, 851706304, 979326784, ...
692061120, 429015104, 217132864, 736067008, 55694400, ...
456152640, 631601984, 787264192, 898599104, 478383808, ...
507774272, 458270272, 392995136, 872482496, 124824768, ...
1034161344, 362141632, 1053833280, 943810496, 428920128, ...
795835200, 835462848, 961843520, 606198080, 785652672, ...
154954432, 491617344, 297351232, 580735552, 634587968, ...
185277760, 141505600, 417673280, 106907456, 395575616, ...
566958656, 352651200, 415242688, 26635200, 1030317504, ...
247212992]';
DIRECT(1:MAXDIM,25)=[
1073741792, 543187040, 536882016, 981766752, 357858144, ...
810665952, 369083488, 613015520, 86115232, 845149216, ...
606076960, 1018241504, 35245536, 635403744, 236633696, ...
407451232, 427671904, 460141792, 116344544, 990246688, ...
1024892576, 883429408, 150655392, 173476896, 197666464, ...
1016740448, 605376608, 970487008, 1006881248, 598265632, ...
1022861728, 489055392, 216680608, 371439072, 53140576, ...
965114400, 98534112, 209692256, 264598496, 321437280, ...
545303840, 324119904, 876587488, 778239712, 802033120, ...
44406496, 665829024, 803213920, 309742112, 735181344, ...
1036125600]';
DIRECT(1:MAXDIM,26)=[
1073741808, 273698896, 805312112, 903123536, 153504624, ...
689632208, 432848944, 859888752, 510853776, 240805744, ...
250610192, 852489168, 139460144, 283082224, 222702928, ...
342181488, 922872432, 187528656, 360637424, 814514736, ...
301037840, 800872624, 272595184, 158627600, 238839088, ...
927181136, 710248688, 788854608, 1048376560, 484709072, ...
85709008, 1065469744, 429237328, 490778384, 848024144, ...
443114288, 687907504, 474573648, 45706416, 681465296, ...
805303216, 14567920, 369839504, 440402480, 797652624, ...
115959088, 929784560, 91226544, 205943056, 288358704, ...
950217296]';
DIRECT(1:MAXDIM,27)=[
1073741816, 947419256, 134232008, 460100200, 1073685336, ...
398354904, 1069834248, 686054696, 108299224, 273898840, ...
731382552, 938170664, 86812552, 677346808, 602208712, ...
652635752, 209797064, 323968376, 384078968, 561178056, ...
923399256, 996597176, 942777416, 885167400, 89791048, ...
956122504, 87393464, 987661336, 993412952, 827749496, ...
903211272, 33649816, 594875176, 65052056, 822835240, ...
625704888, 1065374584, 612232920, 536299720, 1046858504, ...
939518840, 160843032, 654656088, 744496936, 872197704, ...
219111576, 829112632, 455614152, 1064192952, 313010856, ...
820754920]';
DIRECT(1:MAXDIM,28)=[
1073741820, 71582788, 603989028, 37500, 120660, ...
182195932, 213921796, 473570692, 41763004, 156352828, ...
88343188, 698012780, 666108868, 337608156, 1054329884, ...
799472220, 641885244, 392104980, 502284340, 1002405628, ...
249907140, 75586228, 206587660, 565275348, 1021426548, ...
425987996, 598058580, 401940420, 919427316, 822049324, ...
115655868, 759299588, 562394644, 990942164, 1003212268, ...
598750292, 675334852, 675293340, 445665316, 903023756, ...
872412692, 172640916, 1051615436, 91229620, 94586692, ...
344873452, 7029156, 683421900, 434258804, 955002092, ...
436424380]';
DIRECT(1:MAXDIM,29)=[
1073741822, 644245094, 1040195102, 537039474, 537089354, ...
642656334, 73402402, 664239174, 1014620426, 500917234, ...
1042677826, 347788318, 1069154738, 373259762, 362587674, ...
239395914, 132283950, 903121466, 445210638, 968851198, ...
230153254, 935549622, 308815630, 861891286, 496995094, ...
670740382, 657311830, 573565382, 248331478, 1064650798, ...
338312798, 669059078, 1065190902, 379125622, 111897166, ...
520650422, 740300390, 1046483950, 66254898, 992513134, ...
234871606, 610553330, 450553866, 566758134, 787800806, ...
1071709866, 971732606, 528102354, 790919122, 917384366, ...
656244162]';
DIRECT(1:MAXDIM,30)=[
1073741823, 357913941, 50344755, 268538457, 805540473, ...
3487029, 3146769, 592038967, 729591963, 781578389, ...
66781679, 113956361, 331153483, 967802327, 935343371, ...
324351309, 609305915, 818137857, 131059769, 918519549, ...
827341719, 922770101, 456972047, 363883221, 1057014661, ...
900956063, 580478293, 520383687, 315470533, 227601711, ...
169598765, 909227271, 796983815, 349496709, 393974911, ...
378320037, 777004343, 927999269, 616377385, 345930959, ...
989849787, 627400495, 892675125, 260314121, 1041964063, ...
531367163, 195776757, 237309785, 949187605, 719002587, ...
495745187]';
end
%
% TRAP FOR A WRONG SUBROUTINE CALL
%
if ((I<0) | (N<1) | (I>MAXNUM) | (N>MAXDIM)),
disp('LP-TAU CALL FAILED')
disp(' PRESS <ENTER> TO EXIT LPTAU')
pause
return
end
if ((PRVNUM+1==I) & (N<=PRVDIM)),
%
% RECURRENT GENERATION OF THE POINT
%
%
% SEARCH POSITION OF THE RIGHTMOST "1"
% IN THE BINARY REPRESENTATION OF I
%
L=0;
POS=0;
while L<QP & POS==0,
L=L+1;
POS=bitand(bitshift(I,-(L-1)),1);
end
%
% RIGHTMOST POSITION IS L
%
for J=1:N
MASKV(J)=bitxor(MASKV(J),DIRECT(J,L));
VECTOR(J)=MASKV(J)*SCALE;
end
else
%
% GENERATION OF THE POINT FROM "I" AND "N"
%
MASKV=zeros(1,N);
IM=bitxor(I,bitshift(I,-1));
M=0;
while IM~=0 & M<QP,
M=M+1;
if (bitand(IM,1)==1),
for J=1:N
MASKV(J)=bitxor(MASKV(J),DIRECT(J,M));
end
end
IM=bitshift(IM,-1);
end
for J=1:N
VECTOR(J)=MASKV(J)*SCALE;
end
end
%
PRVNUM=I;
PRVDIM=N;
return

View File

@ -1,130 +0,0 @@
function [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group)
% [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group)
%
% Given the Morris sample matrix, the output values and the group matrix compute the Morris measures
% -------------------------------------------------------------------------
% INPUTS
% -------------------------------------------------------------------------
% Group [NumFactor, NumGroups] := Matrix describing the groups.
% Each column represents one group.
% The element of each column are zero if the factor is not in the
% group. Otherwise it is 1.
% Sample := Matrix of the Morris sampled trajectories
% Output := Matrix of the output(s) values in correspondence of each point
% of each trajectory
% k = Number of factors
% -------------------------------------------------------------------------
% OUTPUTS
% OutMatrix (NumFactor*NumOutputs, 3)= [Mu*, Mu, StDev]
% for each output it gives the three measures of each factor
% -------------------------------------------------------------------------
if nargin==0,
disp(' ')
disp('[SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group);')
return
end
OutMatrix=[];
if nargin < 5, Group=[]; end
NumGroups = size(Group,2);
if nargin < 4 | isempty(p),
p = 4;
end
Delt = p/(2*p-2);
if NumGroups ~ 0
sizea = NumGroups; % Number of groups
GroupMat=Group;
GroupMat = GroupMat';
else
sizea = NumFact;
end
r=size(Sample,1)/(sizea+1); % Number of trajectories
% For Each Output
for k=1:size(Output,2)
OutValues=Output(:,k);
% For each r trajectory
for i=1:r
% For each step j in the trajectory
% Read the orientation matrix fact for the r-th sampling
% Read the corresponding output values
Single_Sample = Sample(i+(i-1)*sizea:i+(i-1)*sizea+sizea,:);
Single_OutValues = OutValues(i+(i-1)*sizea:i+(i-1)*sizea+sizea,:);
A = (Single_Sample(2:sizea+1,:)-Single_Sample(1:sizea,:))';
Delta = A(find(A));
% For each point of the fixed trajectory compute the values of the Morris function. The function
% is partitioned in four parts, from order zero to order 4th.
for j=1:sizea % For each point in the trajectory i.e for each factor
% matrix of factor which changes
if NumGroups ~ 0;
AuxFind (:,1) = A(:,j);
% AuxFind(find(A(:,j)),1)=1;
% Pippo = sum((Group - repmat(AuxFind,1,NumGroups)),1);
% Change_factor(j,i) = find(Pippo==0);
Change_factor = find(abs(AuxFind)>1e-010);
% If we deal with groups we can only estimate the new mu*
% measure since factors in the same groups can move in
% opposite direction and the definition of the standard
% Morris mu cannopt be applied.
% In the new version the elementary effect is defined with
% the absolute value.
%SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3));
SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt);
else
Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:));
% If no groups --> we compute both the original and
% modified measure
if Delta(j) > 0 %=> +Delta
SAmeas(Change_factor(j,i),i) = (Single_OutValues(j+1) - Single_OutValues(j) )/Delt; %(2/3);
else %=> -Delta
SAmeas(Change_factor(j,i),i) = (Single_OutValues(j) - Single_OutValues(j+1) )/Delt; %(2/3);
end
end
end %for j=1:sizea
end %for i=1:r
if NumGroups ~ 0
SAmeas = SAmeas';
end
% Compute Mu AbsMu and StDev
if any(any(isnan(SAmeas)))
for j=1:NumFact,
SAm = SAmeas(j,:);
SAm = SAm(find(~isnan(SAm)));
rr=length(SAm);
AbsMu(j,1) = sum(abs(SAm),2)/rr;
if NumGroups == 0
Mu(j,1) = sum(SAm,2)/rr;
StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5;
end
end
else
AbsMu = sum(abs(SAmeas),2)/r;
if NumGroups == 0
Mu = sum(SAmeas,2)/r;
StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5;
end
end
% Define the output Matrix - if we have groups we cannot define the old
% measure mu, only mu* makes sense
if NumGroups > 0
OutMatrix = [OutMatrix; AbsMu];
else
OutMatrix = [OutMatrix; AbsMu, Mu, StDev];
end
end % For Each Output

View File

@ -1,174 +0,0 @@
function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
% Inputs: k (1,1) := number of factors examined or number of groups examined.
% In case the groups are chosen the number of factors is stores in NumFact and
% sizea becomes the number of created groups.
% NumFact (1,1) := number of factors examined in the case when groups are chosen
% r (1,1) := sample size
% p (1,1) := number of intervals considered in [0, 1]
% UB(sizea,1) := Upper Bound for each factor
% LB(sizea,1) := Lower Bound for each factor
% GroupNumber(1,1) := Number of groups (eventually 0)
% GroupMat(NumFact,GroupNumber):= Matrix which describes the chosen groups. Each column represents a group and its elements
% are set to 1 in correspondence of the factors that belong to the fixed group. All
% the other elements are zero.
% Local Variables:
% sizeb (1,1) := sizea+1
% sizec (1,1) := 1
% randmult (sizea,1) := vector of random +1 and -1
% perm_e(1,sizea) := vector of sizea random permutated indeces
% fact(sizea) := vector containing the factor varied within each traj
% DDo(sizea,sizea) := D* in Morris, 1991
% A(sizeb,sizea) := Jk+1,k in Morris, 1991
% B(sizeb,sizea) := B in Morris, 1991
% Po(sizea,sizea) := P* in Morris, 1991
% Bo(sizeb,sizea) := B* in Morris, 1991
% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991
% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory)
% In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory
% of k step in the parameter space and it provides a single elementary
% effect per factor
% MyInt()
% Fact(sizea,1) := for each loop vector indicating which factor or group of factors has been changed
% in each step of the trajectory
% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design
% for single factor analysis, while it constitutes an intermediate step for the group analysis.
%
% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices
% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors
%
% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine
% follows the following steps:
% 1- Creation of P0 and DD0 matrices defined in Morris for the groups. This means that the dimensions of these
% 2 matrices are (GroupNumber,GroupNumber).
% 2- Creation of AuxMat matrix with (GroupNumber+1,GroupNumber) elements.
% 3- Definition of GroupB0 starting from AuxMat, GroupMat and P0.
% 4- The final B0 for groups is obtained as [ones(sizeb,1)*x0' + GroupB0]. The P0 permutation is present in GroupB0
% and it's not necessary to permute the matrix (ones(sizeb,1)*x0') because it's already randomly created.
% Reference:
% A. Saltelli, K. Chan, E.M. Scott, "Sensitivity Analysis" on page 68 ss
%
% F. Campolongo, J. Cariboni, JRC - IPSC Ispra, Varese, IT
% Last Update: 15 November 2005 by J.Cariboni
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters and initialisation of the output matrix
sizea = k;
Delta = p/(2*p-2);
%Delta = 1/3
NumFact = sizea;
GroupNumber = size(GroupMat,2);
if GroupNumber ~ 0;
sizea = size(GroupMat,2);
end
sizeb = sizea + 1;
sizec = 1;
Outmatrix = [];
OutFact = [];
% For each i generate a trajectory
for i=1:r
% Construct DD0 - OLD VERSION - it does not need communication toolbox
% RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0).
% Note that DD0 tells if the factor have to be increased or ddecreased
% by Delta.
randmult = ones(k,1);
v = rand(k,1);
randmult (find(v < 0.5))=-1;
randmult = repmat(randmult,1,k);
DD0 = randmult .* eye(k);
% Construct DD0 - NEW VERSION - it needs communication toolbox
% randsrc(m) generates an m-by-m matrix, each of whose entries independently takes the value -1 with probability 1/2,
% and 1 with probability 1/2.
% DD0 = randsrc(NumFact) .* eye(NumFact);
% Construct B (lower triangular)
B = ones(sizeb,sizea);
for j = 1:sizea
B(1:j,j)=0;
end
% Construct A0, A
A0 = ones(sizeb,1);
A = ones(sizeb,NumFact);
% Construct the permutation matrix P0. In each column of P0 one randomly chosen element equals 1
% while all the others equal zero.
% P0 tells the order in which order factors are changed in each
% trajectory. P0 is created as it follows:
% 1) All the elements of P0 are set equal to zero ==> P0 = zeros (sizea, sizea);
% 2) The function randperm create a random permutation of integer 1:sizea, without repetitions ==> perm_e;
% 3) In each column of P0 the element indicated in perm_e is set equal to one.
% Note that P0 is then used reading it by rows.
P0 = zeros (sizea, sizea);
perm_e = randperm(sizea); % RANDPERM(n) is a random permutation of the integers from 1 to n.
for j = 1:sizea
P0(perm_e(j),j) = 1;
end
% When groups are present the random permutation is done only on B. The effect is the same since
% the added part (A0*x0') is completely random.
if GroupNumber ~ 0
B = B * (GroupMat*P0')';
end
% Compute AuxMat both for single factors and groups analysis. For Single factors analysis
% AuxMat is added to (A0*X0) and then permutated through P0. When groups are active AuxMat is
% used to build GroupB0. AuxMat is created considering DD0. If the element on DD0 diagonal
% is 1 then AuxMat will start with zero and add Delta. If the element on DD0 diagonal is -1
% then DD0 will start Delta and goes to zero.
AuxMat = Delta*0.5*((2*B - A) * DD0 + A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube
% [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]
MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors
% OLD VERSION - it needs communication toolbox
% w = randint(NumFact,1,[1,size(MyInt,2)]);
% NEW VERSION - construct a version of random integers
% 1) create a vector of random integers
% 2) divide [0,1] into the needed steps
% 3) check in which interval the random numbers fall
% 4) generate the corresponding integer
v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1)
IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2)
DiffAuxVec = IntUsed - v; % 3)
for ii = 1:size(DiffAuxVec,1)
w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4)
end
x0 = MyInt(1,w)'; % Define x0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a
% trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors)
if GroupNumber ~ 0
B0 = (A0*x0' + AuxMat);
else
B0 = (A0*x0' + AuxMat)*P0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% c --> Compute values in the original intervals
% B0 has values x(i,j) in [0, 1/(p -1), 2/(p -1), ... , 1].
% To obtain values in the original intervals [LB, UB] we compute
% LB(j) + x(i,j)*(UB(j)-LB(j))
In = repmat(LB,1,sizeb)' + B0 .* repmat((UB-LB),1,sizeb)';
% Create the Factor vector. Each component of this vector indicate which factor or group of factor
% has been changed in each step of the trajectory.
for j=1:sizea
Fact(1,j) = find(P0(j,:));
end
Fact(1,sizea+1) = 0;
Outmatrix = [Outmatrix; In];
OutFact = [OutFact; Fact'];
end

View File

@ -1,38 +0,0 @@
function x = beta_inv(p, a, b)
% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution
%--------------------------------------------------------------
% USAGE: x = beta_inv(p,a,b)
% where: p = vector of probabilities
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%--------------------------------------------------------------
% RETURNS: x at each element of p for the beta(a,b) distribution
%--------------------------------------------------------------
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%--------------------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~= 3)
error('Wrong # of arguments to beta_inv');
end
if any(any((a<=0)|(b<=0)))
error('beta_inv parameter a or b is nonpositive');
end
if any(any(abs(2*p-1)>1))
error('beta_inv: A probability should be 0<=p<=1');
end
x = a ./ (a+b);
dx = 1;
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (betainc(x,a,b) - p) ./ beta_pdf(x,a,b);
x = x - dx;
x = x + (dx - x) / 2 .* (x<0);
end

View File

@ -1,32 +0,0 @@
function pdf = beta_pdf(x, a, b)
% PURPOSE: pdf of the beta(a,b) distribution
%--------------------------------------------------------------
% USAGE: pdf = beta_pdf(x,a,b)
% where: x = vector of components
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%--------------------------------------------------------------
% RETURNS: pdf at each element of x of the beta(a,b) distribution
%--------------------------------------------------------------
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%--------------------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~=3)
error('Wrong # of arguments to beta_pdf');
end
if any(any((a<=0)|(b<=0)))
error('Parameter a or b is nonpositive');
end
I = find((x<0)|(x>1));
pdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b);
pdf(I) = 0*I;

View File

@ -1,14 +0,0 @@
function h = cumplot(x);
%function h =cumplot(x)
% Copyright (C) 2005 Marco Ratto
n=length(x);
x=[-inf; sort(x); Inf];
y=[0:n n]./n;
h0 = stairs(x,y);
grid on,
if nargout,
h=h0;
end

View File

@ -1,30 +0,0 @@
function c = dat_fil_(data_file);
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
try
eval(data_file);
catch
load(data_file);
end
clear data_file;
a=who;
for j=1:length(a)
eval(['c.',a{j},'=',a{j},';']);
end

View File

@ -1,142 +0,0 @@
function dynare_MC(var_list_,OutDir)
%
% Adapted by M. Ratto from dynare_estimation.m and posteriorsmoother.m
% (dynare_estimation.m and posteriorsmoother.m are part of DYNARE,
% copyright M. Juillard)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ options_ oo_ estim_params_
global bayestopt_
if options_.filtered_vars ~= 0 & options_.filter_step_ahead == 0
options_.filter_step_ahead = 1;
end
if options_.filter_step_ahead ~= 0
options_.nk = max(options_.filter_step_ahead);
else
options_.nk = 0;
end
nvx = estim_params_.nvx;
nvn = estim_params_.nvn;
ncx = estim_params_.ncx;
ncn = estim_params_.ncn;
np = estim_params_.np ;
npar = nvx+nvn+ncx+ncn+np;
if isempty(options_.datafile)
error('ESTIMATION: datafile option is missing')
end
if isempty(options_.varobs)
error('ESTIMATION: VAROBS is missing')
end
%% Read and demean data
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1);
gend = options_.nobs;
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
if options_.loglinear == 1 & ~options_.logdata
rawdata = log(rawdata);
end
if options_.prefilter == 1
bayestopt_.mean_varobs = mean(rawdata,1);
data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs);
else
data = transpose(rawdata);
end
if ~isreal(rawdata)
error(['There are complex values in the data. Probably a wrong' ...
' transformation'])
end
offset = npar-np;
fname_=M_.fname;
options_ = set_default_option(options_,'opt_gsa',1);
options_gsa_ = options_.opt_gsa;
if options_gsa_.pprior,
namfile=[fname_,'_prior'];
else
namfile=[fname_,'_mc'];
end
load([OutDir,'\',namfile],'lpmat', 'lpmat0', 'istable')
% load(options_.mode_file)
%%
%%
%%
x=[lpmat0(istable,:) lpmat(istable,:)];
clear lpmat lpmat0 istable %iunstable egg yys T
B = size(x,1);
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(x(1,:)',gend,data);
n1=size(atT,1);
nfil=B/40;
stock_smooth = zeros(M_.endo_nbr,gend,40);
stock_filter = zeros(M_.endo_nbr,gend+1,40);
stock_ys = zeros(40, M_.endo_nbr);
logpo2=zeros(B,1);
%%
h = waitbar(0,'MC smoother ...');
delete([OutDir,'\',namfile,'_*.mat'])
ib=0;
ifil=0;
opt_gsa=options_.opt_gsa;
for b=1:B
ib=ib+1;
deep = x(b,:)';
set_all_parameters(deep);
dr = resol(oo_.steady_state,0);
%deep(1:offset) = xparam1(1:offset);
logpo2(b,1) = DsgeLikelihood(deep,gend,data);
if opt_gsa.lik_only==0,
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(deep,gend,data);
stock_smooth(:,:,ib)=atT(1:M_.endo_nbr,:);
% stock_filter(:,:,ib)=filtered_state_vector(1:M_.endo_nbr,:);
stock_filter(:,:,ib)=aK(1,1:M_.endo_nbr,:);
stock_ys(ib,:)=ys';
if ib==40,
ib=0;
ifil=ifil+1;
save([OutDir,'\',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys')
stock_smooth = zeros(M_.endo_nbr,gend,40);
stock_filter = zeros(M_.endo_nbr,gend+1,40);
stock_ys = zeros(40, M_.endo_nbr);
end
end
waitbar(b/B,h,['MC smoother ...',num2str(b),'/',num2str(B)]);
end
close(h)
if opt_gsa.lik_only==0,
if ib>0,
ifil=ifil+1;
stock_smooth = stock_smooth(:,:,1:ib);
stock_filter = stock_filter(:,:,1:ib);
stock_ys = stock_ys(1:ib,:);
save([OutDir,'\',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys')
end
end
stock_gend=gend;
stock_data=data;
save([OutDir,'\',namfile],'x','logpo2','stock_gend','stock_data','-append')

View File

@ -1,708 +0,0 @@
function [rmse_MC, ixx] = filt_mc_(OutDir)
% function [rmse_MC, ixx] = filt_mc_(OutDir)
% copyright Marco Ratto 2006
% inputs (from opt_gsa structure)
% vvarvecm = options_gsa_.var_rmse;
% loadSA = options_gsa_.load_rmse;
% pfilt = options_gsa_.pfilt_rmse;
% alpha = options_gsa_.alpha_rmse;
% alpha2 = options_gsa_.alpha2_rmse;
% istart = options_gsa_.istart_rmse;
% alphaPC = 0.5;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global bayestopt_ estim_params_ M_ options_ oo_
options_gsa_=options_.opt_gsa;
vvarvecm = options_gsa_.var_rmse;
loadSA = options_gsa_.load_rmse;
pfilt = options_gsa_.pfilt_rmse;
alpha = options_gsa_.alpha_rmse;
alpha2 = options_gsa_.alpha2_rmse;
istart = options_gsa_.istart_rmse;
alphaPC = 0.5;
fname_ = M_.fname;
lgy_ = M_.endo_names;
dr_ = oo_.dr;
disp(' ')
disp(' ')
disp('Starting sensitivity analysis')
disp('for the fit of EACH observed series ...')
disp(' ')
disp('Deleting old SA figures...')
a=dir([OutDir,'\*.*']);
tmp1='0';
if options_.opt_gsa.ppost,
tmp=['_rmse_post'];
else
if options_.opt_gsa.pprior
tmp=['_rmse_prior'];
else
tmp=['_rmse_mc'];
end
if options_gsa_.lik_only,
tmp1 = [tmp,'_post_SA'];
tmp = [tmp,'_lik_SA'];
end
end
for j=1:length(a),
if strmatch([fname_,tmp],a(j).name),
disp(a(j).name)
delete([OutDir,'\',a(j).name])
end,
if strmatch([fname_,tmp1],a(j).name),
disp(a(j).name)
delete([OutDir,'\',a(j).name])
end,
end
disp('done !')
nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn;
npar=estim_params_.np;
if ~isempty(options_.mode_file),
load(options_.mode_file,'xparam1'),
end
if options_.opt_gsa.ppost,
c=load([fname_,'_mean'],'xparam1');
xparam1_mean=c.xparam1;
clear c
elseif ~isempty(options_.mode_file) & ~isempty(ls([fname_,'_mean.mat']))
c=load([fname_,'_mean'],'xparam1');
xparam1_mean=c.xparam1;
clear c
end
if options_.opt_gsa.ppost,
fnamtmp=[fname_,'_post'];
DirectoryName = CheckPath('metropolis');
else
if options_.opt_gsa.pprior
fnamtmp=[fname_,'_prior'];
else
fnamtmp=[fname_,'_mc'];
end
end
if ~loadSA,
if exist('xparam1','var')
set_all_parameters(xparam1);
steady_;
ys_mode=oo_.steady_state;
end
if exist('xparam1_mean','var')
set_all_parameters(xparam1_mean);
steady_;
ys_mean=oo_.steady_state;
end
% eval(options_.datafile)
obs = dat_fil_(options_.datafile);
if ~options_.opt_gsa.ppost
load([OutDir,'\',fnamtmp],'x','logpo2','stock_gend','stock_data');
logpo2=-logpo2;
else
%load([DirectoryName '/' M_.fname '_data.mat']);
[stock_gend, stock_data] = read_data;
filfilt = dir([DirectoryName '/' M_.fname '_filter*.mat']);
filparam = dir([DirectoryName '/' M_.fname '_param*.mat']);
x=[];
logpo2=[];
sto_ys=[];
for j=1:length(filparam),
%load([DirectoryName '/' M_.fname '_param',int2str(j),'.mat']);
if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name))
load([DirectoryName '/' filparam(j).name]);
x=[x; stock];
logpo2=[logpo2; stock_logpo];
sto_ys=[sto_ys; stock_ys];
clear stock stock_logpo stock_ys;
end
end
end
nruns=size(x,1);
nfilt=floor(pfilt*nruns);
if options_.opt_gsa.ppost | (options_.opt_gsa.ppost==0 & options_.opt_gsa.lik_only==0)
disp(' ')
disp('Computing RMSE''s...')
fobs = options_.first_obs;
nobs=options_.nobs;
for i=1:size(vvarvecm,1),
vj=deblank(vvarvecm(i,:));
eval(['vobs =obs.',vj,'(fobs:fobs-1+nobs);'])
if options_.prefilter == 1
%eval([vj,'=',vj,'-bayestopt_.mean_varobs(i);'])
%eval([vj,'=',vj,'-mean(',vj,',1);'])
vobs = vobs-mean(vobs,1);
end
jxj = strmatch(vj,lgy_(dr_.order_var,:),'exact');
js = strmatch(vj,lgy_,'exact');
if exist('xparam1','var')
% if isfield(oo_,'FilteredVariables')
% eval(['rmse_mode(i) = sqrt(mean((vobs(istart:end)-oo_.steady_state(js)-oo_.FilteredVariables.',vj,'(istart:end-1)).^2));'])
% else
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,stock_gend,stock_data);
y0 = squeeze(aK(1,jxj,:)) + ...
kron(ys_mode(js,:),ones(size(aK,3),1));
% y0 = ahat(jxj,:)' + ...
% kron(ys_mode(js,:),ones(size(ahat,2),1));
rmse_mode(i) = sqrt(mean((vobs(istart:end)-y0(istart:length(vobs))).^2));
% end
end
y0=zeros(nobs+1,nruns);
if options_.opt_gsa.ppost
%y0=zeros(nobs+max(options_.filter_step_ahead),nruns);
nbb=0;
for j=1:length(filfilt),
load([DirectoryName '/' M_.fname '_filter_step_ahead',num2str(j),'.mat']);
nb = size(stock,4);
% y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,:,:)) + ...
% kron(sto_ys(nbb+1:nbb+nb,js)',ones(size(stock,3),1));
y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,1:nobs+1,:)) + ...
kron(sto_ys(nbb+1:nbb+nb,js)',ones(nobs+1,1));
%y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock;
nbb=nbb+nb;
clear stock;
end
else
filfilt=ls([OutDir,'\',fnamtmp,'_*.mat']);
nbb=0;
for j=1:size(filfilt,1),
load([OutDir,'\',fnamtmp,'_',num2str(j),'.mat'],'stock_filter','stock_ys');
nb = size(stock_filter,3);
y0(:,nbb+1:nbb+nb) = squeeze(stock_filter(jxj,:,:)) + ...
kron(stock_ys(:,js)',ones(nobs+1,1));
%y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock;
nbb=nbb+nb;
clear stock_filter;
end
% y0 = squeeze(stock_filter(:,jxj,:)) + ...
% kron(stock_ys(js,:),ones(size(stock_filter,1),1));
end
y0M=mean(y0,2);
for j=1:nruns,
rmse_MC(j,i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1,j)).^2));
end
if exist('xparam1_mean','var')
%eval(['rmse_pmean(i) = sqrt(mean((',vj,'(fobs-1+istart:fobs-1+nobs)-y0M(istart:end-1)).^2));'])
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,stock_gend,stock_data);
y0 = squeeze(aK(1,jxj,:)) + ...
kron(ys_mean(js,:),ones(size(aK,3),1));
% y0 = ahat(jxj,:)' + ...
% kron(ys_mean(js,:),ones(size(ahat,2),1));
rmse_pmean(i) = sqrt(mean((vobs(istart:end)-y0(istart:length(vobs))).^2));
end
end
clear stock_filter;
end
for j=1:nruns,
lnprior(j,1) = priordens(x(j,:),bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4);
end
likelihood=logpo2(:)-lnprior(:);
disp('... done!')
if options_.opt_gsa.ppost
save([OutDir,'\',fnamtmp], 'x', 'logpo2', 'likelihood', 'rmse_MC', 'rmse_mode','rmse_pmean')
else
if options_.opt_gsa.lik_only
save([OutDir,'\',fnamtmp], 'likelihood', '-append')
else
save([OutDir,'\',fnamtmp], 'likelihood', 'rmse_MC','-append')
if exist('xparam1_mean','var')
save([OutDir,'\',fnamtmp], 'rmse_pmean','-append')
end
if exist('xparam1','var')
save([OutDir,'\',fnamtmp], 'rmse_mode','-append')
end
end
end
else
if options_.opt_gsa.lik_only & options_.opt_gsa.ppost==0
load([OutDir,'\',fnamtmp],'x','logpo2','likelihood');
else
load([OutDir,'\',fnamtmp],'x','logpo2','likelihood','rmse_MC','rmse_mode','rmse_pmean');
end
lnprior=logpo2(:)-likelihood(:);
nruns=size(x,1);
nfilt=floor(pfilt*nruns);
end
% smirnov tests
nfilt0=nfilt*ones(size(vvarvecm,1),1);
logpo2=logpo2(:);
if ~options_.opt_gsa.ppost
[dum, ipost]=sort(-logpo2);
[dum, ilik]=sort(-likelihood);
end
if ~options_.opt_gsa.ppost & options_.opt_gsa.lik_only
if options_.opt_gsa.pprior
anam='rmse_prior_post';
else
anam='rmse_mc_post';
end
stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir);
stab_map_2(x(ipost(1:nfilt),:),alpha2,anam, OutDir);
if options_.opt_gsa.pprior
anam='rmse_prior_lik';
else
anam='rmse_mc_lik';
end
stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir);
stab_map_2(x(ilik(1:nfilt),:),alpha2,anam, OutDir);
else
for i=1:size(vvarvecm,1),
[dum, ixx(:,i)]=sort(rmse_MC(:,i));
if options_.opt_gsa.ppost,
%nfilt0(i)=length(find(rmse_MC(:,i)<rmse_pmean(i)));
rmse_txt=rmse_pmean;
else
if options_.opt_gsa.pprior | ~exist('rmse_pmean'),
if exist('rmse_mode'),
rmse_txt=rmse_mode;
else
rmse_txt=NaN(1,size(rmse_MC,2));
end
else
%nfilt0(i)=length(find(rmse_MC(:,i)<rmse_pmean(i)));
rmse_txt=rmse_pmean;
end
end
for j=1:npar+nshock,
[H,P,KSSTAT] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
[H1,P1,KSSTAT1] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
[H2,P2,KSSTAT2] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
if H1 & H2==0,
SS(j,i)=1;
elseif H1==0,
SS(j,i)=-1;
else
SS(j,i)=0;
end
PP(j,i)=P;
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Prior ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(lnprior(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, cumplot(lnprior)
h=cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'\',fname_,'_rmse_post_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_lnprior',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_lnprior',int2str(ifig)]);
else
saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_lnprior',int2str(ifig)]);
end
end
close(gcf)
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Likelihood ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(likelihood(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, h=cumplot(likelihood);
h=cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if options_.opt_gsa.ppost==0,
set(gca,'xlim',[min( likelihood(ixx(1:nfilt0(i),i)) ) max( likelihood(ixx(1:nfilt0(i),i)) )])
end
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'\',fname_,'_rmse_post_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_lnlik',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_lnlik',int2str(ifig)]);
else
saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_lnlik',int2str(ifig)]);
end
end
close(gcf)
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Posterior ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(logpo2(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, h=cumplot(logpo2);
h=cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if options_.opt_gsa.ppost==0,
set(gca,'xlim',[min( logpo2(ixx(1:nfilt0(i),i)) ) max( logpo2(ixx(1:nfilt0(i),i)) )])
end
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'\',fname_,'_rmse_post_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_lnpost',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_lnpost',int2str(ifig)]);
else
saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_lnpost',int2str(ifig)]);
end
end
close(gcf)
end
end
param_names='';
for j=1:npar+nshock,
param_names=str2mat(param_names, bayestopt_.name{j});
end
param_names=param_names(2:end,:);
disp(' ')
disp('RMSE over the MC sample:')
disp(' min yr RMSE max yr RMSE')
for j=1:size(vvarvecm,1),
disp([vvarvecm(j,:), sprintf('%15.5g',[(min(rmse_MC(:,j))) [(max(rmse_MC(:,j)))]])])
end
invar = find( std(rmse_MC)./mean(rmse_MC)<=0.0001 );
if ~isempty(invar)
disp(' ')
disp(' ')
disp('RMSE is not varying significantly over the MC sample for the following variables:')
disp(vvarvecm(invar,:))
disp('These variables are excluded from SA')
disp('[Unless you treat these series as exogenous, there is something wrong in your estimation !]')
end
ivar = find( std(rmse_MC)./mean(rmse_MC)>0.0001 );
vvarvecm=vvarvecm(ivar,:);
rmse_MC=rmse_MC(:,ivar);
disp(' ')
% if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior,
disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ])
% else
% disp(['Sample filtered the best RMSE''s smaller than RMSE at the posterior mean ...' ])
% end
% figure, boxplot(rmse_MC)
% set(gca,'xticklabel',vvarvecm)
% saveas(gcf,[fname_,'_SA_RMSE'])
disp(' ')
disp(' ')
disp('RMSE ranges after filtering:')
if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior,
disp([' best ',num2str(pfilt*100),'% filtered remaining 90%'])
disp([' min max min max posterior mode'])
else
disp([' best filtered remaining '])
disp([' min max min max posterior mean'])
end
for j=1:size(vvarvecm,1),
disp([vvarvecm(j,:), sprintf('%15.5g',[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ...
max(rmse_MC(ixx(1:nfilt0(j),j),j)) ...
min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ...
max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ...
rmse_txt(j)])])
% disp([vvarvecm(j,:), sprintf('%15.5g',[min(logpo2(ixx(1:nfilt,j))) ...
% max(logpo2(ixx(1:nfilt,j))) ...
% min(logpo2(ixx(nfilt+1:end,j))) ...
% max(logpo2(ixx(nfilt+1:end,j)))])])
end
SP=zeros(npar+nshock,size(vvarvecm,1));
for j=1:size(vvarvecm,1),
ns=find(PP(:,j)<alpha);
SP(ns,j)=ones(size(ns));
SS(:,j)=SS(:,j).*SP(:,j);
end
for j=1:npar+nshock, %estim_params_.np,
nsp(j)=length(find(SP(j,:)));
end
snam0=param_names(find(nsp==0),:);
snam1=param_names(find(nsp==1),:);
snam2=param_names(find(nsp>1),:);
snam=param_names(find(nsp>0),:);
% snam0=bayestopt_.name(find(nsp==0));
% snam1=bayestopt_.name(find(nsp==1));
% snam2=bayestopt_.name(find(nsp>1));
% snam=bayestopt_.name(find(nsp>0));
nsnam=(find(nsp>1));
disp(' ')
disp(' ')
disp('These parameters do not affect significantly the fit of ANY observed series:')
disp(snam0)
disp(' ')
disp('These parameters affect ONE single observed series:')
disp(snam1)
disp(' ')
disp('These parameters affect MORE THAN ONE observed series: trade off exists!')
disp(snam2)
%pnam=bayestopt_.name(end-estim_params_.np+1:end);
pnam=bayestopt_.name;
% plot trade-offs
a00=jet(size(vvarvecm,1));
for ix=1:ceil(length(nsnam)/5),
figure,
for j=1+5*(ix-1):min(size(snam2,1),5*ix),
subplot(2,3,j-5*(ix-1))
%h0=cumplot(x(:,nsnam(j)+nshock));
h0=cumplot(x(:,nsnam(j)));
set(h0,'color',[0 0 0])
hold on,
np=find(SP(nsnam(j),:));
%a0=jet(nsp(nsnam(j)));
a0=a00(np,:);
for i=1:nsp(nsnam(j)), %size(vvarvecm,1),
%h0=cumplot(x(ixx(1:nfilt,np(i)),nsnam(j)+nshock));
h0=cumplot(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)));
set(h0,'color',a0(i,:))
end
ydum=get(gca,'ylim');
%xdum=xparam1(nshock+nsnam(j));
if exist('xparam1')
xdum=xparam1(nsnam(j));
h1=plot([xdum xdum],ydum);
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
end
xlabel('')
title([pnam{nsnam(j)}],'interpreter','none')
end
%subplot(3,2,6)
h0=legend(str2mat('base',vvarvecm(np,:)),0);
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none')
%h0=legend({'base',vnam{np}}',0);
%set(findobj(get(h0,'children'),'type','text'),'interpreter','none')
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'\',fname_,'_rmse_post_',num2str(ix)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_' int2str(ix)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_' int2str(ix)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_',num2str(ix)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_' int2str(ix)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_' int2str(ix)]);
else
saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_',num2str(ix)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_' int2str(ix)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_' int2str(ix)]);
end
end
end
close all
for j=1:size(SP,2),
nsx(j)=length(find(SP(:,j)));
end
number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two.
bandwidth = 0; % Rule of thumb optimal bandwidth parameter.
kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton.
%kernel_function = 'uniform'; % Gaussian kernel for Fast Fourrier Transform approximaton.
for ix=1:ceil(length(nsnam)/5),
figure,
for j=1+5*(ix-1):min(size(snam2,1),5*ix),
subplot(2,3,j-5*(ix-1))
optimal_bandwidth = mh_optimal_bandwidth(x(:,nsnam(j)),size(x,1),bandwidth,kernel_function);
[x1,f1] = kernel_density_estimate(x(:,nsnam(j)),number_of_grid_points,...
size(x,1),optimal_bandwidth,kernel_function);
h0 = plot(x1, f1,'k');
hold on,
np=find(SP(nsnam(j),:));
%a0=jet(nsp(nsnam(j)));
a0=a00(np,:);
for i=1:nsp(nsnam(j)), %size(vvarvecm,1),
optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),nfilt,bandwidth,kernel_function);
[x1,f1] = kernel_density_estimate(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),number_of_grid_points,...
nfilt,optimal_bandwidth,kernel_function);
h0 = plot(x1, f1);
set(h0,'color',a0(i,:))
end
ydum=get(gca,'ylim');
set(gca,'ylim',[0 ydum(2)]);
if exist('xparam1')
%xdum=xparam1(nshock+nsnam(j));
xdum=xparam1(nsnam(j));
h1=plot([xdum xdum],[0 ydum(2)]);
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
end
xlabel('')
title([pnam{nsnam(j)}],'interpreter','none')
end
h0=legend(str2mat('base',vvarvecm(np,:)),0);
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none')
%h0=legend({'base',vnam{np}}',0);
%set(findobj(get(h0,'children'),'type','text'),'interpreter','none')
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'\',fname_,'_rmse_post_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_dens_' int2str(ix)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_dens_' int2str(ix)]);
else
saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_dens_' int2str(ix)]);
end
end
end
close all
% for j=1:size(SP,2),
% nfig=0;
% np=find(SP(:,j));
% for i=1:nsx(j), %size(vvarvecm,1),
% if mod(i,12)==1,
% nfig=nfig+1;
% %figure('name',['Sensitivity of fit of ',vnam{j}]),
% figure('name',['Sensitivity of fit of ',deblank(vvarvecm(j,:)),' ',num2str(nfig)]),
% end
%
% subplot(3,4,i-12*(nfig-1))
% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt,j),np(i)),nfilt,bandwidth,kernel_function);
% [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt,j),np(i)),number_of_grid_points,...
% optimal_bandwidth,kernel_function);
% plot(x1, f1,':k','linewidth',2)
% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(nfilt+1:end,j),np(i)),nruns-nfilt,bandwidth,kernel_function);
% [x1,f1] = kernel_density_estimate(x(ixx(nfilt+1:end,j),np(i)),number_of_grid_points,...
% optimal_bandwidth,kernel_function);
% hold on, plot(x1, f1,'k','linewidth',2)
% ydum=get(gca,'ylim');
% %xdum=xparam1(nshock+np(i));
% xdum=xparam1(np(i));
% h1=plot([xdum xdum],ydum);
% set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
% %xdum1=mean(x(ixx(1:nfilt,j),np(i)+nshock));
% xdum1=mean(x(ixx(1:nfilt,j),np(i)));
% h2=plot([xdum1 xdum1],ydum);
% set(h2,'color',[0 1 0],'linewidth',2)
% % h0=cumplot(x(nfilt+1:end,np(i)+nshock));
% % set(h0,'color',[1 1 1])
% % hold on,
% % h0=cumplot(x(ixx(1:nfilt,j),np(i)+nshock));
% % set(h0,'linestyle',':','color',[1 1 1])
% %title([pnam{np(i)}])
% title([pnam{np(i)},'. K-S prob ', num2str(PP(np(i),j))],'interpreter','none')
% xlabel('')
% if mod(i,12)==0 | i==nsx(j),
% saveas(gcf,[fname_,'_rmse_',deblank(vvarvecm(j,:)),'_',int2str(nfig)])
% close(gcf)
% end
% end
% end
disp(' ')
disp(' ')
disp('Sensitivity table (significance and direction):')
vav=char(zeros(1, size(param_names,2)+3 ));
ibl = 12-size(vvarvecm,2);
for j=1:size(vvarvecm,1),
vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)];
end
disp(vav)
for j=1:npar+nshock, %estim_params_.np,
%disp([param_names(j,:), sprintf('%8.5g',SP(j,:))])
disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))])
disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))])
end
disp(' ')
disp(' ')
disp('Starting bivariate analysis:')
for i=1:size(vvarvecm,1)
if options_.opt_gsa.ppost
fnam = ['rmse_post_',deblank(vvarvecm(i,:))];
else
if options_.opt_gsa.pprior
fnam = ['rmse_prior_',deblank(vvarvecm(i,:))];
else
fnam = ['rmse_mc_',deblank(vvarvecm(i,:))];
end
end
stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,fnam, OutDir);
% [pc,latent,explained] = pcacov(c0);
% %figure, bar([explained cumsum(explained)])
% ifig=0;
% j2=0;
% for j=1:npar+nshock,
% i2=find(abs(pc(:,j))>alphaPC);
% if ~isempty(i2),
% j2=j2+1;
% if mod(j2,12)==1,
% ifig=ifig+1;
% figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]),
% end
% subplot(3,4,j2-(ifig-1)*12)
% bar(pc(i2,j)),
% set(gca,'xticklabel',bayestopt_.name(i2)),
% set(gca,'xtick',[1:length(i2)])
% title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%'])
% end
% if (mod(j2,12)==0 | j==(npar+nshock)) & j2,
% saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)])
% end
% end
% close all
end
end

View File

@ -1,27 +0,0 @@
function cdf = gamm_cdf (x, a)
% PURPOSE: returns the cdf at x of the gamma(a) distribution
%---------------------------------------------------
% USAGE: cdf = gamm_cdf(x,a)
% where: x = a vector
% a = a scalar gamma(a)
%---------------------------------------------------
% RETURNS:
% a vector of cdf at each element of x of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_inv
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
if nargin ~= 2
error('Wrong # of arguments to gamm_cdf');
end;
if any(any(a<=0))
error('gamm_cdf: parameter a is wrong')
end
cdf = gammainc(x,a);
I0 = find(x<0);
cdf(I0) = zeros(size(I0));

View File

@ -1,50 +0,0 @@
function x = gamm_inv(p,a,b)
% PURPOSE: returns the inverse of the cdf at p of the gamma(a,b) distribution
%---------------------------------------------------
% USAGE: x = gamm_inv(p,a)
% where: p = a vector of probabilities
% a = a scalar parameter gamma(a)
% b = scaling factor for gamma
%---------------------------------------------------
% RETURNS:
% a vector x of the quantile at each element of p of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_cdf
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to fit the format
% of the econometrics toolbox
if (nargin < 2 | isempty(b))
b=1;
end
if (nargin > 3)
error('Wrong # of arguments to gamm_inv');
end
if any(any(abs(2*p-1)>1))
error('gamm_inv: a probability should be 0<=p<=1')
end
if any(any(a<=0))
error('gamma_inv: parameter a is wrong')
end
x = max(a-1,0.1);
dx = 1;
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (gamm_cdf(x,a) - p) ./ gamm_pdf(x,a);
x = x - dx;
x = x + (dx - x) / 2 .* (x<0);
end
I0 = find(p==0);
x(I0) = zeros(size(I0));
I1 = find(p==1);
x(I1) = zeros(size(I0)) + Inf;
x=x.*b;

View File

@ -1,27 +0,0 @@
function f = gamm_pdf (x, a)
% PURPOSE: returns the pdf at x of the gamma(a) distribution
%---------------------------------------------------
% USAGE: pdf = gamm_pdf(x,a)
% where: x = a vector
% a = a scalar for gamma(a)
%---------------------------------------------------
% RETURNS:
% a vector of pdf at each element of x of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_cdf, gamm_rnd, gamm_inv
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
if nargin ~= 2
error('Wrong # of arguments to gamm_cdf');
end;
if any(any(a<=0))
error('gamm_pdf: parameter a is wrong')
end
f = x .^ (a-1) .* exp(-x) ./ gamma(a);
I0 = find(x<0);
f(I0) = zeros(size(I0));

View File

@ -1,41 +0,0 @@
function [A,B] = ghx2transition(mm,iv,ic,aux)
% [A,B] = ghx2transition(mm,iv,ic,aux)
%
% Adapted by M. Ratto from kalman_transition_matrix.m
% (kalman_transition_matrix.m is part of DYNARE, copyright M. Juillard)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_
[nr1, nc1] = size(mm);
ghx = mm(:, [1:(nc1-M_.exo_nbr)]);
ghu = mm(:, [(nc1-M_.exo_nbr+1):end] );
n_iv = length(iv);
n_ir1 = size(aux,1);
nr = n_iv + n_ir1;
A = zeros(nr,nr);
B = zeros(nr,M_.exo_nbr);
i_n_iv = 1:n_iv;
A(i_n_iv,ic) = ghx(iv,:);
if n_ir1 > 0
A(n_iv+1:end,:) = sparse(aux(:,1),aux(:,2),ones(n_ir1,1),n_ir1,nr);
end
B(i_n_iv,:) = ghu(iv,:);

View File

@ -1,54 +0,0 @@
function [yy, xdir, isig, lam]=log_trans_(y0,xdir0)
if nargin==1,
xdir0='';
end
f=inline('skewness(log(y+lam))','lam','y');
isig=1;
if ~(max(y0)<0 | min(y0)>0)
if skewness(y0)<0,
isig=-1;
y0=-y0;
end
n=hist(y0,10);
if n(1)>20*n(end),
try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0);
catch
yl(1)=f(-min(y0)+10*eps,y0);
yl(2)=f(-min(y0)+abs(median(y0)),y0);
if abs(yl(1))<abs(yl(2))
lam=-min(y0)+eps;
else
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
end
end
yy = log(y0+lam);
xdir=[xdir0,'_logskew'];
else
isig=0;
lam=0;
yy = log(y0.^2);
xdir=[xdir0,'_logsquared'];
end
else
if max(y0)<0
isig=-1;
y0=-y0;
%yy=log(-y0);
xdir=[xdir0,'_minuslog'];
elseif min(y0)>0
%yy=log(y0);
xdir=[xdir0,'_log'];
end
try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0);
catch
yl(1)=f(-min(y0)+10*eps,y0);
yl(2)=f(-min(y0)+abs(median(y0)),y0);
if abs(yl(1))<abs(yl(2))
lam=-min(y0)+eps;
else
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
end
end
yy = log(y0+lam);
end

View File

@ -1,25 +0,0 @@
function [lpmat] = lptauSEQ(Nsam,Nvar)
% [lpmat] = lptauSEQ(Nsam,Nvar)
%
% function call LPTAU and generates a sample of dimension Nsam for a
% number of parameters Nvar
%
% Copyright (C) 2005 Marco Ratto
% THIS PROGRAM WAS WRITTEN FOR MATLAB BY
% Marco Ratto,
% Unit of Econometrics and Statistics AF
% (http://www.jrc.cec.eu.int/uasa/),
% IPSC, Joint Research Centre
% The European Commission,
% TP 361, 21020 ISPRA(VA), ITALY
% marco.ratto@jrc.it
%
clear lptau
lpmat = zeros(Nsam, Nvar);
for j=1:Nsam,
lpmat(j,:)=LPTAU(j,Nvar);
end
return

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +0,0 @@
function [vdec, cc, ac] = mc_moments(mm, ss, dr)
global options_ M_
[nr1, nc1, nsam] = size(mm);
disp('Computing theoretical moments ...')
h = waitbar(0,'Theoretical moments ...');
for j=1:nsam,
dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j);
dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j);
if ~isempty(ss),
set_shocks_param(ss(j,:));
end
[vdec(:,:,j), corr, autocorr, z, zz] = th_moments(dr,options_.varobs);
cc(:,:,j)=tril(corr,-1);
ac(:,:,j)=autocorr{1};
waitbar(j/nsam,h)
end
close(h)
disp(' ')
disp('... done !')

View File

@ -1,158 +0,0 @@
function sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
% sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
% % % % endif
if nargin < 5 | isempty(maxwhisker), maxwhisker = 1.5; end
if nargin < 4 | isempty(vertical), vertical = 1; end
if nargin < 3 | isempty(symbol), symbol = ['+','o']; end
if nargin < 2 | isempty(notched), notched = 0; end
if length(symbol)==1, symbol(2)=symbol(1); end
if notched==1, notched=0.25; end
a=1-notched;
% ## figure out how many data sets we have
if iscell(data),
nc = length(data);
else
% if isvector(data), data = data(:); end
nc = size(data,2);
end
% ## compute statistics
% ## s will contain
% ## 1,5 min and max
% ## 2,3,4 1st, 2nd and 3rd quartile
% ## 6,7 lower and upper confidence intervals for median
s = zeros(7,nc);
box = zeros(1,nc);
whisker_x = ones(2,1)*[1:nc,1:nc];
whisker_y = zeros(2,2*nc);
outliers_x = [];
outliers_y = [];
outliers2_x = [];
outliers2_y = [];
for i=1:nc
% ## Get the next data set from the array or cell array
if iscell(data)
col = data{i}(:);
else
col = data(:,i);
end
% ## Skip missing data
% % % % % % % col(isnan(col) | isna (col)) = [];
col(isnan(col)) = [];
% ## Remember the data length
nd = length(col);
box(i) = nd;
if (nd > 1)
% ## min,max and quartiles
% s(1:5,i) = statistics(col)(1:5);
s(1,i)=min(col);
s(5,i)=max(col);
s(2,i)=myprctilecol(col,25);
s(3,i)=myprctilecol(col,50);
s(4,i)=myprctilecol(col,75);
% ## confidence interval for the median
est = 1.57*(s(4,i)-s(2,i))/sqrt(nd);
s(6,i) = max([s(3,i)-est, s(2,i)]);
s(7,i) = min([s(3,i)+est, s(4,i)]);
% ## whiskers out to the last point within the desired inter-quartile range
IQR = maxwhisker*(s(4,i)-s(2,i));
whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)];
whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)];
% ## outliers beyond 1 and 2 inter-quartile ranges
outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR));
outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR);
outliers_x = [outliers_x; i*ones(size(outliers))];
outliers_y = [outliers_y; outliers];
outliers2_x = [outliers2_x; i*ones(size(outliers2))];
outliers2_y = [outliers2_y; outliers2];
elseif (nd == 1)
% ## all statistics collapse to the value of the point
s(:,i) = col;
% ## single point data sets are plotted as outliers.
outliers_x = [outliers_x; i];
outliers_y = [outliers_y; col];
else
% ## no statistics if no points
s(:,i) = NaN;
end
end
% % % % if isempty(outliers2_y)
% % % % outliers2_y=
% ## Note which boxes don't have enough stats
chop = find(box <= 1);
% ## Draw a box around the quartiles, with width proportional to the number of
% ## items in the box. Draw notches if desired.
box = box*0.23/max(box);
quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box;
quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:);
% ## Draw a line through the median
median_x = ones(2,1)*[1:nc] + [-a;+a]*box;
% median_x=median(col);
median_y = s([3,3],:);
% ## Chop all boxes which don't have enough stats
quartile_x(:,chop) = [];
quartile_y(:,chop) = [];
whisker_x(:,[chop,chop+nc]) = [];
whisker_y(:,[chop,chop+nc]) = [];
median_x(:,chop) = [];
median_y(:,chop) = [];
% % % %
% ## Add caps to the remaining whiskers
cap_x = whisker_x;
cap_x(1,:) =cap_x(1,:)- 0.05;
cap_x(2,:) =cap_x(2,:)+ 0.05;
cap_y = whisker_y([1,1],:);
% #quartile_x,quartile_y
% #whisker_x,whisker_y
% #median_x,median_y
% #cap_x,cap_y
%
% ## Do the plot
mm=min(min(data));
MM=max(max(data));
if vertical
plot (quartile_x, quartile_y, 'b', ...
whisker_x, whisker_y, 'b--', ...
cap_x, cap_y, 'k', ...
median_x, median_y, 'r', ...
outliers_x, outliers_y, [symbol(1),'r'], ...
outliers2_x, outliers2_y, [symbol(2),'r']);
set(gca,'XTick',1:nc);
set(gca, 'XLim', [0.5, nc+0.5]);
set(gca, 'YLim', [mm-(MM-mm)*0.05, MM+(MM-mm)*0.05]);
else
% % % % % plot (quartile_y, quartile_x, "b;;",
% % % % % whisker_y, whisker_x, "b;;",
% % % % % cap_y, cap_x, "b;;",
% % % % % median_y, median_x, "r;;",
% % % % % outliers_y, outliers_x, [symbol(1),"r;;"],
% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]);
end
if nargout,
sout=s;
end
% % % endfunction

View File

@ -1,20 +0,0 @@
function y = myprctilecol(x,p);
xx = sort(x);
[m,n] = size(x);
if m==1 | n==1
m = max(m,n);
if m == 1,
y = x*ones(length(p),1);
return;
end
n = 1;
q = 100*(0.5:m - 0.5)./m;
xx = [min(x); xx(:); max(x)];
else
q = 100*(0.5:m - 0.5)./m;
xx = [min(x); xx; max(x)];
end
q = [0 q 100];
y = interp1(q,xx,p);

View File

@ -1,44 +0,0 @@
function invp = norm_inv(x, m, sd)
% PURPOSE: computes the quantile (inverse of the CDF)
% for each component of x with mean m, standard deviation sd
%---------------------------------------------------
% USAGE: invp = norm_inv(x,m,v)
% where: x = variable vector (nx1)
% m = mean vector (default=0)
% sd = standard deviation vector (default=1)
%---------------------------------------------------
% RETURNS: invp (nx1) vector
%---------------------------------------------------
% SEE ALSO: norm_d, norm_rnd, norm_inv, norm_cdf
%---------------------------------------------------
% Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Oct 26, 1994
% Copyright Dept of Probability Theory and Statistics TU Wien
% Converted to MATLAB by JP LeSage, jpl@jpl.econ.utoledo.edu
if nargin > 3
error ('Wrong # of arguments to norm_inv');
end
[r, c] = size (x);
s = r * c;
if (nargin == 1)
m = zeros(1,s);
sd = ones(1,s);
end
x = reshape(x,1,s);
m = reshape(m,1,s);
sd = reshape(sd,1,s);
invp = zeros (1,s);
invp = m + sd .* (sqrt(2) * erfinv(2 * x - 1));
invp = reshape (invp, r, c);

View File

@ -1,125 +0,0 @@
function pdraw = prior_draw_gsa(init,rdraw,cc)
% Draws from the prior distributions
% Adapted by M. Ratto from prior_draw (of DYNARE, copyright M. Juillard),
% for use with Sensitivity Toolbox for DYNARE
%
%
% INPUTS
% o init [integer] scalar equal to 1 (first call) or 0.
% o rdraw
% o cc [double] two columns matrix (same as in
% metropolis.m), constraints over the
% parameter space (upper and lower bounds).
%
% OUTPUTS
% o pdraw [double] draw from the joint prior density.
%
% ALGORITHM
% ...
%
% SPECIAL REQUIREMENTS
% MATLAB Statistics Toolbox
%
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ options_ estim_params_ bayestopt_
persistent fname npar bounds pshape pmean pstd a b p1 p2 p3 p4 condition
if init
nvx = estim_params_.nvx;
nvn = estim_params_.nvn;
ncx = estim_params_.ncx;
ncn = estim_params_.ncn;
np = estim_params_.np ;
npar = nvx+nvn+ncx+ncn+np;
MhDirectoryName = CheckPath('metropolis');
fname = [ MhDirectoryName '/' M_.fname];
pshape = bayestopt_.pshape;
pmean = bayestopt_.pmean;
pstd = bayestopt_.pstdev;
p1 = bayestopt_.p1;
p2 = bayestopt_.p2;
p3 = bayestopt_.p3;
p4 = bayestopt_.p4;
a = zeros(npar,1);
b = zeros(npar,1);
if nargin == 2
bounds = cc;
else
bounds = kron(ones(npar,1),[-Inf Inf]);
end
for i = 1:npar
switch pshape(i)
case 3% Gaussian prior
b(i) = pstd(i)^2/(pmean(i)-p3(i));
a(i) = (pmean(i)-p3(i))/b(i);
case 1% Beta prior
mu = (p1(i)-p3(i))/(p4(i)-p3(i));
stdd = p2(i)/(p4(i)-p3(i));
a(i) = (1-mu)*mu^2/stdd^2 - mu;
b(i) = a(i)*(1/mu - 1);
case 2;%Gamma prior
mu = p1(i)-p3(i);
b(i) = p2(i)^2/mu;
a(i) = mu/b(i);
case {5,4,6}
% Nothing to do here
%
% 4: Inverse gamma, type 1, prior
% p2(i) = nu
% p1(i) = s
% 6: Inverse gamma, type 2, prior
% p2(i) = nu
% p1(i) = s
% 5: Uniform prior
% p3(i) and p4(i) are used.
otherwise
disp('prior_draw :: Error!')
disp('Unknown prior shape.')
return
end
pdraw = zeros(npar,1);
end
condition = 1;
pdraw = zeros(npar,1);
return
end
for i = 1:npar
switch pshape(i)
case 5% Uniform prior.
pdraw(:,i) = rdraw(:,i)*(p4(i)-p3(i)) + p3(i);
case 3% Gaussian prior.
pdraw(:,i) = norm_inv(rdraw(:,i),pmean(i),pstd(i));
case 2% Gamma prior.
pdraw(:,i) = gamm_inv(rdraw(:,i),a(i),b(i))+p3(i);
case 1% Beta distribution (TODO: generalized beta distribution)
pdraw(:,i) = beta_inv(rdraw(:,i),a(i),b(i))*(p4(i)-p3(i))+p3(i);
case 4% INV-GAMMA1 distribution
% TO BE CHECKED
pdraw(:,i) = sqrt(1./gamm_inv(rdraw(:,i),p2(i)/2,2/p1(i)));
case 6% INV-GAMMA2 distribution
% TO BE CHECKED
pdraw(:,i) = 1./gamm_inv(rdraw(:,i),p2(i)/2,2/p1(i));
otherwise
% Nothing to do here.
end
end

View File

@ -1,45 +0,0 @@
function [xcum] = priorcdf(para, pshape, p1, p2, p3, p4)
% This procedure transforms x vectors into cumulative values
% pshape: 0 is point mass, both para and p2 are ignored
% 1 is BETA(mean,stdd)
% 2 is GAMMA(mean,stdd)
% 3 is NORMAL(mean,stdd)
% 4 is INVGAMMA(s^2,nu)
% 5 is UNIFORM [p1,p2]
% Adapted by M. Ratto from MJ priordens.m
nprio = length(pshape);
i = 1;
while i <= nprio;
a = 0;
b = 0;
if pshape(i) == 1; % (generalized) BETA Prior
mu = (p1(i)-p3(i))/(p4(i)-p3(i));
stdd = p2(i)/(p4(i)-p3(i));
a = (1-mu)*mu^2/stdd^2 - mu;
b = a*(1/mu - 1);
%lnprior = lnprior + lpdfgbeta(para(i),a,b,p3(i),p4(i)) ;
para(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i));
xcum(:,i) = betacdf(para(:,i),a,b) ;
elseif pshape(i) == 2; % GAMMA PRIOR
b = p2(i)^2/(p1(i)-p3(i));
a = (p1(i)-p3(i))/b;
%lnprior = lnprior + lpdfgam(para(i)-p3(i),a,b);
xcum(:,i) = gamcdf(para(:,i)-p3(i),a,b);
elseif pshape(i) == 3; % GAUSSIAN PRIOR
%lnprior = lnprior + lpdfnorm(para(i),p1(i),p2(i));
xcum(:,i) = normcdf(para(:,i),p1(i),p2(i));
elseif pshape(i) == 4; % INVGAMMA1 PRIOR
%lnprior = lnprior + lpdfig1(para(i),p1(i),p2(i));
xcum(:,i) = gamcdf(1/para(:,i).^2,p2(i)/2,2/p1(i));
elseif pshape(i) == 5; % UNIFORM PRIOR
%lnprior = lnprior + log(1/(p2(i)-p1(i)));
xcum(:,i) = (para(:,i)-p1(i))./(p2(i)-p1(i));
elseif pshape(i) == 6; % INVGAMMA2 PRIOR
% lnprior = lnprior + lpdfig2(para(i),p1(i),p2(i));
xcum(:,i) = gamcdf(1/para(:,i),p2(i)/2,2/p1(i));
end;
i = i+1;
end;

View File

@ -1,39 +0,0 @@
function [gend, data] = read_data
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global options_ bayestopt_
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1);
gend = options_.nobs;
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
if options_.loglinear == 1 & ~options_.logdata
rawdata = log(rawdata);
end
if options_.prefilter == 1
bayestopt_.mean_varobs = mean(rawdata,1);
data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs);
else
data = transpose(rawdata);
end
if ~isreal(rawdata)
error(['There are complex values in the data. Probably a wrong' ...
' transformation'])
end

View File

@ -1,342 +0,0 @@
function redform_map(dirname)
%function redform_map(dirname)
% inputs (from opt_gsa structure
% anamendo = options_gsa_.namendo;
% anamlagendo = options_gsa_.namlagendo;
% anamexo = options_gsa_.namexo;
% iload = options_gsa_.load_redform;
% pprior = options_gsa_.pprior;
% ilog = options_gsa_.logtrans_redform;
% threshold = options_gsa_.threshold_redform;
% ksstat = options_gsa_.ksstat_redform;
% alpha2 = options_gsa_.alpha2_redform;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ oo_ estim_params_ options_ bayestopt_
options_gsa_ = options_.opt_gsa;
anamendo = options_gsa_.namendo;
anamlagendo = options_gsa_.namlagendo;
anamexo = options_gsa_.namexo;
iload = options_gsa_.load_redform;
pprior = options_gsa_.pprior;
ilog = options_gsa_.logtrans_redform;
threshold = options_gsa_.threshold_redform;
ksstat = options_gsa_.ksstat_redform;
alpha2 = options_gsa_.alpha2_redform;
pnames = M_.param_names(estim_params_.param_vals(:,1),:);
if nargin==0,
dirname='';
end
if pprior
load([dirname,'\',M_.fname,'_prior']);
adir=[dirname '\redform_stab'];
else
load([dirname,'\',M_.fname,'_mc']);
adir=[dirname '\redform_mc'];
end
if ~exist('T')
stab_map_(dirname);
if pprior
load([dirname,'\',M_.fname,'_prior'],'T');
else
load([dirname,'\',M_.fname,'_mc'],'T');
end
end
if isempty(dir(adir))
mkdir(adir)
end
adir0=pwd;
%cd(adir)
nspred=size(T,2)-M_.exo_nbr;
x0=lpmat(istable,:);
[kn, np]=size(x0);
offset = length(bayestopt_.pshape)-np;
if options_gsa_.prior_range,
pshape=5*(ones(np,1));
pd = [NaN(np,1) NaN(np,1) bayestopt_.lb(offset+1:end) bayestopt_.ub(offset+1:end)];
else
pshape = bayestopt_.pshape(offset+1:end);
pd = [bayestopt_.p1(offset+1:end) bayestopt_.p2(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)];
end
nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:)));
clear lpmat lpmat0 egg iunstable yys
js=0;
for j=1:size(anamendo,1)
namendo=deblank(anamendo(j,:));
iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact');
ifig=0;
iplo=0;
for jx=1:size(anamexo,1)
namexo=deblank(anamexo(jx,:));
iexo=strmatch(namexo,M_.exo_names,'exact');
if ~isempty(iexo),
%y0=squeeze(T(iendo,iexo+nspred,istable));
y0=squeeze(T(iendo,iexo+nspred,:));
if (max(y0)-min(y0))>1.e-10,
if mod(iplo,9)==0,
ifig=ifig+1;
figure('name',[namendo,' vs. shocks ',int2str(ifig)]),
iplo=0;
end
iplo=iplo+1;
js=js+1;
xdir0 = [adir,'\',namendo,'_vs_', namexo];
if ilog==0,
if isempty(threshold)
si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namexo, xdir0);
else
iy=find( (y0>threshold(1)) & (y0<threshold(2)));
iyc=find( (y0<=threshold(1)) | (y0>=threshold(2)));
xdir = [xdir0,'_cut'];
if ~isempty(iy),
si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir);
end
if ~isempty(iy) & ~isempty(iyc)
delete([xdir, '\*cut*.*'])
[proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0);
indsmirnov = find(dproba>ksstat);
stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir);
stab_map_2(x0(iy,:),alpha2,'cut',xdir)
stab_map_2(x0(iyc,:),alpha2,'trim',xdir)
end
end
else
[yy, xdir] = log_trans_(y0,xdir0);
silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namexo, xdir);
end
subplot(3,3,iplo),
if ilog,
[saso, iso] = sort(-silog(:,js));
bar([silog(iso(1:min(np,10)),js)])
logflag='log';
else
[saso, iso] = sort(-si(:,js));
bar(si(iso(1:min(np,10)),js))
logflag='';
end
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([logflag,' ',namendo,' vs. ',namexo],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
close(gcf)
end
ifig=0;
iplo=0;
for je=1:size(anamlagendo,1)
namlagendo=deblank(anamlagendo(je,:));
ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact');
if ~isempty(ilagendo),
%y0=squeeze(T(iendo,ilagendo,istable));
y0=squeeze(T(iendo,ilagendo,:));
if (max(y0)-min(y0))>1.e-10,
if mod(iplo,9)==0,
ifig=ifig+1;
figure('name',[namendo,' vs. lags ',int2str(ifig)]),
iplo=0;
end
iplo=iplo+1;
js=js+1;
xdir0 = [adir,'\',namendo,'_vs_', namlagendo];
if ilog==0,
if isempty(threshold)
si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namlagendo, xdir0);
else
iy=find( (y0>threshold(1)) & (y0<threshold(2)));
iyc=find( (y0<=threshold(1)) | (y0>=threshold(2)));
xdir = [xdir0,'_cut'];
if ~isempty(iy)
si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir);
end
if ~isempty(iy) & ~isempty(iyc),
delete([xdir, '\*cut*.*'])
[proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0);
indsmirnov = find(dproba>ksstat);
stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir);
stab_map_2(x0(iy,:),alpha2,'cut',xdir)
stab_map_2(x0(iyc,:),alpha2,'trim',xdir)
end
end
else
[yy, xdir] = log_trans_(y0,xdir0);
silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namlagendo, xdir);
end
subplot(3,3,iplo),
if ilog,
[saso, iso] = sort(-silog(:,js));
bar([silog(iso(1:min(np,10)),js)])
logflag='log';
else
[saso, iso] = sort(-si(:,js));
bar(si(iso(1:min(np,10)),js))
logflag='';
end
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([logflag,' ',namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
close(gcf)
end
end
if ilog==0,
figure, %bar(si)
% boxplot(si','whis',10,'symbol','r.')
myboxplot(si',[],'.',[],10)
xlabel(' ')
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
set(gca,'xlim',[0.5 np+0.5])
set(gca,'ylim',[0 1])
set(gca,'position',[0.13 0.2 0.775 0.7])
for ip=1:np,
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title('Reduced form GSA')
saveas(gcf,[dirname,'\',M_.fname,'_redform_gsa'])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_gsa']);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_gsa']);
else
figure, %bar(silog)
% boxplot(silog','whis',10,'symbol','r.')
myboxplot(silog',[],'.',[],10)
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
xlabel(' ')
set(gca,'xlim',[0.5 np+0.5])
set(gca,'ylim',[0 1])
set(gca,'position',[0.13 0.2 0.775 0.7])
for ip=1:np,
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title('Reduced form GSA - Log-transformed elements')
saveas(gcf,[dirname,'\',M_.fname,'_redform_gsa_log'])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_gsa_log']);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_gsa_log']);
end
function si = redform_private(x0, y0, pshape, pd, iload, pnames, namy, namx, xdir)
global bayestopt_ options_
opt_gsa=options_.opt_gsa;
np=size(x0,2);
if opt_gsa.prior_range,
for j=1:np,
x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3));
end
else
x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4));
end
fname=[xdir,'\map'];
if iload==0,
figure, hist(y0,30), title([namy,' vs. ', namx])
if isempty(dir(xdir))
mkdir(xdir)
end
saveas(gcf,[xdir,'\', namy,'_vs_', namx])
eval(['print -depsc2 ' xdir,'\', namy,'_vs_', namx]);
eval(['print -dpdf ' xdir,'\', namy,'_vs_', namx]);
close(gcf)
% gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames);
nrun=length(y0);
nest=min(250,nrun);
nfit=min(1000,nrun);
gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[],[],0,[fname,'_est'], pnames);
if nfit>nest,
gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[],[],1,fname, pnames);
else
copyfile([fname,'_est.mat'],[fname,'.mat'])
end
figure,
plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'),
title([namy,' vs. ', namx,' fit'])
saveas(gcf,[xdir,'\', namy,'_vs_', namx,'_fit'])
eval(['print -depsc2 ' xdir,'\', namy,'_vs_', namx,'_fit']);
eval(['print -dpdf ' xdir,'\', namy,'_vs_', namx,'_fit']);
close(gcf)
if nfit<nrun,
npred=[nfit+1:nrun];
yf = ss_anova_fcast(x0(npred,:), gsa_);
figure,
plot(y0(npred),[yf y0(npred)],'.'),
title([namy,' vs. ', namx,' pred'])
saveas(gcf,[xdir,'\', namy,'_vs_', namx,'_pred'])
eval(['print -depsc2 ' xdir,'\', namy,'_vs_', namx,'_pred']);
eval(['print -dpdf ' xdir,'\', namy,'_vs_', namx,'_pred']);
close(gcf)
end
else
% gsa_ = gsa_sdp_dyn(y0, x0, 0, [],[],[],0,fname, pnames);
gsa_ = gsa_sdp(y0, x0, 0, [],[],[],0,fname, pnames);
yf = ss_anova_fcast(x0, gsa_);
figure,
plot(y0,[yf y0],'.'),
title([namy,' vs. ', namx,' pred'])
saveas(gcf,[xdir,'\', namy,'_vs_', namx,'_pred'])
eval(['print -depsc2 ' xdir,'\', namy,'_vs_', namx,'_pred']);
eval(['print -dpdf ' xdir,'\', namy,'_vs_', namx,'_pred']);
close(gcf)
end
% si = gsa_.multivariate.si;
si = gsa_.si;

View File

@ -1,165 +0,0 @@
function redform_screen(dirname)
%function redform_map(dirname)
% inputs (from opt_gsa structure
% anamendo = options_gsa_.namendo;
% anamlagendo = options_gsa_.namlagendo;
% anamexo = options_gsa_.namexo;
% iload = options_gsa_.load_redform;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ oo_ estim_params_ options_ bayestopt_
options_gsa_ = options_.opt_gsa;
anamendo = options_gsa_.namendo;
anamlagendo = options_gsa_.namlagendo;
anamexo = options_gsa_.namexo;
iload = options_gsa_.load_redform;
nliv = options_gsa_.morris_nliv;
pnames = M_.param_names(estim_params_.param_vals(:,1),:);
if nargin==0,
dirname='';
end
load([dirname,'\',M_.fname,'_prior'],'lpmat','lpmat0','istable','T');
nspred=oo_.dr.nspred;
[kn, np]=size(lpmat);
nshock = length(bayestopt_.pshape)-np;
nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:)));
js=0;
for j=1:size(anamendo,1),
namendo=deblank(anamendo(j,:));
iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact');
iplo=0;
ifig=0;
for jx=1:size(anamexo,1)
namexo=deblank(anamexo(jx,:));
iexo=strmatch(namexo,M_.exo_names,'exact');
if ~isempty(iexo),
y0=teff(T(iendo,iexo+nspred,:),kn,istable);
if ~isempty(y0),
if mod(iplo,9)==0,
ifig=ifig+1;
figure('name',[namendo,' vs. shocks ',int2str(ifig)]),
iplo=0;
end
iplo=iplo+1;
js=js+1;
subplot(3,3,iplo),
[SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
SAM = squeeze(SAMorris(nshock+1:end,1));
SA(:,js)=SAM./(max(SAM)+eps);
[saso, iso] = sort(-SA(:,js));
bar(SA(iso(1:min(np,10)),js))
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([namendo,' vs. ',namexo],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]);
close(gcf)
end
iplo=0;
ifig=0;
for je=1:size(anamlagendo,1)
namlagendo=deblank(anamlagendo(je,:));
ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact');
if ~isempty(ilagendo),
y0=teff(T(iendo,ilagendo,:),kn,istable);
if ~isempty(y0),
if mod(iplo,9)==0,
ifig=ifig+1;
figure('name',[namendo,' vs. lagged endogenous ',int2str(ifig)]),
iplo=0;
end
iplo=iplo+1;
js=js+1;
subplot(3,3,iplo),
[SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
SAM = squeeze(SAMorris(nshock+1:end,1));
SA(:,js)=SAM./(max(SAM)+eps);
[saso, iso] = sort(-SA(:,js));
bar(SA(iso(1:min(np,10)),js))
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
close(gcf)
end
end
figure,
%bar(SA)
% boxplot(SA','whis',10,'symbol','r.')
myboxplot(SA',[],'.',[],10)
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
set(gca,'xlim',[0.5 np+0.5])
set(gca,'ylim',[0 1])
set(gca,'position',[0.13 0.2 0.775 0.7])
for ip=1:np,
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
xlabel(' ')
ylabel('Elementary Effects')
title('Reduced form screening')
saveas(gcf,[dirname,'\',M_.fname,'_redform_screen'])
eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_screen']);
eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_screen']);

View File

@ -1,30 +0,0 @@
function set_shocks_param(xparam1)
global estim_params_ M_
nvx = estim_params_.nvx;
ncx = estim_params_.ncx;
np = estim_params_.np;
Sigma_e = M_.Sigma_e;
offset = 0;
if nvx
offset = offset + nvx;
var_exo = estim_params_.var_exo;
for i=1:nvx
k = var_exo(i,1);
Sigma_e(k,k) = xparam1(i)^2;
end
end
if ncx
offset = offset + estim_params_.nvn;
corrx = estim_params_.corrx;
for i=1:ncx
k1 = corrx(i,1);
k2 = corrx(i,2);
Sigma_e(k1,k2) = xparam1(i+offset)*sqrt(Sigma_e_(k1,k1)*Sigma_e_(k2,k2));
Sigma_e(k2,k1) = Sigma_e_(k1,k2);
end
end
M_.Sigma_e = Sigma_e;

View File

@ -1,7 +0,0 @@
function s=skewness(y),
% y=stand_(y);
% s=mean(y.^3);
m2=mean((y-mean(y)).^2);
m3=mean((y-mean(y)).^3);
s=m3/m2^1.5;

View File

@ -1,73 +0,0 @@
function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
% Smirnov test for 2 distributions
% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
if nargin<3
alpha = 0.05;
end
if nargin<4,
iflag=0;
end
% empirical cdfs.
xmix= [x1;x2];
bin = [-inf ; sort(xmix) ; inf];
ncount1 = histc (x1 , bin);
ncount1 = ncount1(:);
ncount2 = histc (x2 , bin);
ncount2 = ncount2(:);
cum1 = cumsum(ncount1)./sum(ncount1);
cum1 = cum1(1:end-1);
cum2 = cumsum(ncount2)./sum(ncount2);
cum2 = cum2(1:end-1);
n1= length(x1);
n2= length(x2);
n = n1*n2 /(n1+n2);
% Compute the d(n1,n2) statistics.
if iflag==0,
d = max(abs(cum1 - cum2));
elseif iflag==-1
d = max(cum2 - cum1);
elseif iflag==1
d = max(cum1 - cum2);
end
%
% Compute P-value check H0 hypothesis
%
lam = max((sqrt(n) + 0.12 + 0.11/sqrt(n)) * d , 0);
if iflag == 0
j = [1:101]';
prob = 2 * sum((-1).^(j-1).*exp(-2*lam*lam*j.^2));
prob=max(prob,0);
prob=min(1,prob);
else
prob = exp(-2*lam*lam);
end
H = (alpha >= prob);

View File

@ -1,52 +0,0 @@
function [tadj, iff] = speed(A,B,mf,p),
% [tadj, iff] = speed(A,B,mf,p),
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
nvar=length(mf);
nstate= size(A,1);
nshock = size(B,2);
nrun=size(B,3);
iff=zeros(nvar,nshock,nrun);
tadj=iff;
disp('Computing speed of adjustement ...')
h = waitbar(0,'Speed of adjustement...');
for i=1:nrun,
irf=zeros(nvar,nshock);
a=squeeze(A(:,:,i));
b=squeeze(B(:,:,i));
IFF=inv(eye(nstate)-a)*b;
iff(:,:,i)=IFF(mf,:);
IF=IFF-b;
t=0;
while any(any(irf<0.5))
t=t+1;
IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b;
irf=IFT(mf,:)./(IF(mf,:)+eps);
irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7);
%irf=ft(mf,:);
tt=(irf>0.5).*t;
tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i);
end
waitbar(i/nrun,h)
end
disp(' ')
disp('.. done !')
close(h)

View File

@ -1,511 +0,0 @@
function x0 = stab_map_(OutputDirectoryName)
%
% function x0 = stab_map_(OutputDirectoryName)
%
% Mapping of stability regions in the prior ranges applying
% Monte Carlo filtering techniques.
%
% INPUTS (from opt_gsa structure)
% Nsam = MC sample size
% fload = 0 to run new MC; 1 to load prevoiusly generated analysis
% alpha2 = significance level for bivariate sensitivity analysis
% [abs(corrcoef) > alpha2]
% prepSA = 1: save transition matrices for mapping reduced form
% = 0: no transition matrix saved (default)
% pprior = 1: sample from prior ranges (default): sample saved in
% _prior.mat file
% = 0: sample from posterior ranges: sample saved in
% _mc.mat file
% OUTPUT:
% x0: one parameter vector for which the model is stable.
%
% GRAPHS
% 1) Pdf's of marginal distributions under the stability (dotted
% lines) and unstability (solid lines) regions
% 2) Cumulative distributions of:
% - stable subset (dotted lines)
% - unacceptable subset (solid lines)
% 3) Bivariate plots of significant correlation patterns
% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets
%
% USES lptauSEQ,
% stab_map_1, stab_map_2
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
global bayestopt_ estim_params_ options_ oo_ M_
opt_gsa=options_.opt_gsa;
Nsam = opt_gsa.Nsam;
fload = opt_gsa.load_stab;
ksstat = opt_gsa.ksstat;
alpha2 = opt_gsa.alpha2_stab;
prepSA = (opt_gsa.redform | opt_gsa.identification);
pprior = opt_gsa.pprior;
ilptau = opt_gsa.ilptau;
nliv = opt_gsa.morris_nliv;
ntra = opt_gsa.morris_ntra;
dr_ = oo_.dr;
%if isfield(dr_,'ghx'),
ys_ = oo_.dr.ys;
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
%end
fname_ = M_.fname;
np = estim_params_.np;
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
lpmat0=[];
pshape = bayestopt_.pshape(nshock+1:end);
p1 = bayestopt_.p1(nshock+1:end);
p2 = bayestopt_.p2(nshock+1:end);
p3 = bayestopt_.p3(nshock+1:end);
p4 = bayestopt_.p4(nshock+1:end);
if nargin==0,
OutputDirectoryName='';
end
opt=options_;
options_.periods=0;
options_.nomoments=1;
options_.irf=0;
options_.noprint=1;
options_.simul=0;
if fload==0,
% if prepSA
% T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam/2);
% end
if isfield(dr_,'ghx'),
egg=zeros(length(dr_.eigval),Nsam);
end
yys=zeros(length(dr_.ys),Nsam);
if opt_gsa.morris
if opt_gsa.morris == 1
[lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2;
Nsam=size(lpmat,1);
lpmat0 = lpmat(:,1:nshock);
lpmat = lpmat(:,nshock+1:end);
elseif opt_gsa.morris==2
lpmat = prep_ide(Nsam,np,5);
Nsam=size(lpmat,1);
end
else
if np<52 & ilptau>0,
[lpmat] = lptauSEQ(Nsam,np); % lptau
if np>30 | ilptau==2, % scrambled lptau
for j=1:np,
lpmat(:,j)=lpmat(randperm(Nsam),j);
end
end
else ilptau==0
%[lpmat] = rand(Nsam,np);
for j=1:np,
lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
end
end
end
try
dummy=prior_draw_gsa(1);
catch
if pprior,
if opt_gsa.prior_range==0;
error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!');
end
end
end
if pprior,
for j=1:nshock,
if opt_gsa.morris~=1,
lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
end
if opt_gsa.prior_range
lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j);
end
end
if opt_gsa.prior_range
for j=1:np,
lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock);
end
else
xx=prior_draw_gsa(0,[lpmat0 lpmat]);
lpmat0=xx(:,1:nshock);
lpmat=xx(:,nshock+1:end);
clear xx;
end
else
% for j=1:nshock,
% xparam1(j) = oo_.posterior_mode.shocks_std.(bayestopt_.name{j});
% sd(j) = oo_.posterior_std.shocks_std.(bayestopt_.name{j});
% lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
% lb = max(bayestopt_.lb(j), xparam1(j)-2*sd(j));
% ub1=xparam1(j)+(xparam1(j) - lb); % define symmetric range around the mode!
% ub = min(bayestopt_.ub(j),ub1);
% if ub<ub1,
% lb=xparam1(j)-(ub-xparam1(j)); % define symmetric range around the mode!
% end
% lpmat0(:,j) = lpmat0(:,j).*(ub-lb)+lb;
% end
% %
% for j=1:np,
% xparam1(j+nshock) = oo_.posterior_mode.parameters.(bayestopt_.name{j+nshock});
% sd(j+nshock) = oo_.posterior_std.parameters.(bayestopt_.name{j+nshock});
% lb = max(bayestopt_.lb(j+nshock),xparam1(j+nshock)-2*sd(j+nshock));
% ub1=xparam1(j+nshock)+(xparam1(j+nshock) - lb); % define symmetric range around the mode!
% ub = min(bayestopt_.ub(j+nshock),ub1);
% if ub<ub1,
% lb=xparam1(j+nshock)-(ub-xparam1(j+nshock)); % define symmetric range around the mode!
% end
% %ub = min(bayestopt_.ub(j+nshock),xparam1(j+nshock)+2*sd(j+nshock));
% if np>30 & np<52
% lpmat(:,j) = lpmat(randperm(Nsam),j).*(ub-lb)+lb;
% else
% lpmat(:,j) = lpmat(:,j).*(ub-lb)+lb;
% end
% end
%load([fname_,'_mode'])
eval(['load ' options_.mode_file ';']');
d = chol(inv(hh));
lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1');
for j=1:Nsam*2,
lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub);
end
ireal=[1:2*Nsam];
ireal=ireal(find(lnprior==0));
lp=lp(ireal,:);
Nsam=min(Nsam, length(ireal));
lpmat0=lp(1:Nsam,1:nshock);
lpmat=lp(1:Nsam,nshock+1:end);
clear lp lnprior ireal;
end
%
h = waitbar(0,'Please wait...');
istable=[1:Nsam];
jstab=0;
iunstable=[1:Nsam];
iindeterm=zeros(1,Nsam);
iwrong=zeros(1,Nsam);
for j=1:Nsam,
M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)';
%try stoch_simul([]);
try
[Tt,Rr,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,...
bayestopt_.restrict_columns,...
bayestopt_.restrict_aux);
if ~exist('T')
T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam);
end
catch
if isfield(oo_.dr,'eigval'),
oo_.dr=rmfield(oo_.dr,'eigval');
end
if isfield(oo_.dr,'ghx'),
oo_.dr=rmfield(oo_.dr,'ghx');
end
disp('No solution could be found'),
end
dr_ = oo_.dr;
if isfield(dr_,'ghx'),
egg(:,j) = sort(dr_.eigval);
iunstable(j)=0;
if prepSA
jstab=jstab+1;
T(:,:,jstab) = [dr_.ghx dr_.ghu];
[A,B] = ghx2transition(squeeze(T(:,:,jstab)), ...
bayestopt_.restrict_var_list, ...
bayestopt_.restrict_columns, ...
bayestopt_.restrict_aux);
end
if ~exist('nspred'),
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
end
else
istable(j)=0;
if isfield(dr_,'eigval')
egg(:,j) = sort(dr_.eigval);
if exist('nspred')
if any(isnan(egg(1:nspred,j)))
iwrong(j)=j;
else
if (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium,
iindeterm(j)=j;
end
end
end
else
if exist('egg'),
egg(:,j)=ones(size(egg,1),1).*NaN;
end
iwrong(j)=j;
end
end
ys_=real(dr_.ys);
yys(:,j) = ys_;
ys_=yys(:,1);
waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
end
close(h)
if prepSA,
T=T(:,:,1:jstab);
end
istable=istable(find(istable)); % stable params
iunstable=iunstable(find(iunstable)); % unstable params
iindeterm=iindeterm(find(iindeterm)); % indeterminacy
iwrong=iwrong(find(iwrong)); % dynare could not find solution
% % map stable samples
% istable=[1:Nsam];
% for j=1:Nsam,
% if any(isnan(egg(1:nspred,j)))
% istable(j)=0;
% else
% if abs(egg(nspred,j))>=options_.qz_criterium; %(1-(options_.qz_criterium-1)); %1-1.e-5;
% istable(j)=0;
% %elseif (dr_.nboth | dr_.nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5;
% elseif (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5;
% istable(j)=0;
% end
% end
% end
% istable=istable(find(istable)); % stable params
%
% % map unstable samples
% iunstable=[1:Nsam];
% for j=1:Nsam,
% %if abs(egg(dr_.npred+1,j))>1+1.e-5 & abs(egg(dr_.npred,j))<1-1.e-5;
% %if (dr_.nboth | dr_.nfwrd),
% if ~any(isnan(egg(1:5,j)))
% if (nboth | nfwrd),
% if abs(egg(nspred+1,j))>options_.qz_criterium & abs(egg(nspred,j))<options_.qz_criterium; %(1-(options_.qz_criterium-1));
% iunstable(j)=0;
% end
% else
% if abs(egg(nspred,j))<options_.qz_criterium; %(1-(options_.qz_criterium-1));
% iunstable(j)=0;
% end
% end
% end
% end
% iunstable=iunstable(find(iunstable)); % unstable params
bkpprior.pshape=bayestopt_.pshape;
bkpprior.p1=bayestopt_.p1;
bkpprior.p2=bayestopt_.p2;
bkpprior.p3=bayestopt_.p3;
bkpprior.p4=bayestopt_.p4;
if pprior,
if ~prepSA
save([OutputDirectoryName '\' fname_ '_prior'], ...
'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','nspred','nboth','nfwrd')
else
save([OutputDirectoryName '\' fname_ '_prior'], ...
'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','T','nspred','nboth','nfwrd')
end
else
if ~prepSA
save([OutputDirectoryName '\' fname_ '_mc'], ...
'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','nspred','nboth','nfwrd')
else
save([OutputDirectoryName '\' fname_ '_mc'], ...
'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','T','nspred','nboth','nfwrd')
end
end
else
if pprior,
filetoload=[OutputDirectoryName '\' fname_ '_prior'];
else
filetoload=[OutputDirectoryName '\' fname_ '_mc'];
end
load(filetoload,'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong','egg','yys','nspred','nboth','nfwrd')
Nsam = size(lpmat,1);
if prepSA & isempty(strmatch('T',who('-file', filetoload),'exact')),
h = waitbar(0,'Please wait...');
options_.periods=0;
options_.nomoments=1;
options_.irf=0;
options_.noprint=1;
stoch_simul([]);
%T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),length(istable));
ntrans=length(istable);
for j=1:ntrans,
M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(j),:)';
%stoch_simul([]);
[Tt,Rr,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,...
bayestopt_.restrict_columns,...
bayestopt_.restrict_aux);
if ~exist('T')
T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),ntrans);
end
dr_ = oo_.dr;
T(:,:,j) = [dr_.ghx dr_.ghu];
if ~exist('nspred')
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
end
ys_=real(dr_.ys);
yys(:,j) = ys_;
ys_=yys(:,1);
waitbar(j/ntrans,h,['MC iteration ',int2str(j),'/',int2str(ntrans)])
end
close(h)
save(filetoload,'T','-append')
elseif prepSA
load(filetoload,'T')
end
end
if pprior
aname='prior_stab';
auname='prior_unacceptable';
aunstname='prior_unstable';
aindname='prior_indeterm';
asname='prior_stable';
else
aname='mc_stab';
auname='mc_unacceptable';
aunstname='mc_unstable';
aindname='mc_indeterm';
asname='mc_stable';
end
delete([OutputDirectoryName,'\',fname_,'_',aname,'_*.*']);
%delete([OutputDirectoryName,'\',fname_,'_',aname,'_SA_*.*']);
delete([OutputDirectoryName,'\',fname_,'_',asname,'_corr_*.*']);
delete([OutputDirectoryName,'\',fname_,'_',auname,'_corr_*.*']);
delete([OutputDirectoryName,'\',fname_,'_',aunstname,'_corr_*.*']);
delete([OutputDirectoryName,'\',fname_,'_',aindname,'_corr_*.*']);
if length(iunstable)>0 & length(iunstable)<Nsam,
disp([num2str(length(istable)/Nsam*100,3),'\% of the prior support is stable.'])
disp([num2str( (length(iunstable)-length(iwrong)-length(iindeterm) )/Nsam*100),'\% of the prior support is unstable.'])
if ~isempty(iindeterm),
disp([num2str(length(iindeterm)/Nsam*100,3),'\% of the prior support gives indeterminacy.'])
end
if ~isempty(iwrong),
disp(' ');
disp(['For ',num2str(length(iwrong)/Nsam*100,3),'\% of the prior support dynare could not find a solution.'])
end
disp(' ');
% Blanchard Kahn
[proba, dproba] = stab_map_1(lpmat, istable, iunstable, aname,0);
indstab=find(dproba>ksstat);
disp('Smirnov statistics in driving acceptable behaviour')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indstab)
stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName);
end
ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong])));
if ~isempty(iindeterm),
[proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'],0);
indindet=find(dproba>ksstat);
disp('Smirnov statistics in driving indeterminacy')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indindet)
stab_map_1(lpmat, istable, iindeterm, [aname, '_indet'], 1, indindet, OutputDirectoryName);
end
end
if ~isempty(ixun),
[proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'],0);
indunst=find(dproba>ksstat);
disp('Smirnov statistics in driving instability')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indunst)
stab_map_1(lpmat, istable, ixun, [aname, '_unst'], 1, indunst, OutputDirectoryName);
end
end
disp(' ')
disp('Starting bivariate analysis:')
c0=corrcoef(lpmat(istable,:));
c00=tril(c0,-1);
stab_map_2(lpmat(istable,:),alpha2, asname, OutputDirectoryName);
if length(iunstable)>3,
stab_map_2(lpmat(iunstable,:),alpha2, auname, OutputDirectoryName);
end
if length(iindeterm)>3,
stab_map_2(lpmat(iindeterm,:),alpha2, aindname, OutputDirectoryName);
end
if length(ixun)>3,
stab_map_2(lpmat(ixun,:),alpha2, aunstname, OutputDirectoryName);
end
x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
x0 = [x0; lpmat(istable(1),:)'];
if istable(end)~=Nsam
M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)';
[oo_.dr, info] = resol(oo_.steady_state,0);
% stoch_simul([]);
end
else
if length(iunstable)==0,
disp('All parameter values in the specified ranges are stable!')
x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
x0 = [x0; lpmat(istable(1),:)'];
else
disp('All parameter values in the specified ranges are not acceptable!')
x0=[];
end
end
options_.periods=opt.periods;
if isfield(opt,'nomoments'),
options_.nomoments=opt.nomoments;
end
options_.irf=opt.irf;
options_.noprint=opt.noprint;
if isfield(opt,'simul'),
options_.simul=opt.simul;
end

View File

@ -1,87 +0,0 @@
function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname)
%function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname)
%
% lpmat = Monte Carlo matrix
% ibehaviour = index of behavioural runs
% inonbehaviour = index of non-behavioural runs
% aname = label of the analysis
% iplot = 1 plot cumulative distributions (default)
% iplot = 0 no plots
% ipar = index array of parameters to plot
% dirname = (OPTIONAL) path of the directory where to save
% (default: current directory)
%
% Plots: dotted lines for BEHAVIOURAL
% solid lines for NON BEHAVIOURAL
% USES smirnov
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global estim_params_ bayestopt_ M_ options_
if nargin<5,
iplot=1;
end
fname_ = M_.fname;
if nargin<7,
dirname='';;
end
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
npar=size(lpmat,2);
ishock= npar>estim_params_.np;
if nargin<6 | isempty(ipar),
ipar=[1:npar];
end
nparplot=length(ipar);
% Smirnov test for Blanchard;
for j=1:npar,
[H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j));
proba(j)=P;
dproba(j)=KSSTAT;
end
if iplot
lpmat=lpmat(:,ipar);
ftit=bayestopt_.name(ipar+nshock*(1-ishock));
for i=1:ceil(nparplot/12),
figure('name',aname),
for j=1+12*(i-1):min(nparplot,12*i),
subplot(3,4,j-12*(i-1))
if ~isempty(ibehaviour),
h=cumplot(lpmat(ibehaviour,j));
set(h,'color',[0 0 0], 'linestyle',':')
end
hold on,
if ~isempty(inonbehaviour),
h=cumplot(lpmat(inonbehaviour,j));
set(h,'color',[0 0 0])
end
title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none')
end
saveas(gcf,[dirname,'\',fname_,'_',aname,'_SA_',int2str(i)])
eval(['print -depsc2 ' dirname '\' fname_ '_' aname '_SA_' int2str(i)]);
eval(['print -dpdf ' dirname '\' fname_ '_' aname '_SA_' int2str(i)]);
if options_.nograph, close(gcf), end
end
end

View File

@ -1,97 +0,0 @@
%function stab_map_2(x,alpha2,istab,fnam)
function stab_map_2(x,alpha2,fnam, dirname)
% function stab_map_2(x,alpha2,fnam, dirname)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
global bayestopt_ estim_params_ options_ oo_ M_
npar=size(x,2);
ishock= npar>estim_params_.np;
if nargin<3,
fnam='';
end
if nargin<4,
dirname='';
end
ys_ = oo_.dr.ys;
dr_ = oo_.dr;
fname_ = M_.fname;
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
c0=corrcoef(x);
c00=tril(c0,-1);
fig_nam_=[fname_,'_',fnam,'_corr_'];
ifig=0;
j2=0;
if ishock==0
npar=estim_params_.np;
else
npar=estim_params_.np+nshock;
end
for j=1:npar,
i2=find(abs(c00(:,j))>alpha2);
if length(i2)>0,
for jx=1:length(i2),
j2=j2+1;
if mod(j2,12)==1,
ifig=ifig+1;
figure('name',['Correlations in the ',fnam,' sample ', num2str(ifig)]),
end
subplot(3,4,j2-(ifig-1)*12)
% bar(c0(i2,j)),
% set(gca,'xticklabel',bayestopt_.name(i2)),
% set(gca,'xtick',[1:length(i2)])
%plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k')
%hold on,
plot(x(:,j),x(:,i2(jx)),'.')
% xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'),
% ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'),
if ishock,
xlabel(bayestopt_.name{j},'interpreter','none'),
ylabel(bayestopt_.name{i2(jx)},'interpreter','none'),
else
xlabel(bayestopt_.name{j+nshock},'interpreter','none'),
ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'),
end
title(['cc = ',num2str(c0(i2(jx),j))])
if (mod(j2,12)==0) & j2>0,
saveas(gcf,[dirname,'\',fig_nam_,int2str(ifig)])
eval(['print -depsc2 ' dirname '\' fig_nam_ int2str(ifig)]);
eval(['print -dpdf ' dirname '\' fig_nam_ int2str(ifig)]);
if options_.nograph, close(gcf), end
end
end
end
if (j==(npar)) & j2>0,
saveas(gcf,[dirname,'\',fig_nam_,int2str(ifig)])
eval(['print -depsc2 ' dirname '\' fig_nam_ int2str(ifig)]);
eval(['print -dpdf ' dirname '\' fig_nam_ int2str(ifig)]);
if options_.nograph, close(gcf), end
end
end
if ifig==0,
disp(['No correlation term >', num2str(alpha2),' found for ',fnam])
end
%close all

View File

@ -1,25 +0,0 @@
function [y, meany, stdy] = stand_(x)
% STAND_ Standardise a matrix by columns
%
% [x,my,sy]=stand(y)
%
% y: Time series (column matrix)
%
% x: standardised equivalent of y
% my: Vector of mean values for each column of y
% sy: Vector of standard deviations for each column of y
%
% Copyright (c) 2006 by JRC, European Commission, United Kingdom
% Author : Marco Ratto
if nargin==0,
return;
end
meany=mean(x);
stdy=std(x);
for j=1:size(x,2);
y(:,j)=(x(:,j)-meany(j))./stdy(j);
end
% end of m-file

View File

@ -1,38 +0,0 @@
function [yt, j0, ir, ic]=teff(T,Nsam,istable)
%
% [yt, j0, ir, ic]=teff(T,Nsam,istable)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
if nargin==1,
Nsam=size(T,3);
istable = [1:Nsam]';
end
tmax=max(T,[],3);
tmin=min(T,[],3);
[ir, ic]=(find( (tmax-tmin)>1.e-8));
j0 = length(ir);
yt=zeros(Nsam, j0);
for j=1:j0,
y0=squeeze(T(ir(j),ic(j),:));
%y1=ones(size(lpmat,1),1)*NaN;
y1=ones(Nsam,1)*NaN;
y1(istable,1)=y0;
yt(:,j)=y1;
end
%clear y0 y1;

View File

@ -1,56 +0,0 @@
% Copyright (C) 2001 Michel Juillard
%
function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list)
global M_ oo_ options_
nvar = size(var_list,1);
if nvar == 0
nvar = length(dr.order_var);
ivar = [1:nvar]';
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
if isempty(i_tmp)
error (['One of the variable specified does not exist']) ;
else
ivar(i) = i_tmp;
end
end
end
[gamma_y,ivar] = th_autocovariances(dr,ivar);
m = dr.ys(ivar);
i1 = find(abs(diag(gamma_y{1})) > 1e-12);
s2 = diag(gamma_y{1});
sd = sqrt(s2);
z = [ m sd s2 ];
mean = m;
var = gamma_y{1};
%'THEORETICAL MOMENTS';
%'MEAN','STD. DEV.','VARIANCE');
z;
%'VARIANCE DECOMPOSITION (in percent)';
vdec = 100*gamma_y{options_.ar+2}(i1,:);
%'MATRIX OF CORRELATIONS';
corr = gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)');
if options_.ar > 0
%'COEFFICIENTS OF AUTOCORRELATION';
for i=1:options_.ar
autocorr{i} = gamma_y{i+1};
zz(:,i) = diag(gamma_y{i+1}(i1,i1));
end
end

View File

@ -1,25 +0,0 @@
function yr = trank(y);
% yr = trank(y);
% yr is the rank transformation of y
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
[nr, nc] = size(y);
for j=1:nc,
[dum, is]=sort(y(:,j));
yr(is,j)=[1:nr]'./nr;
end

Binary file not shown.

View File

@ -1,512 +0,0 @@
function VECTOR = LPTAU(I, N)
%
% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN
% KELDYSH INSTITUTE OF APPLIED MATHEMATICS
% RUSSIAN ACADEMY OF SCIENCES
%
% QUASIRANDOM SEQUENCE GENERATORS
% -------------------------------
%
% 28.11.1991
%
% NOTE TO THE USER BY the NEA Data Bank:
% This quasi random number generator has been made available to
% you on condition that its identity is preserved when used
% in computer programs. If its use leads to scientific publication
% of results you should cite it in the references, in addition
% no commercial use should be made unless agreed upon with the
% main author (Prof. I.M. Sobol')
%
% ABSTRACT
% ........
%
% POINTS BELONGING TO LP-TAU SEQUENCES UNIFORMLY DISTRIBUTED IN THE
% N-DIMENSIONAL UNIT CUBE ARE OFTEN USED IN NUMERICAL MATHEMATICS:
%
% - AS NODES FOR MULTIDIMENSIONAL INTEGRATION;
% - AS SEARCHING POINTS IN GLOBAL OPTIMIZATION;
% - AS TRIAL POINTS IN MULTI-CRITERIA DECISION MAKING;
% - AS QUASIRANDOM POINTS FOR QUASI-MONTECARLO ALGORITHMS;
% - ETC.
%
% THIS SUBROUTINE CONTAINS THE ALGORITHM FOR FAST GENERATION OF
% LP-TAU SEQUENCES THAT ARE SUITABLE FOR MULTI-PROCESSOR COMPUTATIONS.
% THE DIMENSIONS N.LE.51, THE NUMBER OF POINTS N.LT.2**30.
% THE PROGRAMMING LANGUAGE IS FORTRAN-77. THIS SUBROUTINE IS AVAILABLE
% ALSO IN %-LANGUAGE.
% THE REPORT DESCRIBING THE ALGORITHM CONTAINS THE DESCRIPTION OF THE
% ALGORITHM AND CERTAIN IMPORTANT PROPERTIES OF LP-TAU SEQUENCES AND
% THEIR GENERALIZATIONS ARE DISCUSSED.
%
% REFERENCE:
% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN
% KELDYSH INSTITUTE OF APPLIED MATHEMATICS
% RUSSIAN ACADEMY OF SCIENCES
%
% QUASIRANDOM SEQUENCE GENERATORS
% MOSCOW 1992, IPM ZAK. NO.30 (100 COPIES)
%
% ------------------------------------------------------------------------
%
% INPUT PARAMETERS:
%
% I - NUMBER OF THE POINT (I=(0,2**30-1)),
% N - DIMENSION OF THE POINT (0<N<52);
%
% OUTPUT PARAMETER:
%
% VECTOR(N) - N-VECTOR CONTAINING THE CARTESIAN CO-ORDINATES OF
% THE I-TH POINT.
%
%
% TO CALL THE SUBROUTINE WRITE:
%
% CALL LPTAU(I,N,VECTOR)
% WHERE I, N: INTEGER CAPABLE OF STORING 2**30 (INTEGER*4 ON IBM
% OR OTHER 32 BIT/WORD MACHINES)
% VECTOR: DOUBLE PRECISION ARRAY WHOSE LENGTH < 52.
%
% INTEGER QP
% QP = QUANTITY POWER
%
% PARAMETER (MAXDIM=51, QP=30, MAXNUM=2**30-1)
MAXDIM=51; QP=30; MAXNUM=2^30-1;
%
% THE DIMENSION OF THE POINT CANNOT EXCEED MAXDIM
% THE TOTAL NUMBER OF GENERATED POINTS CANNOT EXCEED 2**QP
% MAXNUM=2**30-1 // 1073741823
%
% DOUBLE PRECISION VECTOR(N)
% INTEGER I,N
%
% INTEGER PRVNUM,PRVDIM
% INTEGER DIRECT(MAXDIM,QP), MASKV(MAXDIM)
% DOUBLE PRECISION SCALE
%
% Translated into MATLAB by M. Ratto
VECTOR=zeros(1,N);
SCALE =9.31322574615478516E-10;
persistent PRVNUM PRVDIM MASKV DIRECT
if isempty(PRVNUM), PRVNUM=-2; end,
if isempty(PRVDIM), PRVDIM=0; end,
if isempty(DIRECT), ...
DIRECT(1:MAXDIM,1)=[
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912]';
DIRECT(1:MAXDIM,2)=[
805306368, 268435456, 805306368, 268435456, 805306368, ...
268435456, 805306368, 268435456, 268435456, 805306368, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
805306368, 805306368, 268435456, 805306368, 268435456, ...
805306368, 268435456, 805306368, 268435456, 268435456, ...
805306368, 268435456, 805306368, 268435456, 805306368, ...
268435456, 805306368, 805306368, 268435456, 805306368, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
805306368, 268435456, 805306368, 805306368, 268435456, ...
805306368]';
DIRECT(1:MAXDIM,3)=[
939524096, 939524096, 134217728, 671088640, 402653184, ...
402653184, 671088640, 134217728, 671088640, 402653184, ...
939524096, 134217728, 671088640, 939524096, 134217728, ...
671088640, 134217728, 939524096, 939524096, 402653184, ...
402653184, 134217728, 671088640, 402653184, 671088640, ...
402653184, 402653184, 671088640, 134217728, 134217728, ...
939524096, 939524096, 939524096, 939524096, 134217728, ...
671088640, 402653184, 402653184, 671088640, 134217728, ...
671088640, 402653184, 939524096, 134217728, 671088640, ...
939524096, 134217728, 671088640, 134217728, 939524096, ...
939524096]';
DIRECT(1:MAXDIM,4)=[
1006632960, 67108864, 603979776, 1006632960, 335544320, ...
469762048, 872415232, 738197504, 469762048, 872415232, ...
1006632960, 67108864, 872415232, 469762048, 469762048, ...
469762048, 1006632960, 335544320, 872415232, 603979776, ...
201326592, 67108864, 335544320, 67108864, 201326592, ...
738197504, 1006632960, 738197504, 603979776, 335544320, ...
738197504, 67108864, 1006632960, 67108864, 603979776, ...
1006632960, 335544320, 469762048, 872415232, 738197504, ...
469762048, 872415232, 1006632960, 67108864, 872415232, ...
469762048, 469762048, 469762048, 1006632960, 335544320, ...
872415232]';
DIRECT(1:MAXDIM,5)=[
1040187392, 637534208, 1040187392, 838860800, 167772160, ...
234881024, 167772160, 1040187392, 436207616, 33554432, ...
570425344, 1040187392, 503316480, 838860800, 973078528, ...
167772160, 234881024, 436207616, 771751936, 100663296, ...
234881024, 905969664, 771751936, 33554432, 838860800, ...
973078528, 905969664, 33554432, 301989888, 838860800, ...
100663296, 234881024, 1040187392, 637534208, 1040187392, ...
838860800, 167772160, 234881024, 167772160, 1040187392, ...
436207616, 33554432, 570425344, 1040187392, 503316480, ...
838860800, 973078528, 167772160, 234881024, 436207616, ...
771751936]';
DIRECT(1:MAXDIM,6)=[
1056964608, 352321536, 50331648, 419430400, 956301312, ...
889192448, 620756992, 117440512, 956301312, 922746880, ...
822083584, 218103808, 587202560, 385875968, 452984832, ...
218103808, 184549376, 285212672, 150994944, 956301312, ...
352321536, 654311424, 553648128, 352321536, 788529152, ...
956301312, 587202560, 251658240, 218103808, 721420288, ...
251658240, 1056964608, 520093696, 889192448, 587202560, ...
956301312, 419430400, 352321536, 83886080, 654311424, ...
419430400, 385875968, 285212672, 754974720, 50331648, ...
922746880, 989855744, 754974720, 721420288, 822083584, ...
687865856]';
DIRECT(1:MAXDIM,7)=[
1065353216, 1065353216, 578813952, 25165824, 125829120, ...
964689920, 327155712, 310378496, 360710144, 360710144, ...
159383552, 444596224, 947912704, 662700032, 444596224, ...
528482304, 578813952, 578813952, 75497472, 1065353216, ...
92274688, 511705088, 897581056, 847249408, 662700032, ...
931135488, 411041792, 713031680, 696254464, 528482304, ...
209715200, 578813952, 1065353216, 1065353216, 578813952, ...
25165824, 125829120, 964689920, 327155712, 310378496, ...
360710144, 360710144, 159383552, 444596224, 947912704, ...
662700032, 444596224, 528482304, 578813952, 578813952, ...
75497472]';
DIRECT(1:MAXDIM,8)=[
1069547520, 4194304, 826277888, 624951296, 616562688, ...
801112064, 952107008, 406847488, 398458880, 331350016, ...
356515840, 46137344, 1010827264, 1069547520, 734003200, ...
113246208, 490733568, 633339904, 910163968, 801112064, ...
893386752, 851443712, 801112064, 918552576, 742391808, ...
499122176, 62914560, 264241152, 708837376, 717225984, ...
759169024, 499122176, 272629760, 423624704, 155189248, ...
239075328, 205520896, 943718400, 373293056, 457179136, ...
406847488, 71303168, 473956352, 54525952, 624951296, ...
104857600, 1019215872, 901775360, 213909504, 281018368, ...
851443712]';
DIRECT(1:MAXDIM,9)=[
1071644672, 543162368, 190840832, 329252864, 853540864, ...
132120576, 778043392, 73400320, 178257920, 522190848, ...
639631360, 534773760, 991952896, 333447168, 48234496, ...
1059061760, 761266176, 673185792, 220200960, 396361728, ...
362807296, 815792128, 819986432, 346030080, 39845888, ...
752877568, 387973120, 643825664, 291504128, 274726912, ...
568328192, 526385152, 673185792, 98566144, 396361728, ...
727711744, 1042284544, 106954752, 299892736, 912261120, ...
44040192, 895483904, 333447168, 551550976, 467664896, ...
618659840, 606076928, 274726912, 245366784, 446693376, ...
421527552]';
DIRECT(1:MAXDIM,10)=[
1072693248, 273678336, 644874240, 753926144, 495976448, ...
869269504, 355467264, 57671680, 816840704, 961544192, ...
804257792, 495976448, 347078656, 426770432, 1066401792, ...
372244480, 84934656, 208666624, 313524224, 598736896, ...
487587840, 965738496, 1011875840, 296747008, 393216000, ...
523239424, 720371712, 823132160, 128974848, 407896064, ...
747634688, 850395136, 873463808, 504365056, 481296384, ...
686817280, 592445440, 995098624, 498073600, 969932800, ...
586153984, 1039138816, 814743552, 523239424, 294649856, ...
305135616, 506462208, 11534336, 449839104, 619708416, ...
479199232]';
DIRECT(1:MAXDIM,11)=[
1073217536, 947388416, 1070071808, 977797120, 365428736, ...
702021632, 461897728, 829947904, 425197568, 634912768, ...
437780480, 582483968, 792199168, 315097088, 611844096, ...
667418624, 166199296, 513277952, 187170816, 1036517376, ...
25690112, 201850880, 443023360, 990380032, 63438848, ...
211288064, 983040000, 1069023232, 421003264, 742916096, ...
487063552, 363331584, 973602816, 286785536, 171442176, ...
669515776, 110624768, 383254528, 289931264, 352845824, ...
878182400, 655884288, 836239360, 765984768, 549978112, ...
655884288, 85458944, 591921152, 563609600, 277348352, ...
919076864]';
DIRECT(1:MAXDIM,12)=[
1073479680, 71565312, 2359296, 891551744, 158597120, ...
383516672, 1019478016, 947126272, 621019136, 714866688, ...
738459648, 265027584, 468975616, 131858432, 504627200, ...
581173248, 266600448, 865861632, 658243584, 546045952, ...
521404416, 304873472, 1060896768, 163840000, 305922048, ...
257163264, 50069504, 773062656, 59506688, 779354112, ...
165937152, 587988992, 486801408, 160694272, 90439680, ...
423362560, 536608768, 614203392, 56885248, 999030784, ...
10747904, 764674048, 25952256, 989069312, 352583680, ...
799801344, 261357568, 873201664, 40108032, 769392640, ...
254541824]';
DIRECT(1:MAXDIM,13)=[
1073610752, 644218880, 538836992, 455475200, 1062600704, ...
139329536, 205651968, 905052160, 797048832, 452329472, ...
973471744, 627703808, 614072320, 803078144, 637403136, ...
835059712, 949878784, 662044672, 767950848, 426901504, ...
448659456, 23986176, 1016201216, 524943360, 525991936, ...
618790912, 781058048, 761659392, 458096640, 226361344, ...
950665216, 952500224, 516030464, 337510400, 496107520, ...
830865408, 944111616, 636354560, 978452480, 921567232, ...
533594112, 7471104, 678035456, 471203840, 1065746432, ...
575275008, 996540416, 909246464, 879362048, 637927424, ...
25821184]';
DIRECT(1:MAXDIM,14)=[
1073676288, 357892096, 808648704, 2424832, 2555904, ...
624230400, 69271552, 456851456, 1052966912, 600637440, ...
487260160, 794624000, 386727936, 467599360, 798031872, ...
630652928, 340983808, 493944832, 37945344, 264175616, ...
263520256, 833421312, 235077632, 464846848, 534839296, ...
992411648, 10813440, 367067136, 116457472, 115015680, ...
928710656, 619773952, 813760512, 1043398656, 967770112, ...
912850944, 72155136, 1009057792, 668532736, 462356480, ...
267321344, 795803648, 635764736, 574160896, 1003421696, ...
181075968, 56688640, 388562944, 190906368, 657915904, ...
474939392]';
DIRECT(1:MAXDIM,15)=[
1073709056, 1073709056, 137003008, 547782656, 545095680, ...
26836992, 34701312, 354385920, 925663232, 656965632, ...
327581696, 894795776, 110067712, 1038057472, 209354752, ...
596541440, 42631168, 471433216, 52527104, 666861568, ...
706707456, 674070528, 824410112, 305496064, 136282112, ...
847740928, 531464192, 222920704, 379289600, 507740160, ...
11894784, 1053392896, 129990656, 557547520, 666468352, ...
1061912576, 576684032, 1041334272, 380469248, 114196480, ...
133070848, 517046272, 129990656, 790396928, 563773440, ...
388333568, 661749760, 446791680, 737378304, 229998592, ...
348225536]';
DIRECT(1:MAXDIM,16)=[
1073725440, 16384, 605372416, 275234816, 817971200, ...
603963392, 555335680, 721534976, 997801984, 1028767744, ...
407060480, 375275520, 256688128, 1021165568, 303349760, ...
1022476288, 234143744, 106708992, 732971008, 733954048, ...
789889024, 879575040, 764657664, 762658816, 1010843648, ...
941080576, 827932672, 98942976, 1051738112, 624934912, ...
993280000, 134070272, 201375744, 567558144, 882163712, ...
649084928, 356564992, 489439232, 637091840, 60637184, ...
199278592, 815677440, 927678464, 94519296, 419184640, ...
933838848, 426655744, 911130624, 171393024, 561332224, ...
471613440]';
DIRECT(1:MAXDIM,17)=[
1073733632, 536895488, 1043685376, 679944192, 417505280, ...
301981696, 832561152, 210542592, 167501824, 1071341568, ...
229302272, 970661888, 732176384, 576659456, 402464768, ...
451584000, 368467968, 928260096, 933847040, 29319168, ...
582934528, 772612096, 330014720, 647323648, 174071808, ...
1008689152, 295919616, 353869824, 177774592, 580198400, ...
381837312, 638574592, 637558784, 679370752, 504012800, ...
747118592, 429973504, 1032609792, 932667392, 583360512, ...
969498624, 1056333824, 660955136, 247488512, 153509888, ...
242180096, 205840384, 797499392, 824565760, 234348544, ...
842326016]';
DIRECT(1:MAXDIM,18)=[
1073737728, 268455936, 52785152, 1020628992, 345018368, ...
452972544, 704442368, 255987712, 750759936, 697692160, ...
196677632, 764604416, 485625856, 522022912, 680620032, ...
362270720, 838103040, 83972096, 629133312, 46108672, ...
867561472, 725422080, 184504320, 751112192, 191918080, ...
306425856, 507310080, 30453760, 281858048, 604000256, ...
208662528, 319557632, 318779392, 476139520, 863719424, ...
567062528, 521179136, 712790016, 610299904, 293687296, ...
1023086592, 549089280, 1065242624, 707751936, 363024384, ...
16674816, 197136384, 1037561856, 195112960, 372707328, ...
992751616]';
DIRECT(1:MAXDIM,19)=[
1073739776, 939554816, 580732928, 854333440, 172619776, ...
511694848, 936142848, 518199296, 593348608, 225527808, ...
900982784, 180279296, 168904704, 62814208, 754485248, ...
730691584, 1005996032, 411174912, 249866240, 641669120, ...
1008719872, 749066240, 860993536, 94177280, 432564224, ...
226355200, 925784064, 995657728, 967731200, 436226048, ...
913799168, 549894144, 964696064, 843315200, 445863936, ...
1047422976, 548947968, 492066816, 953870336, 1002653696, ...
861440000, 385636352, 325253120, 187353088, 653584384, ...
1008269312, 748693504, 1013016576, 55814144, 255170560, ...
260708352]';
DIRECT(1:MAXDIM,20)=[
1073740800, 67126272, 829514752, 423777280, 968297472, ...
205511680, 147076096, 926669824, 202300416, 118395904, ...
381332480, 1002738688, 743042048, 292551680, 584567808, ...
284339200, 183936000, 616762368, 435221504, 159376384, ...
907322368, 595696640, 247497728, 553735168, 826051584, ...
564454400, 446024704, 214236160, 33661952, 251685888, ...
660327424, 284244992, 859868160, 722502656, 622844928, ...
324342784, 682374144, 400579584, 405353472, 605187072, ...
840682496, 212956160, 157891584, 193201152, 437990400, ...
573578240, 368053248, 580197376, 937905152, 565527552, ...
89064448]';
DIRECT(1:MAXDIM,21)=[
1073741312, 637560320, 189496832, 27474432, 129338880, ...
908054016, 641870336, 186375680, 302677504, 763663872, ...
103878144, 325187072, 858254848, 922041856, 261924352, ...
954978816, 292822528, 849512960, 210311680, 933232128, ...
691981824, 155417088, 627070464, 416795136, 182081024, ...
513433088, 848658944, 515770880, 627273216, 629169664, ...
414566912, 147450368, 698353152, 244844032, 226578944, ...
1020087808, 886978048, 389697024, 1007004160, 839646720, ...
621924864, 549962240, 609583616, 735976960, 87342592, ...
1058542080, 163066368, 307997184, 876471808, 794280448, ...
675386880]';
DIRECT(1:MAXDIM,22)=[
1073741568, 352343296, 644236032, 636735232, 615860480, ...
959444224, 287380736, 1007410432, 890187008, 399480576, ...
520092928, 643311360, 816901376, 695310080, 1019229440, ...
77034240, 733295872, 1035127552, 986582784, 332381952, ...
334852352, 364956416, 596672256, 800381696, 480316672, ...
574863104, 647347968, 702910208, 499965184, 364968704, ...
120862976, 1023256320, 995114240, 13951232, 32520448, ...
702127360, 45176064, 444945664, 237860096, 152839936, ...
530633984, 429135616, 267272448, 884808960, 933712640, ...
61605632, 174335744, 564911360, 302327552, 650589440, ...
450649344]';
DIRECT(1:MAXDIM,23)=[
1073741696, 1065385856, 1073734272, 331949184, 842310784, ...
799537536, 965852032, 369351808, 662886016, 86119808, ...
865109888, 299633792, 422735488, 181087360, 174252416, ...
1041212544, 840196224, 750314368, 391053440, 903306880, ...
742365312, 236995200, 42492800, 946000512, 771692416, ...
897405824, 613803136, 924258688, 808338304, 1038125440, ...
683814272, 177186176, 766008960, 704549248, 194555008, ...
306383744, 496592512, 416020864, 655186816, 1032204928, ...
694773632, 577910144, 45797760, 910332544, 536014976, ...
675946368, 987635840, 788223872, 353993856, 96313472, ...
85248640]';
DIRECT(1:MAXDIM,24)=[
1073741760, 4210752, 12608, 744788544, 494377792, ...
115601344, 769248448, 990895808, 851706304, 979326784, ...
692061120, 429015104, 217132864, 736067008, 55694400, ...
456152640, 631601984, 787264192, 898599104, 478383808, ...
507774272, 458270272, 392995136, 872482496, 124824768, ...
1034161344, 362141632, 1053833280, 943810496, 428920128, ...
795835200, 835462848, 961843520, 606198080, 785652672, ...
154954432, 491617344, 297351232, 580735552, 634587968, ...
185277760, 141505600, 417673280, 106907456, 395575616, ...
566958656, 352651200, 415242688, 26635200, 1030317504, ...
247212992]';
DIRECT(1:MAXDIM,25)=[
1073741792, 543187040, 536882016, 981766752, 357858144, ...
810665952, 369083488, 613015520, 86115232, 845149216, ...
606076960, 1018241504, 35245536, 635403744, 236633696, ...
407451232, 427671904, 460141792, 116344544, 990246688, ...
1024892576, 883429408, 150655392, 173476896, 197666464, ...
1016740448, 605376608, 970487008, 1006881248, 598265632, ...
1022861728, 489055392, 216680608, 371439072, 53140576, ...
965114400, 98534112, 209692256, 264598496, 321437280, ...
545303840, 324119904, 876587488, 778239712, 802033120, ...
44406496, 665829024, 803213920, 309742112, 735181344, ...
1036125600]';
DIRECT(1:MAXDIM,26)=[
1073741808, 273698896, 805312112, 903123536, 153504624, ...
689632208, 432848944, 859888752, 510853776, 240805744, ...
250610192, 852489168, 139460144, 283082224, 222702928, ...
342181488, 922872432, 187528656, 360637424, 814514736, ...
301037840, 800872624, 272595184, 158627600, 238839088, ...
927181136, 710248688, 788854608, 1048376560, 484709072, ...
85709008, 1065469744, 429237328, 490778384, 848024144, ...
443114288, 687907504, 474573648, 45706416, 681465296, ...
805303216, 14567920, 369839504, 440402480, 797652624, ...
115959088, 929784560, 91226544, 205943056, 288358704, ...
950217296]';
DIRECT(1:MAXDIM,27)=[
1073741816, 947419256, 134232008, 460100200, 1073685336, ...
398354904, 1069834248, 686054696, 108299224, 273898840, ...
731382552, 938170664, 86812552, 677346808, 602208712, ...
652635752, 209797064, 323968376, 384078968, 561178056, ...
923399256, 996597176, 942777416, 885167400, 89791048, ...
956122504, 87393464, 987661336, 993412952, 827749496, ...
903211272, 33649816, 594875176, 65052056, 822835240, ...
625704888, 1065374584, 612232920, 536299720, 1046858504, ...
939518840, 160843032, 654656088, 744496936, 872197704, ...
219111576, 829112632, 455614152, 1064192952, 313010856, ...
820754920]';
DIRECT(1:MAXDIM,28)=[
1073741820, 71582788, 603989028, 37500, 120660, ...
182195932, 213921796, 473570692, 41763004, 156352828, ...
88343188, 698012780, 666108868, 337608156, 1054329884, ...
799472220, 641885244, 392104980, 502284340, 1002405628, ...
249907140, 75586228, 206587660, 565275348, 1021426548, ...
425987996, 598058580, 401940420, 919427316, 822049324, ...
115655868, 759299588, 562394644, 990942164, 1003212268, ...
598750292, 675334852, 675293340, 445665316, 903023756, ...
872412692, 172640916, 1051615436, 91229620, 94586692, ...
344873452, 7029156, 683421900, 434258804, 955002092, ...
436424380]';
DIRECT(1:MAXDIM,29)=[
1073741822, 644245094, 1040195102, 537039474, 537089354, ...
642656334, 73402402, 664239174, 1014620426, 500917234, ...
1042677826, 347788318, 1069154738, 373259762, 362587674, ...
239395914, 132283950, 903121466, 445210638, 968851198, ...
230153254, 935549622, 308815630, 861891286, 496995094, ...
670740382, 657311830, 573565382, 248331478, 1064650798, ...
338312798, 669059078, 1065190902, 379125622, 111897166, ...
520650422, 740300390, 1046483950, 66254898, 992513134, ...
234871606, 610553330, 450553866, 566758134, 787800806, ...
1071709866, 971732606, 528102354, 790919122, 917384366, ...
656244162]';
DIRECT(1:MAXDIM,30)=[
1073741823, 357913941, 50344755, 268538457, 805540473, ...
3487029, 3146769, 592038967, 729591963, 781578389, ...
66781679, 113956361, 331153483, 967802327, 935343371, ...
324351309, 609305915, 818137857, 131059769, 918519549, ...
827341719, 922770101, 456972047, 363883221, 1057014661, ...
900956063, 580478293, 520383687, 315470533, 227601711, ...
169598765, 909227271, 796983815, 349496709, 393974911, ...
378320037, 777004343, 927999269, 616377385, 345930959, ...
989849787, 627400495, 892675125, 260314121, 1041964063, ...
531367163, 195776757, 237309785, 949187605, 719002587, ...
495745187]';
end
%
% TRAP FOR A WRONG SUBROUTINE CALL
%
if ((I<0) | (N<1) | (I>MAXNUM) | (N>MAXDIM)),
disp('LP-TAU CALL FAILED')
disp(' PRESS <ENTER> TO EXIT LPTAU')
pause
return
end
if ((PRVNUM+1==I) & (N<=PRVDIM)),
%
% RECURRENT GENERATION OF THE POINT
%
%
% SEARCH POSITION OF THE RIGHTMOST "1"
% IN THE BINARY REPRESENTATION OF I
%
L=0;
POS=0;
while L<QP & POS==0,
L=L+1;
POS=bitand(bitshift(I,-(L-1)),1);
end
%
% RIGHTMOST POSITION IS L
%
for J=1:N
MASKV(J)=bitxor(MASKV(J),DIRECT(J,L));
VECTOR(J)=MASKV(J)*SCALE;
end
else
%
% GENERATION OF THE POINT FROM "I" AND "N"
%
MASKV=zeros(1,N);
IM=bitxor(I,bitshift(I,-1));
M=0;
while IM~=0 & M<QP,
M=M+1;
if (bitand(IM,1)==1),
for J=1:N
MASKV(J)=bitxor(MASKV(J),DIRECT(J,M));
end
end
IM=bitshift(IM,-1);
end
for J=1:N
VECTOR(J)=MASKV(J)*SCALE;
end
end
%
PRVNUM=I;
PRVDIM=N;
return

View File

@ -1,130 +0,0 @@
function [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group)
% [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group)
%
% Given the Morris sample matrix, the output values and the group matrix compute the Morris measures
% -------------------------------------------------------------------------
% INPUTS
% -------------------------------------------------------------------------
% Group [NumFactor, NumGroups] := Matrix describing the groups.
% Each column represents one group.
% The element of each column are zero if the factor is not in the
% group. Otherwise it is 1.
% Sample := Matrix of the Morris sampled trajectories
% Output := Matrix of the output(s) values in correspondence of each point
% of each trajectory
% k = Number of factors
% -------------------------------------------------------------------------
% OUTPUTS
% OutMatrix (NumFactor*NumOutputs, 3)= [Mu*, Mu, StDev]
% for each output it gives the three measures of each factor
% -------------------------------------------------------------------------
if nargin==0,
disp(' ')
disp('[SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group);')
return
end
OutMatrix=[];
if nargin < 5, Group=[]; end
NumGroups = size(Group,2);
if nargin < 4 | isempty(p),
p = 4;
end
Delt = p/(2*p-2);
if NumGroups ~ 0
sizea = NumGroups; % Number of groups
GroupMat=Group;
GroupMat = GroupMat';
else
sizea = NumFact;
end
r=size(Sample,1)/(sizea+1); % Number of trajectories
% For Each Output
for k=1:size(Output,2)
OutValues=Output(:,k);
% For each r trajectory
for i=1:r
% For each step j in the trajectory
% Read the orientation matrix fact for the r-th sampling
% Read the corresponding output values
Single_Sample = Sample(i+(i-1)*sizea:i+(i-1)*sizea+sizea,:);
Single_OutValues = OutValues(i+(i-1)*sizea:i+(i-1)*sizea+sizea,:);
A = (Single_Sample(2:sizea+1,:)-Single_Sample(1:sizea,:))';
Delta = A(find(A));
% For each point of the fixed trajectory compute the values of the Morris function. The function
% is partitioned in four parts, from order zero to order 4th.
for j=1:sizea % For each point in the trajectory i.e for each factor
% matrix of factor which changes
if NumGroups ~ 0;
AuxFind (:,1) = A(:,j);
% AuxFind(find(A(:,j)),1)=1;
% Pippo = sum((Group - repmat(AuxFind,1,NumGroups)),1);
% Change_factor(j,i) = find(Pippo==0);
Change_factor = find(abs(AuxFind)>1e-010);
% If we deal with groups we can only estimate the new mu*
% measure since factors in the same groups can move in
% opposite direction and the definition of the standard
% Morris mu cannopt be applied.
% In the new version the elementary effect is defined with
% the absolute value.
%SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3));
SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt);
else
Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:));
% If no groups --> we compute both the original and
% modified measure
if Delta(j) > 0 %=> +Delta
SAmeas(Change_factor(j,i),i) = (Single_OutValues(j+1) - Single_OutValues(j) )/Delt; %(2/3);
else %=> -Delta
SAmeas(Change_factor(j,i),i) = (Single_OutValues(j) - Single_OutValues(j+1) )/Delt; %(2/3);
end
end
end %for j=1:sizea
end %for i=1:r
if NumGroups ~ 0
SAmeas = SAmeas';
end
% Compute Mu AbsMu and StDev
if any(any(isnan(SAmeas)))
for j=1:NumFact,
SAm = SAmeas(j,:);
SAm = SAm(find(~isnan(SAm)));
rr=length(SAm);
AbsMu(j,1) = sum(abs(SAm),2)/rr;
if NumGroups == 0
Mu(j,1) = sum(SAm,2)/rr;
StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5;
end
end
else
AbsMu = sum(abs(SAmeas),2)/r;
if NumGroups == 0
Mu = sum(SAmeas,2)/r;
StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5;
end
end
% Define the output Matrix - if we have groups we cannot define the old
% measure mu, only mu* makes sense
if NumGroups > 0
OutMatrix = [OutMatrix; AbsMu];
else
OutMatrix = [OutMatrix; AbsMu, Mu, StDev];
end
end % For Each Output

View File

@ -1,174 +0,0 @@
function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
% Inputs: k (1,1) := number of factors examined or number of groups examined.
% In case the groups are chosen the number of factors is stores in NumFact and
% sizea becomes the number of created groups.
% NumFact (1,1) := number of factors examined in the case when groups are chosen
% r (1,1) := sample size
% p (1,1) := number of intervals considered in [0, 1]
% UB(sizea,1) := Upper Bound for each factor
% LB(sizea,1) := Lower Bound for each factor
% GroupNumber(1,1) := Number of groups (eventually 0)
% GroupMat(NumFact,GroupNumber):= Matrix which describes the chosen groups. Each column represents a group and its elements
% are set to 1 in correspondence of the factors that belong to the fixed group. All
% the other elements are zero.
% Local Variables:
% sizeb (1,1) := sizea+1
% sizec (1,1) := 1
% randmult (sizea,1) := vector of random +1 and -1
% perm_e(1,sizea) := vector of sizea random permutated indeces
% fact(sizea) := vector containing the factor varied within each traj
% DDo(sizea,sizea) := D* in Morris, 1991
% A(sizeb,sizea) := Jk+1,k in Morris, 1991
% B(sizeb,sizea) := B in Morris, 1991
% Po(sizea,sizea) := P* in Morris, 1991
% Bo(sizeb,sizea) := B* in Morris, 1991
% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991
% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory)
% In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory
% of k step in the parameter space and it provides a single elementary
% effect per factor
% MyInt()
% Fact(sizea,1) := for each loop vector indicating which factor or group of factors has been changed
% in each step of the trajectory
% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design
% for single factor analysis, while it constitutes an intermediate step for the group analysis.
%
% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices
% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors
%
% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine
% follows the following steps:
% 1- Creation of P0 and DD0 matrices defined in Morris for the groups. This means that the dimensions of these
% 2 matrices are (GroupNumber,GroupNumber).
% 2- Creation of AuxMat matrix with (GroupNumber+1,GroupNumber) elements.
% 3- Definition of GroupB0 starting from AuxMat, GroupMat and P0.
% 4- The final B0 for groups is obtained as [ones(sizeb,1)*x0' + GroupB0]. The P0 permutation is present in GroupB0
% and it's not necessary to permute the matrix (ones(sizeb,1)*x0') because it's already randomly created.
% Reference:
% A. Saltelli, K. Chan, E.M. Scott, "Sensitivity Analysis" on page 68 ss
%
% F. Campolongo, J. Cariboni, JRC - IPSC Ispra, Varese, IT
% Last Update: 15 November 2005 by J.Cariboni
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters and initialisation of the output matrix
sizea = k;
Delta = p/(2*p-2);
%Delta = 1/3
NumFact = sizea;
GroupNumber = size(GroupMat,2);
if GroupNumber ~ 0;
sizea = size(GroupMat,2);
end
sizeb = sizea + 1;
sizec = 1;
Outmatrix = [];
OutFact = [];
% For each i generate a trajectory
for i=1:r
% Construct DD0 - OLD VERSION - it does not need communication toolbox
% RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0).
% Note that DD0 tells if the factor have to be increased or ddecreased
% by Delta.
randmult = ones(k,1);
v = rand(k,1);
randmult (find(v < 0.5))=-1;
randmult = repmat(randmult,1,k);
DD0 = randmult .* eye(k);
% Construct DD0 - NEW VERSION - it needs communication toolbox
% randsrc(m) generates an m-by-m matrix, each of whose entries independently takes the value -1 with probability 1/2,
% and 1 with probability 1/2.
% DD0 = randsrc(NumFact) .* eye(NumFact);
% Construct B (lower triangular)
B = ones(sizeb,sizea);
for j = 1:sizea
B(1:j,j)=0;
end
% Construct A0, A
A0 = ones(sizeb,1);
A = ones(sizeb,NumFact);
% Construct the permutation matrix P0. In each column of P0 one randomly chosen element equals 1
% while all the others equal zero.
% P0 tells the order in which order factors are changed in each
% trajectory. P0 is created as it follows:
% 1) All the elements of P0 are set equal to zero ==> P0 = zeros (sizea, sizea);
% 2) The function randperm create a random permutation of integer 1:sizea, without repetitions ==> perm_e;
% 3) In each column of P0 the element indicated in perm_e is set equal to one.
% Note that P0 is then used reading it by rows.
P0 = zeros (sizea, sizea);
perm_e = randperm(sizea); % RANDPERM(n) is a random permutation of the integers from 1 to n.
for j = 1:sizea
P0(perm_e(j),j) = 1;
end
% When groups are present the random permutation is done only on B. The effect is the same since
% the added part (A0*x0') is completely random.
if GroupNumber ~ 0
B = B * (GroupMat*P0')';
end
% Compute AuxMat both for single factors and groups analysis. For Single factors analysis
% AuxMat is added to (A0*X0) and then permutated through P0. When groups are active AuxMat is
% used to build GroupB0. AuxMat is created considering DD0. If the element on DD0 diagonal
% is 1 then AuxMat will start with zero and add Delta. If the element on DD0 diagonal is -1
% then DD0 will start Delta and goes to zero.
AuxMat = Delta*0.5*((2*B - A) * DD0 + A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube
% [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]
MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors
% OLD VERSION - it needs communication toolbox
% w = randint(NumFact,1,[1,size(MyInt,2)]);
% NEW VERSION - construct a version of random integers
% 1) create a vector of random integers
% 2) divide [0,1] into the needed steps
% 3) check in which interval the random numbers fall
% 4) generate the corresponding integer
v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1)
IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2)
DiffAuxVec = IntUsed - v; % 3)
for ii = 1:size(DiffAuxVec,1)
w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4)
end
x0 = MyInt(1,w)'; % Define x0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a
% trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors)
if GroupNumber ~ 0
B0 = (A0*x0' + AuxMat);
else
B0 = (A0*x0' + AuxMat)*P0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% c --> Compute values in the original intervals
% B0 has values x(i,j) in [0, 1/(p -1), 2/(p -1), ... , 1].
% To obtain values in the original intervals [LB, UB] we compute
% LB(j) + x(i,j)*(UB(j)-LB(j))
In = repmat(LB,1,sizeb)' + B0 .* repmat((UB-LB),1,sizeb)';
% Create the Factor vector. Each component of this vector indicate which factor or group of factor
% has been changed in each step of the trajectory.
for j=1:sizea
Fact(1,j) = find(P0(j,:));
end
Fact(1,sizea+1) = 0;
Outmatrix = [Outmatrix; In];
OutFact = [OutFact; Fact'];
end

View File

@ -1,38 +0,0 @@
function x = beta_inv(p, a, b)
% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution
%--------------------------------------------------------------
% USAGE: x = beta_inv(p,a,b)
% where: p = vector of probabilities
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%--------------------------------------------------------------
% RETURNS: x at each element of p for the beta(a,b) distribution
%--------------------------------------------------------------
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%--------------------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~= 3)
error('Wrong # of arguments to beta_inv');
end
if any(any((a<=0)|(b<=0)))
error('beta_inv parameter a or b is nonpositive');
end
if any(any(abs(2*p-1)>1))
error('beta_inv: A probability should be 0<=p<=1');
end
x = a ./ (a+b);
dx = 1;
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (betainc(x,a,b) - p) ./ beta_pdf(x,a,b);
x = x - dx;
x = x + (dx - x) / 2 .* (x<0);
end

View File

@ -1,32 +0,0 @@
function pdf = beta_pdf(x, a, b)
% PURPOSE: pdf of the beta(a,b) distribution
%--------------------------------------------------------------
% USAGE: pdf = beta_pdf(x,a,b)
% where: x = vector of components
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%--------------------------------------------------------------
% RETURNS: pdf at each element of x of the beta(a,b) distribution
%--------------------------------------------------------------
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%--------------------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~=3)
error('Wrong # of arguments to beta_pdf');
end
if any(any((a<=0)|(b<=0)))
error('Parameter a or b is nonpositive');
end
I = find((x<0)|(x>1));
pdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b);
pdf(I) = 0*I;

View File

@ -1,14 +0,0 @@
function h = cumplot(x);
%function h =cumplot(x)
% Copyright (C) 2005 Marco Ratto
n=length(x);
x=[-inf; sort(x); Inf];
y=[0:n n]./n;
h0 = stairs(x,y);
grid on,
if nargout,
h=h0;
end

View File

@ -1,30 +0,0 @@
function c = dat_fil_(data_file);
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
try
eval(data_file);
catch
load(data_file);
end
clear data_file;
a=who;
for j=1:length(a)
eval(['c.',a{j},'=',a{j},';']);
end

View File

@ -1,149 +0,0 @@
function dynare_MC(var_list_,OutDir)
%
% Adapted by M. Ratto from dynare_estimation.m and posteriorsmoother.m
% (dynare_estimation.m and posteriorsmoother.m are part of DYNARE,
% copyright M. Juillard)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ options_ oo_ estim_params_
global bayestopt_
% if options_.filtered_vars ~= 0 & options_.filter_step_ahead == 0
% options_.filter_step_ahead = 1;
% end
% if options_.filter_step_ahead ~= 0
% options_.nk = max(options_.filter_step_ahead);
% else
% options_.nk = 0;
% end
%
options_.filter_step_ahead=1;
options_.nk = 1;
nvx = estim_params_.nvx;
nvn = estim_params_.nvn;
ncx = estim_params_.ncx;
ncn = estim_params_.ncn;
np = estim_params_.np ;
npar = nvx+nvn+ncx+ncn+np;
if isempty(options_.datafile)
error('ESTIMATION: datafile option is missing')
end
if isempty(options_.varobs)
error('ESTIMATION: VAROBS is missing')
end
%% Read and demean data
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1);
gend = options_.nobs;
n_varobs = size(options_.varobs,1);
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
if options_.loglinear == 1 & ~options_.logdata
rawdata = log(rawdata);
end
if options_.prefilter == 1
bayestopt_.mean_varobs = mean(rawdata,1);
data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs);
else
data = transpose(rawdata);
end
[data_index,number_of_observations,no_more_missing_observations] = describe_missing_data(data,gend,n_varobs);
if ~isreal(rawdata)
error(['There are complex values in the data. Probably a wrong' ...
' transformation'])
end
offset = npar-np;
fname_=M_.fname;
options_ = set_default_option(options_,'opt_gsa',1);
options_gsa_ = options_.opt_gsa;
if options_gsa_.pprior,
namfile=[fname_,'_prior'];
else
namfile=[fname_,'_mc'];
end
load([OutDir,'/',namfile],'lpmat', 'lpmat0', 'istable')
% load(options_.mode_file)
%%
%%
%%
x=[lpmat0(istable,:) lpmat(istable,:)];
clear lpmat lpmat0 istable %iunstable egg yys T
B = size(x,1);
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(x(1,:)',gend,data,{},0);
n1=size(atT,1);
nfil=B/40;
stock_smooth = zeros(M_.endo_nbr,gend,40);
stock_filter = zeros(M_.endo_nbr,gend+1,40);
stock_ys = zeros(40, M_.endo_nbr);
logpo2=zeros(B,1);
%%
h = waitbar(0,'MC smoother ...');
delete([OutDir,'/',namfile,'_*.mat'])
ib=0;
ifil=0;
opt_gsa=options_.opt_gsa;
for b=1:B
ib=ib+1;
deep = x(b,:)';
set_all_parameters(deep);
dr = resol(oo_.steady_state,0);
%deep(1:offset) = xparam1(1:offset);
logpo2(b,1) = DsgeLikelihood(deep,gend,data,data_index,number_of_observations,no_more_missing_observations);
if opt_gsa.lik_only==0,
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(deep,gend,data,data_index,0);
stock_smooth(:,:,ib)=atT(1:M_.endo_nbr,:);
% stock_filter(:,:,ib)=filtered_state_vector(1:M_.endo_nbr,:);
stock_filter(:,:,ib)=aK(1,1:M_.endo_nbr,:);
stock_ys(ib,:)=ys';
if ib==40,
ib=0;
ifil=ifil+1;
save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys')
stock_smooth = zeros(M_.endo_nbr,gend,40);
stock_filter = zeros(M_.endo_nbr,gend+1,40);
stock_ys = zeros(40, M_.endo_nbr);
end
end
waitbar(b/B,h,['MC smoother ...',num2str(b),'/',num2str(B)]);
end
close(h)
if opt_gsa.lik_only==0,
if ib>0,
ifil=ifil+1;
stock_smooth = stock_smooth(:,:,1:ib);
stock_filter = stock_filter(:,:,1:ib);
stock_ys = stock_ys(1:ib,:);
save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys')
end
end
stock_gend=gend;
stock_data=data;
save([OutDir,'/',namfile],'x','logpo2','stock_gend','stock_data','-append')

View File

@ -1,37 +0,0 @@
% FDJAC Computes two-sided finite difference Jacobian
% USAGE
% fjac = fdjac(f,x,P1,P2,...)
% INPUTS
% f : name of function of form fval = f(x)
% x : evaluation point
% P1,P2,... : additional arguments for f (optional)
% OUTPUT
% fjac : finite differnce Jacobian
%
% USER OPTIONS (SET WITH OPSET)
% tol : a factor used in setting the step size
% increase if f is inaccurately computed
% Copyright (c) 1997-2002, Paul L. Fackler & Mario J. Miranda
% paul_fackler@ncsu.edu, miranda.4@osu.edu
function fjac = fdjac(f,x,varargin)
tol = optget(mfilename,'tol',eps.^(1/3));
h = tol.*max(abs(x),1);
xh1=x+h; xh0=x-h;
h=xh1-xh0;
for j=1:length(x);
xx = x;
xx(j) = xh1(j); f1=feval(f,xx,varargin{:});
xx(j) = xh0(j); f0=feval(f,xx,varargin{:});
fjac(:,j) = (f1-f0)/h(j);
% v = (f1-f0);
% k = find(abs(v) < 1e-8);
% v(k) = 0;
%
% fjac(:,j) = v/h(j);
end
feval(f,x,varargin{:});

View File

@ -1,708 +0,0 @@
function [rmse_MC, ixx] = filt_mc_(OutDir)
% function [rmse_MC, ixx] = filt_mc_(OutDir)
% copyright Marco Ratto 2006
% inputs (from opt_gsa structure)
% vvarvecm = options_gsa_.var_rmse;
% loadSA = options_gsa_.load_rmse;
% pfilt = options_gsa_.pfilt_rmse;
% alpha = options_gsa_.alpha_rmse;
% alpha2 = options_gsa_.alpha2_rmse;
% istart = options_gsa_.istart_rmse;
% alphaPC = 0.5;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global bayestopt_ estim_params_ M_ options_ oo_
options_gsa_=options_.opt_gsa;
vvarvecm = options_gsa_.var_rmse;
loadSA = options_gsa_.load_rmse;
pfilt = options_gsa_.pfilt_rmse;
alpha = options_gsa_.alpha_rmse;
alpha2 = options_gsa_.alpha2_rmse;
istart = options_gsa_.istart_rmse;
alphaPC = 0.5;
fname_ = M_.fname;
lgy_ = M_.endo_names;
dr_ = oo_.dr;
disp(' ')
disp(' ')
disp('Starting sensitivity analysis')
disp('for the fit of EACH observed series ...')
disp(' ')
disp('Deleting old SA figures...')
a=dir([OutDir,'/*.*']);
tmp1='0';
if options_.opt_gsa.ppost,
tmp=['_rmse_post'];
else
if options_.opt_gsa.pprior
tmp=['_rmse_prior'];
else
tmp=['_rmse_mc'];
end
if options_gsa_.lik_only,
tmp1 = [tmp,'_post_SA'];
tmp = [tmp,'_lik_SA'];
end
end
for j=1:length(a),
if strmatch([fname_,tmp],a(j).name),
disp(a(j).name)
delete([OutDir,'/',a(j).name])
end,
if strmatch([fname_,tmp1],a(j).name),
disp(a(j).name)
delete([OutDir,'/',a(j).name])
end,
end
disp('done !')
nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn;
npar=estim_params_.np;
if ~isempty(options_.mode_file),
load(options_.mode_file,'xparam1'),
end
if options_.opt_gsa.ppost,
c=load([fname_,'_mean'],'xparam1');
xparam1_mean=c.xparam1;
clear c
elseif ~isempty(options_.mode_file) & ~isempty(ls([fname_,'_mean.mat']))
c=load([fname_,'_mean'],'xparam1');
xparam1_mean=c.xparam1;
clear c
end
if options_.opt_gsa.ppost,
fnamtmp=[fname_,'_post'];
DirectoryName = CheckPath('metropolis');
else
if options_.opt_gsa.pprior
fnamtmp=[fname_,'_prior'];
else
fnamtmp=[fname_,'_mc'];
end
end
if ~loadSA,
if exist('xparam1','var')
set_all_parameters(xparam1);
steady_;
ys_mode=oo_.steady_state;
end
if exist('xparam1_mean','var')
set_all_parameters(xparam1_mean);
steady_;
ys_mean=oo_.steady_state;
end
% eval(options_.datafile)
obs = dat_fil_(options_.datafile);
if ~options_.opt_gsa.ppost
load([OutDir,'/',fnamtmp],'x','logpo2','stock_gend','stock_data');
logpo2=-logpo2;
else
%load([DirectoryName '/' M_.fname '_data.mat']);
[stock_gend, stock_data] = read_data;
filfilt = dir([DirectoryName '/' M_.fname '_filter_step_ahead*.mat']);
filparam = dir([DirectoryName '/' M_.fname '_param*.mat']);
x=[];
logpo2=[];
sto_ys=[];
for j=1:length(filparam),
%load([DirectoryName '/' M_.fname '_param',int2str(j),'.mat']);
if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name))
load([DirectoryName '/' filparam(j).name]);
x=[x; stock];
logpo2=[logpo2; stock_logpo];
sto_ys=[sto_ys; stock_ys];
clear stock stock_logpo stock_ys;
end
end
end
nruns=size(x,1);
nfilt=floor(pfilt*nruns);
if options_.opt_gsa.ppost | (options_.opt_gsa.ppost==0 & options_.opt_gsa.lik_only==0)
disp(' ')
disp('Computing RMSE''s...')
fobs = options_.first_obs;
nobs=options_.nobs;
for i=1:size(vvarvecm,1),
vj=deblank(vvarvecm(i,:));
eval(['vobs =obs.',vj,'(fobs:fobs-1+nobs);'])
if options_.prefilter == 1
%eval([vj,'=',vj,'-bayestopt_.mean_varobs(i);'])
%eval([vj,'=',vj,'-mean(',vj,',1);'])
vobs = vobs-mean(vobs,1);
end
jxj = strmatch(vj,lgy_(dr_.order_var,:),'exact');
js = strmatch(vj,lgy_,'exact');
if exist('xparam1','var')
% if isfield(oo_,'FilteredVariables')
% eval(['rmse_mode(i) = sqrt(mean((vobs(istart:end)-oo_.steady_state(js)-oo_.FilteredVariables.',vj,'(istart:end-1)).^2));'])
% else
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,stock_gend,stock_data,{},0);
y0 = squeeze(aK(1,jxj,:)) + ...
kron(ys_mode(js,:),ones(size(aK,3),1));
% y0 = ahat(jxj,:)' + ...
% kron(ys_mode(js,:),ones(size(ahat,2),1));
rmse_mode(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2));
% end
end
y0=zeros(nobs+1,nruns);
if options_.opt_gsa.ppost
%y0=zeros(nobs+max(options_.filter_step_ahead),nruns);
nbb=0;
for j=1:length(filfilt),
load([DirectoryName '/' M_.fname '_filter_step_ahead',num2str(j),'.mat']);
nb = size(stock,4);
% y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,:,:)) + ...
% kron(sto_ys(nbb+1:nbb+nb,js)',ones(size(stock,3),1));
y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,1:nobs+1,:)) + ...
kron(sto_ys(nbb+1:nbb+nb,js)',ones(nobs+1,1));
%y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock;
nbb=nbb+nb;
clear stock;
end
else
filfilt=dir([OutDir,'/',fnamtmp,'_*.mat']);
nbb=0;
for j=1:size(filfilt,1),
load([OutDir,'/',fnamtmp,'_',num2str(j),'.mat'],'stock_filter','stock_ys');
nb = size(stock_filter,3);
y0(:,nbb+1:nbb+nb) = squeeze(stock_filter(jxj,:,:)) + ...
kron(stock_ys(:,js)',ones(nobs+1,1));
%y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock;
nbb=nbb+nb;
clear stock_filter;
end
% y0 = squeeze(stock_filter(:,jxj,:)) + ...
% kron(stock_ys(js,:),ones(size(stock_filter,1),1));
end
y0M=mean(y0,2);
for j=1:nruns,
rmse_MC(j,i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1,j)).^2));
end
if exist('xparam1_mean','var')
%eval(['rmse_pmean(i) = sqrt(mean((',vj,'(fobs-1+istart:fobs-1+nobs)-y0M(istart:end-1)).^2));'])
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,stock_gend,stock_data,{},0);
y0 = squeeze(aK(1,jxj,:)) + ...
kron(ys_mean(js,:),ones(size(aK,3),1));
% y0 = ahat(jxj,:)' + ...
% kron(ys_mean(js,:),ones(size(ahat,2),1));
rmse_pmean(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2));
end
end
clear stock_filter;
end
for j=1:nruns,
lnprior(j,1) = priordens(x(j,:)',bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4);
end
likelihood=logpo2(:)-lnprior(:);
disp('... done!')
if options_.opt_gsa.ppost
save([OutDir,'/',fnamtmp], 'x', 'logpo2', 'likelihood', 'rmse_MC', 'rmse_mode','rmse_pmean')
else
if options_.opt_gsa.lik_only
save([OutDir,'/',fnamtmp], 'likelihood', '-append')
else
save([OutDir,'/',fnamtmp], 'likelihood', 'rmse_MC','-append')
if exist('xparam1_mean','var')
save([OutDir,'/',fnamtmp], 'rmse_pmean','-append')
end
if exist('xparam1','var')
save([OutDir,'/',fnamtmp], 'rmse_mode','-append')
end
end
end
else
if options_.opt_gsa.lik_only & options_.opt_gsa.ppost==0
load([OutDir,'/',fnamtmp],'x','logpo2','likelihood');
else
load([OutDir,'/',fnamtmp],'x','logpo2','likelihood','rmse_MC','rmse_mode','rmse_pmean');
end
lnprior=logpo2(:)-likelihood(:);
nruns=size(x,1);
nfilt=floor(pfilt*nruns);
end
% smirnov tests
nfilt0=nfilt*ones(size(vvarvecm,1),1);
logpo2=logpo2(:);
if ~options_.opt_gsa.ppost
[dum, ipost]=sort(-logpo2);
[dum, ilik]=sort(-likelihood);
end
if ~options_.opt_gsa.ppost & options_.opt_gsa.lik_only
if options_.opt_gsa.pprior
anam='rmse_prior_post';
else
anam='rmse_mc_post';
end
stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir);
stab_map_2(x(ipost(1:nfilt),:),alpha2,anam, OutDir);
if options_.opt_gsa.pprior
anam='rmse_prior_lik';
else
anam='rmse_mc_lik';
end
stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir);
stab_map_2(x(ilik(1:nfilt),:),alpha2,anam, OutDir);
else
for i=1:size(vvarvecm,1),
[dum, ixx(:,i)]=sort(rmse_MC(:,i));
if options_.opt_gsa.ppost,
%nfilt0(i)=length(find(rmse_MC(:,i)<rmse_pmean(i)));
rmse_txt=rmse_pmean;
else
if options_.opt_gsa.pprior | ~exist('rmse_pmean'),
if exist('rmse_mode'),
rmse_txt=rmse_mode;
else
rmse_txt=NaN(1,size(rmse_MC,2));
end
else
%nfilt0(i)=length(find(rmse_MC(:,i)<rmse_pmean(i)));
rmse_txt=rmse_pmean;
end
end
for j=1:npar+nshock,
[H,P,KSSTAT] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
[H1,P1,KSSTAT1] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
[H2,P2,KSSTAT2] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
if H1 & H2==0,
SS(j,i)=1;
elseif H1==0,
SS(j,i)=-1;
else
SS(j,i)=0;
end
PP(j,i)=P;
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Prior ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(lnprior(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, cumplot(lnprior)
h=cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_lnprior',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_lnprior',int2str(ifig)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig)]);
end
end
close(gcf)
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Likelihood ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(likelihood(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, h=cumplot(likelihood);
h=cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if options_.opt_gsa.ppost==0,
set(gca,'xlim',[min( likelihood(ixx(1:nfilt0(i),i)) ) max( likelihood(ixx(1:nfilt0(i),i)) )])
end
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_lnlik',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_lnlik',int2str(ifig)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_lnlik',int2str(ifig)]);
end
end
close(gcf)
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Posterior ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(logpo2(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, h=cumplot(logpo2);
h=cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if options_.opt_gsa.ppost==0,
set(gca,'xlim',[min( logpo2(ixx(1:nfilt0(i),i)) ) max( logpo2(ixx(1:nfilt0(i),i)) )])
end
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_lnpost',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_lnpost',int2str(ifig)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_lnpost',int2str(ifig)]);
end
end
close(gcf)
end
end
param_names='';
for j=1:npar+nshock,
param_names=str2mat(param_names, bayestopt_.name{j});
end
param_names=param_names(2:end,:);
disp(' ')
disp('RMSE over the MC sample:')
disp(' min yr RMSE max yr RMSE')
for j=1:size(vvarvecm,1),
disp([vvarvecm(j,:), sprintf('%15.5g',[(min(rmse_MC(:,j))) [(max(rmse_MC(:,j)))]])])
end
invar = find( std(rmse_MC)./mean(rmse_MC)<=0.0001 );
if ~isempty(invar)
disp(' ')
disp(' ')
disp('RMSE is not varying significantly over the MC sample for the following variables:')
disp(vvarvecm(invar,:))
disp('These variables are excluded from SA')
disp('[Unless you treat these series as exogenous, there is something wrong in your estimation !]')
end
ivar = find( std(rmse_MC)./mean(rmse_MC)>0.0001 );
vvarvecm=vvarvecm(ivar,:);
rmse_MC=rmse_MC(:,ivar);
disp(' ')
% if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior,
disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ])
% else
% disp(['Sample filtered the best RMSE''s smaller than RMSE at the posterior mean ...' ])
% end
% figure, boxplot(rmse_MC)
% set(gca,'xticklabel',vvarvecm)
% saveas(gcf,[fname_,'_SA_RMSE'])
disp(' ')
disp(' ')
disp('RMSE ranges after filtering:')
if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior,
disp([' best ',num2str(pfilt*100),'% filtered remaining 90%'])
disp([' min max min max posterior mode'])
else
disp([' best filtered remaining '])
disp([' min max min max posterior mean'])
end
for j=1:size(vvarvecm,1),
disp([vvarvecm(j,:), sprintf('%15.5g',[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ...
max(rmse_MC(ixx(1:nfilt0(j),j),j)) ...
min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ...
max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ...
rmse_txt(j)])])
% disp([vvarvecm(j,:), sprintf('%15.5g',[min(logpo2(ixx(1:nfilt,j))) ...
% max(logpo2(ixx(1:nfilt,j))) ...
% min(logpo2(ixx(nfilt+1:end,j))) ...
% max(logpo2(ixx(nfilt+1:end,j)))])])
end
SP=zeros(npar+nshock,size(vvarvecm,1));
for j=1:size(vvarvecm,1),
ns=find(PP(:,j)<alpha);
SP(ns,j)=ones(size(ns));
SS(:,j)=SS(:,j).*SP(:,j);
end
for j=1:npar+nshock, %estim_params_.np,
nsp(j)=length(find(SP(j,:)));
end
snam0=param_names(find(nsp==0),:);
snam1=param_names(find(nsp==1),:);
snam2=param_names(find(nsp>1),:);
snam=param_names(find(nsp>0),:);
% snam0=bayestopt_.name(find(nsp==0));
% snam1=bayestopt_.name(find(nsp==1));
% snam2=bayestopt_.name(find(nsp>1));
% snam=bayestopt_.name(find(nsp>0));
nsnam=(find(nsp>1));
disp(' ')
disp(' ')
disp('These parameters do not affect significantly the fit of ANY observed series:')
disp(snam0)
disp(' ')
disp('These parameters affect ONE single observed series:')
disp(snam1)
disp(' ')
disp('These parameters affect MORE THAN ONE observed series: trade off exists!')
disp(snam2)
%pnam=bayestopt_.name(end-estim_params_.np+1:end);
pnam=bayestopt_.name;
% plot trade-offs
a00=jet(size(vvarvecm,1));
for ix=1:ceil(length(nsnam)/5),
figure,
for j=1+5*(ix-1):min(size(snam2,1),5*ix),
subplot(2,3,j-5*(ix-1))
%h0=cumplot(x(:,nsnam(j)+nshock));
h0=cumplot(x(:,nsnam(j)));
set(h0,'color',[0 0 0])
hold on,
np=find(SP(nsnam(j),:));
%a0=jet(nsp(nsnam(j)));
a0=a00(np,:);
for i=1:nsp(nsnam(j)), %size(vvarvecm,1),
%h0=cumplot(x(ixx(1:nfilt,np(i)),nsnam(j)+nshock));
h0=cumplot(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)));
set(h0,'color',a0(i,:))
end
ydum=get(gca,'ylim');
%xdum=xparam1(nshock+nsnam(j));
if exist('xparam1')
xdum=xparam1(nsnam(j));
h1=plot([xdum xdum],ydum);
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
end
xlabel('')
title([pnam{nsnam(j)}],'interpreter','none')
end
%subplot(3,2,6)
h0=legend(str2mat('base',vvarvecm(np,:)),0);
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none')
%h0=legend({'base',vnam{np}}',0);
%set(findobj(get(h0,'children'),'type','text'),'interpreter','none')
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]);
end
end
end
close all
for j=1:size(SP,2),
nsx(j)=length(find(SP(:,j)));
end
number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two.
bandwidth = 0; % Rule of thumb optimal bandwidth parameter.
kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton.
%kernel_function = 'uniform'; % Gaussian kernel for Fast Fourrier Transform approximaton.
for ix=1:ceil(length(nsnam)/5),
figure,
for j=1+5*(ix-1):min(size(snam2,1),5*ix),
subplot(2,3,j-5*(ix-1))
optimal_bandwidth = mh_optimal_bandwidth(x(:,nsnam(j)),size(x,1),bandwidth,kernel_function);
[x1,f1] = kernel_density_estimate(x(:,nsnam(j)),number_of_grid_points,...
size(x,1),optimal_bandwidth,kernel_function);
h0 = plot(x1, f1,'k');
hold on,
np=find(SP(nsnam(j),:));
%a0=jet(nsp(nsnam(j)));
a0=a00(np,:);
for i=1:nsp(nsnam(j)), %size(vvarvecm,1),
optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),nfilt,bandwidth,kernel_function);
[x1,f1] = kernel_density_estimate(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),number_of_grid_points,...
nfilt, optimal_bandwidth,kernel_function);
h0 = plot(x1, f1);
set(h0,'color',a0(i,:))
end
ydum=get(gca,'ylim');
set(gca,'ylim',[0 ydum(2)]);
if exist('xparam1')
%xdum=xparam1(nshock+nsnam(j));
xdum=xparam1(nsnam(j));
h1=plot([xdum xdum],[0 ydum(2)]);
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
end
xlabel('')
title([pnam{nsnam(j)}],'interpreter','none')
end
h0=legend(str2mat('base',vvarvecm(np,:)),0);
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none')
%h0=legend({'base',vnam{np}}',0);
%set(findobj(get(h0,'children'),'type','text'),'interpreter','none')
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]);
end
end
end
close all
% for j=1:size(SP,2),
% nfig=0;
% np=find(SP(:,j));
% for i=1:nsx(j), %size(vvarvecm,1),
% if mod(i,12)==1,
% nfig=nfig+1;
% %figure('name',['Sensitivity of fit of ',vnam{j}]),
% figure('name',['Sensitivity of fit of ',deblank(vvarvecm(j,:)),' ',num2str(nfig)]),
% end
%
% subplot(3,4,i-12*(nfig-1))
% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt,j),np(i)),nfilt,bandwidth,kernel_function);
% [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt,j),np(i)),number_of_grid_points,...
% nfilt, optimal_bandwidth,kernel_function);
% plot(x1, f1,':k','linewidth',2)
% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(nfilt+1:end,j),np(i)),nruns-nfilt,bandwidth,kernel_function);
% [x1,f1] = kernel_density_estimate(x(ixx(nfilt+1:end,j),np(i)),number_of_grid_points,...
% nruns-nfilt,optimal_bandwidth,kernel_function);
% hold on, plot(x1, f1,'k','linewidth',2)
% ydum=get(gca,'ylim');
% %xdum=xparam1(nshock+np(i));
% xdum=xparam1(np(i));
% h1=plot([xdum xdum],ydum);
% set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
% %xdum1=mean(x(ixx(1:nfilt,j),np(i)+nshock));
% xdum1=mean(x(ixx(1:nfilt,j),np(i)));
% h2=plot([xdum1 xdum1],ydum);
% set(h2,'color',[0 1 0],'linewidth',2)
% % h0=cumplot(x(nfilt+1:end,np(i)+nshock));
% % set(h0,'color',[1 1 1])
% % hold on,
% % h0=cumplot(x(ixx(1:nfilt,j),np(i)+nshock));
% % set(h0,'linestyle',':','color',[1 1 1])
% %title([pnam{np(i)}])
% title([pnam{np(i)},'. K-S prob ', num2str(PP(np(i),j))],'interpreter','none')
% xlabel('')
% if mod(i,12)==0 | i==nsx(j),
% saveas(gcf,[fname_,'_rmse_',deblank(vvarvecm(j,:)),'_',int2str(nfig)])
% close(gcf)
% end
% end
% end
disp(' ')
disp(' ')
disp('Sensitivity table (significance and direction):')
vav=char(zeros(1, size(param_names,2)+3 ));
ibl = 12-size(vvarvecm,2);
for j=1:size(vvarvecm,1),
vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)];
end
disp(vav)
for j=1:npar+nshock, %estim_params_.np,
%disp([param_names(j,:), sprintf('%8.5g',SP(j,:))])
disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))])
disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))])
end
disp(' ')
disp(' ')
disp('Starting bivariate analysis:')
for i=1:size(vvarvecm,1)
if options_.opt_gsa.ppost
fnam = ['rmse_post_',deblank(vvarvecm(i,:))];
else
if options_.opt_gsa.pprior
fnam = ['rmse_prior_',deblank(vvarvecm(i,:))];
else
fnam = ['rmse_mc_',deblank(vvarvecm(i,:))];
end
end
stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,fnam, OutDir);
% [pc,latent,explained] = pcacov(c0);
% %figure, bar([explained cumsum(explained)])
% ifig=0;
% j2=0;
% for j=1:npar+nshock,
% i2=find(abs(pc(:,j))>alphaPC);
% if ~isempty(i2),
% j2=j2+1;
% if mod(j2,12)==1,
% ifig=ifig+1;
% figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]),
% end
% subplot(3,4,j2-(ifig-1)*12)
% bar(pc(i2,j)),
% set(gca,'xticklabel',bayestopt_.name(i2)),
% set(gca,'xtick',[1:length(i2)])
% title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%'])
% end
% if (mod(j2,12)==0 | j==(npar+nshock)) & j2,
% saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)])
% end
% end
% close all
end
end

View File

@ -1,27 +0,0 @@
function cdf = gamm_cdf (x, a)
% PURPOSE: returns the cdf at x of the gamma(a) distribution
%---------------------------------------------------
% USAGE: cdf = gamm_cdf(x,a)
% where: x = a vector
% a = a scalar gamma(a)
%---------------------------------------------------
% RETURNS:
% a vector of cdf at each element of x of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_inv
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
if nargin ~= 2
error('Wrong # of arguments to gamm_cdf');
end;
if any(any(a<=0))
error('gamm_cdf: parameter a is wrong')
end
cdf = gammainc(x,a);
I0 = find(x<0);
cdf(I0) = zeros(size(I0));

View File

@ -1,50 +0,0 @@
function x = gamm_inv(p,a,b)
% PURPOSE: returns the inverse of the cdf at p of the gamma(a,b) distribution
%---------------------------------------------------
% USAGE: x = gamm_inv(p,a)
% where: p = a vector of probabilities
% a = a scalar parameter gamma(a)
% b = scaling factor for gamma
%---------------------------------------------------
% RETURNS:
% a vector x of the quantile at each element of p of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_cdf
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to fit the format
% of the econometrics toolbox
if (nargin < 2 | isempty(b))
b=1;
end
if (nargin > 3)
error('Wrong # of arguments to gamm_inv');
end
if any(any(abs(2*p-1)>1))
error('gamm_inv: a probability should be 0<=p<=1')
end
if any(any(a<=0))
error('gamma_inv: parameter a is wrong')
end
x = max(a-1,0.1);
dx = 1;
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (gamm_cdf(x,a) - p) ./ gamm_pdf(x,a);
x = x - dx;
x = x + (dx - x) / 2 .* (x<0);
end
I0 = find(p==0);
x(I0) = zeros(size(I0));
I1 = find(p==1);
x(I1) = zeros(size(I0)) + Inf;
x=x.*b;

View File

@ -1,27 +0,0 @@
function f = gamm_pdf (x, a)
% PURPOSE: returns the pdf at x of the gamma(a) distribution
%---------------------------------------------------
% USAGE: pdf = gamm_pdf(x,a)
% where: x = a vector
% a = a scalar for gamma(a)
%---------------------------------------------------
% RETURNS:
% a vector of pdf at each element of x of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_cdf, gamm_rnd, gamm_inv
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
if nargin ~= 2
error('Wrong # of arguments to gamm_cdf');
end;
if any(any(a<=0))
error('gamm_pdf: parameter a is wrong')
end
f = x .^ (a-1) .* exp(-x) ./ gamma(a);
I0 = find(x<0);
f(I0) = zeros(size(I0));

Binary file not shown.

View File

@ -1,54 +0,0 @@
function [yy, xdir, isig, lam]=log_trans_(y0,xdir0)
if nargin==1,
xdir0='';
end
f=inline('skewness(log(y+lam))','lam','y');
isig=1;
if ~(max(y0)<0 | min(y0)>0)
if skewness(y0)<0,
isig=-1;
y0=-y0;
end
n=hist(y0,10);
if n(1)>20*n(end),
try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0);
catch
yl(1)=f(-min(y0)+10*eps,y0);
yl(2)=f(-min(y0)+abs(median(y0)),y0);
if abs(yl(1))<abs(yl(2))
lam=-min(y0)+eps;
else
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
end
end
yy = log(y0+lam);
xdir=[xdir0,'_logskew'];
else
isig=0;
lam=0;
yy = log(y0.^2);
xdir=[xdir0,'_logsquared'];
end
else
if max(y0)<0
isig=-1;
y0=-y0;
%yy=log(-y0);
xdir=[xdir0,'_minuslog'];
elseif min(y0)>0
%yy=log(y0);
xdir=[xdir0,'_log'];
end
try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0);
catch
yl(1)=f(-min(y0)+10*eps,y0);
yl(2)=f(-min(y0)+abs(median(y0)),y0);
if abs(yl(1))<abs(yl(2))
lam=-min(y0)+eps;
else
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
end
end
yy = log(y0+lam);
end

View File

@ -1,25 +0,0 @@
function [lpmat] = lptauSEQ(Nsam,Nvar)
% [lpmat] = lptauSEQ(Nsam,Nvar)
%
% function call LPTAU and generates a sample of dimension Nsam for a
% number of parameters Nvar
%
% Copyright (C) 2005 Marco Ratto
% THIS PROGRAM WAS WRITTEN FOR MATLAB BY
% Marco Ratto,
% Unit of Econometrics and Statistics AF
% (http://www.jrc.cec.eu.int/uasa/),
% IPSC, Joint Research Centre
% The European Commission,
% TP 361, 21020 ISPRA(VA), ITALY
% marco.ratto@jrc.it
%
clear lptau
lpmat = zeros(Nsam, Nvar);
for j=1:Nsam,
lpmat(j,:)=LPTAU(j,Nvar);
end
return

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +0,0 @@
function [vdec, cc, ac] = mc_moments(mm, ss, dr)
global options_ M_
[nr1, nc1, nsam] = size(mm);
disp('Computing theoretical moments ...')
h = waitbar(0,'Theoretical moments ...');
for j=1:nsam,
dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j);
dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j);
if ~isempty(ss),
set_shocks_param(ss(j,:));
end
[vdec(:,:,j), corr, autocorr, z, zz] = th_moments(dr,options_.varobs);
cc(:,:,j)=triu(corr);
dum=[];
for i=1:options_.ar
dum=[dum, autocorr{i}];
end
ac(:,:,j)=dum;
waitbar(j/nsam,h)
end
close(h)
disp(' ')
disp('... done !')

View File

@ -1,158 +0,0 @@
function sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
% sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
% % % % endif
if nargin < 5 | isempty(maxwhisker), maxwhisker = 1.5; end
if nargin < 4 | isempty(vertical), vertical = 1; end
if nargin < 3 | isempty(symbol), symbol = ['+','o']; end
if nargin < 2 | isempty(notched), notched = 0; end
if length(symbol)==1, symbol(2)=symbol(1); end
if notched==1, notched=0.25; end
a=1-notched;
% ## figure out how many data sets we have
if iscell(data),
nc = length(data);
else
% if isvector(data), data = data(:); end
nc = size(data,2);
end
% ## compute statistics
% ## s will contain
% ## 1,5 min and max
% ## 2,3,4 1st, 2nd and 3rd quartile
% ## 6,7 lower and upper confidence intervals for median
s = zeros(7,nc);
box = zeros(1,nc);
whisker_x = ones(2,1)*[1:nc,1:nc];
whisker_y = zeros(2,2*nc);
outliers_x = [];
outliers_y = [];
outliers2_x = [];
outliers2_y = [];
for i=1:nc
% ## Get the next data set from the array or cell array
if iscell(data)
col = data{i}(:);
else
col = data(:,i);
end
% ## Skip missing data
% % % % % % % col(isnan(col) | isna (col)) = [];
col(isnan(col)) = [];
% ## Remember the data length
nd = length(col);
box(i) = nd;
if (nd > 1)
% ## min,max and quartiles
% s(1:5,i) = statistics(col)(1:5);
s(1,i)=min(col);
s(5,i)=max(col);
s(2,i)=myprctilecol(col,25);
s(3,i)=myprctilecol(col,50);
s(4,i)=myprctilecol(col,75);
% ## confidence interval for the median
est = 1.57*(s(4,i)-s(2,i))/sqrt(nd);
s(6,i) = max([s(3,i)-est, s(2,i)]);
s(7,i) = min([s(3,i)+est, s(4,i)]);
% ## whiskers out to the last point within the desired inter-quartile range
IQR = maxwhisker*(s(4,i)-s(2,i));
whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)];
whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)];
% ## outliers beyond 1 and 2 inter-quartile ranges
outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR));
outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR);
outliers_x = [outliers_x; i*ones(size(outliers))];
outliers_y = [outliers_y; outliers];
outliers2_x = [outliers2_x; i*ones(size(outliers2))];
outliers2_y = [outliers2_y; outliers2];
elseif (nd == 1)
% ## all statistics collapse to the value of the point
s(:,i) = col;
% ## single point data sets are plotted as outliers.
outliers_x = [outliers_x; i];
outliers_y = [outliers_y; col];
else
% ## no statistics if no points
s(:,i) = NaN;
end
end
% % % % if isempty(outliers2_y)
% % % % outliers2_y=
% ## Note which boxes don't have enough stats
chop = find(box <= 1);
% ## Draw a box around the quartiles, with width proportional to the number of
% ## items in the box. Draw notches if desired.
box = box*0.23/max(box);
quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box;
quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:);
% ## Draw a line through the median
median_x = ones(2,1)*[1:nc] + [-a;+a]*box;
% median_x=median(col);
median_y = s([3,3],:);
% ## Chop all boxes which don't have enough stats
quartile_x(:,chop) = [];
quartile_y(:,chop) = [];
whisker_x(:,[chop,chop+nc]) = [];
whisker_y(:,[chop,chop+nc]) = [];
median_x(:,chop) = [];
median_y(:,chop) = [];
% % % %
% ## Add caps to the remaining whiskers
cap_x = whisker_x;
cap_x(1,:) =cap_x(1,:)- 0.05;
cap_x(2,:) =cap_x(2,:)+ 0.05;
cap_y = whisker_y([1,1],:);
% #quartile_x,quartile_y
% #whisker_x,whisker_y
% #median_x,median_y
% #cap_x,cap_y
%
% ## Do the plot
mm=min(min(data));
MM=max(max(data));
if vertical
plot (quartile_x, quartile_y, 'b', ...
whisker_x, whisker_y, 'b--', ...
cap_x, cap_y, 'k', ...
median_x, median_y, 'r', ...
outliers_x, outliers_y, [symbol(1),'r'], ...
outliers2_x, outliers2_y, [symbol(2),'r']);
set(gca,'XTick',1:nc);
set(gca, 'XLim', [0.5, nc+0.5]);
set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]);
else
% % % % % plot (quartile_y, quartile_x, "b;;",
% % % % % whisker_y, whisker_x, "b;;",
% % % % % cap_y, cap_x, "b;;",
% % % % % median_y, median_x, "r;;",
% % % % % outliers_y, outliers_x, [symbol(1),"r;;"],
% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]);
end
if nargout,
sout=s;
end
% % % endfunction

View File

@ -1,20 +0,0 @@
function y = myprctilecol(x,p);
xx = sort(x);
[m,n] = size(x);
if m==1 | n==1
m = max(m,n);
if m == 1,
y = x*ones(length(p),1);
return;
end
n = 1;
q = 100*(0.5:m - 0.5)./m;
xx = [min(x); xx(:); max(x)];
else
q = 100*(0.5:m - 0.5)./m;
xx = [min(x); xx; max(x)];
end
q = [0 q 100];
y = interp1(q,xx,p);

View File

@ -1,49 +0,0 @@
function invp = norm_inv(x, m, sd)
% PURPOSE: computes the quantile (inverse of the CDF)
% for each component of x with mean m, standard deviation sd
%---------------------------------------------------
% USAGE: invp = norm_inv(x,m,v)
% where: x = variable vector (nx1)
% m = mean vector (default=0)
% sd = standard deviation vector (default=1)
%---------------------------------------------------
% RETURNS: invp (nx1) vector
%---------------------------------------------------
% SEE ALSO: norm_d, norm_rnd, norm_inv, norm_cdf
%---------------------------------------------------
% Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Oct 26, 1994
% Copyright Dept of Probability Theory and Statistics TU Wien
% Converted to MATLAB by JP LeSage, jpl@jpl.econ.utoledo.edu
if nargin > 3
error ('Wrong # of arguments to norm_inv');
end
[r, c] = size (x);
s = r * c;
if (nargin == 1)
m = zeros(1,s);
sd = ones(1,s);
end
if length(m)==1,
m = repmat(m,1,s);
end
if length(sd)==1,
sd = repmat(sd,1,s);
end
x = reshape(x,1,s);
m = reshape(m,1,s);
sd = reshape(sd,1,s);
invp = zeros (1,s);
invp = m + sd .* (sqrt(2) * erfinv(2 * x - 1));
invp = reshape (invp, r, c);

View File

@ -1,39 +0,0 @@
% OPTGET Utility to get previously set function default values
% USAGE
% optvalue=optget(funcname,optname,optvalue);
% INPUTS
% funcname : name of function
% optname : name of option
% optval : option value
% OUTPUT
% optval : the current value of the option
%
% If the named field is not already defined, it will be set to
% optvalue, but optvalue has no effect if the field has already
% been set. Use OPTSET to change a previously set field.
%
% optget(funcname) returns the current values of the options structure.
% Copyright (c) 1997-2000, Paul L. Fackler & Mario J. Miranda
% paul_fackler@ncsu.edu, miranda.4@osu.edu
function optvalue = optget(funcname,optname,optvalue)
funcname = lower(funcname);
optvar=[funcname '_options'];
eval(['global ' optvar]) % declare a global variable
if nargin==1 % return the whole option structure
optvalue=(eval(optvar));
return
end
optname = lower(optname);
% if structure is empty or the named field does not exist
% set to the value passed
if isempty(eval(optvar)) | ~isfield(eval(optvar),optname)
eval([optvar '.' optname '=optvalue;']);
% otherwise return the value in the field
else
optvalue = eval([optvar '.' optname]);
end

View File

@ -1,105 +0,0 @@
function pdraw = prior_draw_gsa(init,rdraw)
% Draws from the prior distributions
% Adapted by M. Ratto from prior_draw (of DYNARE, copyright M. Juillard),
% for use with Sensitivity Toolbox for DYNARE
%
%
% INPUTS
% o init [integer] scalar equal to 1 (first call) or 0.
% o rdraw
%
% OUTPUTS
% o pdraw [double] draw from the joint prior density.
%
% ALGORITHM
% ...
%
% SPECIAL REQUIREMENTS
% MATLAB Statistics Toolbox
%
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
% global M_ options_ estim_params_ bayestopt_
global bayestopt_
persistent npar pshape p6 p7 p3 p4 lbcum ubcum
if init
pshape = bayestopt_.pshape;
p6 = bayestopt_.p6;
p7 = bayestopt_.p7;
p3 = bayestopt_.p3;
p4 = bayestopt_.p4;
npar = length(p6);
pdraw = zeros(npar,1);
lbcum = zeros(npar,1);
ubcum = ones(npar,1);
% set bounds for cumulative probabilities
for i = 1:npar
switch pshape(i)
case 5% Uniform prior.
p4(i) = min(p4(i),bayestopt_.ub(i));
p3(i) = max(p3(i),bayestopt_.lb(i));
case 3% Gaussian prior.
lbcum(i) = 0.5 * erfc(-(bayestopt_.lb(i)-p6(i))/p7(i) ./ sqrt(2));;
ubcum(i) = 0.5 * erfc(-(bayestopt_.ub(i)-p6(i))/p7(i) ./ sqrt(2));;
case 2% Gamma prior.
lbcum(i) = gamm_cdf((bayestopt_.lb(i)-p3(i))/p7(i),p6(i));
ubcum(i) = gamm_cdf((bayestopt_.ub(i)-p3(i))/p7(i),p6(i));
case 1% Beta distribution (TODO: generalized beta distribution)
lbcum(i) = betainc((bayestopt_.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
ubcum(i) = betainc((bayestopt_.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
case 4% INV-GAMMA1 distribution
% TO BE CHECKED
lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i))^2)/(2/p6(i)),p7(i)/2);
ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i))^2)/(2/p6(i)),p7(i)/2);
case 6% INV-GAMMA2 distribution
% TO BE CHECKED
lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i)))/(2/p6(i)),p7(i)/2);
ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i)))/(2/p6(i)),p7(i)/2);
otherwise
% Nothing to do here.
end
end
return
end
for i = 1:npar
rdraw(:,i) = rdraw(:,i).*(ubcum(i)-lbcum(i))+lbcum(i);
switch pshape(i)
case 5% Uniform prior.
pdraw(:,i) = rdraw(:,i)*(p4(i)-p3(i)) + p3(i);
case 3% Gaussian prior.
pdraw(:,i) = norm_inv(rdraw(:,i),p6(i),p7(i));
case 2% Gamma prior.
pdraw(:,i) = gamm_inv(rdraw(:,i),p6(i),p7(i))+p3(i);
case 1% Beta distribution (TODO: generalized beta distribution)
pdraw(:,i) = beta_inv(rdraw(:,i),p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
case 4% INV-GAMMA1 distribution
% TO BE CHECKED
pdraw(:,i) = sqrt(1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i)))+p3(i);
case 6% INV-GAMMA2 distribution
% TO BE CHECKED
pdraw(:,i) = 1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i))+p3(i);
otherwise
% Nothing to do here.
end
end

View File

@ -1,50 +0,0 @@
function [xcum] = priorcdf(para, pshape, p6, p7, p3, p4)
% This procedure transforms x vectors into cumulative values
% pshape: 0 is point mass, both para and p2 are ignored
% 1 is BETA(mean,stdd)
% 2 is GAMMA(mean,stdd)
% 3 is NORMAL(mean,stdd)
% 4 is INVGAMMA(s^2,nu)
% 5 is UNIFORM [p1,p2]
% Adapted by M. Ratto from MJ priordens.m
nprio = length(pshape);
i = 1;
while i <= nprio;
a = 0;
b = 0;
if pshape(i) == 1; % (generalized) BETA Prior
% mu = (p1(i)-p3(i))/(p4(i)-p3(i));
% stdd = p2(i)/(p4(i)-p3(i));
% a = (1-mu)*mu^2/stdd^2 - mu;
% b = a*(1/mu - 1);
%lnprior = lnprior + lpdfgbeta(para(i),a,b,p3(i),p4(i)) ;
para(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i));
% xcum(:,i) = betacdf(para(:,i),a,b) ;
xcum(:,i) = betainc(para(:,i),p6(i),p7(i));
elseif pshape(i) == 2; % GAMMA PRIOR
% b = p2(i)^2/(p1(i)-p3(i));
% a = (p1(i)-p3(i))/b;
%lnprior = lnprior + lpdfgam(para(i)-p3(i),a,b);
% xcum(:,i) = gamcdf(para(:,i)-p3(i),a,b);
xcum(:,i) = gamm_cdf((para(:,i)-p3(i))./p7(i),p6(i));
elseif pshape(i) == 3; % GAUSSIAN PRIOR
%lnprior = lnprior + lpdfnorm(para(i),p1(i),p2(i));
% xcum(:,i) = normcdf(para(:,i),p1(i),p2(i));
xcum(:,i) = 0.5 * erfc(-(para(:,i)-p6(i))/p7(i) ./ sqrt(2));
elseif pshape(i) == 4; % INVGAMMA1 PRIOR
%lnprior = lnprior + lpdfig1(para(i),p1(i),p2(i));
% xcum(:,i) = gamcdf(1/para(:,i).^2,p2(i)/2,2/p1(i));
xcum(:,i) = gamm_cdf((1./(para(:,i)-p3(i)).^2)/(2/p6(i)),p7(i)/2);
elseif pshape(i) == 5; % UNIFORM PRIOR
%lnprior = lnprior + log(1/(p2(i)-p1(i)));
xcum(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i));
elseif pshape(i) == 6; % INVGAMMA2 PRIOR
% lnprior = lnprior + lpdfig2(para(i),p1(i),p2(i));
% xcum(:,i) = gamcdf(1/para(:,i),p2(i)/2,2/p1(i));
xcum(:,i) = gamm_cdf((1./(para(:,i)-p3(i)))./(2/p6(i)),p7(i)/2);
end;
i = i+1;
end;

View File

@ -1,39 +0,0 @@
function [gend, data] = read_data
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global options_ bayestopt_
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1);
gend = options_.nobs;
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
if options_.loglinear == 1 & ~options_.logdata
rawdata = log(rawdata);
end
if options_.prefilter == 1
bayestopt_.mean_varobs = mean(rawdata,1);
data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs);
else
data = transpose(rawdata);
end
if ~isreal(rawdata)
error(['There are complex values in the data. Probably a wrong' ...
' transformation'])
end

View File

@ -1,351 +0,0 @@
function redform_map(dirname)
%function redform_map(dirname)
% inputs (from opt_gsa structure
% anamendo = options_gsa_.namendo;
% anamlagendo = options_gsa_.namlagendo;
% anamexo = options_gsa_.namexo;
% iload = options_gsa_.load_redform;
% pprior = options_gsa_.pprior;
% ilog = options_gsa_.logtrans_redform;
% threshold = options_gsa_.threshold_redform;
% ksstat = options_gsa_.ksstat_redform;
% alpha2 = options_gsa_.alpha2_redform;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ oo_ estim_params_ options_ bayestopt_
options_gsa_ = options_.opt_gsa;
anamendo = options_gsa_.namendo;
anamlagendo = options_gsa_.namlagendo;
anamexo = options_gsa_.namexo;
iload = options_gsa_.load_redform;
pprior = options_gsa_.pprior;
ilog = options_gsa_.logtrans_redform;
threshold = options_gsa_.threshold_redform;
ksstat = options_gsa_.ksstat_redform;
alpha2 = options_gsa_.alpha2_redform;
pnames = M_.param_names(estim_params_.param_vals(:,1),:);
if nargin==0,
dirname='';
end
if pprior
load([dirname,'/',M_.fname,'_prior']);
adir=[dirname '/redform_stab'];
else
load([dirname,'/',M_.fname,'_mc']);
adir=[dirname '/redform_mc'];
end
if ~exist('T')
stab_map_(dirname);
if pprior
load([dirname,'/',M_.fname,'_prior'],'T');
else
load([dirname,'/',M_.fname,'_mc'],'T');
end
end
if isempty(dir(adir))
mkdir(adir)
end
adir0=pwd;
%cd(adir)
nspred=size(T,2)-M_.exo_nbr;
x0=lpmat(istable,:);
[kn, np]=size(x0);
offset = length(bayestopt_.pshape)-np;
if options_gsa_.prior_range,
pshape=5*(ones(np,1));
pd = [NaN(np,1) NaN(np,1) bayestopt_.lb(offset+1:end) bayestopt_.ub(offset+1:end)];
else
pshape = bayestopt_.pshape(offset+1:end);
pd = [bayestopt_.p6(offset+1:end) bayestopt_.p7(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)];
end
nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:)));
clear lpmat lpmat0 egg iunstable yys
js=0;
for j=1:size(anamendo,1)
namendo=deblank(anamendo(j,:));
iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact');
ifig=0;
iplo=0;
for jx=1:size(anamexo,1)
namexo=deblank(anamexo(jx,:));
iexo=strmatch(namexo,M_.exo_names,'exact');
if ~isempty(iexo),
%y0=squeeze(T(iendo,iexo+nspred,istable));
y0=squeeze(T(iendo,iexo+nspred,:));
if (max(y0)-min(y0))>1.e-10,
if mod(iplo,9)==0,
ifig=ifig+1;
hfig = figure('name',[namendo,' vs. shocks ',int2str(ifig)]);
iplo=0;
end
iplo=iplo+1;
js=js+1;
xdir0 = [adir,'/',namendo,'_vs_', namexo];
if ilog==0,
if isempty(threshold)
si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namexo, xdir0);
else
iy=find( (y0>threshold(1)) & (y0<threshold(2)));
iyc=find( (y0<=threshold(1)) | (y0>=threshold(2)));
xdir = [xdir0,'_cut'];
if ~isempty(iy),
si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir);
end
if ~isempty(iy) & ~isempty(iyc)
delete([xdir, '/*cut*.*'])
[proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0);
indsmirnov = find(dproba>ksstat);
stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir);
stab_map_2(x0(iy,:),alpha2,'cut',xdir)
stab_map_2(x0(iyc,:),alpha2,'trim',xdir)
end
end
else
[yy, xdir] = log_trans_(y0,xdir0);
silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namexo, xdir);
end
figure(hfig)
subplot(3,3,iplo),
if ilog,
[saso, iso] = sort(-silog(:,js));
bar([silog(iso(1:min(np,10)),js)])
logflag='log';
else
[saso, iso] = sort(-si(:,js));
bar(si(iso(1:min(np,10)),js))
logflag='';
end
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([logflag,' ',namendo,' vs. ',namexo],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]);
close(gcf)
end
ifig=0;
iplo=0;
for je=1:size(anamlagendo,1)
namlagendo=deblank(anamlagendo(je,:));
ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact');
if ~isempty(ilagendo),
%y0=squeeze(T(iendo,ilagendo,istable));
y0=squeeze(T(iendo,ilagendo,:));
if (max(y0)-min(y0))>1.e-10,
if mod(iplo,9)==0,
ifig=ifig+1;
hfig = figure('name',[namendo,' vs. lags ',int2str(ifig)]);
iplo=0;
end
iplo=iplo+1;
js=js+1;
xdir0 = [adir,'/',namendo,'_vs_', namlagendo];
if ilog==0,
if isempty(threshold)
si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namlagendo, xdir0);
else
iy=find( (y0>threshold(1)) & (y0<threshold(2)));
iyc=find( (y0<=threshold(1)) | (y0>=threshold(2)));
xdir = [xdir0,'_cut'];
if ~isempty(iy)
si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir);
end
if ~isempty(iy) & ~isempty(iyc),
delete([xdir, '/*cut*.*'])
[proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0);
indsmirnov = find(dproba>ksstat);
stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir);
stab_map_2(x0(iy,:),alpha2,'cut',xdir)
stab_map_2(x0(iyc,:),alpha2,'trim',xdir)
end
end
else
[yy, xdir] = log_trans_(y0,xdir0);
silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namlagendo, xdir);
end
figure(hfig),
subplot(3,3,iplo),
if ilog,
[saso, iso] = sort(-silog(:,js));
bar([silog(iso(1:min(np,10)),js)])
logflag='log';
else
[saso, iso] = sort(-si(:,js));
bar(si(iso(1:min(np,10)),js))
logflag='';
end
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([logflag,' ',namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]);
close(gcf)
end
end
if ilog==0,
figure, %bar(si)
% boxplot(si','whis',10,'symbol','r.')
myboxplot(si',[],'.',[],10)
xlabel(' ')
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
set(gca,'xlim',[0.5 np+0.5])
set(gca,'ylim',[0 1])
set(gca,'position',[0.13 0.2 0.775 0.7])
for ip=1:np,
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title('Reduced form GSA')
saveas(gcf,[dirname,'/',M_.fname,'_redform_gsa'])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_gsa']);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_gsa']);
else
figure, %bar(silog)
% boxplot(silog','whis',10,'symbol','r.')
myboxplot(silog',[],'.',[],10)
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
xlabel(' ')
set(gca,'xlim',[0.5 np+0.5])
set(gca,'ylim',[0 1])
set(gca,'position',[0.13 0.2 0.775 0.7])
for ip=1:np,
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title('Reduced form GSA - Log-transformed elements')
saveas(gcf,[dirname,'/',M_.fname,'_redform_gsa_log'])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_gsa_log']);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_gsa_log']);
end
function si = redform_private(x0, y0, pshape, pd, iload, pnames, namy, namx, xdir)
global bayestopt_ options_
opt_gsa=options_.opt_gsa;
np=size(x0,2);
x00=x0;
if opt_gsa.prior_range,
for j=1:np,
x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3));
end
else
x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4));
end
fname=[xdir,'/map'];
if iload==0,
figure, hist(y0,30), title([namy,' vs. ', namx])
if isempty(dir(xdir))
mkdir(xdir)
end
saveas(gcf,[xdir,'/', namy,'_vs_', namx])
eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx]);
eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx]);
close(gcf)
% gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames);
nrun=length(y0);
nest=min(250,nrun);
nfit=min(1000,nrun);
% dotheplots = (nfit<=nest);
gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames);
if nfit>nest,
gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames);
end
save([fname,'.mat'],'gsa_')
[sidum, iii]=sort(-gsa_.si);
gsa_.x0=x00(1:nfit,:);
hfig=gsa_sdp_plot(gsa_,fname,pnames,iii(1:min(12,np)));
close(hfig);
gsa_.x0=x0(1:nfit,:);
% copyfile([fname,'_est.mat'],[fname,'.mat'])
figure,
plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'),
title([namy,' vs. ', namx,' fit'])
saveas(gcf,[xdir,'/', namy,'_vs_', namx,'_fit'])
eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx,'_fit']);
eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx,'_fit']);
close(gcf)
if nfit<nrun,
npred=[nfit+1:nrun];
yf = ss_anova_fcast(x0(npred,:), gsa_);
figure,
plot(y0(npred),[yf y0(npred)],'.'),
title([namy,' vs. ', namx,' pred'])
saveas(gcf,[xdir,'/', namy,'_vs_', namx,'_pred'])
eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx,'_pred']);
eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx,'_pred']);
close(gcf)
end
else
% gsa_ = gsa_sdp_dyn(y0, x0, 0, [],[],[],0,fname, pnames);
gsa_ = gsa_sdp(y0, x0, 0, [],[],[],0,fname, pnames);
yf = ss_anova_fcast(x0, gsa_);
figure,
plot(y0,[yf y0],'.'),
title([namy,' vs. ', namx,' pred'])
saveas(gcf,[xdir,'/', namy,'_vs_', namx,'_pred'])
eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx,'_pred']);
eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx,'_pred']);
close(gcf)
end
% si = gsa_.multivariate.si;
si = gsa_.si;

View File

@ -1,165 +0,0 @@
function redform_screen(dirname)
%function redform_map(dirname)
% inputs (from opt_gsa structure
% anamendo = options_gsa_.namendo;
% anamlagendo = options_gsa_.namlagendo;
% anamexo = options_gsa_.namexo;
% iload = options_gsa_.load_redform;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ oo_ estim_params_ options_ bayestopt_
options_gsa_ = options_.opt_gsa;
anamendo = options_gsa_.namendo;
anamlagendo = options_gsa_.namlagendo;
anamexo = options_gsa_.namexo;
iload = options_gsa_.load_redform;
nliv = options_gsa_.morris_nliv;
pnames = M_.param_names(estim_params_.param_vals(:,1),:);
if nargin==0,
dirname='';
end
load([dirname,'/',M_.fname,'_prior'],'lpmat','lpmat0','istable','T');
nspred=oo_.dr.nspred;
[kn, np]=size(lpmat);
nshock = length(bayestopt_.pshape)-np;
nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:)));
js=0;
for j=1:size(anamendo,1),
namendo=deblank(anamendo(j,:));
iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact');
iplo=0;
ifig=0;
for jx=1:size(anamexo,1)
namexo=deblank(anamexo(jx,:));
iexo=strmatch(namexo,M_.exo_names,'exact');
if ~isempty(iexo),
y0=teff(T(iendo,iexo+nspred,:),kn,istable);
if ~isempty(y0),
if mod(iplo,9)==0,
ifig=ifig+1;
figure('name',[namendo,' vs. shocks ',int2str(ifig)]),
iplo=0;
end
iplo=iplo+1;
js=js+1;
subplot(3,3,iplo),
[SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
SAM = squeeze(SAMorris(nshock+1:end,1));
SA(:,js)=SAM./(max(SAM)+eps);
[saso, iso] = sort(-SA(:,js));
bar(SA(iso(1:min(np,10)),js))
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([namendo,' vs. ',namexo],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]);
close(gcf)
end
iplo=0;
ifig=0;
for je=1:size(anamlagendo,1)
namlagendo=deblank(anamlagendo(je,:));
ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact');
if ~isempty(ilagendo),
y0=teff(T(iendo,ilagendo,:),kn,istable);
if ~isempty(y0),
if mod(iplo,9)==0,
ifig=ifig+1;
figure('name',[namendo,' vs. lagged endogenous ',int2str(ifig)]),
iplo=0;
end
iplo=iplo+1;
js=js+1;
subplot(3,3,iplo),
[SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
SAM = squeeze(SAMorris(nshock+1:end,1));
SA(:,js)=SAM./(max(SAM)+eps);
[saso, iso] = sort(-SA(:,js));
bar(SA(iso(1:min(np,10)),js))
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set(gca,'xticklabel',' ','fontsize',10)
set(gca,'xlim',[0.5 10.5])
for ip=1:min(np,10),
text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
if iplo==9,
saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
close(gcf)
end
end
end
end
if iplo<9 & iplo>0 & ifig,
saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]);
close(gcf)
end
end
figure,
%bar(SA)
% boxplot(SA','whis',10,'symbol','r.')
myboxplot(SA',[],'.',[],10)
set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
set(gca,'xlim',[0.5 np+0.5])
set(gca,'ylim',[0 1])
set(gca,'position',[0.13 0.2 0.775 0.7])
for ip=1:np,
text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
end
xlabel(' ')
ylabel('Elementary Effects')
title('Reduced form screening')
saveas(gcf,[dirname,'/',M_.fname,'_redform_screen'])
eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_screen']);
eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_screen']);

View File

@ -1,30 +0,0 @@
function set_shocks_param(xparam1)
global estim_params_ M_
nvx = estim_params_.nvx;
ncx = estim_params_.ncx;
np = estim_params_.np;
Sigma_e = M_.Sigma_e;
offset = 0;
if nvx
offset = offset + nvx;
var_exo = estim_params_.var_exo;
for i=1:nvx
k = var_exo(i,1);
Sigma_e(k,k) = xparam1(i)^2;
end
end
if ncx
offset = offset + estim_params_.nvn;
corrx = estim_params_.corrx;
for i=1:ncx
k1 = corrx(i,1);
k2 = corrx(i,2);
Sigma_e(k1,k2) = xparam1(i+offset)*sqrt(Sigma_e_(k1,k1)*Sigma_e_(k2,k2));
Sigma_e(k2,k1) = Sigma_e_(k1,k2);
end
end
M_.Sigma_e = Sigma_e;

View File

@ -1,7 +0,0 @@
function s=skewness(y),
% y=stand_(y);
% s=mean(y.^3);
m2=mean((y-mean(y)).^2);
m3=mean((y-mean(y)).^3);
s=m3/m2^1.5;

View File

@ -1,73 +0,0 @@
function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
% Smirnov test for 2 distributions
% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
if nargin<3
alpha = 0.05;
end
if nargin<4,
iflag=0;
end
% empirical cdfs.
xmix= [x1;x2];
bin = [-inf ; sort(xmix) ; inf];
ncount1 = histc (x1 , bin);
ncount1 = ncount1(:);
ncount2 = histc (x2 , bin);
ncount2 = ncount2(:);
cum1 = cumsum(ncount1)./sum(ncount1);
cum1 = cum1(1:end-1);
cum2 = cumsum(ncount2)./sum(ncount2);
cum2 = cum2(1:end-1);
n1= length(x1);
n2= length(x2);
n = n1*n2 /(n1+n2);
% Compute the d(n1,n2) statistics.
if iflag==0,
d = max(abs(cum1 - cum2));
elseif iflag==-1
d = max(cum2 - cum1);
elseif iflag==1
d = max(cum1 - cum2);
end
%
% Compute P-value check H0 hypothesis
%
lam = max((sqrt(n) + 0.12 + 0.11/sqrt(n)) * d , 0);
if iflag == 0
j = [1:101]';
prob = 2 * sum((-1).^(j-1).*exp(-2*lam*lam*j.^2));
prob=max(prob,0);
prob=min(1,prob);
else
prob = exp(-2*lam*lam);
end
H = (alpha >= prob);

View File

@ -1,52 +0,0 @@
function [tadj, iff] = speed(A,B,mf,p),
% [tadj, iff] = speed(A,B,mf,p),
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
nvar=length(mf);
nstate= size(A,1);
nshock = size(B,2);
nrun=size(B,3);
iff=zeros(nvar,nshock,nrun);
tadj=iff;
disp('Computing speed of adjustement ...')
h = waitbar(0,'Speed of adjustement...');
for i=1:nrun,
irf=zeros(nvar,nshock);
a=squeeze(A(:,:,i));
b=squeeze(B(:,:,i));
IFF=inv(eye(nstate)-a)*b;
iff(:,:,i)=IFF(mf,:);
IF=IFF-b;
t=0;
while any(any(irf<0.5))
t=t+1;
IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b;
irf=IFT(mf,:)./(IF(mf,:)+eps);
irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7);
%irf=ft(mf,:);
tt=(irf>0.5).*t;
tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i);
end
waitbar(i/nrun,h)
end
disp(' ')
disp('.. done !')
close(h)

View File

@ -1,556 +0,0 @@
function x0 = stab_map_(OutputDirectoryName)
%
% function x0 = stab_map_(OutputDirectoryName)
%
% Mapping of stability regions in the prior ranges applying
% Monte Carlo filtering techniques.
%
% INPUTS (from opt_gsa structure)
% Nsam = MC sample size
% fload = 0 to run new MC; 1 to load prevoiusly generated analysis
% alpha2 = significance level for bivariate sensitivity analysis
% [abs(corrcoef) > alpha2]
% prepSA = 1: save transition matrices for mapping reduced form
% = 0: no transition matrix saved (default)
% pprior = 1: sample from prior ranges (default): sample saved in
% _prior.mat file
% = 0: sample from posterior ranges: sample saved in
% _mc.mat file
% OUTPUT:
% x0: one parameter vector for which the model is stable.
%
% GRAPHS
% 1) Pdf's of marginal distributions under the stability (dotted
% lines) and unstability (solid lines) regions
% 2) Cumulative distributions of:
% - stable subset (dotted lines)
% - unacceptable subset (solid lines)
% 3) Bivariate plots of significant correlation patterns
% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets
%
% USES lptauSEQ,
% stab_map_1, stab_map_2
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
global bayestopt_ estim_params_ options_ oo_ M_
opt_gsa=options_.opt_gsa;
Nsam = opt_gsa.Nsam;
fload = opt_gsa.load_stab;
ksstat = opt_gsa.ksstat;
alpha2 = opt_gsa.alpha2_stab;
prepSA = (opt_gsa.redform | opt_gsa.identification);
pprior = opt_gsa.pprior;
ilptau = opt_gsa.ilptau;
nliv = opt_gsa.morris_nliv;
ntra = opt_gsa.morris_ntra;
dr_ = oo_.dr;
%if isfield(dr_,'ghx'),
ys_ = oo_.dr.ys;
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
%end
fname_ = M_.fname;
np = estim_params_.np;
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
lpmat0=[];
pshape = bayestopt_.pshape(nshock+1:end);
p1 = bayestopt_.p1(nshock+1:end);
p2 = bayestopt_.p2(nshock+1:end);
p3 = bayestopt_.p3(nshock+1:end);
p4 = bayestopt_.p4(nshock+1:end);
if nargin==0,
OutputDirectoryName='';
end
opt=options_;
options_.periods=0;
options_.nomoments=1;
options_.irf=0;
options_.noprint=1;
options_.simul=0;
if fload==0,
% if prepSA
% T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam/2);
% end
if isfield(dr_,'ghx'),
egg=zeros(length(dr_.eigval),Nsam);
end
yys=zeros(length(dr_.ys),Nsam);
if opt_gsa.morris == 1
[lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2;
Nsam=size(lpmat,1);
lpmat0 = lpmat(:,1:nshock);
lpmat = lpmat(:,nshock+1:end);
elseif opt_gsa.morris==3,
lpmat = prep_ide(Nsam,np,5);
Nsam=size(lpmat,1);
else
if np<52 & ilptau>0,
[lpmat] = lptauSEQ(Nsam,np); % lptau
if np>30 | ilptau==2, % scrambled lptau
for j=1:np,
lpmat(:,j)=lpmat(randperm(Nsam),j);
end
end
else %ilptau==0
%[lpmat] = rand(Nsam,np);
for j=1:np,
lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
end
end
end
% try
dummy=prior_draw_gsa(1);
% catch
% if pprior,
% if opt_gsa.prior_range==0;
% error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!');
% end
% end
%
% end
if pprior,
for j=1:nshock,
if opt_gsa.morris~=1,
lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
end
if opt_gsa.prior_range
lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j);
end
end
if opt_gsa.prior_range
% if opt_gsa.identification,
% deltx=min(0.001, 1/Nsam/2);
% for j=1:np,
% xdelt(:,:,j)=prior_draw_gsa(0,[lpmat0 lpmat]+deltx);
% end
% end
for j=1:np,
lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock);
end
else
xx=prior_draw_gsa(0,[lpmat0 lpmat]);
% if opt_gsa.identification,
% deltx=min(0.001, 1/Nsam/2);
% ldum=[lpmat0 lpmat];
% ldum = prior_draw_gsa(0,ldum+deltx);
% for j=1:nshock+np,
% xdelt(:,:,j)=xx;
% xdelt(:,j,j)=ldum(:,j);
% end
% clear ldum
% end
lpmat0=xx(:,1:nshock);
lpmat=xx(:,nshock+1:end);
clear xx;
end
else
% for j=1:nshock,
% xparam1(j) = oo_.posterior_mode.shocks_std.(bayestopt_.name{j});
% sd(j) = oo_.posterior_std.shocks_std.(bayestopt_.name{j});
% lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
% lb = max(bayestopt_.lb(j), xparam1(j)-2*sd(j));
% ub1=xparam1(j)+(xparam1(j) - lb); % define symmetric range around the mode!
% ub = min(bayestopt_.ub(j),ub1);
% if ub<ub1,
% lb=xparam1(j)-(ub-xparam1(j)); % define symmetric range around the mode!
% end
% lpmat0(:,j) = lpmat0(:,j).*(ub-lb)+lb;
% end
% %
% for j=1:np,
% xparam1(j+nshock) = oo_.posterior_mode.parameters.(bayestopt_.name{j+nshock});
% sd(j+nshock) = oo_.posterior_std.parameters.(bayestopt_.name{j+nshock});
% lb = max(bayestopt_.lb(j+nshock),xparam1(j+nshock)-2*sd(j+nshock));
% ub1=xparam1(j+nshock)+(xparam1(j+nshock) - lb); % define symmetric range around the mode!
% ub = min(bayestopt_.ub(j+nshock),ub1);
% if ub<ub1,
% lb=xparam1(j+nshock)-(ub-xparam1(j+nshock)); % define symmetric range around the mode!
% end
% %ub = min(bayestopt_.ub(j+nshock),xparam1(j+nshock)+2*sd(j+nshock));
% if np>30 & np<52
% lpmat(:,j) = lpmat(randperm(Nsam),j).*(ub-lb)+lb;
% else
% lpmat(:,j) = lpmat(:,j).*(ub-lb)+lb;
% end
% end
%load([fname_,'_mode'])
eval(['load ' options_.mode_file ';']');
d = chol(inv(hh));
lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1');
for j=1:Nsam*2,
lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub);
end
ireal=[1:2*Nsam];
ireal=ireal(find(lnprior==0));
lp=lp(ireal,:);
Nsam=min(Nsam, length(ireal));
lpmat0=lp(1:Nsam,1:nshock);
lpmat=lp(1:Nsam,nshock+1:end);
clear lp lnprior ireal;
end
%
h = waitbar(0,'Please wait...');
istable=[1:Nsam];
jstab=0;
iunstable=[1:Nsam];
iindeterm=zeros(1,Nsam);
iwrong=zeros(1,Nsam);
for j=1:Nsam,
M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)';
%try stoch_simul([]);
try
[Tt,Rr,SteadyState,infox{j}] = dynare_resolve(bayestopt_.restrict_var_list,...
bayestopt_.restrict_columns,...
bayestopt_.restrict_aux);
if infox{j}==0,
check1 = max(abs(feval([M_.fname '_static'],...
SteadyState,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params))) > options_.dynatol ;
if check1,
error(['The seadystate values returned by ' M_.fname ...
'_steadystate.m don''t solve the static model!' ])
end
end
if ~exist('T')
dr_=oo_.dr;
T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam);
egg=zeros(length(dr_.eigval),Nsam);
end
catch
if isfield(oo_.dr,'eigval'),
oo_.dr=rmfield(oo_.dr,'eigval');
end
if isfield(oo_.dr,'ghx'),
oo_.dr=rmfield(oo_.dr,'ghx');
end
disp('No solution could be found'),
end
dr_ = oo_.dr;
if isfield(dr_,'ghx'),
egg(:,j) = sort(dr_.eigval);
iunstable(j)=0;
if prepSA
jstab=jstab+1;
T(:,:,jstab) = [dr_.ghx dr_.ghu];
% [A,B] = ghx2transition(squeeze(T(:,:,jstab)), ...
% bayestopt_.restrict_var_list, ...
% bayestopt_.restrict_columns, ...
% bayestopt_.restrict_aux);
end
if ~exist('nspred'),
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
end
else
istable(j)=0;
if isfield(dr_,'eigval')
egg(:,j) = sort(dr_.eigval);
if exist('nspred')
if any(isnan(egg(1:nspred,j)))
iwrong(j)=j;
else
if (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium,
iindeterm(j)=j;
end
end
end
else
if exist('egg'),
egg(:,j)=ones(size(egg,1),1).*NaN;
end
iwrong(j)=j;
end
end
ys_=real(dr_.ys);
yys(:,j) = ys_;
ys_=yys(:,1);
waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
end
close(h)
if prepSA,
T=T(:,:,1:jstab);
end
istable=istable(find(istable)); % stable params
iunstable=iunstable(find(iunstable)); % unstable params
iindeterm=iindeterm(find(iindeterm)); % indeterminacy
iwrong=iwrong(find(iwrong)); % dynare could not find solution
% % map stable samples
% istable=[1:Nsam];
% for j=1:Nsam,
% if any(isnan(egg(1:nspred,j)))
% istable(j)=0;
% else
% if abs(egg(nspred,j))>=options_.qz_criterium; %(1-(options_.qz_criterium-1)); %1-1.e-5;
% istable(j)=0;
% %elseif (dr_.nboth | dr_.nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5;
% elseif (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5;
% istable(j)=0;
% end
% end
% end
% istable=istable(find(istable)); % stable params
%
% % map unstable samples
% iunstable=[1:Nsam];
% for j=1:Nsam,
% %if abs(egg(dr_.npred+1,j))>1+1.e-5 & abs(egg(dr_.npred,j))<1-1.e-5;
% %if (dr_.nboth | dr_.nfwrd),
% if ~any(isnan(egg(1:5,j)))
% if (nboth | nfwrd),
% if abs(egg(nspred+1,j))>options_.qz_criterium & abs(egg(nspred,j))<options_.qz_criterium; %(1-(options_.qz_criterium-1));
% iunstable(j)=0;
% end
% else
% if abs(egg(nspred,j))<options_.qz_criterium; %(1-(options_.qz_criterium-1));
% iunstable(j)=0;
% end
% end
% end
% end
% iunstable=iunstable(find(iunstable)); % unstable params
bkpprior.pshape=bayestopt_.pshape;
bkpprior.p1=bayestopt_.p1;
bkpprior.p2=bayestopt_.p2;
bkpprior.p3=bayestopt_.p3;
bkpprior.p4=bayestopt_.p4;
if pprior,
if ~prepSA
save([OutputDirectoryName '/' fname_ '_prior'], ...
'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','nspred','nboth','nfwrd')
else
save([OutputDirectoryName '/' fname_ '_prior'], ...
'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','T','nspred','nboth','nfwrd')
end
else
if ~prepSA
save([OutputDirectoryName '/' fname_ '_mc'], ...
'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','nspred','nboth','nfwrd')
else
save([OutputDirectoryName '/' fname_ '_mc'], ...
'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
'egg','yys','T','nspred','nboth','nfwrd')
end
end
else
if pprior,
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
else
filetoload=[OutputDirectoryName '/' fname_ '_mc'];
end
load(filetoload,'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong','egg','yys','nspred','nboth','nfwrd')
Nsam = size(lpmat,1);
if prepSA & isempty(strmatch('T',who('-file', filetoload),'exact')),
h = waitbar(0,'Please wait...');
options_.periods=0;
options_.nomoments=1;
options_.irf=0;
options_.noprint=1;
stoch_simul([]);
%T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),length(istable));
ntrans=length(istable);
for j=1:ntrans,
M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(j),:)';
%stoch_simul([]);
[Tt,Rr,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,...
bayestopt_.restrict_columns,...
bayestopt_.restrict_aux);
if ~exist('T')
T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),ntrans);
end
dr_ = oo_.dr;
T(:,:,j) = [dr_.ghx dr_.ghu];
if ~exist('nspred')
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
end
ys_=real(dr_.ys);
yys(:,j) = ys_;
ys_=yys(:,1);
waitbar(j/ntrans,h,['MC iteration ',int2str(j),'/',int2str(ntrans)])
end
close(h)
save(filetoload,'T','-append')
elseif prepSA
load(filetoload,'T')
end
end
if pprior
aname='prior_stab';
auname='prior_unacceptable';
aunstname='prior_unstable';
aindname='prior_indeterm';
awrongname='prior_wrong';
asname='prior_stable';
else
aname='mc_stab';
auname='mc_unacceptable';
aunstname='mc_unstable';
aindname='mc_indeterm';
awrongname='mc_wrong';
asname='mc_stable';
end
delete([OutputDirectoryName,'/',fname_,'_',aname,'_*.*']);
%delete([OutputDirectoryName,'/',fname_,'_',aname,'_SA_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',asname,'_corr_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',auname,'_corr_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',aunstname,'_corr_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',aindname,'_corr_*.*']);
if length(iunstable)>0 & length(iunstable)<Nsam,
disp([num2str(length(istable)/Nsam*100,3),'\% of the prior support is stable.'])
disp([num2str( (length(iunstable)-length(iwrong)-length(iindeterm) )/Nsam*100),'\% of the prior support is unstable.'])
if ~isempty(iindeterm),
disp([num2str(length(iindeterm)/Nsam*100,3),'\% of the prior support gives indeterminacy.'])
end
if ~isempty(iwrong),
disp(' ');
disp(['For ',num2str(length(iwrong)/Nsam*100,3),'\% of the prior support dynare could not find a solution.'])
end
disp(' ');
% Blanchard Kahn
[proba, dproba] = stab_map_1(lpmat, istable, iunstable, aname,0);
indstab=find(dproba>ksstat);
disp('Smirnov statistics in driving acceptable behaviour')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indstab)
stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName);
end
ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong])));
if ~isempty(iindeterm),
[proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'],0);
indindet=find(dproba>ksstat);
disp('Smirnov statistics in driving indeterminacy')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indindet)
stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'], 1, indindet, OutputDirectoryName);
end
end
if ~isempty(ixun),
[proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'],0);
indunst=find(dproba>ksstat);
disp('Smirnov statistics in driving instability')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indunst)
stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'], 1, indunst, OutputDirectoryName);
end
end
if ~isempty(iwrong),
[proba, dproba] = stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'],0);
indwrong=find(dproba>ksstat);
disp('Smirnov statistics in driving no solution')
for j=1:np,
disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)])
end
disp(' ');
if ~isempty(indwrong)
stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'], 1, indwrong, OutputDirectoryName);
end
end
disp(' ')
disp('Starting bivariate analysis:')
c0=corrcoef(lpmat(istable,:));
c00=tril(c0,-1);
stab_map_2(lpmat(istable,:),alpha2, asname, OutputDirectoryName);
if length(iunstable)>10,
stab_map_2(lpmat(iunstable,:),alpha2, auname, OutputDirectoryName);
end
if length(iindeterm)>10,
stab_map_2(lpmat(iindeterm,:),alpha2, aindname, OutputDirectoryName);
end
if length(ixun)>10,
stab_map_2(lpmat(ixun,:),alpha2, aunstname, OutputDirectoryName);
end
if length(iwrong)>10,
stab_map_2(lpmat(iwrong,:),alpha2, awrongname, OutputDirectoryName);
end
x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
x0 = [x0; lpmat(istable(1),:)'];
if istable(end)~=Nsam
M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)';
[oo_.dr, info] = resol(oo_.steady_state,0);
% stoch_simul([]);
end
else
if length(iunstable)==0,
disp('All parameter values in the specified ranges are stable!')
x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
x0 = [x0; lpmat(istable(1),:)'];
else
disp('All parameter values in the specified ranges are not acceptable!')
x0=[];
end
end
options_.periods=opt.periods;
if isfield(opt,'nomoments'),
options_.nomoments=opt.nomoments;
end
options_.irf=opt.irf;
options_.noprint=opt.noprint;
if isfield(opt,'simul'),
options_.simul=opt.simul;
end

View File

@ -1,87 +0,0 @@
function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname)
%function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname)
%
% lpmat = Monte Carlo matrix
% ibehaviour = index of behavioural runs
% inonbehaviour = index of non-behavioural runs
% aname = label of the analysis
% iplot = 1 plot cumulative distributions (default)
% iplot = 0 no plots
% ipar = index array of parameters to plot
% dirname = (OPTIONAL) path of the directory where to save
% (default: current directory)
%
% Plots: dotted lines for BEHAVIOURAL
% solid lines for NON BEHAVIOURAL
% USES smirnov
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global estim_params_ bayestopt_ M_ options_
if nargin<5,
iplot=1;
end
fname_ = M_.fname;
if nargin<7,
dirname='';;
end
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
npar=size(lpmat,2);
ishock= npar>estim_params_.np;
if nargin<6 | isempty(ipar),
ipar=[1:npar];
end
nparplot=length(ipar);
% Smirnov test for Blanchard;
for j=1:npar,
[H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j));
proba(j)=P;
dproba(j)=KSSTAT;
end
if iplot
lpmat=lpmat(:,ipar);
ftit=bayestopt_.name(ipar+nshock*(1-ishock));
for i=1:ceil(nparplot/12),
figure('name',aname),
for j=1+12*(i-1):min(nparplot,12*i),
subplot(3,4,j-12*(i-1))
if ~isempty(ibehaviour),
h=cumplot(lpmat(ibehaviour,j));
set(h,'color',[0 0 0], 'linestyle',':')
end
hold on,
if ~isempty(inonbehaviour),
h=cumplot(lpmat(inonbehaviour,j));
set(h,'color',[0 0 0])
end
title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none')
end
saveas(gcf,[dirname,'/',fname_,'_',aname,'_SA_',int2str(i)])
eval(['print -depsc2 ' dirname '/' fname_ '_' aname '_SA_' int2str(i)]);
eval(['print -dpdf ' dirname '/' fname_ '_' aname '_SA_' int2str(i)]);
if options_.nograph, close(gcf), end
end
end

View File

@ -1,97 +0,0 @@
%function stab_map_2(x,alpha2,istab,fnam)
function stab_map_2(x,alpha2,fnam, dirname)
% function stab_map_2(x,alpha2,fnam, dirname)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
global bayestopt_ estim_params_ options_ oo_ M_
npar=size(x,2);
ishock= npar>estim_params_.np;
if nargin<3,
fnam='';
end
if nargin<4,
dirname='';
end
ys_ = oo_.dr.ys;
dr_ = oo_.dr;
fname_ = M_.fname;
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
c0=corrcoef(x);
c00=tril(c0,-1);
fig_nam_=[fname_,'_',fnam,'_corr_'];
ifig=0;
j2=0;
if ishock==0
npar=estim_params_.np;
else
npar=estim_params_.np+nshock;
end
for j=1:npar,
i2=find(abs(c00(:,j))>alpha2);
if length(i2)>0,
for jx=1:length(i2),
j2=j2+1;
if mod(j2,12)==1,
ifig=ifig+1;
figure('name',['Correlations in the ',fnam,' sample ', num2str(ifig)]),
end
subplot(3,4,j2-(ifig-1)*12)
% bar(c0(i2,j)),
% set(gca,'xticklabel',bayestopt_.name(i2)),
% set(gca,'xtick',[1:length(i2)])
%plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k')
%hold on,
plot(x(:,j),x(:,i2(jx)),'.')
% xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'),
% ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'),
if ishock,
xlabel(bayestopt_.name{j},'interpreter','none'),
ylabel(bayestopt_.name{i2(jx)},'interpreter','none'),
else
xlabel(bayestopt_.name{j+nshock},'interpreter','none'),
ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'),
end
title(['cc = ',num2str(c0(i2(jx),j))])
if (mod(j2,12)==0) & j2>0,
saveas(gcf,[dirname,'/',fig_nam_,int2str(ifig)])
eval(['print -depsc2 ' dirname '/' fig_nam_ int2str(ifig)]);
eval(['print -dpdf ' dirname '/' fig_nam_ int2str(ifig)]);
if options_.nograph, close(gcf), end
end
end
end
if (j==(npar)) & j2>0,
saveas(gcf,[dirname,'/',fig_nam_,int2str(ifig)])
eval(['print -depsc2 ' dirname '/' fig_nam_ int2str(ifig)]);
eval(['print -dpdf ' dirname '/' fig_nam_ int2str(ifig)]);
if options_.nograph, close(gcf), end
end
end
if ifig==0,
disp(['No correlation term >', num2str(alpha2),' found for ',fnam])
end
%close all

View File

@ -1,25 +0,0 @@
function [y, meany, stdy] = stand_(x)
% STAND_ Standardise a matrix by columns
%
% [x,my,sy]=stand(y)
%
% y: Time series (column matrix)
%
% x: standardised equivalent of y
% my: Vector of mean values for each column of y
% sy: Vector of standard deviations for each column of y
%
% Copyright (c) 2006 by JRC, European Commission, United Kingdom
% Author : Marco Ratto
if nargin==0,
return;
end
for j=1:size(x,2);
meany(j)=mean(x(find(~isnan(x(:,j))),j));
stdy(j)=std(x(find(~isnan(x(:,j))),j));
y(:,j)=(x(:,j)-meany(j))./stdy(j);
end
% end of m-file

View File

@ -1,51 +0,0 @@
function [yt, j0, ir, ic]=teff(T,Nsam,istable)
%
% [yt, j0, ir, ic]=teff(T,Nsam,istable)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
ndim = (length(size(T)));
if ndim==3,
if nargin==1,
Nsam=size(T,3);
istable = [1:Nsam]';
end
tmax=max(T,[],3);
tmin=min(T,[],3);
[ir, ic]=(find( (tmax-tmin)>1.e-8));
j0 = length(ir);
yt=zeros(Nsam, j0);
for j=1:j0,
y0=squeeze(T(ir(j),ic(j),:));
%y1=ones(size(lpmat,1),1)*NaN;
y1=ones(Nsam,1)*NaN;
y1(istable,1)=y0;
yt(:,j)=y1;
end
else
tmax=max(T,[],2);
tmin=min(T,[],2);
ir=(find( (tmax-tmin)>1.e-8));
j0 = length(ir);
yt=NaN(Nsam, j0);
yt(istable,:)=T(ir,:)';
end
%clear y0 y1;

View File

@ -1,66 +0,0 @@
% Copyright (C) 2001 Michel Juillard
%
function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list)
global M_ oo_ options_
nvar = size(var_list,1);
if nvar == 0
nvar = length(dr.order_var);
ivar = [1:nvar]';
else
ivar=zeros(nvar,1);
for i=1:nvar
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
if isempty(i_tmp)
error (['One of the variable specified does not exist']) ;
else
ivar(i) = i_tmp;
end
end
end
[gamma_y,ivar] = th_autocovariances(dr,ivar,M_, options_);
m = dr.ys(ivar);
i1 = find(abs(diag(gamma_y{1})) > 1e-12);
s2 = diag(gamma_y{1});
sd = sqrt(s2);
z = [ m sd s2 ];
mean = m;
var = gamma_y{1};
%'THEORETICAL MOMENTS';
%'MEAN','STD. DEV.','VARIANCE');
z;
%'VARIANCE DECOMPOSITION (in percent)';
if M_.exo_nbr>1,
vdec = 100*gamma_y{options_.ar+2}(i1,:);
else
vdec = 100*ones(size(gamma_y{1}(i1,1)));
end
%'MATRIX OF CORRELATIONS';
if options_.opt_gsa.useautocorr,
corr = gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)');
corr = corr-diag(diag(corr))+diag(diag(gamma_y{1}(i1,i1)));
else
corr = gamma_y{1}(i1,i1);
end
if options_.ar > 0
%'COEFFICIENTS OF AUTOCORRELATION';
for i=1:options_.ar
if options_.opt_gsa.useautocorr,
autocorr{i} = gamma_y{i+1}(i1,i1);
else
autocorr{i} = gamma_y{i+1}(i1,i1).*(sd(i1)*sd(i1)');
end
zz(:,i) = diag(gamma_y{i+1}(i1,i1));
end
end

View File

@ -1,45 +0,0 @@
function tau = thet2tau(params, indx, indexo, flagmoments,mf,nlags,useautocorr)
global M_ oo_ options_
if nargin==1,
indx = [1:M_.param_nbr];
indexo = [];
end
if nargin<4,
flagmoments=0;
end
if nargin<7 | isempty(useautocorr),
useautocorr=0;
end
M_.params(indx) = params(length(indexo)+1:end);
if ~isempty(indexo)
M_.Sigma_e(indexo,indexo) = diag(params(1:length(indexo)).^2);
end
% [A(oo_.dr.order_var,oo_.dr.order_var),B(oo_.dr.order_var,:)]=dynare_resolve;
[A,B]=dynare_resolve;
if flagmoments==0,
tau = [oo_.dr.ys(oo_.dr.order_var); A(:); vech(B*M_.Sigma_e*B')];
else
GAM = lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold);
k = find(abs(GAM) < 1e-12);
GAM(k) = 0;
if useautocorr,
sy = sqrt(diag(GAM));
sy = sy*sy';
sy0 = sy-diag(diag(sy))+eye(length(sy));
dum = GAM./sy0;
tau = vech(dum(mf,mf));
else
tau = vech(GAM(mf,mf));
end
for ii = 1:nlags
dum = A^(ii)*GAM;
if useautocorr,
dum = dum./sy;
end
tau = [tau;vec(dum(mf,mf))];
end
tau = [ oo_.dr.ys(oo_.dr.order_var(mf)); tau];
end

View File

@ -1,25 +0,0 @@
function yr = trank(y);
% yr = trank(y);
% yr is the rank transformation of y
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
[nr, nc] = size(y);
for j=1:nc,
[dum, is]=sort(y(:,j));
yr(is,j)=[1:nr]'./nr;
end

View File

@ -1,512 +0,0 @@
function VECTOR = LPTAU(I, N)
%
% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN
% KELDYSH INSTITUTE OF APPLIED MATHEMATICS
% RUSSIAN ACADEMY OF SCIENCES
%
% QUASIRANDOM SEQUENCE GENERATORS
% -------------------------------
%
% 28.11.1991
%
% NOTE TO THE USER BY the NEA Data Bank:
% This quasi random number generator has been made available to
% you on condition that its identity is preserved when used
% in computer programs. If its use leads to scientific publication
% of results you should cite it in the references, in addition
% no commercial use should be made unless agreed upon with the
% main author (Prof. I.M. Sobol')
%
% ABSTRACT
% ........
%
% POINTS BELONGING TO LP-TAU SEQUENCES UNIFORMLY DISTRIBUTED IN THE
% N-DIMENSIONAL UNIT CUBE ARE OFTEN USED IN NUMERICAL MATHEMATICS:
%
% - AS NODES FOR MULTIDIMENSIONAL INTEGRATION;
% - AS SEARCHING POINTS IN GLOBAL OPTIMIZATION;
% - AS TRIAL POINTS IN MULTI-CRITERIA DECISION MAKING;
% - AS QUASIRANDOM POINTS FOR QUASI-MONTECARLO ALGORITHMS;
% - ETC.
%
% THIS SUBROUTINE CONTAINS THE ALGORITHM FOR FAST GENERATION OF
% LP-TAU SEQUENCES THAT ARE SUITABLE FOR MULTI-PROCESSOR COMPUTATIONS.
% THE DIMENSIONS N.LE.51, THE NUMBER OF POINTS N.LT.2**30.
% THE PROGRAMMING LANGUAGE IS FORTRAN-77. THIS SUBROUTINE IS AVAILABLE
% ALSO IN %-LANGUAGE.
% THE REPORT DESCRIBING THE ALGORITHM CONTAINS THE DESCRIPTION OF THE
% ALGORITHM AND CERTAIN IMPORTANT PROPERTIES OF LP-TAU SEQUENCES AND
% THEIR GENERALIZATIONS ARE DISCUSSED.
%
% REFERENCE:
% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN
% KELDYSH INSTITUTE OF APPLIED MATHEMATICS
% RUSSIAN ACADEMY OF SCIENCES
%
% QUASIRANDOM SEQUENCE GENERATORS
% MOSCOW 1992, IPM ZAK. NO.30 (100 COPIES)
%
% ------------------------------------------------------------------------
%
% INPUT PARAMETERS:
%
% I - NUMBER OF THE POINT (I=(0,2**30-1)),
% N - DIMENSION OF THE POINT (0<N<52);
%
% OUTPUT PARAMETER:
%
% VECTOR(N) - N-VECTOR CONTAINING THE CARTESIAN CO-ORDINATES OF
% THE I-TH POINT.
%
%
% TO CALL THE SUBROUTINE WRITE:
%
% CALL LPTAU(I,N,VECTOR)
% WHERE I, N: INTEGER CAPABLE OF STORING 2**30 (INTEGER*4 ON IBM
% OR OTHER 32 BIT/WORD MACHINES)
% VECTOR: DOUBLE PRECISION ARRAY WHOSE LENGTH < 52.
%
% INTEGER QP
% QP = QUANTITY POWER
%
% PARAMETER (MAXDIM=51, QP=30, MAXNUM=2**30-1)
MAXDIM=51; QP=30; MAXNUM=2^30-1;
%
% THE DIMENSION OF THE POINT CANNOT EXCEED MAXDIM
% THE TOTAL NUMBER OF GENERATED POINTS CANNOT EXCEED 2**QP
% MAXNUM=2**30-1 // 1073741823
%
% DOUBLE PRECISION VECTOR(N)
% INTEGER I,N
%
% INTEGER PRVNUM,PRVDIM
% INTEGER DIRECT(MAXDIM,QP), MASKV(MAXDIM)
% DOUBLE PRECISION SCALE
%
% Translated into MATLAB by M. Ratto
VECTOR=zeros(1,N);
SCALE =9.31322574615478516E-10;
persistent PRVNUM PRVDIM MASKV DIRECT
if isempty(PRVNUM), PRVNUM=-2; end,
if isempty(PRVDIM), PRVDIM=0; end,
if isempty(DIRECT), ...
DIRECT(1:MAXDIM,1)=[
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912, 536870912, 536870912, 536870912, 536870912, ...
536870912]';
DIRECT(1:MAXDIM,2)=[
805306368, 268435456, 805306368, 268435456, 805306368, ...
268435456, 805306368, 268435456, 268435456, 805306368, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
805306368, 805306368, 268435456, 805306368, 268435456, ...
805306368, 268435456, 805306368, 268435456, 268435456, ...
805306368, 268435456, 805306368, 268435456, 805306368, ...
268435456, 805306368, 805306368, 268435456, 805306368, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
268435456, 805306368, 268435456, 805306368, 268435456, ...
805306368, 268435456, 805306368, 805306368, 268435456, ...
805306368]';
DIRECT(1:MAXDIM,3)=[
939524096, 939524096, 134217728, 671088640, 402653184, ...
402653184, 671088640, 134217728, 671088640, 402653184, ...
939524096, 134217728, 671088640, 939524096, 134217728, ...
671088640, 134217728, 939524096, 939524096, 402653184, ...
402653184, 134217728, 671088640, 402653184, 671088640, ...
402653184, 402653184, 671088640, 134217728, 134217728, ...
939524096, 939524096, 939524096, 939524096, 134217728, ...
671088640, 402653184, 402653184, 671088640, 134217728, ...
671088640, 402653184, 939524096, 134217728, 671088640, ...
939524096, 134217728, 671088640, 134217728, 939524096, ...
939524096]';
DIRECT(1:MAXDIM,4)=[
1006632960, 67108864, 603979776, 1006632960, 335544320, ...
469762048, 872415232, 738197504, 469762048, 872415232, ...
1006632960, 67108864, 872415232, 469762048, 469762048, ...
469762048, 1006632960, 335544320, 872415232, 603979776, ...
201326592, 67108864, 335544320, 67108864, 201326592, ...
738197504, 1006632960, 738197504, 603979776, 335544320, ...
738197504, 67108864, 1006632960, 67108864, 603979776, ...
1006632960, 335544320, 469762048, 872415232, 738197504, ...
469762048, 872415232, 1006632960, 67108864, 872415232, ...
469762048, 469762048, 469762048, 1006632960, 335544320, ...
872415232]';
DIRECT(1:MAXDIM,5)=[
1040187392, 637534208, 1040187392, 838860800, 167772160, ...
234881024, 167772160, 1040187392, 436207616, 33554432, ...
570425344, 1040187392, 503316480, 838860800, 973078528, ...
167772160, 234881024, 436207616, 771751936, 100663296, ...
234881024, 905969664, 771751936, 33554432, 838860800, ...
973078528, 905969664, 33554432, 301989888, 838860800, ...
100663296, 234881024, 1040187392, 637534208, 1040187392, ...
838860800, 167772160, 234881024, 167772160, 1040187392, ...
436207616, 33554432, 570425344, 1040187392, 503316480, ...
838860800, 973078528, 167772160, 234881024, 436207616, ...
771751936]';
DIRECT(1:MAXDIM,6)=[
1056964608, 352321536, 50331648, 419430400, 956301312, ...
889192448, 620756992, 117440512, 956301312, 922746880, ...
822083584, 218103808, 587202560, 385875968, 452984832, ...
218103808, 184549376, 285212672, 150994944, 956301312, ...
352321536, 654311424, 553648128, 352321536, 788529152, ...
956301312, 587202560, 251658240, 218103808, 721420288, ...
251658240, 1056964608, 520093696, 889192448, 587202560, ...
956301312, 419430400, 352321536, 83886080, 654311424, ...
419430400, 385875968, 285212672, 754974720, 50331648, ...
922746880, 989855744, 754974720, 721420288, 822083584, ...
687865856]';
DIRECT(1:MAXDIM,7)=[
1065353216, 1065353216, 578813952, 25165824, 125829120, ...
964689920, 327155712, 310378496, 360710144, 360710144, ...
159383552, 444596224, 947912704, 662700032, 444596224, ...
528482304, 578813952, 578813952, 75497472, 1065353216, ...
92274688, 511705088, 897581056, 847249408, 662700032, ...
931135488, 411041792, 713031680, 696254464, 528482304, ...
209715200, 578813952, 1065353216, 1065353216, 578813952, ...
25165824, 125829120, 964689920, 327155712, 310378496, ...
360710144, 360710144, 159383552, 444596224, 947912704, ...
662700032, 444596224, 528482304, 578813952, 578813952, ...
75497472]';
DIRECT(1:MAXDIM,8)=[
1069547520, 4194304, 826277888, 624951296, 616562688, ...
801112064, 952107008, 406847488, 398458880, 331350016, ...
356515840, 46137344, 1010827264, 1069547520, 734003200, ...
113246208, 490733568, 633339904, 910163968, 801112064, ...
893386752, 851443712, 801112064, 918552576, 742391808, ...
499122176, 62914560, 264241152, 708837376, 717225984, ...
759169024, 499122176, 272629760, 423624704, 155189248, ...
239075328, 205520896, 943718400, 373293056, 457179136, ...
406847488, 71303168, 473956352, 54525952, 624951296, ...
104857600, 1019215872, 901775360, 213909504, 281018368, ...
851443712]';
DIRECT(1:MAXDIM,9)=[
1071644672, 543162368, 190840832, 329252864, 853540864, ...
132120576, 778043392, 73400320, 178257920, 522190848, ...
639631360, 534773760, 991952896, 333447168, 48234496, ...
1059061760, 761266176, 673185792, 220200960, 396361728, ...
362807296, 815792128, 819986432, 346030080, 39845888, ...
752877568, 387973120, 643825664, 291504128, 274726912, ...
568328192, 526385152, 673185792, 98566144, 396361728, ...
727711744, 1042284544, 106954752, 299892736, 912261120, ...
44040192, 895483904, 333447168, 551550976, 467664896, ...
618659840, 606076928, 274726912, 245366784, 446693376, ...
421527552]';
DIRECT(1:MAXDIM,10)=[
1072693248, 273678336, 644874240, 753926144, 495976448, ...
869269504, 355467264, 57671680, 816840704, 961544192, ...
804257792, 495976448, 347078656, 426770432, 1066401792, ...
372244480, 84934656, 208666624, 313524224, 598736896, ...
487587840, 965738496, 1011875840, 296747008, 393216000, ...
523239424, 720371712, 823132160, 128974848, 407896064, ...
747634688, 850395136, 873463808, 504365056, 481296384, ...
686817280, 592445440, 995098624, 498073600, 969932800, ...
586153984, 1039138816, 814743552, 523239424, 294649856, ...
305135616, 506462208, 11534336, 449839104, 619708416, ...
479199232]';
DIRECT(1:MAXDIM,11)=[
1073217536, 947388416, 1070071808, 977797120, 365428736, ...
702021632, 461897728, 829947904, 425197568, 634912768, ...
437780480, 582483968, 792199168, 315097088, 611844096, ...
667418624, 166199296, 513277952, 187170816, 1036517376, ...
25690112, 201850880, 443023360, 990380032, 63438848, ...
211288064, 983040000, 1069023232, 421003264, 742916096, ...
487063552, 363331584, 973602816, 286785536, 171442176, ...
669515776, 110624768, 383254528, 289931264, 352845824, ...
878182400, 655884288, 836239360, 765984768, 549978112, ...
655884288, 85458944, 591921152, 563609600, 277348352, ...
919076864]';
DIRECT(1:MAXDIM,12)=[
1073479680, 71565312, 2359296, 891551744, 158597120, ...
383516672, 1019478016, 947126272, 621019136, 714866688, ...
738459648, 265027584, 468975616, 131858432, 504627200, ...
581173248, 266600448, 865861632, 658243584, 546045952, ...
521404416, 304873472, 1060896768, 163840000, 305922048, ...
257163264, 50069504, 773062656, 59506688, 779354112, ...
165937152, 587988992, 486801408, 160694272, 90439680, ...
423362560, 536608768, 614203392, 56885248, 999030784, ...
10747904, 764674048, 25952256, 989069312, 352583680, ...
799801344, 261357568, 873201664, 40108032, 769392640, ...
254541824]';
DIRECT(1:MAXDIM,13)=[
1073610752, 644218880, 538836992, 455475200, 1062600704, ...
139329536, 205651968, 905052160, 797048832, 452329472, ...
973471744, 627703808, 614072320, 803078144, 637403136, ...
835059712, 949878784, 662044672, 767950848, 426901504, ...
448659456, 23986176, 1016201216, 524943360, 525991936, ...
618790912, 781058048, 761659392, 458096640, 226361344, ...
950665216, 952500224, 516030464, 337510400, 496107520, ...
830865408, 944111616, 636354560, 978452480, 921567232, ...
533594112, 7471104, 678035456, 471203840, 1065746432, ...
575275008, 996540416, 909246464, 879362048, 637927424, ...
25821184]';
DIRECT(1:MAXDIM,14)=[
1073676288, 357892096, 808648704, 2424832, 2555904, ...
624230400, 69271552, 456851456, 1052966912, 600637440, ...
487260160, 794624000, 386727936, 467599360, 798031872, ...
630652928, 340983808, 493944832, 37945344, 264175616, ...
263520256, 833421312, 235077632, 464846848, 534839296, ...
992411648, 10813440, 367067136, 116457472, 115015680, ...
928710656, 619773952, 813760512, 1043398656, 967770112, ...
912850944, 72155136, 1009057792, 668532736, 462356480, ...
267321344, 795803648, 635764736, 574160896, 1003421696, ...
181075968, 56688640, 388562944, 190906368, 657915904, ...
474939392]';
DIRECT(1:MAXDIM,15)=[
1073709056, 1073709056, 137003008, 547782656, 545095680, ...
26836992, 34701312, 354385920, 925663232, 656965632, ...
327581696, 894795776, 110067712, 1038057472, 209354752, ...
596541440, 42631168, 471433216, 52527104, 666861568, ...
706707456, 674070528, 824410112, 305496064, 136282112, ...
847740928, 531464192, 222920704, 379289600, 507740160, ...
11894784, 1053392896, 129990656, 557547520, 666468352, ...
1061912576, 576684032, 1041334272, 380469248, 114196480, ...
133070848, 517046272, 129990656, 790396928, 563773440, ...
388333568, 661749760, 446791680, 737378304, 229998592, ...
348225536]';
DIRECT(1:MAXDIM,16)=[
1073725440, 16384, 605372416, 275234816, 817971200, ...
603963392, 555335680, 721534976, 997801984, 1028767744, ...
407060480, 375275520, 256688128, 1021165568, 303349760, ...
1022476288, 234143744, 106708992, 732971008, 733954048, ...
789889024, 879575040, 764657664, 762658816, 1010843648, ...
941080576, 827932672, 98942976, 1051738112, 624934912, ...
993280000, 134070272, 201375744, 567558144, 882163712, ...
649084928, 356564992, 489439232, 637091840, 60637184, ...
199278592, 815677440, 927678464, 94519296, 419184640, ...
933838848, 426655744, 911130624, 171393024, 561332224, ...
471613440]';
DIRECT(1:MAXDIM,17)=[
1073733632, 536895488, 1043685376, 679944192, 417505280, ...
301981696, 832561152, 210542592, 167501824, 1071341568, ...
229302272, 970661888, 732176384, 576659456, 402464768, ...
451584000, 368467968, 928260096, 933847040, 29319168, ...
582934528, 772612096, 330014720, 647323648, 174071808, ...
1008689152, 295919616, 353869824, 177774592, 580198400, ...
381837312, 638574592, 637558784, 679370752, 504012800, ...
747118592, 429973504, 1032609792, 932667392, 583360512, ...
969498624, 1056333824, 660955136, 247488512, 153509888, ...
242180096, 205840384, 797499392, 824565760, 234348544, ...
842326016]';
DIRECT(1:MAXDIM,18)=[
1073737728, 268455936, 52785152, 1020628992, 345018368, ...
452972544, 704442368, 255987712, 750759936, 697692160, ...
196677632, 764604416, 485625856, 522022912, 680620032, ...
362270720, 838103040, 83972096, 629133312, 46108672, ...
867561472, 725422080, 184504320, 751112192, 191918080, ...
306425856, 507310080, 30453760, 281858048, 604000256, ...
208662528, 319557632, 318779392, 476139520, 863719424, ...
567062528, 521179136, 712790016, 610299904, 293687296, ...
1023086592, 549089280, 1065242624, 707751936, 363024384, ...
16674816, 197136384, 1037561856, 195112960, 372707328, ...
992751616]';
DIRECT(1:MAXDIM,19)=[
1073739776, 939554816, 580732928, 854333440, 172619776, ...
511694848, 936142848, 518199296, 593348608, 225527808, ...
900982784, 180279296, 168904704, 62814208, 754485248, ...
730691584, 1005996032, 411174912, 249866240, 641669120, ...
1008719872, 749066240, 860993536, 94177280, 432564224, ...
226355200, 925784064, 995657728, 967731200, 436226048, ...
913799168, 549894144, 964696064, 843315200, 445863936, ...
1047422976, 548947968, 492066816, 953870336, 1002653696, ...
861440000, 385636352, 325253120, 187353088, 653584384, ...
1008269312, 748693504, 1013016576, 55814144, 255170560, ...
260708352]';
DIRECT(1:MAXDIM,20)=[
1073740800, 67126272, 829514752, 423777280, 968297472, ...
205511680, 147076096, 926669824, 202300416, 118395904, ...
381332480, 1002738688, 743042048, 292551680, 584567808, ...
284339200, 183936000, 616762368, 435221504, 159376384, ...
907322368, 595696640, 247497728, 553735168, 826051584, ...
564454400, 446024704, 214236160, 33661952, 251685888, ...
660327424, 284244992, 859868160, 722502656, 622844928, ...
324342784, 682374144, 400579584, 405353472, 605187072, ...
840682496, 212956160, 157891584, 193201152, 437990400, ...
573578240, 368053248, 580197376, 937905152, 565527552, ...
89064448]';
DIRECT(1:MAXDIM,21)=[
1073741312, 637560320, 189496832, 27474432, 129338880, ...
908054016, 641870336, 186375680, 302677504, 763663872, ...
103878144, 325187072, 858254848, 922041856, 261924352, ...
954978816, 292822528, 849512960, 210311680, 933232128, ...
691981824, 155417088, 627070464, 416795136, 182081024, ...
513433088, 848658944, 515770880, 627273216, 629169664, ...
414566912, 147450368, 698353152, 244844032, 226578944, ...
1020087808, 886978048, 389697024, 1007004160, 839646720, ...
621924864, 549962240, 609583616, 735976960, 87342592, ...
1058542080, 163066368, 307997184, 876471808, 794280448, ...
675386880]';
DIRECT(1:MAXDIM,22)=[
1073741568, 352343296, 644236032, 636735232, 615860480, ...
959444224, 287380736, 1007410432, 890187008, 399480576, ...
520092928, 643311360, 816901376, 695310080, 1019229440, ...
77034240, 733295872, 1035127552, 986582784, 332381952, ...
334852352, 364956416, 596672256, 800381696, 480316672, ...
574863104, 647347968, 702910208, 499965184, 364968704, ...
120862976, 1023256320, 995114240, 13951232, 32520448, ...
702127360, 45176064, 444945664, 237860096, 152839936, ...
530633984, 429135616, 267272448, 884808960, 933712640, ...
61605632, 174335744, 564911360, 302327552, 650589440, ...
450649344]';
DIRECT(1:MAXDIM,23)=[
1073741696, 1065385856, 1073734272, 331949184, 842310784, ...
799537536, 965852032, 369351808, 662886016, 86119808, ...
865109888, 299633792, 422735488, 181087360, 174252416, ...
1041212544, 840196224, 750314368, 391053440, 903306880, ...
742365312, 236995200, 42492800, 946000512, 771692416, ...
897405824, 613803136, 924258688, 808338304, 1038125440, ...
683814272, 177186176, 766008960, 704549248, 194555008, ...
306383744, 496592512, 416020864, 655186816, 1032204928, ...
694773632, 577910144, 45797760, 910332544, 536014976, ...
675946368, 987635840, 788223872, 353993856, 96313472, ...
85248640]';
DIRECT(1:MAXDIM,24)=[
1073741760, 4210752, 12608, 744788544, 494377792, ...
115601344, 769248448, 990895808, 851706304, 979326784, ...
692061120, 429015104, 217132864, 736067008, 55694400, ...
456152640, 631601984, 787264192, 898599104, 478383808, ...
507774272, 458270272, 392995136, 872482496, 124824768, ...
1034161344, 362141632, 1053833280, 943810496, 428920128, ...
795835200, 835462848, 961843520, 606198080, 785652672, ...
154954432, 491617344, 297351232, 580735552, 634587968, ...
185277760, 141505600, 417673280, 106907456, 395575616, ...
566958656, 352651200, 415242688, 26635200, 1030317504, ...
247212992]';
DIRECT(1:MAXDIM,25)=[
1073741792, 543187040, 536882016, 981766752, 357858144, ...
810665952, 369083488, 613015520, 86115232, 845149216, ...
606076960, 1018241504, 35245536, 635403744, 236633696, ...
407451232, 427671904, 460141792, 116344544, 990246688, ...
1024892576, 883429408, 150655392, 173476896, 197666464, ...
1016740448, 605376608, 970487008, 1006881248, 598265632, ...
1022861728, 489055392, 216680608, 371439072, 53140576, ...
965114400, 98534112, 209692256, 264598496, 321437280, ...
545303840, 324119904, 876587488, 778239712, 802033120, ...
44406496, 665829024, 803213920, 309742112, 735181344, ...
1036125600]';
DIRECT(1:MAXDIM,26)=[
1073741808, 273698896, 805312112, 903123536, 153504624, ...
689632208, 432848944, 859888752, 510853776, 240805744, ...
250610192, 852489168, 139460144, 283082224, 222702928, ...
342181488, 922872432, 187528656, 360637424, 814514736, ...
301037840, 800872624, 272595184, 158627600, 238839088, ...
927181136, 710248688, 788854608, 1048376560, 484709072, ...
85709008, 1065469744, 429237328, 490778384, 848024144, ...
443114288, 687907504, 474573648, 45706416, 681465296, ...
805303216, 14567920, 369839504, 440402480, 797652624, ...
115959088, 929784560, 91226544, 205943056, 288358704, ...
950217296]';
DIRECT(1:MAXDIM,27)=[
1073741816, 947419256, 134232008, 460100200, 1073685336, ...
398354904, 1069834248, 686054696, 108299224, 273898840, ...
731382552, 938170664, 86812552, 677346808, 602208712, ...
652635752, 209797064, 323968376, 384078968, 561178056, ...
923399256, 996597176, 942777416, 885167400, 89791048, ...
956122504, 87393464, 987661336, 993412952, 827749496, ...
903211272, 33649816, 594875176, 65052056, 822835240, ...
625704888, 1065374584, 612232920, 536299720, 1046858504, ...
939518840, 160843032, 654656088, 744496936, 872197704, ...
219111576, 829112632, 455614152, 1064192952, 313010856, ...
820754920]';
DIRECT(1:MAXDIM,28)=[
1073741820, 71582788, 603989028, 37500, 120660, ...
182195932, 213921796, 473570692, 41763004, 156352828, ...
88343188, 698012780, 666108868, 337608156, 1054329884, ...
799472220, 641885244, 392104980, 502284340, 1002405628, ...
249907140, 75586228, 206587660, 565275348, 1021426548, ...
425987996, 598058580, 401940420, 919427316, 822049324, ...
115655868, 759299588, 562394644, 990942164, 1003212268, ...
598750292, 675334852, 675293340, 445665316, 903023756, ...
872412692, 172640916, 1051615436, 91229620, 94586692, ...
344873452, 7029156, 683421900, 434258804, 955002092, ...
436424380]';
DIRECT(1:MAXDIM,29)=[
1073741822, 644245094, 1040195102, 537039474, 537089354, ...
642656334, 73402402, 664239174, 1014620426, 500917234, ...
1042677826, 347788318, 1069154738, 373259762, 362587674, ...
239395914, 132283950, 903121466, 445210638, 968851198, ...
230153254, 935549622, 308815630, 861891286, 496995094, ...
670740382, 657311830, 573565382, 248331478, 1064650798, ...
338312798, 669059078, 1065190902, 379125622, 111897166, ...
520650422, 740300390, 1046483950, 66254898, 992513134, ...
234871606, 610553330, 450553866, 566758134, 787800806, ...
1071709866, 971732606, 528102354, 790919122, 917384366, ...
656244162]';
DIRECT(1:MAXDIM,30)=[
1073741823, 357913941, 50344755, 268538457, 805540473, ...
3487029, 3146769, 592038967, 729591963, 781578389, ...
66781679, 113956361, 331153483, 967802327, 935343371, ...
324351309, 609305915, 818137857, 131059769, 918519549, ...
827341719, 922770101, 456972047, 363883221, 1057014661, ...
900956063, 580478293, 520383687, 315470533, 227601711, ...
169598765, 909227271, 796983815, 349496709, 393974911, ...
378320037, 777004343, 927999269, 616377385, 345930959, ...
989849787, 627400495, 892675125, 260314121, 1041964063, ...
531367163, 195776757, 237309785, 949187605, 719002587, ...
495745187]';
end
%
% TRAP FOR A WRONG SUBROUTINE CALL
%
if ((I<0) | (N<1) | (I>MAXNUM) | (N>MAXDIM)),
disp('LP-TAU CALL FAILED')
disp(' PRESS <ENTER> TO EXIT LPTAU')
pause
return
end
if ((PRVNUM+1==I) & (N<=PRVDIM)),
%
% RECURRENT GENERATION OF THE POINT
%
%
% SEARCH POSITION OF THE RIGHTMOST "1"
% IN THE BINARY REPRESENTATION OF I
%
L=0;
POS=0;
while L<QP & POS==0,
L=L+1;
POS=bitand(bitshift(I,-(L-1)),1);
end
%
% RIGHTMOST POSITION IS L
%
for J=1:N
MASKV(J)=bitxor(MASKV(J),DIRECT(J,L));
VECTOR(J)=MASKV(J)*SCALE;
end
else
%
% GENERATION OF THE POINT FROM "I" AND "N"
%
MASKV=zeros(1,N);
IM=bitxor(I,bitshift(I,-1));
M=0;
while IM~=0 & M<QP,
M=M+1;
if (bitand(IM,1)==1),
for J=1:N
MASKV(J)=bitxor(MASKV(J),DIRECT(J,M));
end
end
IM=bitshift(IM,-1);
end
for J=1:N
VECTOR(J)=MASKV(J)*SCALE;
end
end
%
PRVNUM=I;
PRVDIM=N;
return

View File

@ -1,130 +0,0 @@
function [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group)
% [SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group)
%
% Given the Morris sample matrix, the output values and the group matrix compute the Morris measures
% -------------------------------------------------------------------------
% INPUTS
% -------------------------------------------------------------------------
% Group [NumFactor, NumGroups] := Matrix describing the groups.
% Each column represents one group.
% The element of each column are zero if the factor is not in the
% group. Otherwise it is 1.
% Sample := Matrix of the Morris sampled trajectories
% Output := Matrix of the output(s) values in correspondence of each point
% of each trajectory
% k = Number of factors
% -------------------------------------------------------------------------
% OUTPUTS
% OutMatrix (NumFactor*NumOutputs, 3)= [Mu*, Mu, StDev]
% for each output it gives the three measures of each factor
% -------------------------------------------------------------------------
if nargin==0,
disp(' ')
disp('[SAmeas, OutMatrix] = Morris_Measure_Groups(NumFact, Sample, Output, p, Group);')
return
end
OutMatrix=[];
if nargin < 5, Group=[]; end
NumGroups = size(Group,2);
if nargin < 4 | isempty(p),
p = 4;
end
Delt = p/(2*p-2);
if NumGroups ~ 0
sizea = NumGroups; % Number of groups
GroupMat=Group;
GroupMat = GroupMat';
else
sizea = NumFact;
end
r=size(Sample,1)/(sizea+1); % Number of trajectories
% For Each Output
for k=1:size(Output,2)
OutValues=Output(:,k);
% For each r trajectory
for i=1:r
% For each step j in the trajectory
% Read the orientation matrix fact for the r-th sampling
% Read the corresponding output values
Single_Sample = Sample(i+(i-1)*sizea:i+(i-1)*sizea+sizea,:);
Single_OutValues = OutValues(i+(i-1)*sizea:i+(i-1)*sizea+sizea,:);
A = (Single_Sample(2:sizea+1,:)-Single_Sample(1:sizea,:))';
Delta = A(find(A));
% For each point of the fixed trajectory compute the values of the Morris function. The function
% is partitioned in four parts, from order zero to order 4th.
for j=1:sizea % For each point in the trajectory i.e for each factor
% matrix of factor which changes
if NumGroups ~ 0;
AuxFind (:,1) = A(:,j);
% AuxFind(find(A(:,j)),1)=1;
% Pippo = sum((Group - repmat(AuxFind,1,NumGroups)),1);
% Change_factor(j,i) = find(Pippo==0);
Change_factor = find(abs(AuxFind)>1e-010);
% If we deal with groups we can only estimate the new mu*
% measure since factors in the same groups can move in
% opposite direction and the definition of the standard
% Morris mu cannopt be applied.
% In the new version the elementary effect is defined with
% the absolute value.
%SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3));
SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt);
else
Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:));
% If no groups --> we compute both the original and
% modified measure
if Delta(j) > 0 %=> +Delta
SAmeas(Change_factor(j,i),i) = (Single_OutValues(j+1) - Single_OutValues(j) )/Delt; %(2/3);
else %=> -Delta
SAmeas(Change_factor(j,i),i) = (Single_OutValues(j) - Single_OutValues(j+1) )/Delt; %(2/3);
end
end
end %for j=1:sizea
end %for i=1:r
if NumGroups ~ 0
SAmeas = SAmeas';
end
% Compute Mu AbsMu and StDev
if any(any(isnan(SAmeas)))
for j=1:NumFact,
SAm = SAmeas(j,:);
SAm = SAm(find(~isnan(SAm)));
rr=length(SAm);
AbsMu(j,1) = sum(abs(SAm),2)/rr;
if NumGroups == 0
Mu(j,1) = sum(SAm,2)/rr;
StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5;
end
end
else
AbsMu = sum(abs(SAmeas),2)/r;
if NumGroups == 0
Mu = sum(SAmeas,2)/r;
StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5;
end
end
% Define the output Matrix - if we have groups we cannot define the old
% measure mu, only mu* makes sense
if NumGroups > 0
OutMatrix = [OutMatrix; AbsMu];
else
OutMatrix = [OutMatrix; AbsMu, Mu, StDev];
end
end % For Each Output

View File

@ -1,174 +0,0 @@
function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat)
% Inputs: k (1,1) := number of factors examined or number of groups examined.
% In case the groups are chosen the number of factors is stores in NumFact and
% sizea becomes the number of created groups.
% NumFact (1,1) := number of factors examined in the case when groups are chosen
% r (1,1) := sample size
% p (1,1) := number of intervals considered in [0, 1]
% UB(sizea,1) := Upper Bound for each factor
% LB(sizea,1) := Lower Bound for each factor
% GroupNumber(1,1) := Number of groups (eventually 0)
% GroupMat(NumFact,GroupNumber):= Matrix which describes the chosen groups. Each column represents a group and its elements
% are set to 1 in correspondence of the factors that belong to the fixed group. All
% the other elements are zero.
% Local Variables:
% sizeb (1,1) := sizea+1
% sizec (1,1) := 1
% randmult (sizea,1) := vector of random +1 and -1
% perm_e(1,sizea) := vector of sizea random permutated indeces
% fact(sizea) := vector containing the factor varied within each traj
% DDo(sizea,sizea) := D* in Morris, 1991
% A(sizeb,sizea) := Jk+1,k in Morris, 1991
% B(sizeb,sizea) := B in Morris, 1991
% Po(sizea,sizea) := P* in Morris, 1991
% Bo(sizeb,sizea) := B* in Morris, 1991
% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991
% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory)
% In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory
% of k step in the parameter space and it provides a single elementary
% effect per factor
% MyInt()
% Fact(sizea,1) := for each loop vector indicating which factor or group of factors has been changed
% in each step of the trajectory
% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design
% for single factor analysis, while it constitutes an intermediate step for the group analysis.
%
% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices
% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors
%
% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine
% follows the following steps:
% 1- Creation of P0 and DD0 matrices defined in Morris for the groups. This means that the dimensions of these
% 2 matrices are (GroupNumber,GroupNumber).
% 2- Creation of AuxMat matrix with (GroupNumber+1,GroupNumber) elements.
% 3- Definition of GroupB0 starting from AuxMat, GroupMat and P0.
% 4- The final B0 for groups is obtained as [ones(sizeb,1)*x0' + GroupB0]. The P0 permutation is present in GroupB0
% and it's not necessary to permute the matrix (ones(sizeb,1)*x0') because it's already randomly created.
% Reference:
% A. Saltelli, K. Chan, E.M. Scott, "Sensitivity Analysis" on page 68 ss
%
% F. Campolongo, J. Cariboni, JRC - IPSC Ispra, Varese, IT
% Last Update: 15 November 2005 by J.Cariboni
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters and initialisation of the output matrix
sizea = k;
Delta = p/(2*p-2);
%Delta = 1/3
NumFact = sizea;
GroupNumber = size(GroupMat,2);
if GroupNumber ~ 0;
sizea = size(GroupMat,2);
end
sizeb = sizea + 1;
sizec = 1;
Outmatrix = [];
OutFact = [];
% For each i generate a trajectory
for i=1:r
% Construct DD0 - OLD VERSION - it does not need communication toolbox
% RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0).
% Note that DD0 tells if the factor have to be increased or ddecreased
% by Delta.
randmult = ones(k,1);
v = rand(k,1);
randmult (find(v < 0.5))=-1;
randmult = repmat(randmult,1,k);
DD0 = randmult .* eye(k);
% Construct DD0 - NEW VERSION - it needs communication toolbox
% randsrc(m) generates an m-by-m matrix, each of whose entries independently takes the value -1 with probability 1/2,
% and 1 with probability 1/2.
% DD0 = randsrc(NumFact) .* eye(NumFact);
% Construct B (lower triangular)
B = ones(sizeb,sizea);
for j = 1:sizea
B(1:j,j)=0;
end
% Construct A0, A
A0 = ones(sizeb,1);
A = ones(sizeb,NumFact);
% Construct the permutation matrix P0. In each column of P0 one randomly chosen element equals 1
% while all the others equal zero.
% P0 tells the order in which order factors are changed in each
% trajectory. P0 is created as it follows:
% 1) All the elements of P0 are set equal to zero ==> P0 = zeros (sizea, sizea);
% 2) The function randperm create a random permutation of integer 1:sizea, without repetitions ==> perm_e;
% 3) In each column of P0 the element indicated in perm_e is set equal to one.
% Note that P0 is then used reading it by rows.
P0 = zeros (sizea, sizea);
perm_e = randperm(sizea); % RANDPERM(n) is a random permutation of the integers from 1 to n.
for j = 1:sizea
P0(perm_e(j),j) = 1;
end
% When groups are present the random permutation is done only on B. The effect is the same since
% the added part (A0*x0') is completely random.
if GroupNumber ~ 0
B = B * (GroupMat*P0')';
end
% Compute AuxMat both for single factors and groups analysis. For Single factors analysis
% AuxMat is added to (A0*X0) and then permutated through P0. When groups are active AuxMat is
% used to build GroupB0. AuxMat is created considering DD0. If the element on DD0 diagonal
% is 1 then AuxMat will start with zero and add Delta. If the element on DD0 diagonal is -1
% then DD0 will start Delta and goes to zero.
AuxMat = Delta*0.5*((2*B - A) * DD0 + A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube
% [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]
MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors
% OLD VERSION - it needs communication toolbox
% w = randint(NumFact,1,[1,size(MyInt,2)]);
% NEW VERSION - construct a version of random integers
% 1) create a vector of random integers
% 2) divide [0,1] into the needed steps
% 3) check in which interval the random numbers fall
% 4) generate the corresponding integer
v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1)
IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2)
DiffAuxVec = IntUsed - v; % 3)
for ii = 1:size(DiffAuxVec,1)
w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4)
end
x0 = MyInt(1,w)'; % Define x0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a
% trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors)
if GroupNumber ~ 0
B0 = (A0*x0' + AuxMat);
else
B0 = (A0*x0' + AuxMat)*P0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% c --> Compute values in the original intervals
% B0 has values x(i,j) in [0, 1/(p -1), 2/(p -1), ... , 1].
% To obtain values in the original intervals [LB, UB] we compute
% LB(j) + x(i,j)*(UB(j)-LB(j))
In = repmat(LB,1,sizeb)' + B0 .* repmat((UB-LB),1,sizeb)';
% Create the Factor vector. Each component of this vector indicate which factor or group of factor
% has been changed in each step of the trajectory.
for j=1:sizea
Fact(1,j) = find(P0(j,:));
end
Fact(1,sizea+1) = 0;
Outmatrix = [Outmatrix; In];
OutFact = [OutFact; Fact'];
end

View File

@ -1,38 +0,0 @@
function x = beta_inv(p, a, b)
% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution
%--------------------------------------------------------------
% USAGE: x = beta_inv(p,a,b)
% where: p = vector of probabilities
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%--------------------------------------------------------------
% RETURNS: x at each element of p for the beta(a,b) distribution
%--------------------------------------------------------------
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%--------------------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~= 3)
error('Wrong # of arguments to beta_inv');
end
if any(any((a<=0)|(b<=0)))
error('beta_inv parameter a or b is nonpositive');
end
if any(any(abs(2*p-1)>1))
error('beta_inv: A probability should be 0<=p<=1');
end
x = a ./ (a+b);
dx = 1;
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (betainc(x,a,b) - p) ./ beta_pdf(x,a,b);
x = x - dx;
x = x + (dx - x) / 2 .* (x<0);
end

View File

@ -1,32 +0,0 @@
function pdf = beta_pdf(x, a, b)
% PURPOSE: pdf of the beta(a,b) distribution
%--------------------------------------------------------------
% USAGE: pdf = beta_pdf(x,a,b)
% where: x = vector of components
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%--------------------------------------------------------------
% RETURNS: pdf at each element of x of the beta(a,b) distribution
%--------------------------------------------------------------
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%--------------------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~=3)
error('Wrong # of arguments to beta_pdf');
end
if any(any((a<=0)|(b<=0)))
error('Parameter a or b is nonpositive');
end
I = find((x<0)|(x>1));
pdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b);
pdf(I) = 0*I;

View File

@ -1,14 +0,0 @@
function h = cumplot(x);
%function h =cumplot(x)
% Copyright (C) 2005 Marco Ratto
n=length(x);
x=[-inf; sort(x); Inf];
y=[0:n n]./n;
h0 = stairs(x,y);
grid on,
if nargout,
h=h0;
end

View File

@ -1,30 +0,0 @@
function c = dat_fil_(data_file);
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
try
eval(data_file);
catch
load(data_file);
end
clear data_file;
a=who;
for j=1:length(a)
eval(['c.',a{j},'=',a{j},';']);
end

View File

@ -1,133 +0,0 @@
function dynare_MC(var_list_,OutDir,data,rawdata,data_info)
%
% Adapted by M. Ratto from dynare_estimation.m and posteriorsmoother.m
% (dynare_estimation.m and posteriorsmoother.m are part of DYNARE,
% copyright M. Juillard)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global M_ options_ oo_ estim_params_
global bayestopt_
% if options_.filtered_vars ~= 0 & options_.filter_step_ahead == 0
% options_.filter_step_ahead = 1;
% end
% if options_.filter_step_ahead ~= 0
% options_.nk = max(options_.filter_step_ahead);
% else
% options_.nk = 0;
% end
%
options_.filter_step_ahead=1;
options_.nk = 1;
nvx = estim_params_.nvx;
nvn = estim_params_.nvn;
ncx = estim_params_.ncx;
ncn = estim_params_.ncn;
np = estim_params_.np ;
npar = nvx+nvn+ncx+ncn+np;
if isempty(options_.datafile)
error('ESTIMATION: datafile option is missing')
end
if isempty(options_.varobs)
error('ESTIMATION: VAROBS is missing')
end
gend = data_info.gend;
n_varobs = size(options_.varobs,1);
data_index = data_info.data_index;
number_of_observations = data_info.number_of_observations;
no_more_missing_observations = data_info.no_more_missing_observations;
missing_value = data_info.missing_value;
offset = npar-np;
fname_=M_.fname;
options_ = set_default_option(options_,'opt_gsa',1);
options_gsa_ = options_.opt_gsa;
if options_gsa_.pprior,
namfile=[fname_,'_prior'];
else
namfile=[fname_,'_mc'];
end
load([OutDir,'/',namfile],'lpmat', 'lpmat0', 'istable')
% load(options_.mode_file)
%%
%%
%%
x=[lpmat0(istable,:) lpmat(istable,:)];
clear lpmat lpmat0 istable %iunstable egg yys T
B = size(x,1);
[atT,innov,measurement_error,updated_variables,ys,trend_coeff, aK] = DsgeSmoother(x(1,:)',gend,data,data_index,missing_value);
n1=size(atT,1);
nfil=B/40;
stock_smooth = zeros(M_.endo_nbr,gend,40);
stock_filter = zeros(M_.endo_nbr,gend+1,40);
stock_ys = zeros(40, M_.endo_nbr);
logpo2=zeros(B,1);
%%
h = waitbar(0,'MC smoother ...');
delete([OutDir,'/',namfile,'_*.mat'])
ib=0;
ifil=0;
opt_gsa=options_.opt_gsa;
for b=1:B
ib=ib+1;
deep = x(b,:)';
set_all_parameters(deep);
dr = resol(oo_.steady_state,0);
%deep(1:offset) = xparam1(1:offset);
logpo2(b,1) = DsgeLikelihood(deep,gend,data,data_index,number_of_observations,no_more_missing_observations);
if opt_gsa.lik_only==0,
[atT,innov,measurement_error,updated_variables,ys,trend_coeff, aK] = DsgeSmoother(deep,gend,data,data_index,missing_value);
stock_smooth(:,:,ib)=atT(1:M_.endo_nbr,:);
% stock_filter(:,:,ib)=updated_variables(1:M_.endo_nbr,:);
stock_filter(:,:,ib)=aK(1,1:M_.endo_nbr,:);
stock_ys(ib,:)=ys';
if ib==40,
ib=0;
ifil=ifil+1;
save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys')
stock_smooth = zeros(M_.endo_nbr,gend,40);
stock_filter = zeros(M_.endo_nbr,gend+1,40);
stock_ys = zeros(40, M_.endo_nbr);
end
end
waitbar(b/B,h,['MC smoother ...',num2str(b),'/',num2str(B)]);
end
close(h)
if opt_gsa.lik_only==0,
if ib>0,
ifil=ifil+1;
stock_smooth = stock_smooth(:,:,1:ib);
stock_filter = stock_filter(:,:,1:ib);
stock_ys = stock_ys(1:ib,:);
save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys')
end
end
stock_gend=gend;
stock_data=data;
save([OutDir,'/',namfile],'x','logpo2','stock_gend','stock_data','-append')

View File

@ -1,37 +0,0 @@
% FDJAC Computes two-sided finite difference Jacobian
% USAGE
% fjac = fdjac(f,x,P1,P2,...)
% INPUTS
% f : name of function of form fval = f(x)
% x : evaluation point
% P1,P2,... : additional arguments for f (optional)
% OUTPUT
% fjac : finite differnce Jacobian
%
% USER OPTIONS (SET WITH OPSET)
% tol : a factor used in setting the step size
% increase if f is inaccurately computed
% Copyright (c) 1997-2002, Paul L. Fackler & Mario J. Miranda
% paul_fackler@ncsu.edu, miranda.4@osu.edu
function fjac = fdjac(f,x,varargin)
tol = optget(mfilename,'tol',eps.^(1/3));
h = tol.*max(abs(x),1);
xh1=x+h; xh0=x-h;
h=xh1-xh0;
for j=1:length(x);
xx = x;
xx(j) = xh1(j); f1=feval(f,xx,varargin{:});
xx(j) = xh0(j); f0=feval(f,xx,varargin{:});
fjac(:,j) = (f1-f0)/h(j);
% v = (f1-f0);
% k = find(abs(v) < 1e-8);
% v(k) = 0;
%
% fjac(:,j) = v/h(j);
end
feval(f,x,varargin{:});

View File

@ -1,687 +0,0 @@
function [rmse_MC, ixx] = filt_mc_(OutDir,data_info)
% function [rmse_MC, ixx] = filt_mc_(OutDir)
% copyright Marco Ratto 2006
% inputs (from opt_gsa structure)
% vvarvecm = options_gsa_.var_rmse;
% loadSA = options_gsa_.load_rmse;
% pfilt = options_gsa_.pfilt_rmse;
% alpha = options_gsa_.alpha_rmse;
% alpha2 = options_gsa_.alpha2_rmse;
% istart = options_gsa_.istart_rmse;
% alphaPC = 0.5;
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global bayestopt_ estim_params_ M_ options_ oo_
options_gsa_=options_.opt_gsa;
vvarvecm = options_gsa_.var_rmse;
loadSA = options_gsa_.load_rmse;
pfilt = options_gsa_.pfilt_rmse;
alpha = options_gsa_.alpha_rmse;
alpha2 = options_gsa_.alpha2_rmse;
istart = options_gsa_.istart_rmse;
alphaPC = 0.5;
fname_ = M_.fname;
lgy_ = M_.endo_names;
dr_ = oo_.dr;
disp(' ')
disp(' ')
disp('Starting sensitivity analysis')
disp('for the fit of EACH observed series ...')
disp(' ')
disp('Deleting old SA figures...')
a=dir([OutDir,'/*.*']);
tmp1='0';
if options_.opt_gsa.ppost,
tmp=['_rmse_post'];
else
if options_.opt_gsa.pprior
tmp=['_rmse_prior'];
else
tmp=['_rmse_mc'];
end
if options_gsa_.lik_only,
tmp1 = [tmp,'_post_SA'];
tmp = [tmp,'_lik_SA'];
end
end
for j=1:length(a),
if strmatch([fname_,tmp],a(j).name),
disp(a(j).name)
delete([OutDir,'/',a(j).name])
end,
if strmatch([fname_,tmp1],a(j).name),
disp(a(j).name)
delete([OutDir,'/',a(j).name])
end,
end
disp('done !')
nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn;
npar=estim_params_.np;
if ~isempty(options_.mode_file),
load(options_.mode_file,'xparam1'),
end
if options_.opt_gsa.ppost,
c=load([fname_,'_mean'],'xparam1');
xparam1_mean=c.xparam1;
clear c
elseif ~isempty(options_.mode_file) & ~isempty(ls([fname_,'_mean.mat']))
c=load([fname_,'_mean'],'xparam1');
xparam1_mean=c.xparam1;
clear c
end
if options_.opt_gsa.ppost,
fnamtmp=[fname_,'_post'];
DirectoryName = CheckPath('metropolis');
else
if options_.opt_gsa.pprior
fnamtmp=[fname_,'_prior'];
DirectoryName = CheckPath(['gsa' filesep 'prior']);
else
fnamtmp=[fname_,'_mc'];
DirectoryName = CheckPath(['gsa' filesep 'mc']);
end
end
if ~loadSA,
if exist('xparam1','var')
set_all_parameters(xparam1);
steady_;
ys_mode=oo_.steady_state;
end
if exist('xparam1_mean','var')
set_all_parameters(xparam1_mean);
steady_;
ys_mean=oo_.steady_state;
end
% eval(options_.datafile)
obs = dat_fil_(options_.datafile);
%stock_gend=data_info.gend;
%stock_data = data_info.data;
load([DirectoryName '/' M_.fname '_data.mat']); filfilt = dir([DirectoryName '/' M_.fname '_filter_step_ahead*.mat']);
filparam = dir([DirectoryName '/' M_.fname '_param*.mat']);
x=[];
logpo2=[];
sto_ys=[];
for j=1:length(filparam),
%load([DirectoryName '/' M_.fname '_param',int2str(j),'.mat']);
if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name))
load([DirectoryName '/' filparam(j).name]);
x=[x; stock];
logpo2=[logpo2; stock_logpo];
sto_ys=[sto_ys; stock_ys];
clear stock stock_logpo stock_ys;
end
end
nruns=size(x,1);
nfilt=floor(pfilt*nruns);
if options_.opt_gsa.ppost || (options_.opt_gsa.ppost==0 && options_.opt_gsa.lik_only==0)
disp(' ')
disp('Computing RMSE''s...')
fobs = options_.first_obs;
nobs=options_.nobs;
for i=1:size(vvarvecm,1),
vj=deblank(vvarvecm(i,:));
eval(['vobs =obs.',vj,'(fobs:fobs-1+nobs);'])
if options_.prefilter == 1
%eval([vj,'=',vj,'-bayestopt_.mean_varobs(i);'])
%eval([vj,'=',vj,'-mean(',vj,',1);'])
vobs = vobs-mean(vobs,1);
end
jxj = strmatch(vj,lgy_(dr_.order_var,:),'exact');
js = strmatch(vj,lgy_,'exact');
if exist('xparam1','var')
% if isfield(oo_,'FilteredVariables')
% eval(['rmse_mode(i) = sqrt(mean((vobs(istart:end)-oo_.steady_state(js)-oo_.FilteredVariables.',vj,'(istart:end-1)).^2));'])
% else
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,stock_gend,stock_data,{},0);
y0 = squeeze(aK(1,jxj,:)) + ...
kron(ys_mode(js,:),ones(size(aK,3),1));
% y0 = ahat(jxj,:)' + ...
% kron(ys_mode(js,:),ones(size(ahat,2),1));
rmse_mode(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2));
% end
end
y0=zeros(nobs+1,nruns);
nbb=0;
for j=1:length(filfilt),
load([DirectoryName '/' M_.fname '_filter_step_ahead',num2str(j),'.mat']);
nb = size(stock,4);
% y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,:,:)) + ...
% kron(sto_ys(nbb+1:nbb+nb,js)',ones(size(stock,3),1));
y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,1:nobs+1,:)) + ...
kron(sto_ys(nbb+1:nbb+nb,js)',ones(nobs+1,1));
%y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock;
nbb=nbb+nb;
clear stock;
end
y0M=mean(y0,2);
for j=1:nruns,
rmse_MC(j,i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1,j)).^2));
end
if exist('xparam1_mean','var')
%eval(['rmse_pmean(i) = sqrt(mean((',vj,'(fobs-1+istart:fobs-1+nobs)-y0M(istart:end-1)).^2));'])
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,stock_gend,stock_data,{},0);
y0 = squeeze(aK(1,jxj,:)) + ...
kron(ys_mean(js,:),ones(size(aK,3),1));
% y0 = ahat(jxj,:)' + ...
% kron(ys_mean(js,:),ones(size(ahat,2),1));
rmse_pmean(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2));
end
end
clear stock_filter;
end
for j=1:nruns,
lnprior(j,1) = priordens(x(j,:)',bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4);
end
likelihood=logpo2(:)-lnprior(:);
disp('... done!')
if options_.opt_gsa.ppost
save([OutDir,'/',fnamtmp], 'x', 'logpo2', 'likelihood', 'rmse_MC', 'rmse_mode','rmse_pmean')
else
if options_.opt_gsa.lik_only
save([OutDir,'/',fnamtmp], 'likelihood', '-append')
else
save([OutDir,'/',fnamtmp], 'likelihood', 'rmse_MC','-append')
if exist('xparam1_mean','var')
save([OutDir,'/',fnamtmp], 'rmse_pmean','-append')
end
if exist('xparam1','var')
save([OutDir,'/',fnamtmp], 'rmse_mode','-append')
end
end
end
else
if options_.opt_gsa.lik_only & options_.opt_gsa.ppost==0
load([OutDir,'/',fnamtmp],'x','logpo2','likelihood');
else
load([OutDir,'/',fnamtmp],'x','logpo2','likelihood','rmse_MC','rmse_mode','rmse_pmean');
end
lnprior=logpo2(:)-likelihood(:);
nruns=size(x,1);
nfilt=floor(pfilt*nruns);
end
% smirnov tests
nfilt0=nfilt*ones(size(vvarvecm,1),1);
logpo2=logpo2(:);
if ~options_.opt_gsa.ppost
[dum, ipost]=sort(-logpo2);
[dum, ilik]=sort(-likelihood);
end
if ~options_.opt_gsa.ppost & options_.opt_gsa.lik_only
if options_.opt_gsa.pprior
anam='rmse_prior_post';
else
anam='rmse_mc_post';
end
stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir);
stab_map_2(x(ipost(1:nfilt),:),alpha2,anam, OutDir);
if options_.opt_gsa.pprior
anam='rmse_prior_lik';
else
anam='rmse_mc_lik';
end
stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir);
stab_map_2(x(ilik(1:nfilt),:),alpha2,anam, OutDir);
else
for i=1:size(vvarvecm,1),
[dum, ixx(:,i)]=sort(rmse_MC(:,i));
if options_.opt_gsa.ppost,
%nfilt0(i)=length(find(rmse_MC(:,i)<rmse_pmean(i)));
rmse_txt=rmse_pmean;
else
if options_.opt_gsa.pprior | ~exist('rmse_pmean'),
if exist('rmse_mode'),
rmse_txt=rmse_mode;
else
rmse_txt=NaN(1,size(rmse_MC,2));
end
else
%nfilt0(i)=length(find(rmse_MC(:,i)<rmse_pmean(i)));
rmse_txt=rmse_pmean;
end
end
for j=1:npar+nshock,
[H,P,KSSTAT] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
[H1,P1,KSSTAT1] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
[H2,P2,KSSTAT2] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
if H1 & H2==0,
SS(j,i)=1;
elseif H1==0,
SS(j,i)=-1;
else
SS(j,i)=0;
end
PP(j,i)=P;
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Prior ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(lnprior(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, cumplot(lnprior)
h=cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_lnprior',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_lnprior',int2str(ifig)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_lnprior',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig)]);
end
end
close(gcf)
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Likelihood ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(likelihood(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, h=cumplot(likelihood);
h=cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if options_.opt_gsa.ppost==0,
set(gca,'xlim',[min( likelihood(ixx(1:nfilt0(i),i)) ) max( likelihood(ixx(1:nfilt0(i),i)) )])
end
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_lnlik',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_lnlik',int2str(ifig)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_lnlik',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_lnlik',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_lnlik',int2str(ifig)]);
end
end
close(gcf)
end
end
ifig=0;
for i=1:size(vvarvecm,1),
if mod(i,9)==1,
ifig=ifig+1;
figure('name',['Posterior ',int2str(ifig)])
end
subplot(3,3,i-9*(ifig-1))
h=cumplot(logpo2(ixx(1:nfilt0(i),i)));
set(h,'color','red')
hold on, h=cumplot(logpo2);
h=cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
set(h,'color','green')
title(vvarvecm(i,:))
if options_.opt_gsa.ppost==0,
set(gca,'xlim',[min( logpo2(ixx(1:nfilt0(i),i)) ) max( logpo2(ixx(1:nfilt0(i),i)) )])
end
if mod(i,9)==0 | i==size(vvarvecm,1)
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_lnpost',int2str(ifig)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_lnpost',int2str(ifig)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_lnpost',int2str(ifig)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_lnpost',int2str(ifig)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_lnpost',int2str(ifig)]);
end
end
close(gcf)
end
end
param_names='';
for j=1:npar+nshock,
param_names=str2mat(param_names, bayestopt_.name{j});
end
param_names=param_names(2:end,:);
disp(' ')
disp('RMSE over the MC sample:')
disp(' min yr RMSE max yr RMSE')
for j=1:size(vvarvecm,1),
disp([vvarvecm(j,:), sprintf('%15.5g',[(min(rmse_MC(:,j))) [(max(rmse_MC(:,j)))]])])
end
invar = find( std(rmse_MC)./mean(rmse_MC)<=0.0001 );
if ~isempty(invar)
disp(' ')
disp(' ')
disp('RMSE is not varying significantly over the MC sample for the following variables:')
disp(vvarvecm(invar,:))
disp('These variables are excluded from SA')
disp('[Unless you treat these series as exogenous, there is something wrong in your estimation !]')
end
ivar = find( std(rmse_MC)./mean(rmse_MC)>0.0001 );
vvarvecm=vvarvecm(ivar,:);
rmse_MC=rmse_MC(:,ivar);
disp(' ')
% if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior,
disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ])
% else
% disp(['Sample filtered the best RMSE''s smaller than RMSE at the posterior mean ...' ])
% end
% figure, boxplot(rmse_MC)
% set(gca,'xticklabel',vvarvecm)
% saveas(gcf,[fname_,'_SA_RMSE'])
disp(' ')
disp(' ')
disp('RMSE ranges after filtering:')
if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior,
disp([' best ',num2str(pfilt*100),'% filtered remaining 90%'])
disp([' min max min max posterior mode'])
else
disp([' best filtered remaining '])
disp([' min max min max posterior mean'])
end
for j=1:size(vvarvecm,1),
disp([vvarvecm(j,:), sprintf('%15.5g',[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ...
max(rmse_MC(ixx(1:nfilt0(j),j),j)) ...
min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ...
max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ...
rmse_txt(j)])])
% disp([vvarvecm(j,:), sprintf('%15.5g',[min(logpo2(ixx(1:nfilt,j))) ...
% max(logpo2(ixx(1:nfilt,j))) ...
% min(logpo2(ixx(nfilt+1:end,j))) ...
% max(logpo2(ixx(nfilt+1:end,j)))])])
end
SP=zeros(npar+nshock,size(vvarvecm,1));
for j=1:size(vvarvecm,1),
ns=find(PP(:,j)<alpha);
SP(ns,j)=ones(size(ns));
SS(:,j)=SS(:,j).*SP(:,j);
end
for j=1:npar+nshock, %estim_params_.np,
nsp(j)=length(find(SP(j,:)));
end
snam0=param_names(find(nsp==0),:);
snam1=param_names(find(nsp==1),:);
snam2=param_names(find(nsp>1),:);
snam=param_names(find(nsp>0),:);
% snam0=bayestopt_.name(find(nsp==0));
% snam1=bayestopt_.name(find(nsp==1));
% snam2=bayestopt_.name(find(nsp>1));
% snam=bayestopt_.name(find(nsp>0));
nsnam=(find(nsp>1));
disp(' ')
disp(' ')
disp('These parameters do not affect significantly the fit of ANY observed series:')
disp(snam0)
disp(' ')
disp('These parameters affect ONE single observed series:')
disp(snam1)
disp(' ')
disp('These parameters affect MORE THAN ONE observed series: trade off exists!')
disp(snam2)
%pnam=bayestopt_.name(end-estim_params_.np+1:end);
pnam=bayestopt_.name;
% plot trade-offs
a00=jet(size(vvarvecm,1));
for ix=1:ceil(length(nsnam)/5),
figure,
for j=1+5*(ix-1):min(size(snam2,1),5*ix),
subplot(2,3,j-5*(ix-1))
%h0=cumplot(x(:,nsnam(j)+nshock));
h0=cumplot(x(:,nsnam(j)));
set(h0,'color',[0 0 0])
hold on,
np=find(SP(nsnam(j),:));
%a0=jet(nsp(nsnam(j)));
a0=a00(np,:);
for i=1:nsp(nsnam(j)), %size(vvarvecm,1),
%h0=cumplot(x(ixx(1:nfilt,np(i)),nsnam(j)+nshock));
h0=cumplot(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)));
set(h0,'color',a0(i,:))
end
ydum=get(gca,'ylim');
%xdum=xparam1(nshock+nsnam(j));
if exist('xparam1')
xdum=xparam1(nsnam(j));
h1=plot([xdum xdum],ydum);
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
end
xlabel('')
title([pnam{nsnam(j)}],'interpreter','none')
end
%subplot(3,2,6)
h0=legend(str2mat('base',vvarvecm(np,:)),0);
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none')
%h0=legend({'base',vnam{np}}',0);
%set(findobj(get(h0,'children'),'type','text'),'interpreter','none')
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]);
end
end
end
close all
for j=1:size(SP,2),
nsx(j)=length(find(SP(:,j)));
end
number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two.
bandwidth = 0; % Rule of thumb optimal bandwidth parameter.
kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton.
%kernel_function = 'uniform'; % Gaussian kernel for Fast Fourrier Transform approximaton.
for ix=1:ceil(length(nsnam)/5),
figure,
for j=1+5*(ix-1):min(size(snam2,1),5*ix),
subplot(2,3,j-5*(ix-1))
optimal_bandwidth = mh_optimal_bandwidth(x(:,nsnam(j)),size(x,1),bandwidth,kernel_function);
[x1,f1] = kernel_density_estimate(x(:,nsnam(j)),number_of_grid_points,...
size(x,1),optimal_bandwidth,kernel_function);
h0 = plot(x1, f1,'k');
hold on,
np=find(SP(nsnam(j),:));
%a0=jet(nsp(nsnam(j)));
a0=a00(np,:);
for i=1:nsp(nsnam(j)), %size(vvarvecm,1),
optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),nfilt,bandwidth,kernel_function);
[x1,f1] = kernel_density_estimate(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),number_of_grid_points,...
nfilt, optimal_bandwidth,kernel_function);
h0 = plot(x1, f1);
set(h0,'color',a0(i,:))
end
ydum=get(gca,'ylim');
set(gca,'ylim',[0 ydum(2)]);
if exist('xparam1')
%xdum=xparam1(nshock+nsnam(j));
xdum=xparam1(nsnam(j));
h1=plot([xdum xdum],[0 ydum(2)]);
set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
end
xlabel('')
title([pnam{nsnam(j)}],'interpreter','none')
end
h0=legend(str2mat('base',vvarvecm(np,:)),0);
set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none')
%h0=legend({'base',vnam{np}}',0);
%set(findobj(get(h0,'children'),'type','text'),'interpreter','none')
if options_.opt_gsa.ppost
saveas(gcf,[OutDir,'/',fname_,'_rmse_post_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]);
else
if options_.opt_gsa.pprior
saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]);
else
saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_dens_',num2str(ix)])
eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]);
eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]);
end
end
end
close all
% for j=1:size(SP,2),
% nfig=0;
% np=find(SP(:,j));
% for i=1:nsx(j), %size(vvarvecm,1),
% if mod(i,12)==1,
% nfig=nfig+1;
% %figure('name',['Sensitivity of fit of ',vnam{j}]),
% figure('name',['Sensitivity of fit of ',deblank(vvarvecm(j,:)),' ',num2str(nfig)]),
% end
%
% subplot(3,4,i-12*(nfig-1))
% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt,j),np(i)),nfilt,bandwidth,kernel_function);
% [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt,j),np(i)),number_of_grid_points,...
% nfilt, optimal_bandwidth,kernel_function);
% plot(x1, f1,':k','linewidth',2)
% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(nfilt+1:end,j),np(i)),nruns-nfilt,bandwidth,kernel_function);
% [x1,f1] = kernel_density_estimate(x(ixx(nfilt+1:end,j),np(i)),number_of_grid_points,...
% nruns-nfilt,optimal_bandwidth,kernel_function);
% hold on, plot(x1, f1,'k','linewidth',2)
% ydum=get(gca,'ylim');
% %xdum=xparam1(nshock+np(i));
% xdum=xparam1(np(i));
% h1=plot([xdum xdum],ydum);
% set(h1,'color',[0.85 0.85 0.85],'linewidth',2)
% %xdum1=mean(x(ixx(1:nfilt,j),np(i)+nshock));
% xdum1=mean(x(ixx(1:nfilt,j),np(i)));
% h2=plot([xdum1 xdum1],ydum);
% set(h2,'color',[0 1 0],'linewidth',2)
% % h0=cumplot(x(nfilt+1:end,np(i)+nshock));
% % set(h0,'color',[1 1 1])
% % hold on,
% % h0=cumplot(x(ixx(1:nfilt,j),np(i)+nshock));
% % set(h0,'linestyle',':','color',[1 1 1])
% %title([pnam{np(i)}])
% title([pnam{np(i)},'. K-S prob ', num2str(PP(np(i),j))],'interpreter','none')
% xlabel('')
% if mod(i,12)==0 | i==nsx(j),
% saveas(gcf,[fname_,'_rmse_',deblank(vvarvecm(j,:)),'_',int2str(nfig)])
% close(gcf)
% end
% end
% end
disp(' ')
disp(' ')
disp('Sensitivity table (significance and direction):')
vav=char(zeros(1, size(param_names,2)+3 ));
ibl = 12-size(vvarvecm,2);
for j=1:size(vvarvecm,1),
vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)];
end
disp(vav)
for j=1:npar+nshock, %estim_params_.np,
%disp([param_names(j,:), sprintf('%8.5g',SP(j,:))])
disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))])
disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))])
end
disp(' ')
disp(' ')
disp('Starting bivariate analysis:')
for i=1:size(vvarvecm,1)
if options_.opt_gsa.ppost
fnam = ['rmse_post_',deblank(vvarvecm(i,:))];
else
if options_.opt_gsa.pprior
fnam = ['rmse_prior_',deblank(vvarvecm(i,:))];
else
fnam = ['rmse_mc_',deblank(vvarvecm(i,:))];
end
end
stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,fnam, OutDir);
% [pc,latent,explained] = pcacov(c0);
% %figure, bar([explained cumsum(explained)])
% ifig=0;
% j2=0;
% for j=1:npar+nshock,
% i2=find(abs(pc(:,j))>alphaPC);
% if ~isempty(i2),
% j2=j2+1;
% if mod(j2,12)==1,
% ifig=ifig+1;
% figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]),
% end
% subplot(3,4,j2-(ifig-1)*12)
% bar(pc(i2,j)),
% set(gca,'xticklabel',bayestopt_.name(i2)),
% set(gca,'xtick',[1:length(i2)])
% title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%'])
% end
% if (mod(j2,12)==0 | j==(npar+nshock)) & j2,
% saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)])
% end
% end
% close all
end
end

View File

@ -1,27 +0,0 @@
function cdf = gamm_cdf (x, a)
% PURPOSE: returns the cdf at x of the gamma(a) distribution
%---------------------------------------------------
% USAGE: cdf = gamm_cdf(x,a)
% where: x = a vector
% a = a scalar gamma(a)
%---------------------------------------------------
% RETURNS:
% a vector of cdf at each element of x of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_inv
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
if nargin ~= 2
error('Wrong # of arguments to gamm_cdf');
end;
if any(any(a<=0))
error('gamm_cdf: parameter a is wrong')
end
cdf = gammainc(x,a);
I0 = find(x<0);
cdf(I0) = zeros(size(I0));

View File

@ -1,50 +0,0 @@
function x = gamm_inv(p,a,b)
% PURPOSE: returns the inverse of the cdf at p of the gamma(a,b) distribution
%---------------------------------------------------
% USAGE: x = gamm_inv(p,a)
% where: p = a vector of probabilities
% a = a scalar parameter gamma(a)
% b = scaling factor for gamma
%---------------------------------------------------
% RETURNS:
% a vector x of the quantile at each element of p of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_cdf
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
% documentation modified by LeSage to fit the format
% of the econometrics toolbox
if (nargin < 2 | isempty(b))
b=1;
end
if (nargin > 3)
error('Wrong # of arguments to gamm_inv');
end
if any(any(abs(2*p-1)>1))
error('gamm_inv: a probability should be 0<=p<=1')
end
if any(any(a<=0))
error('gamma_inv: parameter a is wrong')
end
x = max(a-1,0.1);
dx = 1;
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (gamm_cdf(x,a) - p) ./ gamm_pdf(x,a);
x = x - dx;
x = x + (dx - x) / 2 .* (x<0);
end
I0 = find(p==0);
x(I0) = zeros(size(I0));
I1 = find(p==1);
x(I1) = zeros(size(I0)) + Inf;
x=x.*b;

View File

@ -1,27 +0,0 @@
function f = gamm_pdf (x, a)
% PURPOSE: returns the pdf at x of the gamma(a) distribution
%---------------------------------------------------
% USAGE: pdf = gamm_pdf(x,a)
% where: x = a vector
% a = a scalar for gamma(a)
%---------------------------------------------------
% RETURNS:
% a vector of pdf at each element of x of the gamma(a) distribution
% --------------------------------------------------
% SEE ALSO: gamm_cdf, gamm_rnd, gamm_inv
%---------------------------------------------------
% Anders Holtsberg, 18-11-93
% Copyright (c) Anders Holtsberg
if nargin ~= 2
error('Wrong # of arguments to gamm_cdf');
end;
if any(any(a<=0))
error('gamm_pdf: parameter a is wrong')
end
f = x .^ (a-1) .* exp(-x) ./ gamma(a);
I0 = find(x<0);
f(I0) = zeros(size(I0));

View File

@ -1,54 +0,0 @@
function [A,B] = ghx2transition(mm,iv,ic,aux)
% [A,B] = ghx2transition(mm,iv,ic,aux)
%
% Adapted by M. Ratto from kalman_transition_matrix.m
% (kalman_transition_matrix.m is part of DYNARE, copyright M. Juillard)
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
global oo_ M_
[nr1, nc1] = size(mm);
ghx = mm(:, [1:(nc1-M_.exo_nbr)]);
ghu = mm(:, [(nc1-M_.exo_nbr+1):end] );
if nargin == 1
oo_.dr.ghx = ghx;
oo_.dr.ghu = ghu;
endo_nbr = M_.endo_nbr;
nstatic = oo_.dr.nstatic;
npred = oo_.dr.npred;
iv = (1:endo_nbr)';
ic = [ nstatic+(1:npred) endo_nbr+(1:size(oo_.dr.ghx,2)-npred) ]';
aux = oo_.dr.transition_auxiliary_variables;
k = find(aux(:,2) > npred);
aux(:,2) = aux(:,2) + nstatic;
aux(k,2) = aux(k,2) + oo_.dr.nfwrd;
end
n_iv = length(iv);
n_ir1 = size(aux,1);
nr = n_iv + n_ir1;
A = zeros(nr,nr);
B = zeros(nr,M_.exo_nbr);
i_n_iv = 1:n_iv;
A(i_n_iv,ic) = ghx(iv,:);
if n_ir1 > 0
A(n_iv+1:end,:) = sparse(aux(:,1),aux(:,2),ones(n_ir1,1),n_ir1,nr);
end
B(i_n_iv,:) = ghu(iv,:);

View File

@ -1,54 +0,0 @@
function [yy, xdir, isig, lam]=log_trans_(y0,xdir0)
if nargin==1,
xdir0='';
end
f=inline('skewness(log(y+lam))','lam','y');
isig=1;
if ~(max(y0)<0 | min(y0)>0)
if skewness(y0)<0,
isig=-1;
y0=-y0;
end
n=hist(y0,10);
if n(1)>20*n(end),
try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0);
catch
yl(1)=f(-min(y0)+10*eps,y0);
yl(2)=f(-min(y0)+abs(median(y0)),y0);
if abs(yl(1))<abs(yl(2))
lam=-min(y0)+eps;
else
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
end
end
yy = log(y0+lam);
xdir=[xdir0,'_logskew'];
else
isig=0;
lam=0;
yy = log(y0.^2);
xdir=[xdir0,'_logsquared'];
end
else
if max(y0)<0
isig=-1;
y0=-y0;
%yy=log(-y0);
xdir=[xdir0,'_minuslog'];
elseif min(y0)>0
%yy=log(y0);
xdir=[xdir0,'_log'];
end
try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0);
catch
yl(1)=f(-min(y0)+10*eps,y0);
yl(2)=f(-min(y0)+abs(median(y0)),y0);
if abs(yl(1))<abs(yl(2))
lam=-min(y0)+eps;
else
lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0)));
end
end
yy = log(y0+lam);
end

View File

@ -1,25 +0,0 @@
function [lpmat] = lptauSEQ(Nsam,Nvar)
% [lpmat] = lptauSEQ(Nsam,Nvar)
%
% function call LPTAU and generates a sample of dimension Nsam for a
% number of parameters Nvar
%
% Copyright (C) 2005 Marco Ratto
% THIS PROGRAM WAS WRITTEN FOR MATLAB BY
% Marco Ratto,
% Unit of Econometrics and Statistics AF
% (http://www.jrc.cec.eu.int/uasa/),
% IPSC, Joint Research Centre
% The European Commission,
% TP 361, 21020 ISPRA(VA), ITALY
% marco.ratto@jrc.it
%
clear lptau
lpmat = zeros(Nsam, Nvar);
for j=1:Nsam,
lpmat(j,:)=LPTAU(j,Nvar);
end
return

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +0,0 @@
function [vdec, cc, ac] = mc_moments(mm, ss, dr)
global options_ M_
[nr1, nc1, nsam] = size(mm);
disp('Computing theoretical moments ...')
h = waitbar(0,'Theoretical moments ...');
for j=1:nsam,
dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j);
dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j);
if ~isempty(ss),
set_shocks_param(ss(j,:));
end
[vdec(:,:,j), corr, autocorr, z, zz] = th_moments(dr,options_.varobs);
cc(:,:,j)=triu(corr);
dum=[];
for i=1:options_.ar
dum=[dum, autocorr{i}];
end
ac(:,:,j)=dum;
waitbar(j/nsam,h)
end
close(h)
disp(' ')
disp('... done !')

View File

@ -1,158 +0,0 @@
function sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
% sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
% % % % endif
if nargin < 5 | isempty(maxwhisker), maxwhisker = 1.5; end
if nargin < 4 | isempty(vertical), vertical = 1; end
if nargin < 3 | isempty(symbol), symbol = ['+','o']; end
if nargin < 2 | isempty(notched), notched = 0; end
if length(symbol)==1, symbol(2)=symbol(1); end
if notched==1, notched=0.25; end
a=1-notched;
% ## figure out how many data sets we have
if iscell(data),
nc = length(data);
else
% if isvector(data), data = data(:); end
nc = size(data,2);
end
% ## compute statistics
% ## s will contain
% ## 1,5 min and max
% ## 2,3,4 1st, 2nd and 3rd quartile
% ## 6,7 lower and upper confidence intervals for median
s = zeros(7,nc);
box = zeros(1,nc);
whisker_x = ones(2,1)*[1:nc,1:nc];
whisker_y = zeros(2,2*nc);
outliers_x = [];
outliers_y = [];
outliers2_x = [];
outliers2_y = [];
for i=1:nc
% ## Get the next data set from the array or cell array
if iscell(data)
col = data{i}(:);
else
col = data(:,i);
end
% ## Skip missing data
% % % % % % % col(isnan(col) | isna (col)) = [];
col(isnan(col)) = [];
% ## Remember the data length
nd = length(col);
box(i) = nd;
if (nd > 1)
% ## min,max and quartiles
% s(1:5,i) = statistics(col)(1:5);
s(1,i)=min(col);
s(5,i)=max(col);
s(2,i)=myprctilecol(col,25);
s(3,i)=myprctilecol(col,50);
s(4,i)=myprctilecol(col,75);
% ## confidence interval for the median
est = 1.57*(s(4,i)-s(2,i))/sqrt(nd);
s(6,i) = max([s(3,i)-est, s(2,i)]);
s(7,i) = min([s(3,i)+est, s(4,i)]);
% ## whiskers out to the last point within the desired inter-quartile range
IQR = maxwhisker*(s(4,i)-s(2,i));
whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)];
whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)];
% ## outliers beyond 1 and 2 inter-quartile ranges
outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR));
outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR);
outliers_x = [outliers_x; i*ones(size(outliers))];
outliers_y = [outliers_y; outliers];
outliers2_x = [outliers2_x; i*ones(size(outliers2))];
outliers2_y = [outliers2_y; outliers2];
elseif (nd == 1)
% ## all statistics collapse to the value of the point
s(:,i) = col;
% ## single point data sets are plotted as outliers.
outliers_x = [outliers_x; i];
outliers_y = [outliers_y; col];
else
% ## no statistics if no points
s(:,i) = NaN;
end
end
% % % % if isempty(outliers2_y)
% % % % outliers2_y=
% ## Note which boxes don't have enough stats
chop = find(box <= 1);
% ## Draw a box around the quartiles, with width proportional to the number of
% ## items in the box. Draw notches if desired.
box = box*0.23/max(box);
quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box;
quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:);
% ## Draw a line through the median
median_x = ones(2,1)*[1:nc] + [-a;+a]*box;
% median_x=median(col);
median_y = s([3,3],:);
% ## Chop all boxes which don't have enough stats
quartile_x(:,chop) = [];
quartile_y(:,chop) = [];
whisker_x(:,[chop,chop+nc]) = [];
whisker_y(:,[chop,chop+nc]) = [];
median_x(:,chop) = [];
median_y(:,chop) = [];
% % % %
% ## Add caps to the remaining whiskers
cap_x = whisker_x;
cap_x(1,:) =cap_x(1,:)- 0.05;
cap_x(2,:) =cap_x(2,:)+ 0.05;
cap_y = whisker_y([1,1],:);
% #quartile_x,quartile_y
% #whisker_x,whisker_y
% #median_x,median_y
% #cap_x,cap_y
%
% ## Do the plot
mm=min(min(data));
MM=max(max(data));
if vertical
plot (quartile_x, quartile_y, 'b', ...
whisker_x, whisker_y, 'b--', ...
cap_x, cap_y, 'k', ...
median_x, median_y, 'r', ...
outliers_x, outliers_y, [symbol(1),'r'], ...
outliers2_x, outliers2_y, [symbol(2),'r']);
set(gca,'XTick',1:nc);
set(gca, 'XLim', [0.5, nc+0.5]);
set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]);
else
% % % % % plot (quartile_y, quartile_x, "b;;",
% % % % % whisker_y, whisker_x, "b;;",
% % % % % cap_y, cap_x, "b;;",
% % % % % median_y, median_x, "r;;",
% % % % % outliers_y, outliers_x, [symbol(1),"r;;"],
% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]);
end
if nargout,
sout=s;
end
% % % endfunction

View File

@ -1,20 +0,0 @@
function y = myprctilecol(x,p);
xx = sort(x);
[m,n] = size(x);
if m==1 | n==1
m = max(m,n);
if m == 1,
y = x*ones(length(p),1);
return;
end
n = 1;
q = 100*(0.5:m - 0.5)./m;
xx = [min(x); xx(:); max(x)];
else
q = 100*(0.5:m - 0.5)./m;
xx = [min(x); xx; max(x)];
end
q = [0 q 100];
y = interp1(q,xx,p);

View File

@ -1,49 +0,0 @@
function invp = norm_inv(x, m, sd)
% PURPOSE: computes the quantile (inverse of the CDF)
% for each component of x with mean m, standard deviation sd
%---------------------------------------------------
% USAGE: invp = norm_inv(x,m,v)
% where: x = variable vector (nx1)
% m = mean vector (default=0)
% sd = standard deviation vector (default=1)
%---------------------------------------------------
% RETURNS: invp (nx1) vector
%---------------------------------------------------
% SEE ALSO: norm_d, norm_rnd, norm_inv, norm_cdf
%---------------------------------------------------
% Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Oct 26, 1994
% Copyright Dept of Probability Theory and Statistics TU Wien
% Converted to MATLAB by JP LeSage, jpl@jpl.econ.utoledo.edu
if nargin > 3
error ('Wrong # of arguments to norm_inv');
end
[r, c] = size (x);
s = r * c;
if (nargin == 1)
m = zeros(1,s);
sd = ones(1,s);
end
if length(m)==1,
m = repmat(m,1,s);
end
if length(sd)==1,
sd = repmat(sd,1,s);
end
x = reshape(x,1,s);
m = reshape(m,1,s);
sd = reshape(sd,1,s);
invp = zeros (1,s);
invp = m + sd .* (sqrt(2) * erfinv(2 * x - 1));
invp = reshape (invp, r, c);

View File

@ -1,39 +0,0 @@
% OPTGET Utility to get previously set function default values
% USAGE
% optvalue=optget(funcname,optname,optvalue);
% INPUTS
% funcname : name of function
% optname : name of option
% optval : option value
% OUTPUT
% optval : the current value of the option
%
% If the named field is not already defined, it will be set to
% optvalue, but optvalue has no effect if the field has already
% been set. Use OPTSET to change a previously set field.
%
% optget(funcname) returns the current values of the options structure.
% Copyright (c) 1997-2000, Paul L. Fackler & Mario J. Miranda
% paul_fackler@ncsu.edu, miranda.4@osu.edu
function optvalue = optget(funcname,optname,optvalue)
funcname = lower(funcname);
optvar=[funcname '_options'];
eval(['global ' optvar]) % declare a global variable
if nargin==1 % return the whole option structure
optvalue=(eval(optvar));
return
end
optname = lower(optname);
% if structure is empty or the named field does not exist
% set to the value passed
if isempty(eval(optvar)) | ~isfield(eval(optvar),optname)
eval([optvar '.' optname '=optvalue;']);
% otherwise return the value in the field
else
optvalue = eval([optvar '.' optname]);
end

View File

@ -1,105 +0,0 @@
function pdraw = prior_draw_gsa(init,rdraw)
% Draws from the prior distributions
% Adapted by M. Ratto from prior_draw (of DYNARE, copyright M. Juillard),
% for use with Sensitivity Toolbox for DYNARE
%
%
% INPUTS
% o init [integer] scalar equal to 1 (first call) or 0.
% o rdraw
%
% OUTPUTS
% o pdraw [double] draw from the joint prior density.
%
% ALGORITHM
% ...
%
% SPECIAL REQUIREMENTS
% MATLAB Statistics Toolbox
%
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
% marco.ratto@jrc.it
%
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%
% global M_ options_ estim_params_ bayestopt_
global bayestopt_
persistent npar pshape p6 p7 p3 p4 lbcum ubcum
if init
pshape = bayestopt_.pshape;
p6 = bayestopt_.p6;
p7 = bayestopt_.p7;
p3 = bayestopt_.p3;
p4 = bayestopt_.p4;
npar = length(p6);
pdraw = zeros(npar,1);
lbcum = zeros(npar,1);
ubcum = ones(npar,1);
% set bounds for cumulative probabilities
for i = 1:npar
switch pshape(i)
case 5% Uniform prior.
p4(i) = min(p4(i),bayestopt_.ub(i));
p3(i) = max(p3(i),bayestopt_.lb(i));
case 3% Gaussian prior.
lbcum(i) = 0.5 * erfc(-(bayestopt_.lb(i)-p6(i))/p7(i) ./ sqrt(2));;
ubcum(i) = 0.5 * erfc(-(bayestopt_.ub(i)-p6(i))/p7(i) ./ sqrt(2));;
case 2% Gamma prior.
lbcum(i) = gamm_cdf((bayestopt_.lb(i)-p3(i))/p7(i),p6(i));
ubcum(i) = gamm_cdf((bayestopt_.ub(i)-p3(i))/p7(i),p6(i));
case 1% Beta distribution (TODO: generalized beta distribution)
lbcum(i) = betainc((bayestopt_.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
ubcum(i) = betainc((bayestopt_.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
case 4% INV-GAMMA1 distribution
% TO BE CHECKED
lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i))^2)/(2/p6(i)),p7(i)/2);
ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i))^2)/(2/p6(i)),p7(i)/2);
case 6% INV-GAMMA2 distribution
% TO BE CHECKED
lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i)))/(2/p6(i)),p7(i)/2);
ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i)))/(2/p6(i)),p7(i)/2);
otherwise
% Nothing to do here.
end
end
return
end
for i = 1:npar
rdraw(:,i) = rdraw(:,i).*(ubcum(i)-lbcum(i))+lbcum(i);
switch pshape(i)
case 5% Uniform prior.
pdraw(:,i) = rdraw(:,i)*(p4(i)-p3(i)) + p3(i);
case 3% Gaussian prior.
pdraw(:,i) = norm_inv(rdraw(:,i),p6(i),p7(i));
case 2% Gamma prior.
pdraw(:,i) = gamm_inv(rdraw(:,i),p6(i),p7(i))+p3(i);
case 1% Beta distribution (TODO: generalized beta distribution)
pdraw(:,i) = beta_inv(rdraw(:,i),p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
case 4% INV-GAMMA1 distribution
% TO BE CHECKED
pdraw(:,i) = sqrt(1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i)))+p3(i);
case 6% INV-GAMMA2 distribution
% TO BE CHECKED
pdraw(:,i) = 1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i))+p3(i);
otherwise
% Nothing to do here.
end
end

Some files were not shown because too many files have changed in this diff Show More