00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SWIGETIRM_H_
00022 #define SWIGETIRM_H_
00023
00024
00025
00026
00027 #include "swig_etirm_types.h"
00028
00029 #ifdef ETIRM_NO_DIR_PREFIX
00030 #include "EStepDiscrete.h"
00031 #else
00032 #include "etirm/EStepDiscrete.h"
00033 #endif
00034
00035 #include "Uncmin.h"
00036
00037 #include <vector>
00038 #include <string>
00039
00040
00041
00042 #include <boost/random/uniform_01.hpp>
00043
00044 #ifndef SWIG
00045 namespace etirm
00046 {
00047 #endif
00048
00049
00050 #ifndef SWIG
00051
00052 typedef RealVector double_vector;
00053
00054
00055 typedef SCPPNT::Vector<int> int_vector;
00056
00057
00058 typedef std::vector<item_type *> ItemVector;
00059
00060
00061 typedef EStepDiscrete<examinee_type, item_type, ItemVector::iterator, lvdist_type> estep_type;
00062
00063
00064 typedef std::vector<Uncmin<RealVector, RealMatrix, item_type> *> UncminVector;
00065
00066
00067 typedef std::vector<examinee_type *> ExamineeVector;
00068
00069
00070
00071
00072
00073
00074 class ItemRespCounts
00075 {
00076 public:
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 ItemRespCounts(int ncat, int ngroup) :
00088 catCounts(ngroup+1, ncat, 0.0), totalCount(ngroup+1, 0.0)
00089 {
00090 }
00091
00092
00093 virtual ~ItemRespCounts()
00094 {
00095 }
00096
00097
00098 void AddResponse(int respIndex, Real count, int group);
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 Real RespCount(int group)
00112 {
00113 return totalCount[group];
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 RealVector CategoryCounts(int group)
00127 {
00128 return RealVector(catCounts.begin_row(group+1), catCounts.begin_row(group+1)
00129 +catCounts.num_columns());
00130 }
00131
00132
00133 protected:
00134
00135
00136
00137
00138
00139
00140
00141 RealVector totalCount;
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 RealMatrix catCounts;
00152 };
00153
00154
00155 typedef std::vector<ItemRespCounts *> ItemStatsVector;
00156
00157
00158 class SwigEtirmRun
00159 {
00160
00161 public:
00162
00163 SwigEtirmRun(int nitems, int nlatentcat, int ngroups, Real minTheta = -4.0,
00164 Real maxTheta = 4.0, bool uniquePoints = false);
00165
00166 virtual ~SwigEtirmRun();
00167
00168 ExamineeVector examinees;
00169
00170
00171 ItemVector items;
00172
00173
00174 ItemStatsVector itemStats;
00175
00176
00177 UncminVector minProc;
00178
00179
00180 lvdist_type latentDist;
00181
00182
00183 random_type *rand_boot;
00184
00185
00186 random_type *base_rand_simulate;
00187
00188
00189 boost::uniform_01<random_type> *rand_simulate;
00190
00191
00192 std::string returnString;
00193
00194
00195 int numItems;
00196
00197
00198 int numLatentCat;
00199
00200
00201 int numGroups;
00202
00203
00204 RealVector examineeCounts;
00205
00206
00207 double mstepMaxDiff;
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 void CheckExaminees(const char *funcname);
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 void CheckExamineeNumber(int examno, const char *funcname);
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 void CheckItemNumber(int itemno, const char *funcname);
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 void CheckGroup(int group, const char *funcname);
00252 };
00253
00254
00255
00256
00257
00258
00259
00260
00261 void CheckRunInit();
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 void CheckItemParam(item_type *item, int index, const char *funcname);
00274
00275
00276 ItemParamPrior *CreatePrior(const std::string &pstr, const double_vector &priorparam,
00277 const char *funcname);
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 template <class V> V ItemSubset(int_vector *itemnums, V &all, const char *funcname)
00298 {
00299 int i;
00300 int nsub = itemnums->size();
00301 int nall = all.size();
00302
00303 if (nsub < 1 || nsub> nall)
00304 {
00305 throw RuntimeError("Invalid number of items", funcname);
00306 }
00307
00308 V sub(nsub);
00309 int *flag = new int[nall];
00310 for (i = 0; i < nall; ++i) flag[i] = 0;
00311
00312 typename V::iterator iall = all.begin();
00313 typename V::iterator isub = sub.begin();
00314 int_vector::iterator ino = itemnums->begin();
00315 for(i = 0; i < nsub; ++i, ++isub, ++ino)
00316 {
00317 int index = *ino - 1;
00318 if (index < 0 || index >= nall)
00319 {
00320 delete [] flag;
00321 throw RuntimeError("Invalid item number", funcname);
00322 }
00323 if (flag[index] == 1)
00324 {
00325 delete [] flag;
00326 throw RuntimeError("Duplicate item number", funcname);
00327 }
00328 flag[index] = 1;
00329 *isub = iall[index];
00330 }
00331 delete [] flag;
00332
00333 return sub;
00334 }
00335
00336
00337
00338 char Resp2Char(Response r, const item_type *item);
00339
00340 #endif // SWIG
00341
00342
00343
00344 class estep
00345 {
00346
00347 public:
00348
00349 estep(int_vector *ilist1 = 0);
00350 ~estep();
00351
00352 double compute(bool compute_prior = TRUE, bool store_prior = FALSE, int_vector *ilist4 = 0);
00353
00354
00355 #ifndef SWIG
00356
00357
00358
00359
00360
00361
00362 estep_type *GetEStep()
00363 { return mEStep;}
00364 #endif
00365
00366 private:
00367
00368 estep_type *mEStep;
00369 ItemVector *mItems;
00370 };
00371
00372
00373
00374 void set_missing_resp(char nr);
00375
00376
00377
00378 int num_items();
00379 int num_latent_dist_points();
00380 int num_groups();
00381
00382
00383 int num_examinees();
00384
00385
00386
00387
00388 const char * item_get_model(int itemno);
00389
00390
00391 void item_set_param(int paramno, int itemno, double paramvalue);
00392
00393
00394 void item_set_params(int itemno, double_vector *params);
00395
00396
00397 void item_set_all_params(int itemno, double_vector *params);
00398
00399
00400 double item_get_param(int paramno, int itemno);
00401
00402
00403 double_vector *item_get_params(int itemno);
00404
00405
00406 double_vector *item_get_all_params(int itemno);
00407
00408
00409 int item_num_params(int itemno);
00410
00411
00412 int item_num_resp_cat(int itemno);
00413
00414
00415 void item_set_prior(int paramno, int itemno, char *priortype, double_vector *dlist4 = 0);
00416
00417
00418 const char *item_get_prior_type(int paramno, int itemno);
00419
00420
00421 double_vector *item_get_prior_param(int paramno, int item);
00422
00423
00424 double item_prob_resp(int itemno, int response, double theta);
00425
00426
00427 int item_scale_params(int itemno, double slope, double intercept, bool ignorePriorError = 0);
00428
00429
00430
00431
00432 double_vector *item_cat_counts(int itemno, int group = 0);
00433
00434
00435
00436 double item_resp_count(int itemno, int group = 0);
00437
00438
00439 double_vector *test_characteristic_curve(double_vector *thetas, int_vector *ilist2 = 0);
00440
00441
00442
00443
00444 void dist_set_point(int index, double p, int group = 1);
00445
00446
00447 void dist_set_points(double_vector *dlist, int group = 1);
00448
00449
00450 double dist_get_point(int index, int group = 1);
00451
00452
00453 double_vector *dist_get_points(int group = 1);
00454
00455
00456 void dist_set_prob(int index, double w, int group = 1);
00457
00458
00459 void dist_set_probs(double_vector *dlist, int group = 1);
00460
00461
00462 double dist_get_prob(int index, int group = 1);
00463
00464
00465 double_vector *dist_get_probs(int group = 1);
00466
00467
00468 void dist_transform(double slope, double intercept);
00469
00470
00471
00472 double_vector *dist_scale(double mean, double sd, int group = 1);
00473
00474
00475 double_vector *dist_mean_sd(int group = 1);
00476
00477
00478
00479 int dist_unique_points();
00480
00481
00482 double_vector *normal_dist_prob(int npoints, double minPoint, double maxPoint,
00483 double mean = 0.0, double sd = 1.0);
00484
00485
00486 double_vector *normal_dist_points(int npoints, double minPoint, double maxPoint, double mean = 0.0,
00487 double sd = 1.0);
00488
00489
00490
00491
00492 int mstep_items(bool ignore_max_iter = FALSE, int_vector *ilist2 = 0);
00493
00494
00495
00496
00497 double mstep_max_diff();
00498
00499
00500
00501 int mstep_message(int itemno);
00502
00503
00504
00505 void mstep_max_iter(int itemno, int maxiter);
00506
00507
00508
00509 double mstep_dist(estep *e, int group);
00510
00511
00512
00513
00514 int add_examinee(int_vector *responses, int group = 1, double count = 1.0);
00515
00516
00517 int_vector *examinee_responses(int examineeno);
00518
00519
00520
00521 const char *examinee_response_str(int examineeno);
00522
00523
00524 int examinee_get_group(int examineeno);
00525
00526
00527 void examinee_set_group(int examineeno, int group);
00528
00529
00530 void examinee_set_count(int examineeno, double count);
00531
00532
00533 double examinee_get_count(int examineeno);
00534
00535
00536
00537 double examinees_count(int group = 0);
00538
00539
00540 void examinee_set_posterior(int examineeno, double_vector *posterior);
00541
00542
00543 double_vector* examinee_get_posterior(int examineeno);
00544
00545
00546 double examinee_posterior_mean(int examineeno);
00547
00548
00549 double examinee_theta_MLE(int examineeno, double minTheta, double maxTheta,
00550 double precision = 0.001, int_vector *ilist5 = 0);
00551
00552
00553 void bootstrap_seed(unsigned long seed);
00554
00555
00556 void bootstrap_sample();
00557
00558
00559 void simulate_seed(unsigned long seed);
00560
00561
00562 int_vector *simulate_responses(double theta, int_vector *ilist2 = 0);
00563
00564
00565 const char *simulate_response_str(double theta, int_vector *ilist2 = 0);
00566
00567
00568 int_vector *get_responses(char *line, int_vector *offset, int_vector *len);
00569
00570
00571 int_vector *get_responses_missing(char *line, int_vector *offset, int_vector *len,
00572 int_vector *items);
00573
00574 #ifndef SWIG
00575 }
00576 #endif // SWIG
00577
00578 #endif