コード例 #1
0
ファイル: maxout.cpp プロジェクト: maddin79/darch
 void operator()(std::size_t begin_pool, std::size_t end_pool)
 {
   int poolStart, poolEnd, maxIndex;
   float activation, currentActivation, derivative;
   bool dropout = (dropoutMask.length() > 0);
   
   for (int i = begin_pool; i < end_pool; i++)
   {
     poolStart = poolSize * i;
     poolEnd = poolStart + (poolSize - 1);
     
     for (int j = 0; j < colLength; j++)
     {
       activation = -INFINITY;
       derivative = 0;
       maxIndex = 0;
       
       // Find maximum within pool
       for (int k = 0; k < poolSize; k++)
       {
         currentActivation = activations(j, poolStart + k);
         
         if (currentActivation > activation &&
             (!dropout || dropoutMask[poolStart + k] == 1))
         {
           activation = currentActivation;
           derivative = derivatives(j, poolStart + k);
           maxIndex = k;
         }
         
         // Set everything to 0
         activations(j, poolStart + k) = 0;
         derivatives(j, poolStart + k) = 0;
       }
       
       // Restore maximum
       if (activation != -INFINITY)
       {
         activations(j, poolStart + maxIndex) = activation;
         derivatives(j, poolStart + maxIndex) = derivative;
       }
     }
   }
 }