Changeset b86a123 in tol
- Timestamp:
- Dec 5, 2008, 8:22:58 AM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 3c0146e
- Parents:
- 9ea7897
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_estimOneNode.tol
r9ea7897 rb86a123 22 22 " Real _.sigma; //Sigma value or ? to simulate it\n" 23 23 "//Optional members \n" 24 " Set _.orderRelation; //Set of Bsr.OrderRelation.Info\n" 24 25 " Set _.arima; //Set of ARIMAStruct\n" 25 26 " Set _.timeInfo; //Set of BSR.NoiseTimeInfo\n" 26 " Set _.orderRelation; //Set of Bsr.OrderRelation.Info\n"27 27 "]];\n"; 28 28 Set EstimOneNode(NameBlock data_, Set nonLinFil, NameBlock config_) 29 29 ////////////////////////////////////////////////////////////////////////////// 30 30 { 31 Text _MID = _MID+"";31 Text _MID = "[EstimOneNode]"; 32 32 //Data source for model defining 33 33 NameBlock data = data_; … … 127 127 }); 128 128 129 Real m.full = m+prior.num; 130 129 131 //WriteLn(_MID+" TRACE 6"); 130 132 //Observational information … … 139 141 data::_.arima, Copy(Empty)); 140 142 Set ArimaAuxInfo = Copy(Empty); 141 VMatrix Cov = Eye(m );142 VMatrix L = Eye(m);143 VMatrix Li = Eye(m);143 VMatrix Cov = Eye(m.full,m.full,0,Rand(m,1,1,1)<<Rand(prior.num,1,0,0)); 144 VMatrix L = Cov; 145 VMatrix Li = Cov; 144 146 Set EquIdx = Range(1,m,1); 145 147 Set TimeInfo = If(ObjectExist("Set","data::_.timeInfo"), … … 151 153 VMatrix prior.X = Triplet(prior.X.triplet,prior.num,n); 152 154 Set noisePrior = If(!prior.num,Copy(Empty), 153 {[[ 155 { 156 [[ 154 157 BSR.NoiseDistrib( 155 158 Text Name = data::_.segmentName+".Prior::Noise"; … … 159 162 Set arima = Copy(Empty); 160 163 Set ArimaAuxInfo = Copy(Empty); 161 VMatrix Cov = Eye(m );162 VMatrix L = Eye(m);163 VMatrix Li = Eye(m);164 VMatrix Cov = Eye(m.full,m.full,0,Rand(m,1,0,0)<<Rand(prior.num,1,1,1)); 165 VMatrix L = Cov; 166 VMatrix Li = Cov; 164 167 Set EquIdx = Range(m+1,m+prior.num,1); 165 168 Set TimeInfo = Copy(Empty) … … 192 195 VMatrix A = domain.A << order.A 193 196 ); 194 //WriteLn(_MID+" TRACE 10"); 195 //Calling BSR simulator 196 Set aux = BysMcmc::Bsr::Gibbs::EstimParsed 197 ( 198 modelDef, 199 nonLinearFilters, 200 config_, 201 BysMcmc::Bsr::Gibbs::NoNotifier(0) 202 ); 203 //WriteLn(_MID+" TRACE 11"); 204 //Adding data source information 205 Set bsr.estim = [[data]]<<aux; 197 Set result = If(Not(config_::mcmc.sampleLength), [[data, modelDef]], 198 { 199 //WriteLn(_MID+" TRACE 10"); 200 //Calling BSR simulator 201 Set aux = BysMcmc::Bsr::Gibbs::EstimParsed 202 ( 203 modelDef, 204 nonLinearFilters, 205 config_, 206 BysMcmc::Bsr::Gibbs::NoNotifier(0) 207 ); 208 //WriteLn(_MID+" TRACE 11"); 209 //Adding data source information 210 [[data]]<<aux 211 }); 206 212 //Checks unique name and prepares for hashed searching by name 207 Real SetIndexByName( bsr.estim);213 Real SetIndexByName(result); 208 214 //WriteLn(_MID+" TRACE 12"); 209 bsr.estim215 result 210 216 }; 211 217 ///////////////////////////////////////////////////////////////////////////// … … 215 221 ////////////////////////////////////////////////////////////////////////////// 216 222 Text _.autodoc.member.EstimOneNodeProbit = 217 "Estimates a model with just one node, usually observational and dense." 223 "Estimates a probit model with just one node, usually observational and " 224 "dense." 218 225 "Model is defined as a BSR basic and an non linear ProbitFilter." 219 "BSR will be built from simplified data argument matching this API" 226 "BSR will be built from simplified data argument matching the same API " 227 "used by BysMcmc::Bsr::Gibbs::EstimOneNode, fixing _.sigma to 1" 220 228 "NameBlock data = \n" 221 229 "[[\n" 230 "//Mandatory members \n" 222 231 " Set _.docInfo //BSR.DocInfo \n" 223 232 " Text _.segmentName; //Node name\n" 224 " Set _.linearParamInfo; //Set of Bsr.Param.Info\n" 225 " Matrix _.Y; //Input data\n" 226 " Matrix _.X; //Output data\n" 227 " Real _.sigma=1; //Sigma value must be fixed as 1\n" 233 " Set _.linearParamInfo; //Set of Bsr.OneNode.LinearParamInfo\n" 234 " Anything _.Y; //Output data (Matrix or VMatrix)\n" 235 " Anything _.X; //Input data (Matrix or VMatrix)\n" 236 " Real _.sigma = 1; //Sigma value or ? to simulate it\n" 237 "//Optional members \n" 238 " Set _.orderRelation; //Set of Bsr.OrderRelation.Info\n" 239 " Set _.arima; //Set of ARIMAStruct\n" 240 " Set _.timeInfo; //Set of BSR.NoiseTimeInfo\n" 228 241 "]];\n"; 229 242 NameBlock EstimOneNodeProbit(NameBlock data, NameBlock config_) 230 243 ////////////////////////////////////////////////////////////////////////////// 231 244 { 245 //All methods are performed for being _.sigma=1 246 Real data::_.sigma:=1; 232 247 Set nonLinearFilters = {[[ 233 248 //Filtro no lineal del output para el modelo probit … … 242 257 Set _.estim = BysMcmc::Bsr::Gibbs::EstimOneNode 243 258 (data, nonLinearFilters, config_); 244 Matrix _.param = Tra(_.estim::param.average); 259 Matrix _.param = If(Not(config_::mcmc.sampleLength), Rand(0,0,0,0), 260 Tra(_.estim::param.average)); 261 262 ////////////////////////////////////////////////////////////////////////// 263 Text _.autodoc.member.GetProbPoint = 264 "Returns output probabilities for given input matrix and parameters " 265 "vector"; 266 Matrix GetProbPoint(Matrix X, Matrix beta) 267 ////////////////////////////////////////////////////////////////////////// 268 { 269 F01(X*beta) 270 }; 271 ////////////////////////////////////////////////////////////////////////// 272 Text _.autodoc.member.GetProbAvg = 273 "Returns output probabilities for given input matrix and average vector " 274 "of simulated parameters"; 275 Matrix GetProbAvg(Matrix X) 276 ////////////////////////////////////////////////////////////////////////// 277 { 278 GetProbPoint(X,_.param) 279 }; 280 ////////////////////////////////////////////////////////////////////////// 281 Text _.autodoc.member.GetProb = 282 "Returns output probabilities for given input matrix integrated " 283 "over all simulated vectors of parameters"; 245 284 Matrix GetProb(Matrix X) 285 ////////////////////////////////////////////////////////////////////////// 246 286 { 247 F01(X*_.param) 248 }; 249 Matrix _.outputProb = GetProb(data::_.X) 287 Real numSim = Rows(_.estim::report::mcmc); 288 Matrix prob = Rand(Rows(X),1,0,0); 289 Set For(1,numSim,Real (Real sim) 290 { 291 Matrix pr=GetProbPoint(X,Tra(SubRow(_.estim::report::mcmc,[[sim]]))); 292 Matrix prob := prob + pr; 293 0 294 }); 295 prob*(1/numSim) 296 } 250 297 ]] 251 298 };
Note: See TracChangeset
for help on using the changeset viewer.
