 #if 1
 /* stochastic gradient descent */
   int iter = 0;
-//  int batchSize = 64;
-
-//  printf("Learning rate Lambda is %f\n",lambda);
- // printf("Batchsize is %d\n",batchSize);
 
   while(iter < iterations )
   {
-//  for( int i = 0; i < 500; i++ )
- // {
     for( int j = 0; j < Xexamples; j+=batchSize )
     {
-   //   int j = (int) ((double(rand()) / (double(RAND_MAX) + 1.0))*5000);
       
       costFunction( &X[INDX(0,j,Xfeatures)], batchSize, Xfeatures,
                     theta1, theta1Rows, theta1Cols, 

  *cost = jTemp;
#endif
#endif
#if 1
  floatType_t *delta3;
  delta3 = yTemp;


  memset( theta1Grad, 0, sizeof(floatType_t) * theta1Rows * theta1Cols );

  memset( theta2Grad, 0, sizeof(floatType_t) * theta2Rows * theta2Cols );

  for( int row = 0; row < Xexamples; row++ )
  { 
    memset( delta3, 0, sizeof( floatType_t) * 11 );
    delta3[ (int) Y[row] ] = (floatType_t) 1.0;
#if 1
    for( int j = 0; j < 10; j++ ) 
    {
      delta3[j+1] = a3[INDX(row,j,Xexamples)] - delta3[j+1];
    } /* end for j */

    if( sizeof( floatType_t ) == 4 )
    {
      cblas_sgemv( CblasColMajor, CblasTrans,
                 theta2Rows, theta2Cols,
                 1.0f, theta2, theta2Rows, 
                 &delta3[1], 1, 0.0f,
                 delta2, 1 );

      for( int j = 1; j <= theta1Rows; j++ )
      {
        delta2[j] *= sigmoidGradient_f( z2[INDX(row,j,Xexamples)] );
      } /* end for */
    } /* end if */
    else
    { 
    } /* end else */
#endif
#if 1
    for( int j = 0; j < theta1Cols; j++ )
    {
      for( int i = 0; i < theta1Rows; i++ )
      {
        theta1Grad[INDX(i,j,theta1Rows)] += 
          ( delta2[i+1] * X[INDX(j,row,Xfeatures)] );
      } /* end for i */    
    } /* end for j */

    for( int j = 0; j < theta2Cols; j++ )
    {
      for( int i = 0; i < theta2Rows; i++ )
      {
        theta2Grad[INDX(i,j,theta2Rows)] +=
          ( delta3[i+1] * a2[INDX(row,j,Xexamples)] );
      } /* end for i */
    } /* end for j */
#endif
  } /* end for row */

  floatType_t recip = (floatType_t) 1.0 / (floatType_t) Xexamples;

//  for( int j = 0; j < theta1Cols; j++ )
 // {
  //  for( int i = 0; i < theta1Rows; i++ )
   // {
    //  theta1Grad[INDX(i,j,theta1Rows)] *= recip;
  //  } /* end for i */    
//  } /* end for j */

  for( int i = 0; i < theta1Rows*theta1Cols; i++ )
    theta1Grad[i] *= recip;

//  for( int j = 0; j < theta2Cols; j++ )
 // {
  //  for( int i = 0; i < theta2Rows; i++ )
   // {
    //  theta2Grad[INDX(i,j,theta2Rows)] *= recip;
  //  } /* end for i */
//  } /* end for j */
  for( int i = 0; i < theta2Cols*theta2Rows; i++ )
    theta2Grad[i] *= recip;
#endif
} /* end costFunction */


                                theta2Rows * theta2Cols );

  tempMatrix = (floatType_t *) malloc( sizeof(floatType_t) *
                               ( Xexamples * (theta1Rows+1) + //z2
                                 Xexamples * (theta1Rows+1) + //a2
                                 Xexamples * (theta2Rows+1) + //a3
                                 Xexamples * (theta1Rows+1) + //delta2
                                 Xexamples * 11) );           //delta3

  for( int i = 0; i < Xexamples; i++ ) 
    X[INDX(0,i,Xfeatures)] = (floatType_t) 1.0;
