00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef ETIRM_ESTEPDISCRETE_H_
00034 #define ETIRM_ESTEPDISCRETE_H_
00035
00036 #ifdef ETIRM_NO_DIR_PREFIX
00037 #include "etirmtypes.h"
00038 #include "ItemParamPrior.h"
00039 #else
00040 #include "etirm/etirmtypes.h"
00041 #include "etirm/ItemParamPrior.h"
00042 #endif
00043
00044 #include <cmath>
00045 #include <vector>
00046
00047
00048 #ifdef BOOST_NO_STDC_NAMESPACE
00049 namespace std
00050 { using ::exp; using ::log;}
00051 #endif
00052
00053 namespace etirm
00054 {
00055
00056 const double logZero = -1021.0;
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 template <class II> class NMatrixVec
00068 {
00069
00070 public:
00071
00072
00073 typedef std::vector<RealMatrix *>::iterator iterator;
00074
00075 NMatrixVec(II bitem, II eitem, int nlatentcat);
00076 ~NMatrixVec();
00077
00078 iterator begin()
00079 {
00080 return mVector.begin();
00081 }
00082
00083
00084 RealMatrix *operator[](int Index)
00085 {
00086 return mVector[Index];
00087 }
00088
00089
00090 private:
00091
00092 std::vector<RealMatrix *> mVector;
00093
00094
00095
00096
00097 };
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 template <class II> NMatrixVec<II>::NMatrixVec(II bitem, II eitem, int nlatentcat) :
00115 mVector(eitem-bitem)
00116 {
00117 iterator ri = mVector.begin();
00118 for (II i = bitem; i != eitem; ++ri, ++i)
00119 {
00120 *ri = new RealMatrix((*i)->NumRespCat(), nlatentcat);
00121 }
00122 }
00123
00124
00125 template <class II> NMatrixVec<II>::~NMatrixVec()
00126 {
00127 iterator ri = mVector.begin();
00128 for (int i = mVector.size(); i--; ++ri)
00129 {
00130 if (*ri)
00131 delete *ri;
00132 }
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 template <class E, class I, class II, class D> class EStepDiscrete
00148 {
00149
00150 public:
00151
00152 typedef RealMatrix::row_iterator ngroup_iterator;
00153
00154
00155 typedef typename D::point_iterator point_iterator;
00156
00157
00158 EStepDiscrete(II bitem, II eitem, D &dist);
00159
00160
00161 ~EStepDiscrete();
00162
00163
00164 #ifndef BOOST_MSVC6_MEMBER_TEMPLATES
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 template <class EI>
00216 Real DoEStep(EI examinees_begin, EI examinees_end, II itemsNR_begin, II itemsNR_end,
00217 bool computeExamineePosterior, bool storeExamineePosterior);
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 template <class EI>
00251 Real DoEStep(EI examinees_begin, EI examinees_end, bool computeExamineePosterior,
00252 bool storeExamineePosterior);
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 template <class PI>
00276 Real ExamineePosterior(E &examinee, PI begin_posterior, PI end_posterior);
00277
00278 #endif
00279
00280 void CalcResponseProb();
00281
00282
00283 ngroup_iterator GetNGroup(int group)
00284 {
00285 return (*nGroups).begin_row(group);
00286 }
00287
00288
00289 int size()
00290 {
00291 return numLatentVarCat;
00292 }
00293
00294
00295 point_iterator GetPoints()
00296 {
00297 return latentvar_dist.begin_points();
00298 }
00299
00300
00301 protected:
00302
00303 RealMatrix *nGroups;
00304
00305
00306
00307
00308
00309 std::vector<NMatrixVec<II> *> mRespProb;
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 II items_begin;
00323
00324
00325 II items_end;
00326
00327
00328 D &latentvar_dist;
00329
00330
00331 RealMatrix logLatentProb;
00332
00333
00334
00335
00336
00337
00338
00339 int numItems;
00340
00341 int numLatentVarCat;
00342
00343 int numGroupUnique;
00344
00345 std::vector<int> *itemIndices;
00346
00347
00348
00349
00350 Response notPresentedResponse;
00351
00352
00353
00354
00355
00356
00357
00358 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
00359 public:
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 template <class PI> Real ExamineePosterior(E &examinee, PI begin_posterior, PI end_posterior)
00379 {
00380
00381 int i, il;
00382
00383 int group = examinee.Group();
00384
00385 if ((end_posterior - begin_posterior) != numLatentVarCat)
00386 {
00387 throw InvalidArgument("Incorrect size of vector to hold posterior probabilities",
00388 "EStepDiscrete::ExamineePosterior");
00389 }
00390
00391
00392 int Ndiv4 = numLatentVarCat / 4;
00393 int Nmod4 = numLatentVarCat - Ndiv4*4;
00394
00395
00396 RealVector::iterator ipost = begin_posterior;
00397 RealMatrix::row_iterator iwt = logLatentProb.begin_row(group);
00398 for (i = Ndiv4; i--; ipost+=4, iwt+=4)
00399 {
00400 *ipost = *iwt;
00401 ipost[1] = iwt[1];
00402 ipost[2] = iwt[2];
00403 ipost[3] = iwt[3];
00404 }
00405 for (i = Nmod4; i--; ++ipost, ++iwt)
00406 {
00407 *ipost = *iwt;
00408 }
00409
00410 NMatrixVec<II>::iterator item = (numGroupUnique == 1) ? mRespProb[0]->begin()
00411 : mRespProb[group-1]->begin();
00412 II iitem = items_begin;
00413 typename E::response_iterator presp = examinee.responses_begin();
00414 std::vector<int>::iterator ii = itemIndices->begin();
00415 for (i = numItems; i--; ++item, ++iitem, ++ii)
00416 {
00417 Response resp = presp[*ii];
00418 if (resp != notPresentedResponse)
00419 {
00420 ipost = begin_posterior;
00421 int index = (*iitem)->ResponseIndex(resp);
00422 RealMatrix::row_iterator ir = (*item)->begin_row(index+1);
00423 for (il=Ndiv4; il--; ipost+=4, ir+=4)
00424 {
00425 *ipost += *ir;
00426 ipost[1] += ir[1];
00427 ipost[2] += ir[2];
00428 ipost[3] += ir[3];
00429 }
00430 for (il=Nmod4; il--; ++ipost, ++ir)
00431 {
00432 *ipost += *ir;
00433 }
00434 }
00435 }
00436
00437
00438 ipost = begin_posterior;
00439 iwt = logLatentProb.begin_row(group);
00440 Real sum = 0.0;
00441 for (i = numLatentVarCat; i--; ++ipost, ++iwt)
00442 {
00443 if (*iwt != logZero)
00444 sum += std::exp(*ipost);
00445 else
00446 *ipost = logZero;
00447 }
00448
00449
00450 ipost = begin_posterior;
00451 Real logsum = std::log(sum);
00452 for (i = numLatentVarCat; i--; ++ipost)
00453 {
00454 if (*ipost != logZero)
00455 {
00456 *ipost -= logsum;
00457 *ipost = std::exp(*ipost);
00458 }
00459 else
00460 *ipost = 0.0;
00461 }
00462
00463 return sum;
00464 }
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513 template <class EI> Real DoEStep(EI examinees_begin, EI examinees_end, II itemsNR_begin,
00514 II itemsNR_end, bool computeExamineePosterior, bool storeExamineePosterior)
00515 {
00516
00517 int i, j;
00518 Real loglikelihood = 0.0;
00519
00520 RealVector posterior(numLatentVarCat);
00521
00522 *nGroups = 0.0;
00523 int numItemsNR = itemsNR_end - itemsNR_begin;
00524 II iitem = itemsNR_begin;
00525 for (i=numItemsNR; i--; ++iitem)
00526 {
00527
00528
00529
00530
00531
00532
00533 j = (*iitem)->NumLatentVarCat();
00534 if (j != numLatentVarCat)
00535 {
00536 throw RuntimeError("Mismatch in number of latent variable categories",
00537 "EStepDiscrete::DoEStep");
00538 }
00539
00540
00541 (*iitem)->InitializeNR();
00542 }
00543
00544 if (computeExamineePosterior)
00545 {
00546
00547
00548 if (numLatentVarCat != latentvar_dist.size())
00549 {
00550 throw RuntimeError("Number of latent variable categories has changed",
00551 "EStepDiscrete::DoEStep");
00552 }
00553
00554
00555
00556 CalcResponseProb();
00557
00558
00559 for (i = 1; i <= latentvar_dist.NumGroups(); ++i)
00560 {
00561 RealMatrix::row_iterator ip = logLatentProb.begin_row(i);
00562 typename D::weight_iterator iwt = latentvar_dist.begin_weights(i);
00563 for (j = numLatentVarCat; j--; ++ip, ++iwt)
00564 {
00565 *ip = (*iwt != 0.0) ? std::log(*iwt) : logZero;
00566 }
00567 }
00568 }
00569
00570
00571
00572
00573 for (EI examinee_i = examinees_begin; examinee_i != examinees_end; ++examinee_i)
00574 {
00575
00576 Real marginalLikelihood;
00577 if (computeExamineePosterior)
00578
00579 {
00580 marginalLikelihood = ExamineePosterior(**examinee_i, posterior.begin(), posterior.end());
00581
00582 if (storeExamineePosterior)
00583 {
00584 typename E::posterior_vector epost(numLatentVarCat);
00585 typename E::posterior_vector::iterator iep = epost.begin();
00586 RealVector::iterator ip = posterior.begin();
00587 for (i = numLatentVarCat; i--; ++iep, ++ip)
00588 *iep = *ip;
00589 (*examinee_i)->SetPosterior(epost);
00590
00591 (*examinee_i)->SetMarginalRespLikelihood(marginalLikelihood);
00592 }
00593 }
00594 else
00595
00596 {
00597 typename E::posterior_vector::iterator iep = (*examinee_i)->posterior_begin();
00598 RealVector::iterator ip = posterior.begin();
00599 for (i = numLatentVarCat; i--; ++iep, ++ip)
00600 *ip = *iep;
00601
00602 marginalLikelihood = (*examinee_i)->GetMarginalRespLikelihood();
00603 }
00604
00605
00606 loglikelihood += std::log(marginalLikelihood);
00607
00608 typename E::response_iterator iresp = (*examinee_i)->responses_begin();
00609 Real casewt = (*examinee_i)->Count();
00610 int group = (*examinee_i)->Group();
00611 iitem = itemsNR_begin;
00612 for (i = numItemsNR; i--; ++iitem)
00613 {
00614
00615 Response resp = iresp[(*iitem)->Index()];
00616 if (resp != notPresentedResponse)
00617 {
00618 typename I::r_iterator ir = (*iitem)->RVector(resp, group);
00619 typename I::n_iterator in = (*iitem)->NVector(group);
00620 RealVector::iterator ipost = posterior.begin();
00621 for (j = numLatentVarCat; j--; ++ir, ++in, ++ipost)
00622 {
00623 *ir += *ipost * casewt;
00624 *in += *ipost * casewt;
00625 }
00626 }
00627
00628 }
00629
00630
00631 RealVector::iterator ipost = posterior.begin();
00632 RealMatrix::row_iterator igroup = nGroups->begin_row(group);
00633 for (j = numLatentVarCat; j--; ++ipost, ++igroup)
00634 {
00635 *igroup += *ipost * casewt;
00636 }
00637
00638 }
00639
00640
00641 for (II ii = itemsNR_begin; ii != itemsNR_end; ++ii)
00642 {
00643 PriorVector::iterator iprior = (*ii)->PriorsIterator();
00644 RealVector::iterator iparam = (*ii)->ParametersIterator();
00645 for (i = (*ii)->NumParameters(); i--; ++iprior, ++iparam)
00646 {
00647 if (*iprior)
00648 loglikelihood += (*iprior)->LogDensity(*iparam);
00649 }
00650 }
00651
00652 return loglikelihood;
00653
00654 }
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 template <class EI> Real DoEStep(EI examinees_begin, EI examinees_end,
00684 bool computeExamineePosterior, bool storeExamineePosterior)
00685 {
00686 return DoEStep(examinees_begin, examinees_end, items_begin, items_end,
00687 computeExamineePosterior, storeExamineePosterior);
00688 }
00689 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
00690 };
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 template <class E, class I, class II, class D>
00711 EStepDiscrete<E, I, II, D>::EStepDiscrete( II bitem, II eitem, D &dist) :
00712 items_begin(bitem), items_end(eitem), latentvar_dist(dist), nGroups(0),
00713 logLatentProb( dist.NumGroups(), dist.size()),
00714 mRespProb(dist.NumGroupsUnique())
00715 {
00716 int i;
00717 numItems = items_end - items_begin;
00718 numLatentVarCat = dist.size();
00719 numGroupUnique = dist.NumGroupsUnique();
00720
00721 notPresentedResponse = I::NotPresentedResponse();
00722
00723 nGroups = new RealMatrix(dist.NumGroups(), numLatentVarCat);
00724
00725 for (i=0; i<numGroupUnique; ++i)
00726 {
00727 mRespProb[i] = new NMatrixVec<II>(bitem, eitem, dist.size());
00728 }
00729
00730
00731 II iitem = items_begin;
00732 itemIndices = new std::vector<int>(numItems);
00733 std::vector<int>::iterator ii = itemIndices->begin();
00734 for (i=numItems; i--; ++ii, ++iitem)
00735 {
00736 *ii = (*iitem)->Index();
00737 }
00738
00739
00740 for (i = 1; i <= latentvar_dist.NumGroups(); ++i)
00741 {
00742 RealMatrix::row_iterator ip = logLatentProb.begin_row(i);
00743 typename D::weight_iterator iwt = latentvar_dist.begin_weights(i);
00744 for (int j = numLatentVarCat; j--; ++ip, ++iwt)
00745 {
00746 *ip = (*iwt != 0.0) ? std::log(*iwt) : logZero;
00747 }
00748 }
00749 }
00750
00751
00752 template <class E, class I, class II, class D> EStepDiscrete<E, I, II, D>::~EStepDiscrete()
00753 {
00754 delete nGroups;
00755
00756 delete itemIndices;
00757
00758 for (int i = 0; i<numGroupUnique; ++i)
00759 delete mRespProb[i];
00760 }
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774 template <class E, class I, class II, class D> void EStepDiscrete<E, I, II, D>::CalcResponseProb()
00775 {
00776 for (int g=0; g<numGroupUnique; ++g)
00777 {
00778 typename NMatrixVec<II>::iterator vi = mRespProb[g]->begin();
00779 for (II iitem = items_begin; iitem != items_end; ++iitem, ++vi)
00780
00781 {
00782 Response response;
00783 int n = (*iitem)->NumRespCat();
00784 for (int j = 1; j <= n; ++j)
00785
00786 {
00787 typename D::point_iterator ipoint = latentvar_dist.begin_points(g+1);
00788 response = (*iitem)->IndexResponse(j-1);
00789 RealMatrix::row_iterator il = (**vi).begin_row(j);
00790 for (int k = numLatentVarCat; k--; ++il, ++ipoint)
00791
00792 {
00793 *il = std::log((*iitem)->ProbResp(response, *ipoint));
00794 }
00795 }
00796 }
00797 }
00798 }
00799
00800
00801
00802
00803 #ifndef BOOST_MSVC6_MEMBER_TEMPLATES
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825 template <class E, class I, class II, class D> template <class PI> Real
00826 EStepDiscrete<E, I, II, D>::ExamineePosterior( E &examinee,
00827 PI begin_posterior, PI end_posterior)
00828 {
00829 int i, il;
00830
00831 int group = examinee.Group();
00832
00833 if ((end_posterior - begin_posterior) != numLatentVarCat)
00834 {
00835 throw InvalidArgument("Incorrect size of vector to hold posterior probabilities",
00836 "EStepDiscrete::ExamineePosterior");
00837 }
00838
00839
00840 int Ndiv4 = numLatentVarCat / 4;
00841 int Nmod4 = numLatentVarCat - Ndiv4*4;
00842
00843
00844 RealVector::iterator ipost = begin_posterior;
00845 RealMatrix::row_iterator iwt = logLatentProb.begin_row(group);
00846 for (i = Ndiv4; i--; ipost+=4, iwt+=4)
00847 {
00848 *ipost = *iwt;
00849 ipost[1] = iwt[1];
00850 ipost[2] = iwt[2];
00851 ipost[3] = iwt[3];
00852 }
00853 for (i = Nmod4; i--; ++ipost, ++iwt)
00854 {
00855 *ipost = *iwt;
00856 }
00857
00858 typename NMatrixVec<II>::iterator item =
00859 (numGroupUnique == 1) ? mRespProb[0]->begin() : mRespProb[group-1]->begin();
00860 II iitem = items_begin;
00861 typename E::response_iterator presp = examinee.responses_begin();
00862 std::vector<int>::iterator ii = itemIndices->begin();
00863 for (i = numItems; i--; ++item, ++iitem, ++ii)
00864 {
00865 Response resp = presp[*ii];
00866 if (resp != notPresentedResponse)
00867 {
00868 ipost = begin_posterior;
00869 int index = (*iitem)->ResponseIndex(resp);
00870 RealMatrix::row_iterator ir = (*item)->begin_row(index+1);
00871 for (il=Ndiv4; il--; ipost+=4, ir+=4)
00872 {
00873 *ipost += *ir;
00874 ipost[1] += ir[1];
00875 ipost[2] += ir[2];
00876 ipost[3] += ir[3];
00877 }
00878 for (il=Nmod4; il--; ++ipost, ++ir)
00879 {
00880 *ipost += *ir;
00881 }
00882 }
00883 }
00884
00885
00886 ipost = begin_posterior;
00887 iwt = logLatentProb.begin_row(group);
00888 Real sum = 0.0;
00889 for (i = numLatentVarCat; i--; ++ipost, ++iwt)
00890 {
00891 if (*iwt != logZero)
00892 sum += std::exp(*ipost);
00893 else
00894 *ipost = logZero;
00895 }
00896
00897
00898 ipost = begin_posterior;
00899 Real logsum = std::log(sum);
00900 for (i = numLatentVarCat; i--; ++ipost)
00901 {
00902 if (*ipost != logZero)
00903 {
00904 *ipost -= logsum;
00905 *ipost = std::exp(*ipost);
00906 }
00907 else
00908 *ipost = 0.0;
00909 }
00910
00911 return sum;
00912 }
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964 template <class E, class I, class II, class D> template <class EI> Real EStepDiscrete<E, I, II, D>::DoEStep(
00965 EI examinees_begin, EI examinees_end, II itemsNR_begin, II itemsNR_end,
00966 bool computeExamineePosterior, bool storeExamineePosterior)
00967 {
00968 int i, j;
00969 Real loglikelihood = 0.0;
00970
00971 RealVector posterior(numLatentVarCat);
00972
00973 *nGroups = 0.0;
00974 int numItemsNR = itemsNR_end - itemsNR_begin;
00975 II iitem = itemsNR_begin;
00976 for (i=numItemsNR; i--; ++iitem)
00977 {
00978
00979
00980
00981
00982
00983
00984 j = (*iitem)->NumLatentVarCat();
00985 if (j != numLatentVarCat)
00986 {
00987 throw RuntimeError("Mismatch in number of latent variable categories",
00988 "EStepDiscrete::DoEStep");
00989 }
00990
00991
00992 (*iitem)->InitializeNR();
00993 }
00994
00995 if (computeExamineePosterior)
00996 {
00997
00998
00999 if (numLatentVarCat != latentvar_dist.size())
01000 {
01001 throw RuntimeError("Number of latent variable categories has changed",
01002 "EStepDiscrete::DoEStep");
01003 }
01004
01005
01006
01007 CalcResponseProb();
01008
01009
01010 for (i = 1; i <= latentvar_dist.NumGroups(); ++i)
01011 {
01012 RealMatrix::row_iterator ip = logLatentProb.begin_row(i);
01013 typename D::weight_iterator iwt = latentvar_dist.begin_weights(i);
01014 for (j = numLatentVarCat; j--; ++ip, ++iwt)
01015 {
01016 *ip = (*iwt != 0.0) ? std::log(*iwt) : logZero;
01017 }
01018 }
01019 }
01020
01021
01022
01023
01024 for (EI examinee_i = examinees_begin; examinee_i != examinees_end; ++examinee_i)
01025 {
01026
01027 Real marginalLikelihood;
01028 if (computeExamineePosterior)
01029
01030 {
01031 marginalLikelihood = ExamineePosterior(**examinee_i, posterior.begin(), posterior.end());
01032
01033 if (storeExamineePosterior)
01034 {
01035 typename E::posterior_vector epost(numLatentVarCat);
01036 typename E::posterior_vector::iterator iep = epost.begin();
01037 RealVector::iterator ip = posterior.begin();
01038 for (i = numLatentVarCat; i--; ++iep, ++ip)
01039 *iep = *ip;
01040 (*examinee_i)->SetPosterior(epost);
01041
01042 (*examinee_i)->SetMarginalRespLikelihood(marginalLikelihood);
01043 }
01044 }
01045 else
01046
01047 {
01048 typename E::posterior_vector::iterator iep = (*examinee_i)->posterior_begin();
01049 RealVector::iterator ip = posterior.begin();
01050 for (i = numLatentVarCat; i--; ++iep, ++ip)
01051 *ip = *iep;
01052
01053 marginalLikelihood = (*examinee_i)->GetMarginalRespLikelihood();
01054 }
01055
01056
01057 loglikelihood += std::log(marginalLikelihood);
01058
01059 typename E::response_iterator iresp = (*examinee_i)->responses_begin();
01060 Real casewt = (*examinee_i)->Count();
01061 int group = (*examinee_i)->Group();
01062 iitem = itemsNR_begin;
01063 for (i = numItemsNR; i--; ++iitem)
01064 {
01065
01066 Response resp = iresp[(*iitem)->Index()];
01067 if (resp != notPresentedResponse)
01068 {
01069 typename I::r_iterator ir = (*iitem)->RVector(resp, group);
01070 typename I::n_iterator in = (*iitem)->NVector(group);
01071 RealVector::iterator ipost = posterior.begin();
01072 for (j = numLatentVarCat; j--; ++ir, ++in, ++ipost)
01073 {
01074 *ir += *ipost * casewt;
01075 *in += *ipost * casewt;
01076 }
01077 }
01078
01079 }
01080
01081
01082 RealVector::iterator ipost = posterior.begin();
01083 RealMatrix::row_iterator igroup = nGroups->begin_row(group);
01084 for (j = numLatentVarCat; j--; ++ipost, ++igroup)
01085 {
01086 *igroup += *ipost * casewt;
01087 }
01088
01089 }
01090
01091
01092 for (II ii = itemsNR_begin; ii != itemsNR_end; ++ii)
01093 {
01094 PriorVector::iterator iprior = (*ii)->PriorsIterator();
01095 RealVector::iterator iparam = (*ii)->ParametersIterator();
01096 for (i = (*ii)->NumParameters(); i--; ++iprior, ++iparam)
01097 {
01098 if (*iprior)
01099 loglikelihood += (*iprior)->LogDensity(*iparam);
01100 }
01101 }
01102
01103 return loglikelihood;
01104
01105 }
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138 template <class E, class I, class II, class D> template <class EI> Real EStepDiscrete<E, I, II, D>::DoEStep(
01139 EI examinees_begin, EI examinees_end, bool computeExamineePosterior,
01140 bool storeExamineePosterior)
01141 {
01142 return DoEStep(examinees_begin, examinees_end, items_begin, items_end,
01143 computeExamineePosterior, storeExamineePosterior);
01144 }
01145
01146 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
01147 }
01148
01149 #endif // ETIRM_ESTEPDISCRETE_H_