source: tol/doc/modeling/BSR/BSR_P2_S4_Import.lyx

devel
Last change on this file was 2fa3a27, checked in by Víctor de Buen <vdebuen@…>, 17 years ago

Documentación de la nueva API modular

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1468 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 59.9 KB
Line 
1#LyX 1.6.0 created this file. For more info see http://www.lyx.org/
2\lyxformat 345
3\begin_document
4\begin_header
5\textclass amsbook
6\begin_preamble
7\usepackage{a4wide}
8%\documentclass[spanish]{article}
9\usepackage{babel}
10\usepackage{a4wide}
11\usepackage{varioref}
12\usepackage{amssymb}
13\usepackage{latexsym}
14\usepackage{amssymb}
15\usepackage{amsmath}
16
17\usepackage{graphics}
18\usepackage{graphicx}
19\usepackage{ulem}
20\usepackage{color}
21\usepackage{multicol}
22\usepackage{longtable}
23
24%\usepackage{makeidx}
25\usepackage{hyperref}
26\makeindex
27
28\hypersetup{urlbordercolor=0 0 0,pdfborder=0 0 1 [3 2]}
29\end_preamble
30\use_default_options false
31\begin_modules
32theorems-ams
33\end_modules
34\language spanish
35\inputencoding auto
36\font_roman default
37\font_sans default
38\font_typewriter default
39\font_default_family default
40\font_sc false
41\font_osf false
42\font_sf_scale 100
43\font_tt_scale 100
44
45\graphics default
46\paperfontsize default
47\spacing single
48\use_hyperref false
49\papersize default
50\use_geometry false
51\use_amsmath 1
52\use_esint 0
53\cite_engine basic
54\use_bibtopic false
55\paperorientation portrait
56\secnumdepth 3
57\tocdepth 3
58\paragraph_separation indent
59\defskip medskip
60\quotes_language english
61\papercolumns 1
62\papersides 1
63\paperpagestyle default
64\tracking_changes false
65\output_changes false
66\author ""
67\author ""
68\end_header
69
70\begin_body
71
72\begin_layout Chapter
73\begin_inset CommandInset label
74LatexCommand label
75name "cha:BysMcmc::Bsr::Import"
76
77\end_inset
78
79API BysMcmc::Bsr::Import
80\end_layout
81
82\begin_layout Standard
83Se describen los miembros y métodos generales del NameBlock BysMcmc::Bsr::Import
84\end_layout
85
86\begin_layout Section
87Descripción
88\end_layout
89
90\begin_layout Standard
91El
92\family typewriter
93\series bold
94API
95\series default
96 BysMcmc::Bsr::Import
97\family default
98, en lo adelante
99\family typewriter
100\series bold
101API
102\series default
103 Import
104\family default
105, es un nivel de abstracción que permite definir modelos
106\series bold
107BSR
108\series default
109 sin necesidad de conocer el formato en archivo de dichos modelos.
110 Semánticamente esta orientado a los conceptos ya definidos en la sección
111 
112\begin_inset CommandInset ref
113LatexCommand ref
114reference "sec:clase_modelos_BSR"
115
116\end_inset
117
118 y se centran en los segmentos de regresión y la estructura del error.
119\end_layout
120
121\begin_layout Standard
122Por recordar, un modelo
123\series bold
124BSR
125\series default
126 define una regresion lineal restringida compuesta de segmentos de regresion
127 con errores independientes entre sí y un sistema de restricciones lineales
128 entre los parámetros.
129 
130\end_layout
131
132\begin_layout Standard
133El
134\family typewriter
135\series bold
136API
137\series default
138 Import
139\family default
140 es un mecanismo para definir las caracteristicas de cada uno de los segmentos
141 de regresión tales como:
142\end_layout
143
144\begin_layout Itemize
145estructura temporal de las observaciones
146\end_layout
147
148\begin_layout Itemize
149distribución del error
150\end_layout
151
152\begin_layout Itemize
153parámetros lineales
154\end_layout
155
156\begin_layout Itemize
157omitidos en el output e inputs
158\end_layout
159
160\begin_layout Itemize
161restricciones entre los parámetros
162\end_layout
163
164\begin_layout Standard
165Para cada una de las categorías anteriores deben definirse un conjunto de
166 métodos que dan acceso a los elementos de las mismas, por ejemplo en la
167 definición de los parámetros lineales de un segmento debemos tener un método
168 para retornar el número de parámetros del segmento y otro para retornar
169 la información del i-ésimo parámetro.
170 Este estilo de interfaz se ha escogido para dar flexibilidad a la hora
171 de definir el modelo
172\color red
173(amplia un poco más esto)
174\color inherit
175.
176\end_layout
177
178\begin_layout Standard
179De forma global el modelo
180\series bold
181BSR
182\series default
183 debe satisfacer también unos requerimientos de interfaz como son retornar
184 el número de segmentos que lo componen, el i-ésimo segmento y las restricciones
185 entre parámetros de diferentes bloques.
186 El segmento retornado debe ser un
187\family typewriter
188NameBlock
189\family default
190 que cumpla con el API del segmento requerida.
191\end_layout
192
193\begin_layout Standard
194En las secciones siguientes describiremos en detalle los metodos que deben
195 implementarse a nivel global del modelo BSR como a nivel de segmento.
196 Finalmente describiremos mediante un ejemplo el uso del
197\family typewriter
198\series bold
199API
200\series default
201 Import.
202\end_layout
203
204\begin_layout Section
205NameBlock del sistema BSR
206\end_layout
207
208\begin_layout Standard
209Un sistema BSR se implementa a través de un NameBlock que debe responder
210 a un interfaz que permita conocer atributos como: nombre del modelo, directorio
211 de salida del modelo .bsr, nombre de la session, número de segmentos de
212 regresion así como el acceso a cada uno de los segmentos, entre otros.
213\end_layout
214
215\begin_layout Standard
216A partir de un NameBlock o instancia que cumpla los requeriemiento del API
217 Import podemos generar el archivo .bsr asociado mediante la función
218\family typewriter
219Text BysMcmc::Bsr::Import::Write(NameBlock BSR)
220\family default
221.
222 Esta función retorna el camino del archivo generado.
223 
224\end_layout
225
226\begin_layout Standard
227El nombre del archivo y la localización es determinado haciendo uso de metodos
228 que deben estar implementados en el NameBlock
229\end_layout
230
231\begin_layout Standard
232A continuación se describe en detalles los métodos requeridos en el API
233 de un
234\family typewriter
235NameBlock
236\family default
237 para un sistema
238\family typewriter
239BSR
240\family default
241.
242 Para ligar la descripción a un ejemplo concreto usaremos el siguiente modelo
243 simple
244\begin_inset Formula $ARMA(2,1)$
245\end_inset
246
247 para un nodo de observación:
248\end_layout
249
250\begin_layout Standard
251\begin_inset Formula \begin{equation}
252\begin{array}{rl}
253y_{t} & =\beta_{0}+\sum_{1}^{k}\beta_{i}x_{t,i}+z_{t}\\
254\phi\left(B\right)z_{t} & =\theta\left(B\right)\varepsilon_{t},\varepsilon_{t}\sim N(0,\sigma^{2})\\
255\phi(B) & =1-\phi_{1}B-\phi_{2}B^{2}\\
256\theta(B) & =1-\theta_{1}B\\
257\beta_{1} & \ge\beta_{2}\end{array}\end{equation}
258
259\end_inset
260
261
262\begin_inset CommandInset label
263LatexCommand label
264name "eq:mod_exa_bsr"
265
266\end_inset
267
268
269\end_layout
270
271\begin_layout Description
272Get.Doc.Model.Name el método
273\family typewriter
274Text Get.Doc.Model.Name(Real void)
275\family default
276 debe retornar un identificador del modelo.
277 Ejemplo:
278\begin_inset listings
279lstparams "basicstyle={\small\ttfamily}"
280inline false
281status open
282
283\begin_layout Plain Layout
284
285Text Get.Doc.Model.Name(Real void)
286\end_layout
287
288\begin_layout Plain Layout
289
290{
291\end_layout
292
293\begin_layout Plain Layout
294
295  Text "BSRExample"
296\end_layout
297
298\begin_layout Plain Layout
299
300};
301\end_layout
302
303\end_inset
304
305
306\end_layout
307
308\begin_layout Description
309Get.Doc.Model.Description el método
310\family typewriter
311Text Get.Doc.Model.Description(Real void)
312\family default
313 implementa una función que retorna una descripción del modelo.
314\begin_inset listings
315lstparams "basicstyle={\small\ttfamily}"
316inline false
317status open
318
319\begin_layout Plain Layout
320
321Text Get.Doc.Model.Description(Real void)
322\end_layout
323
324\begin_layout Plain Layout
325
326{
327\end_layout
328
329\begin_layout Plain Layout
330
331  Text "Modelo simple ARMA(2,1)"
332\end_layout
333
334\begin_layout Plain Layout
335
336};
337\end_layout
338
339\end_inset
340
341
342\end_layout
343
344\begin_layout Description
345Get.Doc.Session.Name el método
346\family typewriter
347Text Get.Doc.Session.Name(Real void)
348\family default
349 implementa una función que retorna un identificador de la sessión.
350 Para un mismo modelo podemos tener diferentes sesiones que consiste en
351 una parametrización distinto.
352 Poder mantener diferentes sesiones de un modelo nos permite almacenar y
353 comparar los resultado para diferentes versiones del modelo.
354 El modelo BSR para una sesión dada se escribe en directorio indicado por
355 el valor de retorno de la función
356\family typewriter
357Text Get.Doc.Path(Real void)
358\family default
359.
360 Ejemplo:
361\begin_inset listings
362lstparams "basicstyle={\small\ttfamily}"
363inline false
364status open
365
366\begin_layout Plain Layout
367
368Text Get.Doc.Session.Name(Real void)
369\end_layout
370
371\begin_layout Plain Layout
372
373{
374\end_layout
375
376\begin_layout Plain Layout
377
378  Text _.session.id
379\end_layout
380
381\begin_layout Plain Layout
382
383};
384\end_layout
385
386\end_inset
387
388
389\end_layout
390
391\begin_layout Description
392Get.Doc.Session.Description el método
393\family typewriter
394Text Get.Doc.Session.Description(Real void)
395\family default
396 implementa una función que retorna una descripción de la sessión.
397 Ejemplo:
398\begin_inset listings
399lstparams "basicstyle={\small\ttfamily}"
400inline false
401status open
402
403\begin_layout Plain Layout
404
405Text Get.Doc.Session.Description(Real void)
406\end_layout
407
408\begin_layout Plain Layout
409
410{
411\end_layout
412
413\begin_layout Plain Layout
414
415  Text "Session "+_.session.id+" para el modelo: " +
416\end_layout
417
418\begin_layout Plain Layout
419
420       Get.Doc.Model.Name(0) + " " + Get.Doc.Model.Description(0)
421\end_layout
422
423\begin_layout Plain Layout
424
425};
426\end_layout
427
428\end_inset
429
430
431\end_layout
432
433\begin_layout Description
434Get.Doc.Session.Authors el método
435\family typewriter
436Text Get.Doc.Session.Authors(Real void)
437\family default
438 retorna una cadena que contenga los autores de la sesión.
439 Ejemplo:
440\begin_inset listings
441lstparams "basicstyle={\small\ttfamily}"
442inline false
443status open
444
445\begin_layout Plain Layout
446
447Text Get.Doc.Session.Authors(Real void)
448\end_layout
449
450\begin_layout Plain Layout
451
452{
453\end_layout
454
455\begin_layout Plain Layout
456
457  Text "user@bayesforecast.com"
458\end_layout
459
460\begin_layout Plain Layout
461
462};
463\end_layout
464
465\end_inset
466
467
468\end_layout
469
470\begin_layout Description
471Get.Doc.Path el método
472\family typewriter
473Text Get.Doc.Path(Real void)
474\family default
475 retorna el directorio de salida donde se escribirá el archivo .bsr asociado
476 al modelo.
477 Ejemplo:
478\begin_inset listings
479lstparams "basicstyle={\small\ttfamily}"
480inline false
481status open
482
483\begin_layout Plain Layout
484
485Text Get.Doc.Path(Real void)
486\end_layout
487
488\begin_layout Plain Layout
489
490{
491\end_layout
492
493\begin_layout Plain Layout
494
495  Text _.path.out
496\end_layout
497
498\begin_layout Plain Layout
499
500};
501\end_layout
502
503\end_inset
504
505
506\end_layout
507
508\begin_layout Description
509Get.LinReg.Size el método
510\family typewriter
511Real Get.LinReg.Size(Real void)
512\family default
513 retorna el número de segmentos independientes del sistema BSR.
514 Ejemplo:
515\begin_inset listings
516lstparams "basicstyle={\small\ttfamily}"
517inline false
518status open
519
520\begin_layout Plain Layout
521
522Real Get.LinReg.Size(Real void)
523\end_layout
524
525\begin_layout Plain Layout
526
527{
528\end_layout
529
530\begin_layout Plain Layout
531
532  // para el ejemplo actual solo tenemos un segmento de regresión
533\end_layout
534
535\begin_layout Plain Layout
536
537  Real 1
538\end_layout
539
540\begin_layout Plain Layout
541
542};
543\end_layout
544
545\end_inset
546
547
548\end_layout
549
550\begin_layout Description
551Get.LinReg.Segment el método
552\family typewriter
553NameBlock Get.LinReg.Segment(Real iS)
554\family default
555 retorna el
556\family typewriter
557NameBlock
558\family default
559 que implementa el API import para el segmento con ndice
560\family typewriter
561iS
562\family default
563.
564 El API que debe satisfacer este
565\family typewriter
566NameBlock
567\family default
568 lo describimos en la sección
569\begin_inset CommandInset ref
570LatexCommand ref
571reference "sec:API-segmento-BSR"
572
573\end_inset
574
575.
576 Ejemplo:
577\begin_inset listings
578lstparams "basicstyle={\small\ttfamily}"
579inline false
580status open
581
582\begin_layout Plain Layout
583
584NameBlock Get.LinReg.Segment(Real iS)
585\end_layout
586
587\begin_layout Plain Layout
588
589{
590\end_layout
591
592\begin_layout Plain Layout
593
594  // en este caso retornamos el NameBlock para el único segmento
595\end_layout
596
597\begin_layout Plain Layout
598
599  // que se modela para mas de un segmento de regresión se suele
600\end_layout
601
602\begin_layout Plain Layout
603
604  // usar un Set que es indexado por iS: _bsr.blocks[iS]
605\end_layout
606
607\begin_layout Plain Layout
608
609  NameBlock _.bsr.ARMA.2_1
610\end_layout
611
612\begin_layout Plain Layout
613
614};
615\end_layout
616
617\end_inset
618
619
620\end_layout
621
622\begin_layout Description
623Get.Constraints.Handler el método
624\family typewriter
625NameBlock Get.Constraints.Handler(Real void)
626\family default
627 retorna el
628\family typewriter
629NameBlock
630\family default
631 que implementa el interfaz necesaria para definir las restricciones entre
632 parametros de diferentes segmentos.
633 En la sección
634\begin_inset CommandInset ref
635LatexCommand ref
636reference "sec:Restricciones-en-BSR"
637
638\end_inset
639
640 se describe el API que debe satisfacerse.
641 Para nuestro ejemplo como solo tenemos un segmento de regresión las restriccion
642es están definidas en dicho segmento, no obstante también las podíamos haber
643 definido en el las restricciones globales.
644 Ejemplo:
645\begin_inset listings
646lstparams "basicstyle={\small\ttfamily}"
647inline false
648status open
649
650\begin_layout Plain Layout
651
652NameBlock Get.Constraints.Handler(Real void)
653\end_layout
654
655\begin_layout Plain Layout
656
657{
658\end_layout
659
660\begin_layout Plain Layout
661
662  // retornamos un NameBlock predefinido para el caso
663\end_layout
664
665\begin_layout Plain Layout
666
667  // no restringido
668\end_layout
669
670\begin_layout Plain Layout
671
672  NameBlock BysMcmc::Bsr::Import::Unconstrained(0)
673\end_layout
674
675\begin_layout Plain Layout
676
677};
678\end_layout
679
680\end_inset
681
682
683\end_layout
684
685\begin_layout Standard
686Finalmente el una función que retorna el NameBlock que implementa el API
687 del sistema BSR del para el modelo anterior sería similar a:
688\end_layout
689
690\begin_layout Standard
691\begin_inset listings
692lstparams "basicstyle={\small\ttfamily}"
693inline false
694status open
695
696\begin_layout Plain Layout
697
698NameBlock Build.Example.BSR(Text path.out, Text session.id,
699\end_layout
700
701\begin_layout Plain Layout
702
703                            Serie Y, Set X)
704\end_layout
705
706\begin_layout Plain Layout
707
708{
709\end_layout
710
711\begin_layout Plain Layout
712
713  NameBlock [[
714\end_layout
715
716\begin_layout Plain Layout
717
718    Text _.path.out = path.out;
719\end_layout
720
721\begin_layout Plain Layout
722
723    Text _.session.id = session.id;
724\end_layout
725
726\begin_layout Plain Layout
727
728    NameBlock _.bsr.ARMA.2_1 = [[
729\end_layout
730
731\begin_layout Plain Layout
732
733      Text _.dating.name = DatingName(Y);
734\end_layout
735
736\begin_layout Plain Layout
737
738      Date _.first = First(Y);
739\end_layout
740
741\begin_layout Plain Layout
742
743      Date _.last = Last(Y),
744\end_layout
745
746\begin_layout Plain Layout
747
748      Matrix _.Y = SerMat(Y);
749\end_layout
750
751\begin_layout Plain Layout
752
753      Matrix _.X = SerSetMat(X);
754\end_layout
755
756\begin_layout Plain Layout
757
758      /* ...
759 */
760\end_layout
761
762\begin_layout Plain Layout
763
764      /* aquí implementamos el NameBlock para el nodo de observación */
765\end_layout
766
767\begin_layout Plain Layout
768
769    ]];
770\end_layout
771
772\begin_layout Plain Layout
773
774\end_layout
775
776\begin_layout Plain Layout
777
778    Text Get.Doc.Model.Name(Real void)
779\end_layout
780
781\begin_layout Plain Layout
782
783    {
784\end_layout
785
786\begin_layout Plain Layout
787
788      Text "BSRExample"
789\end_layout
790
791\begin_layout Plain Layout
792
793    };
794\end_layout
795
796\begin_layout Plain Layout
797
798\end_layout
799
800\begin_layout Plain Layout
801
802    Text Get.Doc.Model.Description(Real void)
803\end_layout
804
805\begin_layout Plain Layout
806
807    {
808\end_layout
809
810\begin_layout Plain Layout
811
812      Text "Modelo simple ARMA(3,1)"
813\end_layout
814
815\begin_layout Plain Layout
816
817    };
818\end_layout
819
820\begin_layout Plain Layout
821
822\end_layout
823
824\begin_layout Plain Layout
825
826    Text Get.Doc.Session.Name(Real void)
827\end_layout
828
829\begin_layout Plain Layout
830
831    {
832\end_layout
833
834\begin_layout Plain Layout
835
836      Text _.session.id
837\end_layout
838
839\begin_layout Plain Layout
840
841    };
842\end_layout
843
844\begin_layout Plain Layout
845
846\end_layout
847
848\begin_layout Plain Layout
849
850    Text Get.Doc.Session.Description(Real void)
851\end_layout
852
853\begin_layout Plain Layout
854
855    {
856\end_layout
857
858\begin_layout Plain Layout
859
860      Text "Session "+_.session.id+" para el modelo: " +
861\end_layout
862
863\begin_layout Plain Layout
864
865           Get.Doc.Model.Name(0) + " " + Get.Doc.Model.Description(0)
866\end_layout
867
868\begin_layout Plain Layout
869
870    };
871\end_layout
872
873\begin_layout Plain Layout
874
875\end_layout
876
877\begin_layout Plain Layout
878
879    Text Get.Doc.Session.Authors(Real void)
880\end_layout
881
882\begin_layout Plain Layout
883
884    {
885\end_layout
886
887\begin_layout Plain Layout
888
889      Text "user@bayesforecast.com"
890\end_layout
891
892\begin_layout Plain Layout
893
894    };
895\end_layout
896
897\begin_layout Plain Layout
898
899\end_layout
900
901\begin_layout Plain Layout
902
903    Text Get.Doc.Path(Real void)
904\end_layout
905
906\begin_layout Plain Layout
907
908    {
909\end_layout
910
911\begin_layout Plain Layout
912
913      Text _.path.output
914\end_layout
915
916\begin_layout Plain Layout
917
918    };
919\end_layout
920
921\begin_layout Plain Layout
922
923\end_layout
924
925\begin_layout Plain Layout
926
927    Real Get.LinReg.Size(Real void)
928\end_layout
929
930\begin_layout Plain Layout
931
932    {
933\end_layout
934
935\begin_layout Plain Layout
936
937      // para el ejemplo actual solo tenemos un segmento de regresión
938\end_layout
939
940\begin_layout Plain Layout
941
942      Real 1
943\end_layout
944
945\begin_layout Plain Layout
946
947    };
948\end_layout
949
950\begin_layout Plain Layout
951
952\end_layout
953
954\begin_layout Plain Layout
955
956    NameBlock Get.LinReg.Segment(Real iS)
957\end_layout
958
959\begin_layout Plain Layout
960
961    {
962\end_layout
963
964\begin_layout Plain Layout
965
966      // en este caso retornamos el NameBlock para el único segmento
967\end_layout
968
969\begin_layout Plain Layout
970
971      // que se modela para mas de un segmento de regresión se suele
972\end_layout
973
974\begin_layout Plain Layout
975
976      // usar un Set que es indexado por iS: _bsr.blocks[iS]
977\end_layout
978
979\begin_layout Plain Layout
980
981      NameBlock _.bsr.ARMA.2_1
982\end_layout
983
984\begin_layout Plain Layout
985
986    };
987\end_layout
988
989\begin_layout Plain Layout
990
991\end_layout
992
993\begin_layout Plain Layout
994
995    NameBlock Get.Constraints.Handler(Real void)
996\end_layout
997
998\begin_layout Plain Layout
999
1000    {
1001\end_layout
1002
1003\begin_layout Plain Layout
1004
1005      // retornamos un NameBlock predefinido para el caso
1006\end_layout
1007
1008\begin_layout Plain Layout
1009
1010      // no restringido
1011\end_layout
1012
1013\begin_layout Plain Layout
1014
1015      NameBlock BysMcmc::Bsr::Import::Unconstrained(0)
1016\end_layout
1017
1018\begin_layout Plain Layout
1019
1020    }
1021\end_layout
1022
1023\begin_layout Plain Layout
1024
1025  ]]
1026\end_layout
1027
1028\begin_layout Plain Layout
1029
1030};
1031\end_layout
1032
1033\end_inset
1034
1035
1036\end_layout
1037
1038\begin_layout Section
1039API del segmento BSR
1040\begin_inset CommandInset label
1041LatexCommand label
1042name "sec:API-segmento-BSR"
1043
1044\end_inset
1045
1046
1047\end_layout
1048
1049\begin_layout Standard
1050Después de haber visto el API global del un sistema BSR, ahora pasamos al
1051 API de un segmento BSR concreto
1052\end_layout
1053
1054\begin_layout Description
1055Get.Name la función
1056\family typewriter
1057Get.Name(Real void)
1058\family default
1059 retorna el nombre del segmento BSR.
1060 Debe ser un nombre único entre todos los segmentos del sistema BSR.
1061 En el ejemplo que llevamos pudiera quedar así:
1062\begin_inset listings
1063lstparams "basicstyle={\small\ttfamily}"
1064inline false
1065status open
1066
1067\begin_layout Plain Layout
1068
1069Text Get.Name(Real void)
1070\end_layout
1071
1072\begin_layout Plain Layout
1073
1074{
1075\end_layout
1076
1077\begin_layout Plain Layout
1078
1079  Text "ObsY"
1080\end_layout
1081
1082\begin_layout Plain Layout
1083
1084};
1085\end_layout
1086
1087\end_inset
1088
1089
1090\end_layout
1091
1092\begin_layout Description
1093Get.Sigma2
1094\family typewriter
1095la función Anything Get.Sigma2(Real void)
1096\family default
1097 retorna un identificador o un valor para el parámetro
1098\begin_inset Formula $\sigma$
1099\end_inset
1100
1101 del segmento de regresión.
1102 Si se retorna un
1103\family typewriter
1104Text
1105\family default
1106 entonces se asume un identificador de parámetro
1107\begin_inset Formula $\sigma$
1108\end_inset
1109
1110 desconocido y se simulará según su distribución condicional, en tal caso
1111 el identificador debe ser único entre todos los nombres de parémetros
1112\begin_inset Formula $\sigma$
1113\end_inset
1114
1115 de todos los segmentos.
1116 Si el valor retornado es un
1117\family typewriter
1118Real
1119\family default
1120 entonces se asume una
1121\begin_inset Formula $\sigma$
1122\end_inset
1123
1124 conocida y no se simula.
1125 En nuestro ejemplo
1126\begin_inset Formula $\sigma$
1127\end_inset
1128
1129 es desconocido por tanto le damos un nombre:
1130\begin_inset listings
1131lstparams "basicstyle={\small\ttfamily}"
1132inline false
1133status open
1134
1135\begin_layout Plain Layout
1136
1137Text Get.Sigma2(Real void)
1138\end_layout
1139
1140\begin_layout Plain Layout
1141
1142{
1143\end_layout
1144
1145\begin_layout Plain Layout
1146
1147  Text "sigma2"
1148\end_layout
1149
1150\begin_layout Plain Layout
1151
1152};
1153\end_layout
1154
1155\end_inset
1156
1157
1158\end_layout
1159
1160\begin_layout Description
1161Get.TimeInfo si el segmento tiene estructura temporal, el método
1162\family typewriter
1163Set Get.TimeInfo(Real void)
1164\family default
1165 retorna información asociada al fechado del segmento.
1166 Ejemplo:
1167\begin_inset listings
1168lstparams "basicstyle={\small\ttfamily}"
1169inline false
1170status open
1171
1172\begin_layout Plain Layout
1173
1174Set Get.TimeInfo(Real void)
1175\end_layout
1176
1177\begin_layout Plain Layout
1178
1179{
1180\end_layout
1181
1182\begin_layout Plain Layout
1183
1184  Set BSR.NoiseTimeInfo(TimeSet Eval(_.dating.name), _.first, _.last)
1185\end_layout
1186
1187\begin_layout Plain Layout
1188
1189};
1190\end_layout
1191
1192\end_inset
1193
1194el objeto resultado debe ser de tipo
1195\family typewriter
1196BSR.NoiseTimeInfo
1197\family default
1198 que es una estructura definida internamente en TOL y que tiene la siguiente
1199 definición:
1200\begin_inset listings
1201lstparams "basicstyle={\small\ttfamily}"
1202inline false
1203status open
1204
1205\begin_layout Plain Layout
1206
1207Struct BSR.NoiseTimeInfo
1208\end_layout
1209
1210\begin_layout Plain Layout
1211
1212{
1213\end_layout
1214
1215\begin_layout Plain Layout
1216
1217  TimeSet Dating,
1218\end_layout
1219
1220\begin_layout Plain Layout
1221
1222  Date FirstDate,
1223\end_layout
1224
1225\begin_layout Plain Layout
1226
1227  Date LastDate
1228\end_layout
1229
1230\begin_layout Plain Layout
1231
1232};
1233\end_layout
1234
1235\end_inset
1236
1237
1238\end_layout
1239
1240\begin_layout Description
1241Get.ARIMA.Size la función
1242\family typewriter
1243Get.ARIMA.Size(Real void)
1244\family default
1245 retorna el número de factores
1246\family typewriter
1247ARIMA
1248\family default
1249 para el segmento
1250\family typewriter
1251BSR
1252\family default
1253.
1254 Si el segmento es no dinámico o es un ruido blanco entonces se debe retornar
1255 0.
1256 Recuérdese que en la versión actual un factor
1257\family typewriter
1258ARIMA
1259\family default
1260 no debe superar el grado 2.
1261 Un polinomio de grado superior a 2 debe darse descompuesto en factores
1262 de grado 2 ó 1.
1263 Para el modelo
1264\begin_inset CommandInset ref
1265LatexCommand ref
1266reference "eq:mod_exa_bsr"
1267
1268\end_inset
1269
1270 con un factor bastaría.
1271 
1272\begin_inset listings
1273lstparams "basicstyle={\small\ttfamily}"
1274inline false
1275status open
1276
1277\begin_layout Plain Layout
1278
1279Real Get.ARIMA.Size(Real void)
1280\end_layout
1281
1282\begin_layout Plain Layout
1283
1284{
1285\end_layout
1286
1287\begin_layout Plain Layout
1288
1289  Real 1
1290\end_layout
1291
1292\begin_layout Plain Layout
1293
1294};
1295\end_layout
1296
1297\end_inset
1298
1299
1300\end_layout
1301
1302\begin_layout Description
1303Get.ARIMA.Factor la función
1304\family typewriter
1305Get.ARIMA.Factor(Real f)
1306\family default
1307 retorna el f-ésimo factor del ruido
1308\family typewriter
1309ARIMA
1310\family default
1311.
1312 El valor del argumento
1313\family typewriter
1314f
1315\family default
1316 va desde 1 hasta
1317\family typewriter
1318n=Get.ARIMA.Size(0)
1319\family default
1320.
1321 El valor de retorno de la función debe ser un Set con estructura
1322\family typewriter
1323ARIMAStruct
1324\family default
1325:
1326\begin_inset listings
1327lstparams "basicstyle={\small\ttfamily}"
1328inline false
1329status open
1330
1331\begin_layout Plain Layout
1332
1333Struct ARIMAStruct
1334\end_layout
1335
1336\begin_layout Plain Layout
1337
1338{
1339\end_layout
1340
1341\begin_layout Plain Layout
1342
1343  Real Periodicity,
1344\end_layout
1345
1346\begin_layout Plain Layout
1347
1348  Polyn AR,
1349\end_layout
1350
1351\begin_layout Plain Layout
1352
1353  Polyn MA,
1354\end_layout
1355
1356\begin_layout Plain Layout
1357
1358  Polyn DIF
1359\end_layout
1360
1361\begin_layout Plain Layout
1362
1363};
1364\end_layout
1365
1366\end_inset
1367
1368Para el modelo
1369\begin_inset CommandInset ref
1370LatexCommand ref
1371reference "eq:mod_exa_bsr"
1372
1373\end_inset
1374
1375 la función sería:
1376\begin_inset listings
1377lstparams "basicstyle={\small\ttfamily}"
1378inline false
1379status open
1380
1381\begin_layout Plain Layout
1382
1383Set Get.ARIMA.Factor(Real f)
1384\end_layout
1385
1386\begin_layout Plain Layout
1387
1388{
1389\end_layout
1390
1391\begin_layout Plain Layout
1392
1393  Set ARIMAStruct(1, 1-0.1*B-0.1*B^2, 1-0.1*B, 1)
1394\end_layout
1395
1396\begin_layout Plain Layout
1397
1398};
1399\end_layout
1400
1401\end_inset
1402
1403
1404\end_layout
1405
1406\begin_layout Description
1407Get.Param.Size la función
1408\family typewriter
1409Real Get.Param.Size(Real void)
1410\family default
1411 retorna el número de parámetros lineales de la regresión.
1412 En el caso del ejemplo que llevamos se corresponde
1413\family typewriter
1414Rows(X)=3
1415\family default
1416 ya que los variables predictivas están almacenadas por filas:
1417\begin_inset listings
1418lstparams "basicstyle={\small\ttfamily}"
1419inline false
1420status open
1421
1422\begin_layout Plain Layout
1423
1424Real Get.Param.Size(Real void)
1425\end_layout
1426
1427\begin_layout Plain Layout
1428
1429{
1430\end_layout
1431
1432\begin_layout Plain Layout
1433
1434  Real Rows(_.X)
1435\end_layout
1436
1437\begin_layout Plain Layout
1438
1439};
1440\end_layout
1441
1442\end_inset
1443
1444
1445\end_layout
1446
1447\begin_layout Description
1448Get.Param la función
1449\family typewriter
1450Set Get.Param(Real numParam)
1451\family default
1452 retorna la información para el i-ésimo parámetro.
1453 El valor del argumento
1454\family typewriter
1455iP
1456\family default
1457 va desde
1458\family typewriter
14591
1460\family default
1461 hasta
1462\family typewriter
1463n=Get.Param.Size(0)
1464\family default
1465.
1466 El valor de retorno de la función es
1467\family typewriter
1468Set
1469\family default
1470 con estructura
1471\family typewriter
1472Bsr.Param.Info
1473\family default
1474:
1475\begin_inset listings
1476lstparams "basicstyle={\small\ttfamily}"
1477inline false
1478status open
1479
1480\begin_layout Plain Layout
1481
1482Struct Bsr.Param.Info
1483\end_layout
1484
1485\begin_layout Plain Layout
1486
1487{
1488\end_layout
1489
1490\begin_layout Plain Layout
1491
1492  Text Name,              // identificador único del parámetro
1493\end_layout
1494
1495\begin_layout Plain Layout
1496
1497  Real InitValue,         // valor inicial conocido o ?
1498\end_layout
1499
1500\begin_layout Plain Layout
1501
1502  Real Prior.LowerBound,  // cota inf.
1503 del intervalo de definición o -1/0
1504\end_layout
1505
1506\begin_layout Plain Layout
1507
1508  Real Prior.UpperBound   // cota sup.
1509 del intervalo de definición o +1/0
1510\end_layout
1511
1512\begin_layout Plain Layout
1513
1514};   
1515\end_layout
1516
1517\end_inset
1518
1519En nuestro caso retornamos los nombres
1520\family typewriter
1521beta_1
1522\family default
1523,
1524\family typewriter
1525beta_2
1526\family default
1527,...,
1528\family typewriter
1529beta_k
1530\family default
1531 y todos no acotados:
1532\begin_inset listings
1533lstparams "basicstyle={\small\ttfamily}"
1534inline false
1535status open
1536
1537\begin_layout Plain Layout
1538
1539Set Get.Param(Real iP)
1540\end_layout
1541
1542\begin_layout Plain Layout
1543
1544{
1545\end_layout
1546
1547\begin_layout Plain Layout
1548
1549  Set Bsr.Param.Info("beta_"+IntText(iP), Real Rand(0,1), -1/0, 1/0)
1550\end_layout
1551
1552\begin_layout Plain Layout
1553
1554};
1555\end_layout
1556
1557\end_inset
1558
1559
1560\end_layout
1561
1562\begin_layout Description
1563Get.Missing.Size la función
1564\family typewriter
1565Real Get.Missing.Size(Real void)
1566\family default
1567 retorna el número de parámetros asociados a los valores omitidos de las
1568 observaciones y variables.
1569 En nuestro caso no tenemos omitidos por lo que retornamos 0.
1570\begin_inset listings
1571lstparams "basicstyle={\small\ttfamily}"
1572inline false
1573status open
1574
1575\begin_layout Plain Layout
1576
1577Real Get.Missing.Size(Real void)
1578\end_layout
1579
1580\begin_layout Plain Layout
1581
1582{
1583\end_layout
1584
1585\begin_layout Plain Layout
1586
1587  Real 0
1588\end_layout
1589
1590\begin_layout Plain Layout
1591
1592};
1593\end_layout
1594
1595\end_inset
1596
1597
1598\end_layout
1599
1600\begin_layout Description
1601Get.Missing la función
1602\family typewriter
1603Set Get.Missing(Real iP)
1604\family default
1605 retorna la información acerca del i-ésimo valor/parámetro omitido.
1606 El valor del argumento
1607\family typewriter
1608iP
1609\family default
1610 va desde
1611\family typewriter
16121
1613\family default
1614 hasta
1615\family typewriter
1616n=Get.Missing.Size(0).
1617
1618\family default
1619 El valor de retorno es la información a priori para este parámetro y que
1620 será usada en el muestreo del parámetro.
1621 Esta información es dada como un Set con estructura Bsr.Missing.Info:
1622\begin_inset listings
1623lstparams "basicstyle={\small\ttfamily}"
1624inline false
1625status open
1626
1627\begin_layout Plain Layout
1628
1629Struct Bsr.Missing.Info
1630\end_layout
1631
1632\begin_layout Plain Layout
1633
1634{
1635\end_layout
1636
1637\begin_layout Plain Layout
1638
1639  Text Name,              // identificador único para el valor missing
1640\end_layout
1641
1642\begin_layout Plain Layout
1643
1644  Real Prior.Average,     // prior media or initial value
1645\end_layout
1646
1647\begin_layout Plain Layout
1648
1649  Real Prior.Sigma,       // sigma del prior or +1/0 si no inf.
1650\end_layout
1651
1652\begin_layout Plain Layout
1653
1654  Real Prior.LowerBound,  // límite inf.
1655 del intervalo o -1/0
1656\end_layout
1657
1658\begin_layout Plain Layout
1659
1660  Real Prior.UpperBound   // límite sup.
1661 del intervalo o +1/0
1662\end_layout
1663
1664\begin_layout Plain Layout
1665
1666};   
1667\end_layout
1668
1669\end_inset
1670
1671como no tenemos omitidos retornamos el conjunto vacío:
1672\begin_inset listings
1673lstparams "basicstyle={\small\ttfamily}"
1674inline false
1675status open
1676
1677\begin_layout Plain Layout
1678
1679Set Get.Missing(Real iP)
1680\end_layout
1681
1682\begin_layout Plain Layout
1683
1684{
1685\end_layout
1686
1687\begin_layout Plain Layout
1688
1689  Set Empty
1690\end_layout
1691
1692\begin_layout Plain Layout
1693
1694};
1695\end_layout
1696
1697\end_inset
1698
1699
1700\end_layout
1701
1702\begin_layout Description
1703Get.Equation.Size la función
1704\family typewriter
1705Real Get.Equation.Size(Real void)
1706\family default
1707 retorna el número de ecuaciones del segmento.
1708 Para nuestro ejemplo tendríamos la implementación:Para nuestro ejemplo
1709 como solo tenemos un segmento de regresión las restricciones están definidas
1710 en dicho segmento, no obstante también las podíamos haber definido en el
1711 las restricciones globales.
1712\begin_inset listings
1713lstparams "basicstyle={\small\ttfamily}"
1714inline false
1715status open
1716
1717\begin_layout Plain Layout
1718
1719Real Get.Equation.Size(Real void)
1720\end_layout
1721
1722\begin_layout Plain Layout
1723
1724{
1725\end_layout
1726
1727\begin_layout Plain Layout
1728
1729  // _.X e _.Y están dispuestas por filas
1730\end_layout
1731
1732\begin_layout Plain Layout
1733
1734  Real Columns(_.X);
1735\end_layout
1736
1737\begin_layout Plain Layout
1738
1739};
1740\end_layout
1741
1742\end_inset
1743
1744
1745\end_layout
1746
1747\begin_layout Description
1748Get.Equation.Output la función
1749\family typewriter
1750{Text|Real} Get.Equation.Output(Real iE)
1751\family default
1752 retorna el valor de la observación i-ésima para el segmento.
1753 El valor del parámetro
1754\family typewriter
1755iE
1756\family default
1757 va desde
1758\family typewriter
17591
1760\family default
1761 hasta
1762\family typewriter
1763n=Get.Equation.Size(0)
1764\family default
1765.
1766 El valor de retorno puede ser un
1767\family typewriter
1768Text
1769\family default
1770 o un
1771\family typewriter
1772Real
1773\family default
1774.
1775 Cuando el valor de la observación es omitido debemos retornar el identifcador
1776 de parámetro definido con
1777\family typewriter
1778Get.Missing
1779\family default
1780.
1781 Si el valor es conocido se debe retornar el valor observado.
1782 En nuestro ejemplo las observaciones están en la variable
1783\family typewriter
1784_.Y
1785\family default
1786:
1787\begin_inset listings
1788lstparams "basicstyle={\small\ttfamily}"
1789inline false
1790status open
1791
1792\begin_layout Plain Layout
1793
1794Real Get.Equation.Output(Real iE)
1795\end_layout
1796
1797\begin_layout Plain Layout
1798
1799{
1800\end_layout
1801
1802\begin_layout Plain Layout
1803
1804  Real MatDat(_.Y,1,iE)
1805\end_layout
1806
1807\begin_layout Plain Layout
1808
1809};
1810\end_layout
1811
1812\end_inset
1813
1814
1815\end_layout
1816
1817\begin_layout Description
1818Get.Equation.Input.Size la función
1819\family typewriter
1820Real Get.Equation.Input.Size(Real iE)
1821\family default
1822 retorna el número de términos distintos de 0 que tiene la ecuación i-esima.
1823 El valor del parámetro
1824\family typewriter
1825iE
1826\family default
1827 va desde 1 hasta
1828\family typewriter
1829n=Get.Equation.Size(0)
1830\family default
1831.
1832 En nuestro ejemplo la matriz
1833\family typewriter
1834X
1835\family default
1836 es densa y todas las ecuaciones tienen el mismo número de términos distintos
1837 de
1838\family typewriter
18390
1840\family default
1841:
1842\begin_inset listings
1843lstparams "basicstyle={\small\ttfamily}"
1844inline false
1845status open
1846
1847\begin_layout Plain Layout
1848
1849Real Get.Equation.Input.Size(Real iE)
1850\end_layout
1851
1852\begin_layout Plain Layout
1853
1854{
1855\end_layout
1856
1857\begin_layout Plain Layout
1858
1859  Real Rows(_.X)
1860\end_layout
1861
1862\begin_layout Plain Layout
1863
1864};
1865\end_layout
1866
1867\end_inset
1868
1869
1870\end_layout
1871
1872\begin_layout Description
1873Get.Equation.Input.Coef la función
1874\family typewriter
1875{Text|Real} Get.Equation.Input.Coef(Real iE, Real iT)
1876\family default
1877 retorna el coeficiente t-ésimo término de la e-ésima ecuación.
1878 El valor del parámetro
1879\family typewriter
1880iE
1881\family default
1882 va desde
1883\family typewriter
18841
1885\family default
1886 hasta
1887\family typewriter
1888n=Get.Equation.Size(0)
1889\family default
1890, mientras que el valor del parámetro
1891\family typewriter
1892iT
1893\family default
1894 va desde
1895\family typewriter
18961
1897\family default
1898 hasta
1899\family typewriter
1900n=
1901\family default
1902Get.Equation.Input.Size
1903\family typewriter
1904(0)
1905\family default
1906.
1907 El valor de retorno puede ser un
1908\family typewriter
1909Text
1910\family default
1911 o un
1912\family typewriter
1913Real
1914\family default
1915.
1916 Cuando el valor de la variable es omitido debemos retornar el identificador
1917 de parámetro definido con
1918\family typewriter
1919Get.Missing
1920\family default
1921.
1922 Si el valor es conocido se debe retornar el valor observado de la variable.
1923 En nuestro ejemplo todos los valores son conocidos y los coeficiente de
1924 las ecuaciones están por columnas:
1925\begin_inset listings
1926lstparams "basicstyle={\small\ttfamily}"
1927inline false
1928status open
1929
1930\begin_layout Plain Layout
1931
1932Real Get.Equation.Input.Coef(Real iE, Real iT)
1933\end_layout
1934
1935\begin_layout Plain Layout
1936
1937{
1938\end_layout
1939
1940\begin_layout Plain Layout
1941
1942  Real MatDat(_.X, iT,iE)
1943\end_layout
1944
1945\begin_layout Plain Layout
1946
1947};
1948\end_layout
1949
1950\end_inset
1951
1952
1953\end_layout
1954
1955\begin_layout Description
1956Get.Equation.Input.Param la función
1957\family typewriter
1958Text Get.Equation.Input.Param(Real iE, Real iT)
1959\family default
1960 retorna el identificador del parámetro del t-ésimo término en la e-ésima
1961 ecuación.
1962 Los identificadores de parámetros pueden estar definidos en cualquiera
1963 de los segmentos del sistema BSR.
1964 En nuestro ejemplo los identificadores de parámetros son del tipo
1965\family typewriter
1966beta
1967\family default
1968_k
1969\family typewriter
1970:
1971\family default
1972 
1973\begin_inset listings
1974lstparams "basicstyle={\small\ttfamily}"
1975inline false
1976status open
1977
1978\begin_layout Plain Layout
1979
1980Text Get.Equation.Input.Param(Real iE, Real iT)
1981\end_layout
1982
1983\begin_layout Plain Layout
1984
1985{
1986\end_layout
1987
1988\begin_layout Plain Layout
1989
1990  Text "beta_"+IntText(iT)
1991\end_layout
1992
1993\begin_layout Plain Layout
1994
1995};
1996\end_layout
1997
1998\end_inset
1999
2000
2001\end_layout
2002
2003\begin_layout Description
2004Get.Constraints.Handler la función
2005\family typewriter
2006NameBlock Get.Constraints.Handler(Real void)
2007\family default
2008 el método
2009\family typewriter
2010NameBlock Get.Constraints.Handler(Real void)
2011\family default
2012 retorna el
2013\family typewriter
2014NameBlock
2015\family default
2016 que implementa el interfaz necesaria para definir las restricciones entre
2017 parametros de este segmentos.
2018 En la sección
2019\begin_inset CommandInset ref
2020LatexCommand ref
2021reference "sec:Restricciones-en-BSR"
2022
2023\end_inset
2024
2025 se describe el API que debe satisfacerse.
2026 En el modelo planetado en
2027\begin_inset CommandInset ref
2028LatexCommand ref
2029reference "eq:mod_exa_bsr"
2030
2031\end_inset
2032
2033 solo tenemos una restricción lineal de tipo orden
2034\begin_inset Formula $\beta1\ge\beta2$
2035\end_inset
2036
2037 y pudiera quedar:
2038\begin_inset listings
2039lstparams "basicstyle={\small\ttfamily}"
2040inline false
2041status open
2042
2043\begin_layout Plain Layout
2044
2045NameBlock Get.Constraints.Handler(Real void)
2046\end_layout
2047
2048\begin_layout Plain Layout
2049
2050{
2051\end_layout
2052
2053\begin_layout Plain Layout
2054
2055  NameBlock Explicit.Constraints([["0>=-beta_1+beta_2"]])
2056\end_layout
2057
2058\begin_layout Plain Layout
2059
2060};
2061\end_layout
2062
2063\end_inset
2064
2065
2066\end_layout
2067
2068\begin_layout Section
2069Restricciones en BSR
2070\begin_inset CommandInset label
2071LatexCommand label
2072name "sec:Restricciones-en-BSR"
2073
2074\end_inset
2075
2076
2077\end_layout
2078
2079\begin_layout Standard
2080Las restricción en un sistema
2081\family typewriter
2082BSR
2083\family default
2084 la podemos definir dentro de un segmento de regresión en el caso en que
2085 sean restricciones que involucren a parámetros propios de ese segmento
2086 o a nivel global si es que se involucran parámetros de diferentes segmentos.
2087\end_layout
2088
2089\begin_layout Standard
2090La definición de las restricciones es dada mediante un
2091\family typewriter
2092NameBlock
2093\family default
2094 que debe satisfacer unos equerimientos de interfaz.
2095 Primeramente definimos unas estructuras que son necesarias en el API de
2096 restricciones.
2097 
2098\end_layout
2099
2100\begin_layout Description
2101Bsr.OrderRelation.Info es una estructura para codificar las relaciones de
2102 orden entre dos parámetros
2103\begin_inset listings
2104lstparams "basicstyle={\small\ttfamily}"
2105inline false
2106status open
2107
2108\begin_layout Plain Layout
2109
2110////////////////////////////////////////////////////////////////////
2111\end_layout
2112
2113\begin_layout Plain Layout
2114
2115// Lower <= Upper
2116\end_layout
2117
2118\begin_layout Plain Layout
2119
2120////////////////////////////////////////////////////////////////////
2121\end_layout
2122
2123\begin_layout Plain Layout
2124
2125Struct Bsr.OrderRelation.Info
2126\end_layout
2127
2128\begin_layout Plain Layout
2129
2130{
2131\end_layout
2132
2133\begin_layout Plain Layout
2134
2135  Text Lower, //Left parameter
2136\end_layout
2137
2138\begin_layout Plain Layout
2139
2140  Text Upper  //Right parameter
2141\end_layout
2142
2143\begin_layout Plain Layout
2144
2145}; 
2146\end_layout
2147
2148\end_inset
2149
2150por ejemplo en nuestro caso tenemos la restricción
2151\begin_inset Formula $\beta1\ge\beta2$
2152\end_inset
2153
2154 la cual quedaría codificada de esta manera:
2155\begin_inset Box Frameless
2156position "t"
2157hor_pos "c"
2158has_inner_box 1
2159inner_pos "t"
2160use_parbox 0
2161width "100col%"
2162special "none"
2163height "1in"
2164height_special "totalheight"
2165status open
2166
2167\begin_layout Plain Layout
2168
2169\family typewriter
2170Set Bsr.OrdeRelation.Info(
2171\begin_inset Quotes eld
2172\end_inset
2173
2174beta_2
2175\begin_inset Quotes erd
2176\end_inset
2177
2178,
2179\begin_inset Quotes erd
2180\end_inset
2181
2182beta_1
2183\begin_inset Quotes erd
2184\end_inset
2185
2186)
2187\end_layout
2188
2189\end_inset
2190
2191.
2192\end_layout
2193
2194\begin_layout Description
2195Bsr.LinearCombTerm es una estructura para codificar un término de una combinación
2196 lineal de parámetros
2197\begin_inset listings
2198lstparams "basicstyle={\small\ttfamily}"
2199inline false
2200status open
2201
2202\begin_layout Plain Layout
2203
2204///////////////////////////////////////////////////////////////////
2205\end_layout
2206
2207\begin_layout Plain Layout
2208
2209// Coefficient * Parameter
2210\end_layout
2211
2212\begin_layout Plain Layout
2213
2214//////////////////////////////////////////////////////////////////
2215\end_layout
2216
2217\begin_layout Plain Layout
2218
2219Struct Bsr.LinearCombTerm
2220\end_layout
2221
2222\begin_layout Plain Layout
2223
2224{
2225\end_layout
2226
2227\begin_layout Plain Layout
2228
2229  Real Coefficient,
2230\end_layout
2231
2232\begin_layout Plain Layout
2233
2234  Text Parameter
2235\end_layout
2236
2237\begin_layout Plain Layout
2238
2239};   
2240\end_layout
2241
2242\end_inset
2243
2244
2245\end_layout
2246
2247\begin_layout Description
2248Bsr.GenericConstraint.Info es una estructura para codificar una combinación
2249 lineal de parámetros acotada a un intervalo.
2250 
2251\begin_inset listings
2252lstparams "basicstyle={\small\ttfamily}"
2253inline false
2254status open
2255
2256\begin_layout Plain Layout
2257
2258///////////////////////////////////////////////////////////////////
2259\end_layout
2260
2261\begin_layout Plain Layout
2262
2263// LowerBound <= c_1*alfa_1 + ...
2264 + c_n*alfa_n <= UpperBound
2265\end_layout
2266
2267\begin_layout Plain Layout
2268
2269///////////////////////////////////////////////////////////////////
2270\end_layout
2271
2272\begin_layout Plain Layout
2273
2274Struct Bsr.GenericConstraint.Info
2275\end_layout
2276
2277\begin_layout Plain Layout
2278
2279{
2280\end_layout
2281
2282\begin_layout Plain Layout
2283
2284  Real LowerBound, // cota inferior de la combinación lineal o -1/0
2285\end_layout
2286
2287\begin_layout Plain Layout
2288
2289  Set  LinearComb, // un conjutno de Bsr.LinearCombTerm
2290\end_layout
2291
2292\begin_layout Plain Layout
2293
2294  Real UpperBound  // cota superior de la combinación lineal o +1/0
2295\end_layout
2296
2297\begin_layout Plain Layout
2298
2299};
2300\end_layout
2301
2302\end_inset
2303
2304
2305\end_layout
2306
2307\begin_layout Standard
2308A continuación describimos los requerimientos del
2309\family typewriter
2310API
2311\family default
2312 de restricciones expresadas en un conjunto de funciones que deben estar
2313 implementadas en el
2314\family typewriter
2315NameBlock
2316\family default
2317:
2318\end_layout
2319
2320\begin_layout Description
2321Get.OrderRelation.Size la función
2322\family typewriter
2323Real Get.OrderRelation.Size (Real void)
2324\family default
2325 retorna el número de restricciones de orden.
2326 Para nuestro ejemplo tenemos solo una:
2327\begin_inset listings
2328lstparams "basicstyle={\small\ttfamily}"
2329inline false
2330status open
2331
2332\begin_layout Plain Layout
2333
2334Real Get.OrderRelation.Size (Real void)
2335\end_layout
2336
2337\begin_layout Plain Layout
2338
2339{
2340\end_layout
2341
2342\begin_layout Plain Layout
2343
2344  Real 1
2345\end_layout
2346
2347\begin_layout Plain Layout
2348
2349};
2350\end_layout
2351
2352\end_inset
2353
2354
2355\end_layout
2356
2357\begin_layout Description
2358Get.OrderRelation la función
2359\family typewriter
2360Set  Get.OrderRelation (Real r)
2361\family default
2362 retorna la r-ésima relación de orden entre dos parámetros.
2363 El parámetro r va desde
2364\family typewriter
23651
2366\family default
2367 hasta
2368\family typewriter
2369n=Get.OrderRelation.Size(0)
2370\family default
2371.
2372 El valor de retorno es una estructura del tipo
2373\family typewriter
2374Bsr.OrdeRelation.Info
2375\family default
2376.
2377 Siguiendo nuestro ejemplo:
2378\begin_inset listings
2379lstparams "basicstyle={\small\ttfamily}"
2380inline false
2381status open
2382
2383\begin_layout Plain Layout
2384
2385Set  Get.OrderRelation (Real r)
2386\end_layout
2387
2388\begin_layout Plain Layout
2389
2390{
2391\end_layout
2392
2393\begin_layout Plain Layout
2394
2395  Set Bsr.OrdeRelation.Info("beta_2","beta_1")
2396\end_layout
2397
2398\begin_layout Plain Layout
2399
2400};
2401\end_layout
2402
2403\end_inset
2404
2405
2406\end_layout
2407
2408\begin_layout Description
2409Get.GenericConstraint.Size la función
2410\family typewriter
2411Real Get.GenericConstraint.Size (Real void)
2412\family default
2413 retorna el número de restricciones genéricas.
2414 Las restricciones genéricas son aquella que no pueden definirse como restriccio
2415nes de dominio de un parámetro o como relaciones de orden entre dos parámetros.
2416 Este es el tipo de restricción líneal más general que podemos expresar
2417 y por tanto los otros tipos de restricciones, como las de orden, pueden
2418 expresarse también de este tipo.
2419 En nuestro caso como ya hemos definido la restricción como de orden no
2420 la definimos como genérica:
2421\begin_inset listings
2422lstparams "basicstyle={\small\ttfamily}"
2423inline false
2424status open
2425
2426\begin_layout Plain Layout
2427
2428Real Get.GenericConstraint.Size (Real void)
2429\end_layout
2430
2431\begin_layout Plain Layout
2432
2433{
2434\end_layout
2435
2436\begin_layout Plain Layout
2437
2438  Real 0
2439\end_layout
2440
2441\begin_layout Plain Layout
2442
2443};
2444\end_layout
2445
2446\end_inset
2447
2448
2449\end_layout
2450
2451\begin_layout Description
2452Get.GenericConstraint la función
2453\family typewriter
2454Set  Get.GenericConstraint (Real r)
2455\family default
2456 retorna la r-ésima restricción genérica.
2457 El argumento
2458\family typewriter
2459r
2460\family default
2461 va desde
2462\family typewriter
24631
2464\family default
2465 hasta
2466\family typewriter
2467n=Get.GenericConstraint.Size(0)
2468\family default
2469.
2470 El valor de retorno es un
2471\family typewriter
2472Set
2473\family default
2474 con estructura
2475\family typewriter
2476Bsr.GenericConstraint.Info
2477\family default
2478.
2479 Por ejemplo la restricción de orden ya definida anteriormente podríamos
2480 definirla de esta manera:
2481\begin_inset listings
2482lstparams "basicstyle={\small\ttfamily}"
2483inline false
2484status open
2485
2486\begin_layout Plain Layout
2487
2488Set  Get.GenericConstraint (Real r)
2489\end_layout
2490
2491\begin_layout Plain Layout
2492
2493{
2494\end_layout
2495
2496\begin_layout Plain Layout
2497
2498  Set Bsr.GenericConstraint.Info
2499\end_layout
2500
2501\begin_layout Plain Layout
2502
2503  ( 0.0,
2504\end_layout
2505
2506\begin_layout Plain Layout
2507
2508    [[Set Bsr.LinearCombTerm(1.0,  "beta_1"),
2509\end_layout
2510
2511\begin_layout Plain Layout
2512
2513      Set Bsr.LinearCombTerm(-1.0, "beta_2")]],
2514\end_layout
2515
2516\begin_layout Plain Layout
2517
2518    +1/0 )
2519\end_layout
2520
2521\begin_layout Plain Layout
2522
2523};
2524\end_layout
2525
2526\end_inset
2527
2528
2529\end_layout
2530
2531\begin_layout Description
2532Get.ExplicitConstraint.Size la función
2533\family typewriter
2534Real Get.ExplicitConstraint.Size(Real void)
2535\family default
2536 retorna el número de restricciónes explícitas.
2537 Las restricciones explícitas son restricciones en formato texto tal y como
2538 se escriben en el archivo
2539\family typewriter
2540.bsr
2541\family default
2542.
2543 Para nuestro ejemplo no definimos ninguna restricción del tipo explícita
2544 ya que han sido convenientemente definidas anteriormente:
2545\begin_inset listings
2546lstparams "basicstyle={\small\ttfamily}"
2547inline false
2548status open
2549
2550\begin_layout Plain Layout
2551
2552Real Get.ExplicitConstraint.Size(Real void)
2553\end_layout
2554
2555\begin_layout Plain Layout
2556
2557{
2558\end_layout
2559
2560\begin_layout Plain Layout
2561
2562  Real 0
2563\end_layout
2564
2565\begin_layout Plain Layout
2566
2567};
2568\end_layout
2569
2570\end_inset
2571
2572
2573\end_layout
2574
2575\begin_layout Description
2576Get.ExplicitConstraint la función
2577\family typewriter
2578Text Get.ExplicitConstraint(Real r)
2579\family default
2580 retorna la r-ésima restricción explícita.
2581\begin_inset listings
2582lstparams "basicstyle={\small\ttfamily}"
2583inline false
2584status open
2585
2586\begin_layout Plain Layout
2587
2588Text Get.ExplicitConstraint(Real r)
2589\end_layout
2590
2591\begin_layout Plain Layout
2592
2593{
2594\end_layout
2595
2596\begin_layout Plain Layout
2597
2598  Text ""
2599\end_layout
2600
2601\begin_layout Plain Layout
2602
2603};
2604\end_layout
2605
2606\end_inset
2607
2608
2609\end_layout
2610
2611\begin_layout Standard
2612Se dan también funciones de conveniencia para construir un
2613\family typewriter
2614NameBlock
2615\family default
2616 que satisfaga el
2617\family typewriter
2618API
2619\family default
2620 de definición de restricciones.
2621 Estas funciones son:
2622\end_layout
2623
2624\begin_layout Description
2625Order.Relations la función
2626\family typewriter
2627NameBlock Order.Relations(Set order.relations)
2628\family default
2629 crea un
2630\family typewriter
2631NameBlock
2632\family default
2633 de restricciones en la que solo están definidas restricciones de orden.
2634 Ejemplo:
2635\begin_inset listings
2636lstparams "basicstyle={\small\ttfamily}"
2637inline false
2638status open
2639
2640\begin_layout Plain Layout
2641
2642NameBlock Order.Relations([[Bsr.OrdeRelation.Info("beta_2","beta_1")]])
2643\end_layout
2644
2645\end_inset
2646
2647
2648\end_layout
2649
2650\begin_layout Description
2651Generic.Constraints la función
2652\family typewriter
2653NameBlock
2654\family default
2655 
2656\family typewriter
2657Generic.Constraints(Set generic.constraints)
2658\family default
2659 crea un
2660\family typewriter
2661NameBlock
2662\family default
2663 de restricciones en la que solo están definidas restricciones genéricas.
2664 Ejemplo:
2665\begin_inset listings
2666lstparams "basicstyle={\small\ttfamily}"
2667inline false
2668status open
2669
2670\begin_layout Plain Layout
2671
2672NameBlock Generic.Constraints
2673\end_layout
2674
2675\begin_layout Plain Layout
2676
2677(
2678\end_layout
2679
2680\begin_layout Plain Layout
2681
2682[[
2683\end_layout
2684
2685\begin_layout Plain Layout
2686
2687  Bsr.GenericConstraint.Info
2688\end_layout
2689
2690\begin_layout Plain Layout
2691
2692  ( 0.0,
2693\end_layout
2694
2695\begin_layout Plain Layout
2696
2697    [[Set Bsr.LinearCombTerm(1.0,  "beta_1"),
2698\end_layout
2699
2700\begin_layout Plain Layout
2701
2702      Set Bsr.LinearCombTerm(-1.0, "beta_2")]],
2703\end_layout
2704
2705\begin_layout Plain Layout
2706
2707    +1/0 )
2708\end_layout
2709
2710\begin_layout Plain Layout
2711
2712]]
2713\end_layout
2714
2715\begin_layout Plain Layout
2716
2717)
2718\end_layout
2719
2720\end_inset
2721
2722
2723\end_layout
2724
2725\begin_layout Description
2726Explicit.Constraints la función
2727\family typewriter
2728NameBlock Explicit.Constraints(Set explicit.constraints)
2729\family default
2730 crea un
2731\family typewriter
2732NameBlock
2733\family default
2734 de restricciones en la que solo están definidas restricciones explícitas.
2735 Ejemplo:
2736\begin_inset listings
2737lstparams "basicstyle={\small\ttfamily}"
2738inline false
2739status open
2740
2741\begin_layout Plain Layout
2742
2743NameBlock Explicit.Constraints([["0<=+beta_1-beta_2"]])
2744\end_layout
2745
2746\end_inset
2747
2748
2749\end_layout
2750
2751\begin_layout Description
2752Constraints la función
2753\family typewriter
2754NameBlock Constraints(Set order.relations,Set generic.constraints,Set explicit.cons
2755traints)
2756\family default
2757 crea un
2758\family typewriter
2759NameBlock
2760\family default
2761 de restricciones a partir de los 3 tipos de restricciones posibles.
2762 Ejemplo:
2763\begin_inset listings
2764lstparams "basicstyle={\small\ttfamily}"
2765inline false
2766status open
2767
2768\begin_layout Plain Layout
2769
2770NameBlock Constraints(Empty,Empty,[["0<=+beta_1-beta_2"]])
2771\end_layout
2772
2773\end_inset
2774
2775
2776\end_layout
2777
2778\begin_layout Description
2779Unconstrained la función
2780\family typewriter
2781NameBlock Unconstrained(Real void)
2782\family default
2783 crea un
2784\family typewriter
2785NameBlock
2786\family default
2787 de restricciones vacío.
2788 Ejemplo:
2789\begin_inset listings
2790lstparams "basicstyle={\small\ttfamily}"
2791inline false
2792status open
2793
2794\begin_layout Plain Layout
2795
2796NameBlock Unconstrained(0)
2797\end_layout
2798
2799\end_inset
2800
2801
2802\end_layout
2803
2804\begin_layout Section
2805Ejemplo de API Import
2806\end_layout
2807
2808\begin_layout Standard
2809El código completo para el ejemplo dado en las ecuaciones
2810\begin_inset CommandInset ref
2811LatexCommand ref
2812reference "eq:mod_exa_bsr"
2813
2814\end_inset
2815
2816 quedaría de la siguiente manera:
2817\end_layout
2818
2819\begin_layout Standard
2820\begin_inset listings
2821lstparams "basicstyle={\small\ttfamily}"
2822inline false
2823status open
2824
2825\begin_layout Plain Layout
2826
2827NameBlock Build.Example.BSR(Text path.out, Text session.id,
2828\end_layout
2829
2830\begin_layout Plain Layout
2831
2832                            Serie Y, Set X)
2833\end_layout
2834
2835\begin_layout Plain Layout
2836
2837{
2838\end_layout
2839
2840\begin_layout Plain Layout
2841
2842  Real beta1 = Rand(-1,1);
2843\end_layout
2844
2845\begin_layout Plain Layout
2846
2847  Real beta2 = Rand(-1,beta1);
2848\end_layout
2849
2850\begin_layout Plain Layout
2851
2852  NameBlock [[
2853\end_layout
2854
2855\begin_layout Plain Layout
2856
2857    Text _.path.out = path.out;
2858\end_layout
2859
2860\begin_layout Plain Layout
2861
2862    Text _.session.id = session.id;
2863\end_layout
2864
2865\begin_layout Plain Layout
2866
2867    NameBlock _.bsr.ARMA.2_1 = [[
2868\end_layout
2869
2870\begin_layout Plain Layout
2871
2872      Text _.dating.name = DatingName(Y);
2873\end_layout
2874
2875\begin_layout Plain Layout
2876
2877      _.first = First(Y);
2878\end_layout
2879
2880\begin_layout Plain Layout
2881
2882      _.last = Last(Y),
2883\end_layout
2884
2885\begin_layout Plain Layout
2886
2887      Matrix _.Y = SerMat(Y);
2888\end_layout
2889
2890\begin_layout Plain Layout
2891
2892      Matrix _.X = SerSetMat(X);
2893\end_layout
2894
2895\begin_layout Plain Layout
2896
2897      Set _.beta.ini = [[beta1, beta2]];
2898\end_layout
2899
2900\begin_layout Plain Layout
2901
2902\end_layout
2903
2904\begin_layout Plain Layout
2905
2906      Text Get.Name(Real void)
2907\end_layout
2908
2909\begin_layout Plain Layout
2910
2911      {
2912\end_layout
2913
2914\begin_layout Plain Layout
2915
2916        Text "ObsY"
2917\end_layout
2918
2919\begin_layout Plain Layout
2920
2921      };
2922\end_layout
2923
2924\begin_layout Plain Layout
2925
2926\end_layout
2927
2928\begin_layout Plain Layout
2929
2930      Text Get.Sigma2(Real void)
2931\end_layout
2932
2933\begin_layout Plain Layout
2934
2935      {
2936\end_layout
2937
2938\begin_layout Plain Layout
2939
2940        Text "sigma2"
2941\end_layout
2942
2943\begin_layout Plain Layout
2944
2945      };
2946\end_layout
2947
2948\begin_layout Plain Layout
2949
2950\end_layout
2951
2952\begin_layout Plain Layout
2953
2954      Set Get.TimeInfo(Real void)
2955\end_layout
2956
2957\begin_layout Plain Layout
2958
2959      {
2960\end_layout
2961
2962\begin_layout Plain Layout
2963
2964        Set BSR.NoiseTimeInfo(TimeSet Eval(_.dating.name), _.first, _.last)
2965\end_layout
2966
2967\begin_layout Plain Layout
2968
2969      };
2970\end_layout
2971
2972\begin_layout Plain Layout
2973
2974\end_layout
2975
2976\begin_layout Plain Layout
2977
2978      Real Get.ARIMA.Size(Real void)
2979\end_layout
2980
2981\begin_layout Plain Layout
2982
2983      {
2984\end_layout
2985
2986\begin_layout Plain Layout
2987
2988        Real 1
2989\end_layout
2990
2991\begin_layout Plain Layout
2992
2993      };
2994\end_layout
2995
2996\begin_layout Plain Layout
2997
2998\end_layout
2999
3000\begin_layout Plain Layout
3001
3002      Set Get.ARIMA.Factor(Real f)
3003\end_layout
3004
3005\begin_layout Plain Layout
3006
3007      {
3008\end_layout
3009
3010\begin_layout Plain Layout
3011
3012        Set ARIMAStruct(1, 1-0.1*B-0.1*B^2, 1-0.1*B, 1)
3013\end_layout
3014
3015\begin_layout Plain Layout
3016
3017      };
3018\end_layout
3019
3020\begin_layout Plain Layout
3021
3022\end_layout
3023
3024\begin_layout Plain Layout
3025
3026      Real Get.Param.Size(Real void)
3027\end_layout
3028
3029\begin_layout Plain Layout
3030
3031      {
3032\end_layout
3033
3034\begin_layout Plain Layout
3035
3036        Real Rows(_.X)
3037\end_layout
3038
3039\begin_layout Plain Layout
3040
3041      };
3042\end_layout
3043
3044\begin_layout Plain Layout
3045
3046\end_layout
3047
3048\begin_layout Plain Layout
3049
3050      Set Get.Param(Real iP)
3051\end_layout
3052
3053\begin_layout Plain Layout
3054
3055      {
3056\end_layout
3057
3058\begin_layout Plain Layout
3059
3060        Real value = If(iP>2,Real Rand(-1,1),_.beta.ini[iP]);
3061\end_layout
3062
3063\begin_layout Plain Layout
3064
3065        Set Bsr.Param.Info("beta_"+IntText(iP), value, -1/0, 1/0)
3066\end_layout
3067
3068\begin_layout Plain Layout
3069
3070      };
3071\end_layout
3072
3073\begin_layout Plain Layout
3074
3075\end_layout
3076
3077\begin_layout Plain Layout
3078
3079      Real Get.Missing.Size(Real void)
3080\end_layout
3081
3082\begin_layout Plain Layout
3083
3084      {
3085\end_layout
3086
3087\begin_layout Plain Layout
3088
3089        Real 0
3090\end_layout
3091
3092\begin_layout Plain Layout
3093
3094      };
3095\end_layout
3096
3097\begin_layout Plain Layout
3098
3099\end_layout
3100
3101\begin_layout Plain Layout
3102
3103      Set Get.Missing(Real iP)
3104\end_layout
3105
3106\begin_layout Plain Layout
3107
3108      {
3109\end_layout
3110
3111\begin_layout Plain Layout
3112
3113        Set Empty
3114\end_layout
3115
3116\begin_layout Plain Layout
3117
3118      };
3119\end_layout
3120
3121\begin_layout Plain Layout
3122
3123\end_layout
3124
3125\begin_layout Plain Layout
3126
3127      Real Get.Equation.Size(Real void)
3128\end_layout
3129
3130\begin_layout Plain Layout
3131
3132      {
3133\end_layout
3134
3135\begin_layout Plain Layout
3136
3137        // _.X e _.Y están dispuestas por filas
3138\end_layout
3139
3140\begin_layout Plain Layout
3141
3142        Real Columns(_.X)
3143\end_layout
3144
3145\begin_layout Plain Layout
3146
3147      };
3148\end_layout
3149
3150\begin_layout Plain Layout
3151
3152\end_layout
3153
3154\begin_layout Plain Layout
3155
3156      Real Get.Equation.Output(Real iE)
3157\end_layout
3158
3159\begin_layout Plain Layout
3160
3161      {
3162\end_layout
3163
3164\begin_layout Plain Layout
3165
3166        Real MatDat(_.Y,1,iE)
3167\end_layout
3168
3169\begin_layout Plain Layout
3170
3171      };
3172\end_layout
3173
3174\begin_layout Plain Layout
3175
3176\end_layout
3177
3178\begin_layout Plain Layout
3179
3180      Real Get.Equation.Input.Size(Real iE)
3181\end_layout
3182
3183\begin_layout Plain Layout
3184
3185      {
3186\end_layout
3187
3188\begin_layout Plain Layout
3189
3190        Real Rows(_.X)
3191\end_layout
3192
3193\begin_layout Plain Layout
3194
3195      };
3196\end_layout
3197
3198\begin_layout Plain Layout
3199
3200\end_layout
3201
3202\begin_layout Plain Layout
3203
3204      Real Get.Equation.Input.Coef(Real iE, Real iT)
3205\end_layout
3206
3207\begin_layout Plain Layout
3208
3209      {
3210\end_layout
3211
3212\begin_layout Plain Layout
3213
3214        Real MatDat(_.X, iT,iE)
3215\end_layout
3216
3217\begin_layout Plain Layout
3218
3219      };
3220\end_layout
3221
3222\begin_layout Plain Layout
3223
3224\end_layout
3225
3226\begin_layout Plain Layout
3227
3228      Text Get.Equation.Input.Param(Real iE, Real iT)
3229\end_layout
3230
3231\begin_layout Plain Layout
3232
3233      {
3234\end_layout
3235
3236\begin_layout Plain Layout
3237
3238        Text "beta_"+IntText(iT)
3239\end_layout
3240
3241\begin_layout Plain Layout
3242
3243      };
3244\end_layout
3245
3246\begin_layout Plain Layout
3247
3248\end_layout
3249
3250\begin_layout Plain Layout
3251
3252      NameBlock Get.Constraints.Handler(Real void)
3253\end_layout
3254
3255\begin_layout Plain Layout
3256
3257      {
3258\end_layout
3259
3260\begin_layout Plain Layout
3261
3262        NameBlock BysMcmc::Bsr::Import::Explicit.Constraints([["0>=-beta1+beta2"]
3263])
3264\end_layout
3265
3266\begin_layout Plain Layout
3267
3268      }
3269\end_layout
3270
3271\begin_layout Plain Layout
3272
3273    ]];
3274\end_layout
3275
3276\begin_layout Plain Layout
3277
3278\end_layout
3279
3280\begin_layout Plain Layout
3281
3282    Text Get.Doc.Model.Name(Real void)
3283\end_layout
3284
3285\begin_layout Plain Layout
3286
3287    {
3288\end_layout
3289
3290\begin_layout Plain Layout
3291
3292      Text "BSRExample"
3293\end_layout
3294
3295\begin_layout Plain Layout
3296
3297    };
3298\end_layout
3299
3300\begin_layout Plain Layout
3301
3302\end_layout
3303
3304\begin_layout Plain Layout
3305
3306    Text Get.Doc.Model.Description(Real void)
3307\end_layout
3308
3309\begin_layout Plain Layout
3310
3311    {
3312\end_layout
3313
3314\begin_layout Plain Layout
3315
3316      Text "Modelo simple ARMA(2,1)"
3317\end_layout
3318
3319\begin_layout Plain Layout
3320
3321    };
3322\end_layout
3323
3324\begin_layout Plain Layout
3325
3326\end_layout
3327
3328\begin_layout Plain Layout
3329
3330    Text Get.Doc.Session.Name(Real void)
3331\end_layout
3332
3333\begin_layout Plain Layout
3334
3335    {
3336\end_layout
3337
3338\begin_layout Plain Layout
3339
3340      Text _.session.id
3341\end_layout
3342
3343\begin_layout Plain Layout
3344
3345    };
3346\end_layout
3347
3348\begin_layout Plain Layout
3349
3350\end_layout
3351
3352\begin_layout Plain Layout
3353
3354    Text Get.Doc.Session.Description(Real void)
3355\end_layout
3356
3357\begin_layout Plain Layout
3358
3359    {
3360\end_layout
3361
3362\begin_layout Plain Layout
3363
3364      Text "Session "+_.session.id+" para el modelo: " +
3365\end_layout
3366
3367\begin_layout Plain Layout
3368
3369           Get.Doc.Model.Name(0) + " " + Get.Doc.Model.Description(0)
3370\end_layout
3371
3372\begin_layout Plain Layout
3373
3374    };
3375\end_layout
3376
3377\begin_layout Plain Layout
3378
3379\end_layout
3380
3381\begin_layout Plain Layout
3382
3383    Text Get.Doc.Session.Authors(Real void)
3384\end_layout
3385
3386\begin_layout Plain Layout
3387
3388    {
3389\end_layout
3390
3391\begin_layout Plain Layout
3392
3393      Text "user@bayesforecast.com"
3394\end_layout
3395
3396\begin_layout Plain Layout
3397
3398    };
3399\end_layout
3400
3401\begin_layout Plain Layout
3402
3403\end_layout
3404
3405\begin_layout Plain Layout
3406
3407    Text Get.Doc.Path(Real void)
3408\end_layout
3409
3410\begin_layout Plain Layout
3411
3412    {
3413\end_layout
3414
3415\begin_layout Plain Layout
3416
3417      Text _.path.out
3418\end_layout
3419
3420\begin_layout Plain Layout
3421
3422    };
3423\end_layout
3424
3425\begin_layout Plain Layout
3426
3427\end_layout
3428
3429\begin_layout Plain Layout
3430
3431    Real Get.LinReg.Size(Real void)
3432\end_layout
3433
3434\begin_layout Plain Layout
3435
3436    {
3437\end_layout
3438
3439\begin_layout Plain Layout
3440
3441      // para el ejemplo actual solo tenemos un segmento de regresión
3442\end_layout
3443
3444\begin_layout Plain Layout
3445
3446      Real 1
3447\end_layout
3448
3449\begin_layout Plain Layout
3450
3451    };
3452\end_layout
3453
3454\begin_layout Plain Layout
3455
3456\end_layout
3457
3458\begin_layout Plain Layout
3459
3460    NameBlock Get.LinReg.Segment(Real iS)
3461\end_layout
3462
3463\begin_layout Plain Layout
3464
3465    {
3466\end_layout
3467
3468\begin_layout Plain Layout
3469
3470      // en este caso retornamos el NameBlock para el único segmento
3471\end_layout
3472
3473\begin_layout Plain Layout
3474
3475      // que se modela para mas de un segmento de regresión se suele
3476\end_layout
3477
3478\begin_layout Plain Layout
3479
3480      // usar un Set que es indexado por iS: _bsr.blocks[iS]
3481\end_layout
3482
3483\begin_layout Plain Layout
3484
3485      NameBlock _.bsr.ARMA.2_1
3486\end_layout
3487
3488\begin_layout Plain Layout
3489
3490    };
3491\end_layout
3492
3493\begin_layout Plain Layout
3494
3495\end_layout
3496
3497\begin_layout Plain Layout
3498
3499    NameBlock Get.Constraints.Handler(Real void)
3500\end_layout
3501
3502\begin_layout Plain Layout
3503
3504    {
3505\end_layout
3506
3507\begin_layout Plain Layout
3508
3509      // retornamos un NameBlock predefinido para el caso
3510\end_layout
3511
3512\begin_layout Plain Layout
3513
3514      // no restringido
3515\end_layout
3516
3517\begin_layout Plain Layout
3518
3519      NameBlock BysMcmc::Bsr::Import::Unconstrained(0)
3520\end_layout
3521
3522\begin_layout Plain Layout
3523
3524    }
3525\end_layout
3526
3527\begin_layout Plain Layout
3528
3529  ]]
3530\end_layout
3531
3532\begin_layout Plain Layout
3533
3534};
3535\end_layout
3536
3537\end_inset
3538
3539
3540\end_layout
3541
3542\begin_layout Section
3543API modular
3544\end_layout
3545
3546\begin_layout Standard
3547Como se ha visto anteriormente
3548\begin_inset CommandInset ref
3549LatexCommand ref
3550reference "sec:API-modular"
3551
3552\end_inset
3553
3554, desde la versión 2.0.1 de TOL es posible definir un modelo BSR de forma
3555 modular.
3556 Para que el Import sea capaz de crear este tipo de expresión de modeos
3557 se le han añadido una serie métodos que entrarán en acción si el NameBlock
3558 de definición del usuario implementa a su vez los siguientes métodos opcionales
3559\end_layout
3560
3561\begin_layout Description
3562Get.ModuleType retorna el tipo de módulo que puede ser
3563\begin_inset Quotes eld
3564\end_inset
3565
3566primary
3567\begin_inset Quotes erd
3568\end_inset
3569
3570,
3571\begin_inset Quotes erd
3572\end_inset
3573
3574joint
3575\begin_inset Quotes erd
3576\end_inset
3577
3578 o
3579\begin_inset Quotes eld
3580\end_inset
3581
3582master
3583\begin_inset Quotes erd
3584\end_inset
3585
3586.
3587 Si no existe método se sobreentiende
3588\begin_inset Quotes eld
3589\end_inset
3590
3591joint
3592\begin_inset Quotes erd
3593\end_inset
3594
3595 para guardar compatibilidad hacia atrás
3596\begin_inset listings
3597lstparams "basicstyle={\small\ttfamily}"
3598inline false
3599status open
3600
3601\begin_layout Plain Layout
3602
3603Text Get.ModuleType(Real unused)
3604\end_layout
3605
3606\end_inset
3607
3608
3609\end_layout
3610
3611\begin_layout Standard
3612Si se trata de un módulo de tipo
3613\begin_inset Quotes eld
3614\end_inset
3615
3616master
3617\begin_inset Quotes erd
3618\end_inset
3619
3620, entonces deberá implementar estos métodos en lugar de los definidos en
3621 la sección anterior y que corresponden al actual
3622\begin_inset Quotes eld
3623\end_inset
3624
3625joint
3626\begin_inset Quotes erd
3627\end_inset
3628
3629
3630\end_layout
3631
3632\begin_layout Description
3633Get.Modular.Schema retorna el esquema modular o modo en el que se resolverán
3634 las simulaciones que puede ser
3635\begin_inset Quotes eld
3636\end_inset
3637
3638monophasic
3639\begin_inset Quotes erd
3640\end_inset
3641
3642,
3643\begin_inset Quotes eld
3644\end_inset
3645
3646sequential
3647\begin_inset Quotes erd
3648\end_inset
3649
3650 Ã³
3651\begin_inset Quotes eld
3652\end_inset
3653
3654parallel
3655\begin_inset Quotes erd
3656\end_inset
3657
3658 
3659\begin_inset listings
3660lstparams "basicstyle={\small\ttfamily}"
3661inline false
3662status open
3663
3664\begin_layout Plain Layout
3665
3666Text Get.Modular.Schema(Real unused)
3667\end_layout
3668
3669\end_inset
3670
3671
3672\end_layout
3673
3674\begin_layout Description
3675Get.Modules retorna el conjunto de módulos, cada uno de los cuales es un
3676 NameBlock utilizable a su vez por el Import de forma recursiva
3677\begin_inset listings
3678lstparams "basicstyle={\small\ttfamily}"
3679inline false
3680status open
3681
3682\begin_layout Plain Layout
3683
3684Set Get.Modules(Real unused)
3685\end_layout
3686
3687\end_inset
3688
3689
3690\end_layout
3691
3692\begin_layout Standard
3693Si se trata de un módulo de tipo
3694\begin_inset Quotes eld
3695\end_inset
3696
3697primary
3698\begin_inset Quotes erd
3699\end_inset
3700
3701, entonces sólo puede tener un segmento el cual debe tener estos métodos
3702 en lugar de los descritos en la sección Get.Equation.Output, Get.Equation.Input.Size
3703, Get.Equation.Input.Coef y Get.Equation.Input.Param
3704\end_layout
3705
3706\begin_layout Description
3707Get.OutputVMatrix devuelve la matriz de output del segmento de regresión
3708 
3709\begin_inset listings
3710lstparams "basicstyle={\small\ttfamily}"
3711inline false
3712status open
3713
3714\begin_layout Plain Layout
3715
3716VMatrix Get.OutputVMatrix(Real unused)
3717\end_layout
3718
3719\end_inset
3720
3721
3722\end_layout
3723
3724\begin_layout Description
3725Get.InputVMatrix devuelve la matriz de input del segmento de regresión
3726\begin_inset listings
3727lstparams "basicstyle={\small\ttfamily}"
3728inline false
3729status open
3730
3731\begin_layout Plain Layout
3732
3733VMatrix Get.InputVMatrix(Real unused)
3734\end_layout
3735
3736\end_inset
3737
3738
3739\end_layout
3740
3741\begin_layout Standard
3742El método Get.Equation.Size se mantiene porque el reconocedor sintáctico no
3743 va a caragr la matriz y desconoce por tanto sus dimensiones.
3744\end_layout
3745
3746\begin_layout Standard
3747Tanto en los módulos
3748\begin_inset Quotes eld
3749\end_inset
3750
3751primary
3752\begin_inset Quotes erd
3753\end_inset
3754
3755 como en los
3756\begin_inset Quotes eld
3757\end_inset
3758
3759joint
3760\begin_inset Quotes erd
3761\end_inset
3762
3763 los segmentos pueden ahora añadir la información referida a los fitrosno
3764 lineales que antes se introducían a BSR de forma externa.
3765 Para ello se deberá definir el método
3766\end_layout
3767
3768\begin_layout Description
3769Get.NonLinearFilters Devuelve un conjunto de NameBlock's cada uno de los
3770 cuales define un filtro no lineal sobre el mismo segmento
3771\begin_inset listings
3772lstparams "basicstyle={\small\ttfamily}"
3773inline false
3774status open
3775
3776\begin_layout Plain Layout
3777
3778Set Get.NonLinearFilters(Real unused)
3779\end_layout
3780
3781\end_inset
3782
3783
3784\end_layout
3785
3786\end_body
3787\end_document
Note: See TracBrowser for help on using the repository browser.