C:/programs/etirm/src/MStepIRT.h

Go to the documentation of this file.
00001 /*! \file MStepIRT.h
00002  
00003   \brief
00004   Functions used in implementing the M-step for IRT models.
00005 
00006   Estimation Toolkit for Item Response Models (ETIRM)
00007   http://www.smallwaters.com/software/cpp/etirm.html
00008 
00009   Author(s): 
00010   Werner Wothke, maintenance (http://www.smallwaters.com)
00011   Brad Hanson (http://www.b-a-h.com/)
00012   See the file LICENSE for information on usage and redistribution.
00013 
00014   Copyright (C) 2008, Werner Wothke
00015   Copyright (c) 2000-2001, Bradley A. Hanson
00016  */
00017 
00018 #ifndef ETIRM_MSTEPIRT_H_
00019 #define ETIRM_MSTEPIRT_H_
00020 
00021 #ifdef ETIRM_NO_DIR_PREFIX
00022 #include "etirmtypes.h"
00023 #else
00024 #include "etirm/etirmtypes.h"
00025 #endif
00026 
00027 namespace etirm
00028 {
00029 
00030   /*!
00031     \brief
00032     Returns the maximum relative difference between an old and new set of item parameters.
00033     
00034     \param[in] &oldParam  Address of vector containing base parameter values.
00035     \param[in] &newParam  Address of vector containing comparison (new) parameter values.
00036     \param[in] typicalValue Minimum denominator for relative comparison.
00037   */
00038   double MaxRelParamDiff(RealVector &oldParam, RealVector &newParam, Real typicalValue = 1.0);
00039 
00040   /*!
00041     \brief
00042     Executes M-step for each item.
00043     
00044     This function is used when the M-step can be carried out separately for each item.
00045    
00046     Returns 0 if successful.
00047     
00048     If ignoreMaxIter is true, and the only error that occurs is that the
00049     maximum number of M-step iterations is exceeded, then returns
00050     negative of number of items for which maximum number iterations were
00051     exceeded. 
00052     
00053     If ignoreMaxIter is false and an error occurs, or an error
00054     other than exceeding the maximum number of M-step iterations occurs,
00055     then returns the item number (1-offset) for which error occurred and
00056     processing is stopped at the point of the error.
00057 
00058     \section template_args Template Parameters
00059    
00060     \param II Iterator to Item object pointer.
00061     \param MI Iterator to pointers to minimization routines (interface is for 
00062         Uncmin, but any minimization routine with the same interface as Uncmin 
00063         could be used).
00064 
00065     \section function_args Function Parameters
00066 
00067     \param[in]  min_routines Object holding minimization routine (any minimization
00068        parameters set will be used for each item).
00069     \param[in]  item_begin  Iterator pointing to first item (*item_begin is a pointer to the first item)
00070     \param[in]  item_end  Iterator pointing to one past last item (*(item_end-1) is a pointer to the last item)
00071     \param[out]  &maxreldiff Address of maximum relative difference between an old and new parameter 
00072        estimate across all items.
00073     \param[in]  ignoreMaxIter If true and maximum number of M-step iterations are exceeded then
00074        parameters are used anyway. If false and maximum number of M-step iterations
00075        are exceeded the function returns immediately with item number at which error occurred.
00076    */
00077   template<class MI, class II> int MStepItems(MI min_routines, II item_begin, II item_end,
00078       double &maxreldiff, bool ignoreMaxIter = false)
00079   {
00080     int nMaxIter = 0;
00081     maxreldiff = 0.0;
00082 
00083     for (II iitem = item_begin; iitem != item_end; ++iitem, ++min_routines)
00084     {
00085       (*min_routines)->SetFunction(*iitem);
00086 
00087       int dim = (*iitem)->dim();
00088       RealVector start = (*iitem)->GetParameters();
00089       RealVector xpls(dim), gpls(dim);
00090       double fpls;
00091 
00092       int result = (*min_routines)->Minimize(start, xpls, fpls, gpls);
00093 
00094       if (result != 0)
00095       {
00096         int message = (*min_routines)->GetMessage();
00097         if (ignoreMaxIter && message == 4)
00098           nMaxIter--; // assumes message==4 means maximum number of iterations exceeded
00099         else
00100           return iitem-item_begin+1; // return number of item where minimization failed
00101       }
00102       (*iitem)->SetParameters(xpls);
00103 
00104       double d = MaxRelParamDiff(start, xpls);
00105       if (maxreldiff < d)
00106         maxreldiff = d;
00107     }
00108     return nMaxIter;
00109   }
00110 
00111 } // namespace etirm
00112 
00113 #endif // ETIRM_MSTEPIRT_H_

Generated on Sat Mar 1 21:40:16 2008 for ETIRM by  doxygen 1.5.4