close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Ticket #1714: ejemplo.tol

File ejemplo.tol, 3.9 KB (added by Pedro Gea, 11 years ago)
Line 
1
2#Require MMS;
3
4Real PutRandomSeed(2143);
5NameBlock Project = [[
6  Real sigma = 0.5;
7  Matrix noise = Gaussian(100, 1, 0, sigma);
8  Matrix input1 = Rand(100, 1, 0, 1);
9  Real beta1 = 0.3;
10  Matrix input2 = Rand(100, 1, 0, 1);
11  Real beta2 = -0.3;
12  Matrix filter = input1 * beta1 + input2 * beta2;
13  Matrix output = noise + filter;
14  Matrix a = Rand(100, 100, -1, 1);
15  Matrix input1A = a*input1;
16  Matrix input2A = a*input2;
17  Matrix outputA = a*output;
18  Matrix covA = a*Tra(a);
19  Matrix covAI = GaussInverse(Tra(a))*GaussInverse(a)
20]];
21
22MMS::@DataSet dataSet = MMS::Container::ReplaceDataSet([[
23  Text _.name = "Dat.Ej"
24]]);
25Anything dataSet::CreateVariable_Data(Project::output);
26Anything dataSet::CreateVariable_Data(Project::input1);
27Anything dataSet::CreateVariable_Data(Project::input2);
28Anything dataSet::CreateVariable_Data(Project::outputA);
29Anything dataSet::CreateVariable_Data(Project::input1A);
30Anything dataSet::CreateVariable_Data(Project::input2A);
31Anything covA = dataSet::CreateVariable_Data(Project::covA);
32Anything covAI = dataSet::CreateVariable_Data(Project::covAI);
33// -- model --
34MMS::@Model model = MMS::Container::ReplaceModel([[
35  Text _.name = "Mod.Ej";
36  Text _.dataSet = "Dat.Ej"
37]]);
38// -- submodel 1 --
39MMS::@Submodel submodel = model::CreateSubmodel([[
40  Text _.name = "Submodel1";
41  NameBlock _.output = [[
42    Text _.name = "output";
43    Text _.variable = "output"
44  ]];
45  NameBlock _.noise = [[
46    Text _.type = "Normal"
47  ]]
48]]);
49Anything submodel::CreateExpTerm([[
50  Text _.name = "ExpTerm1";
51  NameBlock _.input = [[
52    Text _.name = "input1";
53    Text _.variable = "input1"
54  ]];
55  Real _.coefficient = 1
56]]);
57Anything submodel::CreateExpTerm([[
58  Text _.name = "ExpTerm2";
59  NameBlock _.input = [[
60    Text _.name = "input2";
61    Text _.variable = "input2"
62  ]];
63  Real _.coefficient = 1
64]]);
65// -- submodel 2 --
66MMS::@Submodel submodel2 = model::CreateSubmodel([[
67  Text _.name = "Submodel2";
68  NameBlock _.output = [[
69    Text _.name = "outputA";
70    Text _.variable = "outputA"
71  ]];
72  NameBlock _.noise = [[
73    Text _.type = "Normal";
74    Real _.sigma = 0.5;
75    Real _.sigmaFixed = 0.1;
76    Matrix _.relativeCovariance = covA::GetData(?)
77  ]]
78]]);
79Anything submodel2::CreateExpTerm([[
80  Text _.name = "ExpTerm1";
81  NameBlock _.input = [[
82    Text _.name = "input1A";
83    Text _.variable = "input1A"
84  ]];
85  Real _.coefficient = 1
86]]);
87Anything submodel2::CreateExpTerm([[
88  Text _.name = "ExpTerm2";
89  NameBlock _.input = [[
90    Text _.name = "input2A";
91    Text _.variable = "input2A"
92  ]];
93  Real _.coefficient = 1
94]]);
95// -- submodel 3 --
96MMS::@Submodel submodel3 = model::CreateSubmodel([[
97  Text _.name = "Submodel3";
98  NameBlock _.output = [[
99    Text _.name = "outputA";
100    Text _.variable = "outputA"
101  ]];
102  NameBlock _.noise = [[
103    Text _.type = "Normal";
104    Real _.sigma = 0.1;
105    Real _.sigmaFixed = 0.1;
106    Matrix _.relativeCovariance = covA::GetData(?)*0.01
107  ]]
108]]);
109Anything submodel3::CreateExpTerm([[
110  Text _.name = "ExpTerm1";
111  NameBlock _.input = [[
112    Text _.name = "input1A";
113    Text _.variable = "input1A"
114  ]];
115  Real _.coefficient = 1
116]]);
117Anything submodel3::CreateExpTerm([[
118  Text _.name = "ExpTerm2";
119  NameBlock _.input = [[
120    Text _.name = "input2A";
121    Text _.variable = "input2A"
122  ]];
123  Real _.coefficient = 1
124]]);
125// -- estimation mle --
126MMS::@Estimation estimation = MMS::Container::ReplaceEstimation([[
127  Text _.name = "Est.Ej";
128  NameBlock _.model = model;
129  MMS::@SettingsMultiMLE _.settings = [[
130    Real _.showTraces = 0
131  ]]
132]]);
133Real estimation::Execute(?);
134// -- estimation bsr --
135MMS::@Estimation estimationBSR = MMS::Container::ReplaceEstimation([[
136  Text _.name = "Est.Ej_BSR";
137  NameBlock _.model = model;
138  MMS::@SettingsBSR _.settings = [[
139    Real _.showTraces = 0;
140    Real mcmc.sampleLength = 5000
141  ]]
142]]);
143Real estimationBSR::Execute(?);
144
145