示例#1
0
  void updateXi_MA(int *seed,
		   int *nAccept,
		   double *xi,
		   const int *Q,
		   const int *G,
		   const int *delta,
		   const double *alphaXi,
		   const double *betaXi) {
    unsigned int seedU = (unsigned int) *seed;

    updateXi(&seedU,nAccept,xi,*Q,*G,delta,*alphaXi,*betaXi);

    *seed = (int) seedU;

    return;
  }
示例#2
0
void optimiseAlpha(int violator)
{
   int i, flag;

   double L = 0.0, H = 0.0, a, F_tmp, delta_tmp, slope, d_right, d_left;

   double aleph = alpha[violator];

   /* bracket minimum with interval excluding zero (except at a boundary) */

   if (violator == 0)
   {
      /* case 1 - unregularised bias term */

      L     = -DBL_MAX;
      H     = +DBL_MAX;
      slope = -F[0];
   }
   else
   {
      /* the violator is a regularised parameter */

      if (aleph == 0.0)
      {
         d_right = +lambda - F[violator];
         d_left  = -lambda - F[violator]; 

         if (d_right < 0.0)
         {
            /* case 2 - alpha = 0 and right derivative is negative */
   
            L     = 0.0;
	    H     = DBL_MAX;
	    slope = d_right; 
         }
         else if (d_left > 0.0)
         {
            /* case 3 - alpha = 0 and left derivative is positive */

            L     = -DBL_MAX;
	    H     = +0.0;
	    slope = d_left; 
         }
         else
         {
            /* case 4 - parameter stable at zero (should never happen) */

            set[violator] = I_z;
      
	    return;
         }
      }
      else if (aleph != 0.0)
      {
         slope = (aleph > 0.0 ? +lambda : -lambda) - F[violator];

         if (aleph > 0.0 && slope < 0.0)
         {
            /* case 5 - aleph positive and derivative is negative */
   
            L = aleph;
            H = +DBL_MAX;
         }
         else if (aleph < 0.0 && slope > 0)
         {
            /* case 6 - alpha negative and derivative is positve */

            L = -DBL_MAX;
            H = aleph;
         }
         else
         {
            /* store a copy of xi, exp_xi, F[violator] and delta[violator] */

            memcpy(tmp1,     xi, ntp*sizeof(double));
            memcpy(tmp2, exp_xi, ntp*sizeof(double));

            F_tmp     = F[violator];
            delta_tmp = delta[violator];

            /* update statistics assuming alpha[violator] = 0.0 */
   
            updateXi(violator, aleph);
            updateFAndDelta(violator);

	    alpha[violator] = 0.0;
	    set[violator]   = I_z;
	    N               = N - 1;
	    E_alpha         = E_alpha - fabs(aleph);

	    /* compute left and right derivaltives */

            d_right = +lambda - F[violator];
            d_left  = -lambda - F[violator]; 

	    if ((d_right>0.0 && d_left<0.0) || d_right==0.0 || d_left==0.0)
	    {
               /* parameter can be safely pruned */

	       return;
	    }
	    else
            {
               /* bracket minimum */

               if (aleph > 0.0 && slope > 0.0 && d_right > 0.0)
               {
                  /* case 2 */
   
	          aleph = 0.0;
	          slope = d_left;
	          L     = -DBL_MAX;
	          H     = +0.0;
               }
               else if (aleph < 0.0 && slope < 0.0 && d_left < 0.0)
               {
                  /* case 5 */
   
	          aleph = 0.0;
	          slope = d_right;
	          L     = 0.0;
	          H     = DBL_MAX;
               }
               else
	       {
	          if (aleph > 0.0 && slope > 0.0 && d_right < 0.0)
                  {
                     /* case 3 */
      
                     L = 0.0;
	             H = aleph;
	          }
                  else if (aleph < 0 && slope < 0 && d_left > 0)
                  {
                     /* case 6 */
      
	             L = aleph; 
	             H = 0.0;
                  }

                  /* restore xi and exp_xi etc. */
   
	          SWAP(    xi, tmp1, double*)
	          SWAP(exp_xi, tmp2, double*)
   
	          alpha[violator] = aleph;
	          set[violator]   = I_nz;
	          F[violator]     = F_tmp;
	          delta[violator] = delta_tmp;
	          N               = N + 1;
	          E_alpha         = E_alpha + fabs(aleph);
               }
            }
         }
      }
   }