#include <ItemPolytomous.h>
Public Member Functions | |
ItemPolytomous (int index, M &icrf, LC *dist) | |
Constructor of polytomous response model class. | |
virtual | ~ItemPolytomous () |
Deconstructor of polytomous response model class. | |
virtual RealVector | GetAllParameters () const |
Returns a vector of estimated and fixed parameters. | |
virtual void | SetAllParameters (const RealVector &allParam) |
Assigns values of fixed and estimated parameters. | |
virtual Real | ICRF (const Response r, const RealVector ¶meters, const Real &theta) const |
Returns value of item characteristic curve for response "r", item parameters "parameters", and latent variable value "theta". | |
virtual int | ScaleParameters (Real slope, Real intercept, bool ignorePrior=false) |
Transforms parameter estimates to new latent variable scale. | |
virtual std::string | ModelName () const |
Returns string containing name of model used for item. | |
virtual IRTModel | Model () const |
Returns type of model used for item. | |
virtual double | f_to_minimize (RealVector &p) |
Function to maximize in M-step. | |
virtual void | gradient (RealVector &p, RealVector &g) |
Gradient of function to maximize in M-step. | |
virtual void | hessian (RealVector &, RealMatrix &) |
Computes hessian of function to maximize in M-step. | |
virtual int | HasAnalyticGradient () const |
Function to indicate that the algebraic gradient of the item (ICCDeriv1) is defined. | |
virtual int | HasAnalyticHessian () const |
Function to indicate that the algebraic hessian of the item (ICCDeriv2) is defined. | |
Protected Attributes | |
M | mICRF |
Object for calculating ICRF and its derivatives. |
Defines functions used in M-step of EM algorithm to compute item parameter estimates.
LC | Type of container holding possible values of the discrete latent variable. | |
M | Type containing functions defining item characteristic response function (ICRF) and derivatives of ICRF. |
Definition at line 62 of file ItemPolytomous.h.
etirm::ItemPolytomous< LC, M >::ItemPolytomous | ( | int | index, | |
M & | icrf, | |||
LC * | dist | |||
) | [inline] |
Constructor of polytomous response model class.
LC | Type of container holding possible values of the discrete latent variable. | |
M | Type containing functions defining item characteristic response function (ICRF) and derivatives of ICRF. |
[in] | index | Zero-offset index of the item in the vector of all item responses. |
[in] | icrf | Address of item category response function for the model. |
[in] | dist | Pointer to discrete latent variable points used in calculating the r's. |
Definition at line 156 of file ItemPolytomous.h.
00156 : 00157 ItemNR<LC>(icrf.NumParameters(), index, icrf.NumRespCat(), dist), mICRF(icrf) 00158 { 00159 if (ItemNR<LC>::mNRespCat != icrf.NumRespCat()) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00160 { 00161 throw InvalidArgument("Mismatch in number of response categories for item and ICRF", 00162 "ItemPolytomous::ItemPolytomous"); 00163 } 00164 }
etirm::ItemPolytomous< LC, M >::~ItemPolytomous | ( | ) | [inline, virtual] |
virtual RealVector etirm::ItemPolytomous< LC, M >::GetAllParameters | ( | ) | const [inline, virtual] |
Returns a vector of estimated and fixed parameters.
The order of the parameters in the vector is determined by the GetAllParameters member function of mICRF.
Reimplemented from etirm::Item< LC::latentvar_type >.
Definition at line 96 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00097 { 00098 RealVector allParam(mICRF.NumAllParameters()); 00099 mICRF.GetAllParameters(ItemNR<LC>::mParameterEstimates, allParam); // Added "ItemNR<LC>::" reference. ww, 1/12/2008. 00100 return allParam; 00101 }
virtual void etirm::ItemPolytomous< LC, M >::SetAllParameters | ( | const RealVector & | allParam | ) | [inline, virtual] |
Assigns values of fixed and estimated parameters.
Reimplemented from etirm::Item< LC::latentvar_type >.
Definition at line 104 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00105 { 00106 mICRF.SetAllParameters(allParam.begin(), allParam.end(), ItemNR<LC>::mParameterEstimates); 00107 } // Added "ItemNR<LC>::" reference. ww, 1/12/2008.
Real etirm::ItemPolytomous< LC, M >::ICRF | ( | const Response | r, | |
const RealVector & | parameters, | |||
const Real & | theta | |||
) | const [inline, virtual] |
Returns value of item characteristic curve for response "r", item parameters "parameters", and latent variable value "theta".
LC | Type of container holding possible values of the discrete latent variable. | |
M | Type containing functions defining item characteristic response function (ICRF) and derivatives of ICRF. |
[in] | r | Response category. |
[in] | ¶meters | Item parameter vector. |
[in] | &theta | Ability parameter. |
Definition at line 189 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00191 { 00192 return mICRF.ICRF(r, parameters, theta); 00193 }
int etirm::ItemPolytomous< LC, M >::ScaleParameters | ( | Real | slope, | |
Real | intercept, | |||
bool | ignorePriors = false | |||
) | [inline, virtual] |
Transforms parameter estimates to new latent variable scale.
Returns 1 if scaling results in invalid parameters. In this case, the parameters are not modified.
LC | Type of container holding possible values of the discrete latent variable. | |
M | Type containing functions defining item characteristic response function (ICRF) and derivatives of ICRF. |
[in] | slope | Scale parameter for transformation. |
[in] | intercept | Intercept parameter for transformation. |
[in] | ignorePriors | Flag to ignore prior information when checking validity of transformed parameters. |
Implements etirm::Item< LC::latentvar_type >.
Definition at line 349 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00351 { 00352 RealVector scaledParam(ItemNR<LC>::mParameterEstimates); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00353 00354 mICRF.Scale(slope, intercept, scaledParam); 00355 00356 // Check if scaled parameters are valid 00357 if (!(ItemNR<LC>::ValidParameters(scaledParam, ignorePriors))) 00358 return 1; // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00359 00360 ItemNR<LC>::mParameterEstimates = scaledParam; // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00361 00362 return 0; 00363 }
virtual std::string etirm::ItemPolytomous< LC, M >::ModelName | ( | ) | const [inline, virtual] |
Returns string containing name of model used for item.
Implements etirm::Item< LC::latentvar_type >.
Definition at line 115 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
virtual IRTModel etirm::ItemPolytomous< LC, M >::Model | ( | ) | const [inline, virtual] |
Returns type of model used for item.
Implements etirm::Item< LC::latentvar_type >.
Definition at line 121 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
double etirm::ItemPolytomous< LC, M >::f_to_minimize | ( | RealVector & | param | ) | [inline, virtual] |
Function to maximize in M-step.
LC | Type of container holding possible values of the discrete latent variable. | |
M | Type containing functions defining item characteristic response function (ICRF) and derivatives of ICRF. |
[in] | ¶m | Address of item parameter vector. |
Implements etirm::ItemNR< LC >.
Definition at line 213 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00214 { 00215 int i, j, grp; 00216 Real value = 0.0; 00217 int ngroups = ItemNR<LC>::mLatentDist->NumGroupsUnique(); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00218 00219 /* Compute loglikelihood */ 00220 for (grp=1; grp<=ngroups; ++grp) 00221 { 00222 Response r = ItemNR<LC>::FirstResponse(); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00223 for (i = ItemNR<LC>::mNRespCat; i--; ++r) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00224 { 00225 typename ItemNR<LC>::r_iterator ir = ItemNR<LC>::RVector(r, grp); // Added "typename" and "ItemNR<LC>::" references. ww, 1/13/2008. 00226 typename ItemNR<LC>::point_iterator it = ItemNR<LC>::mLatentDist->begin_points(grp); // Added "typename" and "ItemNR<LC>::" reference. ww, 1/13/2008. 00227 for (j=ItemNR<LC>::mNumLatentVarCat; j--; ++ir, ++it) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00228 { 00229 Real prob = mICRF.OpenICRF(r, param, *it); 00230 value += *ir * std::log(prob); 00231 } 00232 } 00233 } 00234 00235 /* Add priors */ 00236 PriorVector::const_iterator iprior = ItemNR<LC>::mPriors.begin(); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00237 RealVector::iterator iparam = param.begin(); 00238 for (int j = ItemNR<LC>::NumParameters(); j--; ++iprior, ++iparam) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00239 { 00240 if (*iprior) 00241 { 00242 if ((*iprior)->ZeroDensity(*iparam)) 00243 { 00244 // If density of prior is zero then log of prior density is 00245 // minus infinity (negative of minus infinity is returned 00246 // because the function is being minimized) 00247 if (std::numeric_limits<Real>::has_infinity) 00248 { 00249 return std::numeric_limits<Real>::infinity(); 00250 } 00251 else 00252 { 00253 return std::numeric_limits<Real>::max(); 00254 } 00255 } 00256 else 00257 { 00258 value += (*iprior)->LogDensity(*iparam); 00259 } 00260 } 00261 } 00262 00263 return -value; // return negative value to find minimum rather than maximum 00264 }
void etirm::ItemPolytomous< LC, M >::gradient | ( | RealVector & | param, | |
RealVector & | g | |||
) | [inline, virtual] |
Gradient of function to maximize in M-step.
LC | Type of container holding possible values of the discrete latent variable. | |
M | Type containing functions defining item characteristic response function (ICRF) and derivatives of ICRF. |
[in] | ¶m | Address of item parameter vector. |
[out] | &g | Address of gradient vector. Gradient values are returned in the vector elements. |
Implements etirm::ItemNR< LC >.
Definition at line 285 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00287 { 00288 g = 0.0; 00289 RealVector deriv(ItemNR<LC>::NumParameters(), 0.0); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00290 00291 int i, j, grp; 00292 int ngroups = ItemNR<LC>::mLatentDist->NumGroupsUnique(); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00293 00294 for (grp=1; grp<=ngroups; ++grp) 00295 { 00296 Response r = ItemNR<LC>::FirstResponse(); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00297 for (i = ItemNR<LC>::mNRespCat; i--; ++r) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00298 { 00299 00300 typename ItemNR<LC>::r_iterator ir = ItemNR<LC>::RVector(r, grp); // Added "typename" and "ItemNR<LC>::" references. ww, 1/13/2008. 00301 typename ItemNR<LC>::point_iterator itheta = ItemNR<LC>::mLatentDist->begin_points(grp); // Added "typename" and "ItemNR<LC>::" references. ww, 1/13/2008. 00302 for (j=ItemNR<LC>::mNumLatentVarCat; j--; ++ir, ++itheta) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00303 { 00304 Real t = *ir / mICRF.OpenICRF(r, param, *itheta); 00305 00306 mICRF.ICRFDeriv1(r, param, *itheta, deriv); 00307 00308 // use -t since function is to be minimized, not maximized 00309 deriv *= -t; 00310 g += deriv; 00311 00312 } 00313 } 00314 } 00315 00316 /* Add priors */ 00317 PriorVector::const_iterator iprior = ItemNR<LC>::mPriors.begin(); // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00318 RealVector::iterator iparam = param.begin(); 00319 RealVector::iterator ig = g.begin(); 00320 for (int j = ItemNR<LC>::NumParameters(); j--; ++iprior, ++iparam, ++ig) // Added "ItemNR<LC>::" reference. ww, 1/13/2008. 00321 { 00322 // subtract because function is to be minimized 00323 if (*iprior) 00324 *ig -= (*iprior)->DerivLogDensity1(*iparam); 00325 } 00326 00327 }
virtual void etirm::ItemPolytomous< LC, M >::hessian | ( | RealVector & | x, | |
RealMatrix & | h | |||
) | [inline, virtual] |
Computes hessian of function to maximize in M-step.
Note: Technically, the negative value of the function is to be minimized by UNCMIN++, see inline comments in function code.
Note: The hessian is stored in the lower trangle of h.
Implements etirm::ItemNR< LC >.
Definition at line 134 of file ItemPolytomous.h.
virtual int etirm::ItemPolytomous< LC, M >::HasAnalyticGradient | ( | ) | const [inline, virtual] |
Function to indicate that the algebraic gradient of the item (ICCDeriv1) is defined.
This function can be used by UNCMIN++.
Implements etirm::ItemNR< LC >.
Definition at line 138 of file ItemPolytomous.h.
References etirm::ItemPolytomous< LC, M >::mICRF.
00139 { 00140 return mICRF.GradientDefined(); 00141 }
virtual int etirm::ItemPolytomous< LC, M >::HasAnalyticHessian | ( | ) | const [inline, virtual] |
Function to indicate that the algebraic hessian of the item (ICCDeriv2) is defined.
This function can be used by UNCMIN++.
Implements etirm::ItemNR< LC >.
Definition at line 143 of file ItemPolytomous.h.
M etirm::ItemPolytomous< LC, M >::mICRF [protected] |
Object for calculating ICRF and its derivatives.
Definition at line 151 of file ItemPolytomous.h.
Referenced by etirm::ItemPolytomous< LC, M >::f_to_minimize(), etirm::ItemPolytomous< LC, M >::GetAllParameters(), etirm::ItemPolytomous< LC, M >::gradient(), etirm::ItemPolytomous< LC, M >::HasAnalyticGradient(), etirm::ItemPolytomous< LC, M >::ICRF(), etirm::ItemPolytomous< LC, M >::Model(), etirm::ItemPolytomous< LC, M >::ModelName(), etirm::ItemPolytomous< LC, M >::ScaleParameters(), and etirm::ItemPolytomous< LC, M >::SetAllParameters().