etirm::DiscreteLatentDist< L > Class Template Reference

Class approximating the latent ability distribution by numeric quadrature. More...

#include <DiscreteLatentDist.h>

List of all members.

Public Types

typedef L latentvar_type
 Type of latent variable.
typedef std::vector< L > point_container
 Type of container for points.
typedef std::vector< L >::iterator point_iterator
 Type of iterator over quadrature points.
typedef RealMatrix::row_iterator weight_iterator
 Type of iterator over quadrature weigths.

Public Member Functions

 DiscreteLatentDist (int ntheta, int ngroups=1, bool uniquePoints=false)
 Constructor using number of quadrature points, number of groups, etc.
 DiscreteLatentDist (const DiscreteLatentDist &dist)
 Copy constructor using DiscreteLatentDist object.
point_iterator begin_points (int g=1)
 Returns iterator to first point for group g (1-offset).
weight_iterator begin_weights (int g=1)
 Returns iterator to first weight for group g (1-offset).
int size ()
 Returns the number of discrete points for each group.
int NumGroups ()
 Returns the number of groups of examinees.
int NumGroupsUnique ()
 Returns number of examinee groups for which points of latent distribution are unique.
void Transform (Real slope, Real intercept)
 Transforms scale of points using a specified linear transformation.
void Scale (Real mean, Real sd, int group, Real &slope, Real &intercept)
 Transforms scale of points so that mean and standard deviation in the specified group are equal to the values indicated.
void MeanSD (int group, Real &mean, Real &sd)
 Computes mean and standard deviation in the specified group.
virtual Real MStep (const RealVector &eprob, int g)
 Computes an M-step for the probabilities of the multinomial discrete latent variable distribution in one examinee group.

Private Attributes

bool mUniquePoints
 If true then unique latent distribution points are used for each group.
int mNumPoints
 Number of points in latent variable distribution for each group.
int mNumGroups
 Number of examinee groups.
std::vector< L > mPoints
RealMatrix mWeights
 Each row gives the distribution for one group of examinees.


Detailed Description

template<class L>
class etirm::DiscreteLatentDist< L >

Class approximating the latent ability distribution by numeric quadrature.

Template Parameters

Parameters:
L Type of latent variable.

Definition at line 46 of file DiscreteLatentDist.h.


Member Typedef Documentation

template<class L>
typedef L etirm::DiscreteLatentDist< L >::latentvar_type

Type of latent variable.

Definition at line 51 of file DiscreteLatentDist.h.

template<class L>
typedef std::vector<L> etirm::DiscreteLatentDist< L >::point_container

Type of container for points.

Definition at line 52 of file DiscreteLatentDist.h.

template<class L>
typedef std::vector<L>::iterator etirm::DiscreteLatentDist< L >::point_iterator

Type of iterator over quadrature points.

Definition at line 53 of file DiscreteLatentDist.h.

template<class L>
typedef RealMatrix::row_iterator etirm::DiscreteLatentDist< L >::weight_iterator

Type of iterator over quadrature weigths.

Definition at line 54 of file DiscreteLatentDist.h.


Constructor & Destructor Documentation

template<class L>
etirm::DiscreteLatentDist< L >::DiscreteLatentDist ( int  ntheta,
int  ngroups = 1,
bool  uniquePoints = false 
) [inline]

Constructor using number of quadrature points, number of groups, etc.

Definition at line 115 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::mPoints.

00116                          :
00117     mNumPoints(ntheta), mPoints(ntheta), mWeights(ngroups, ntheta), mUniquePoints(uniquePoints),
00118         mNumGroups(ngroups)
00119   {
00120     if (uniquePoints)
00121       mPoints.resize(ntheta*ngroups);
00122   }

template<class L>
etirm::DiscreteLatentDist< L >::DiscreteLatentDist ( const DiscreteLatentDist< L > &  dist  )  [inline]

Copy constructor using DiscreteLatentDist object.

