Java 类weka.core.Optimization 实例源码

项目:autoweka    文件:RBFModel.java   
/**
  * Builds the RBF network regressor based on the given dataset.
  */
 @Override
 public void buildClassifier(Instances data) throws Exception {

   // Set up the initial arrays
   m_data = initializeClassifier(data);

   if (m_ZeroR != null) {
     return;
   }

   // Initialise thread pool
   m_Pool = Executors.newFixedThreadPool(m_poolSize);

   // Apply optimization class to train the network
   Optimization opt = null;
   if (!m_useCGD) {
     opt = new OptEng();
   } else {
     opt = new OptEngCGD();
   }
   opt.setDebug(m_Debug);

   // No constraints
   double[][] b = new double[2][m_RBFParameters.length];
   for (int i = 0; i < 2; i++) {
     for (int j = 0; j < m_RBFParameters.length; j++) {
       b[i][j] = Double.NaN;
     }
   }

   m_RBFParameters = opt.findArgmin(m_RBFParameters, b);
   while (m_RBFParameters == null) {
     m_RBFParameters = opt.getVarbValues();
     if (m_Debug) {
       System.out.println("200 iterations finished, not enough!");
     }
     m_RBFParameters = opt.findArgmin(m_RBFParameters, b);
     if(Thread.interrupted())
break;

   }
   if (m_Debug) {
     System.out.println("SE (normalized space) after optimization: "
       + opt.getMinFunction());
   }

   m_data = new Instances(m_data, 0); // Save memory

   // Shut down thread pool
   m_Pool.shutdown();
 }