Definition at line 125 of file DiscreteLatentDist.h.

00125                                                                                             :
00126     mUniquePoints(dist.mUniquePoints), mNumPoints(dist.mNumPoints), mNumGroups(dist.mNumGroups),
00127         mPoints(dist.mPoints), mWeights(dist.mWeights)
00128   {
00129   }


Member Function Documentation

template<class L>
std::vector< L >::iterator etirm::DiscreteLatentDist< L >::begin_points ( int  g = 1  )  [inline]

Returns iterator to first point for group g (1-offset).

Template Parameters

Parameters:
L Type of latent variable.

Function Parameters

Parameters:
[in] g Group to return pointer for, where first group = 1, second group = 2, etc.

Definition at line 182 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::mNumPoints, etirm::DiscreteLatentDist< L >::mPoints, and etirm::DiscreteLatentDist< L >::mUniquePoints.

Referenced by etirm::DiscreteLatentDist< L >::MeanSD(), etirm::SwigEtirmRun::SwigEtirmRun(), and etirm::DiscreteLatentDist< L >::Transform().

00184   {
00185     return mUniquePoints ? (mPoints.begin()+mNumPoints*(g-1)) : mPoints.begin();
00186   }

Here is the caller graph for this function:

template<class L>
RealMatrix::row_iterator etirm::DiscreteLatentDist< L >::begin_weights ( int  g = 1  )  [inline]

Returns iterator to first weight for group g (1-offset).

Template Parameters

Parameters:
L Type of latent variable.

Function Parameters

Parameters:
g Group to return weights for, where first group = 1, second group = 2, etc.

Definition at line 200 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::mWeights.

Referenced by etirm::DiscreteLatentDist< L >::MeanSD(), etirm::DiscreteLatentDist< L >::MStep(), and etirm::SwigEtirmRun::SwigEtirmRun().

00202   {
00203     return mWeights.begin_row(g);
00204   }

Here is the caller graph for this function:

template<class L>
int etirm::DiscreteLatentDist< L >::size (  )  [inline]

Returns the number of discrete points for each group.

Template Parameters

Parameters:
L Type of latent variable.

Definition at line 139 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::mNumPoints.

00140   {
00141     return mNumPoints;
00142   }

template<class L>
int etirm::DiscreteLatentDist< L >::NumGroups (  )  [inline]

Returns the number of groups of examinees.

Template Parameters

Parameters:
L Type of latent variable.

Definition at line 152 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::mNumGroups.

00153   {
00154     return mNumGroups;
00155   }

template<class L>
int etirm::DiscreteLatentDist< L >::NumGroupsUnique (  )  [inline]

Returns number of examinee groups for which points of latent distribution are unique.

Template Parameters

Parameters:
L Type of latent variable.

Definition at line 165 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::mNumGroups, and etirm::DiscreteLatentDist< L >::mUniquePoints.

00166   {
00167     return mUniquePoints ? mNumGroups : 1;
00168   }

template<class L>
void etirm::DiscreteLatentDist< L >::Transform ( Real  slope,
Real  intercept 
) [inline]

Transforms scale of points using a specified linear transformation.

Points for all groups are transformed.

Template Parameters

Parameters:
L Type of latent variable.

Function Parameters

Parameters:
[in] slope Slope of scale transformation.
[in] intercept Intercept of scale transformation.

Definition at line 265 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::begin_points(), etirm::DiscreteLatentDist< L >::mNumGroups, etirm::DiscreteLatentDist< L >::mNumPoints, and etirm::DiscreteLatentDist< L >::mUniquePoints.

Referenced by etirm::DiscreteLatentDist< L >::Scale().

00266   {
00267 
00268     int n, i;
00269 
00270     if (mUniquePoints) n = mNumGroups;
00271     else n = 1;
00272 
00273     /* Transform points for all groups */
00274     for (int g = 1; g <= n; ++g)
00275     {
00276       point_iterator ip = begin_points(g);
00277       for (i = mNumPoints; i--; ++ip)
00278       {
00279         *ip *= slope;
00280         *ip += intercept;
00281       }
00282     }
00283   }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class L>
void etirm::DiscreteLatentDist< L >::Scale ( Real  mean,
Real  sd,
int  group,
Real slope,
Real intercept 
) [inline]

Transforms scale of points so that mean and standard deviation in the specified group are equal to the values indicated.

Points for all groups are transformed.

Template Parameters

Parameters:
L Type of latent variable.

Function Parameters

Parameters:
[in] mean Desired mean of distribution.
[in] sd Desired standard deviation of distribution.
[in] group Group for which mean and s.d. are specified.
[out] slope Slope of scale transformation.
[out] intercept Intercept of scale transformation.

Definition at line 306 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::MeanSD(), etirm::DiscreteLatentDist< L >::mNumGroups, and etirm::DiscreteLatentDist< L >::Transform().

00308   {
00309 
00310     /* Check for valid group */
00311     if (group < 1 || group> mNumGroups)
00312     throw InvalidArgument("Invalid examinee group", "DiscreteLatentDist::Scale");
00313 
00314     Real oldmean;
00315     Real oldsd;
00316     MeanSD(group, oldmean, oldsd);
00317 
00318     /* Compute slope and intercept to transfer from old scale to new scale */
00319     slope = sd / oldsd;
00320     intercept = mean - slope * oldmean;
00321 
00322     /* Transform points */
00323     Transform(slope, intercept);
00324   }

Here is the call graph for this function:

template<class L>
void etirm::DiscreteLatentDist< L >::MeanSD ( int  group,
Real mean,
Real sd 
) [inline]

Computes mean and standard deviation in the specified group.

Template Parameters

Parameters:
L Type of latent variable.

Function Parameters

Parameters:
[in] group Group whose distribution is used.
[out] &mean Address if mean of distribution.
[out] &sd Address of standard deviation of distribution.

Definition at line 220 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::begin_points(), etirm::DiscreteLatentDist< L >::begin_weights(), etirm::DiscreteLatentDist< L >::mNumGroups, and etirm::DiscreteLatentDist< L >::mNumPoints.

Referenced by etirm::DiscreteLatentDist< L >::Scale().

00221   {
00222     /* Check for valid group */
00223     if (group < 1 || group > mNumGroups)
00224     throw InvalidArgument("Invalid examinee group", "DiscreteLatentDist::MeanSD");
00225 
00226     int i;
00227 
00228     /* Compute mean of distribution in specified group */
00229     point_iterator ip = begin_points(group);
00230     weight_iterator iw = begin_weights(group);
00231     mean = 0.0;
00232     for (i = mNumPoints; i--; ++ip, ++iw)
00233     {
00234       mean += *ip * *iw;
00235     }
00236 
00237     /* Compute s.d. of distribution in specified group */
00238     ip = begin_points(group);
00239     iw = begin_weights(group);
00240     sd = 0.0;
00241     for (i = mNumPoints; i--; ++ip, ++iw)
00242     {
00243       Real dev = *ip - mean;
00244       sd += dev * dev * *iw;
00245     }
00246     sd = std::sqrt(sd);
00247   }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class L>
Real etirm::DiscreteLatentDist< L >::MStep ( const RealVector eprob,
int  g 
) [inline, virtual]

Computes an M-step for the probabilities of the multinomial discrete latent variable distribution in one examinee group.

Template Parameters

Parameters:
L Type of latent variable.

Function Parameters

Parameters:
[in] &eprob Address of vector containing probabilities for each latent variable category, computed in last E-step for group.
[in] g Group to estimate latent distribution for (g = 1, 2, ..., "number of groups").

Definition at line 342 of file DiscreteLatentDist.h.

References etirm::DiscreteLatentDist< L >::begin_weights(), etirm::DiscreteLatentDist< L >::mNumGroups, and etirm::DiscreteLatentDist< L >::mNumPoints.

00343   {
00344     int ncat = mNumPoints;
00345 
00346     if (ncat != eprob.size())
00347     {
00348       throw RuntimeError("Mismatch in number of latent variable points",
00349       "DiscreteLatentDist::MStep");
00350     }
00351 
00352     if (g < 1 || g> mNumGroups)
00353     {
00354       throw RuntimeError("Invalid examinee group number",
00355       "DiscreteLatentDist::MStep");
00356     }
00357 
00358     /* Find total N for this group */
00359     RealVector::const_iterator in = eprob.begin();
00360     Real ntot = 0.0;
00361     int i;
00362     for (i = ncat; i--; ++in) ntot += *in;
00363 
00364     /* Update group latent variable distribution */
00365     Real reldiff = 0.0;
00366     Real typicalValue = 1.0 / ncat;
00367     in = eprob.begin();
00368     weight_iterator iw = begin_weights(g);
00369     for (i = ncat; i--; ++in, ++iw)
00370     {
00371       Real old = *iw;
00372       *iw = *in / ntot;
00373 
00374       // Compute absolute relative difference between old and new probability
00375       Real d = old - *iw;
00376       Real denom = (*iw < typicalValue) ? typicalValue : *iw;
00377       if (denom != 0.0) d /= denom;
00378       d = (d < 0.0) ? -d : d; // fabs(d)
00379       if (reldiff < d) reldiff = d;
00380     }
00381 
00382     return reldiff;
00383 
00384   }

Here is the call graph for this function:


Member Data Documentation

template<class L>
bool etirm::DiscreteLatentDist< L >::mUniquePoints [private]

If true then unique latent distribution points are used for each group.

Definition at line 93 of file DiscreteLatentDist.h.

Referenced by etirm::DiscreteLatentDist< L >::begin_points(), etirm::DiscreteLatentDist< L >::NumGroupsUnique(), and etirm::DiscreteLatentDist< L >::Transform().

template<class L>
int etirm::DiscreteLatentDist< L >::mNumPoints [private]

Number of points in latent variable distribution for each group.

Definition at line 96 of file DiscreteLatentDist.h.

Referenced by etirm::DiscreteLatentDist< L >::begin_points(), etirm::DiscreteLatentDist< L >::MeanSD(), etirm::DiscreteLatentDist< L >::MStep(), etirm::DiscreteLatentDist< L >::size(), and etirm::DiscreteLatentDist< L >::Transform().

template<class L>
int etirm::DiscreteLatentDist< L >::mNumGroups [private]

Number of examinee groups.

Definition at line 99 of file DiscreteLatentDist.h.

Referenced by etirm::DiscreteLatentDist< L >::MeanSD(), etirm::DiscreteLatentDist< L >::MStep(), etirm::DiscreteLatentDist< L >::NumGroups(), etirm::DiscreteLatentDist< L >::NumGroupsUnique(), etirm::DiscreteLatentDist< L >::Scale(), and etirm::DiscreteLatentDist< L >::Transform().

template<class L>
std::vector<L> etirm::DiscreteLatentDist< L >::mPoints [private]

Vector of latent distribution points. If unique latent distribution points are used for each group then the size of this vector will be the product of the number of points in each group and the number of groups. The points for each group are stacked in this vector, so the first point for group g is mPoints[mNumPoints * (g-1)].

Definition at line 102 of file DiscreteLatentDist.h.

Referenced by etirm::DiscreteLatentDist< L >::begin_points(), and etirm::DiscreteLatentDist< L >::DiscreteLatentDist().

template<class L>
RealMatrix etirm::DiscreteLatentDist< L >::mWeights [private]

Each row gives the distribution for one group of examinees.

Definition at line 111 of file DiscreteLatentDist.h.

Referenced by etirm::DiscreteLatentDist< L >::begin_weights().


The documentation for this class was generated from the following file:
Generated on Sat Mar 1 21:41:13 2008 for ETIRM by  doxygen 1.5.4