亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? smotutor.cpp

?? 神經網絡VC++代碼 人工神經網絡原理及仿真實例.
?? CPP
字號:
/******************************************************************************

File        : SmoTutor.cc

Date        : Wednesday 13th September 2000

Author      : Dr Gavin C. Cawley

Description : Implementation of the sequential minimal optimisation (SMO)
              training algorithm for Vapnik's support vector machine (SVM)
              [1], due to Platt [2].

References  : [1] V. N. Vapnik, "The Nature of Statistical Learning Theory",
                  Springer-Verlag, New York, ISBN 0-387-94559-8, 1995.

              [2] J. C. Platt, "Fast Training of Support Vector Machines using
                  Sequential Minimal Optimization".  In B. Scholkopf, C. J. C.
                  Burges and A. J. Smola, editors, "Advances in Kernel Methods
                  - Support Vector Learning", pp 185-208, MIT Press, 1998.

History     : 07/07/2000 - v1.00
              13/09/2000 - v1.01 minor improvements to comments
              13/09/2000 - v1.10 zeta (pattern replication factors) and C
                                 removed from svc objects

Copyright   : (c) Dr Gavin C. Cawley, September 2000.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

******************************************************************************/

#include <stdlib.h>
#include <math.h>

#include "mex.h"

#include "Cache.h"
#include "SmoTutor.h"

#include "utils.hh"

void rotor()
{
   static int counter = 0;

   char symbol[] = {'/', '-', '\\', '|'};

   counter = (counter + 1) % 4;

   mexPrintf("%c\b", symbol[counter]);
}

SmoTutor::SmoTutor(mxArray *x,
                   mxArray *y,
                   mxArray *C,
                   mxArray *kernel,
                   mxArray *zeta,
                   mxArray *alpha,
                   mxArray *bias,
                   Cache   *cache)
{
   this->ntp       = mxGetM(x);
   this->y         = mxGetPr(y);
   this->C         = (double*)mxCalloc(ntp, sizeof(double));
   this->bias      = mxGetScalar(bias);
   this->epsilon   = 1e-12;
   this->tolerance = 1e-3;
   this->minimum   = -1;
   this->maximum   = -1;
   this->error     = (double*)mxCalloc(ntp, sizeof(double));
   this->alpha     = mxGetPr(alpha);
   this->zeta      = zeta;
   this->x         = x;
   this->kernel    = kernel;
   this->cache     = cache;

   double c = mxGetScalar(C);

   double *z = mxGetPr(zeta);

   for (int i = 0; i < ntp; i++)
   {
      this->C[i] = c*z[i];

      if (this->alpha[i] > 0.0 && this->alpha[i] < this->C[i])
      {
         this->error[i] = fwd(i) - this->y[i];
      }
      else
      {
         this->error[i] = 0.0;
      }
   }
}

double SmoTutor::fwd(int n)
{
   double result = -bias;

   for (int i = 0; i < ntp; i++)
   {
      if (alpha[i] > 0.0)
      {
         result += y[i]*alpha[i]*cache->fetch(n, i);
      }
   }

   return result;
}

int SmoTutor::nonBoundLagrangeMultipliers()
{
   int result = 0;

   for (int i = 0; i < ntp; i++)
   {
      if (alpha[i] > 0.0 && alpha[i] < C[i])
      {
         result++;
      }
   }

   return result;
}

int SmoTutor::nonZeroLagrangeMultipliers()
{
   int result = 0;

   for (int i = 0; i < ntp; i++)
   {
      if (alpha[i] > 0.0)
      {
         result++;
      }
   }

   return result;
}

int SmoTutor::takeStep(int i1, int i2, double e2)
{
   if (i1 == i2)
   {
      return 0;
   }

   /* compute upper and lower constraints, L and H, on multiplier a2 */

   double alpha1 = alpha[i1];
   double alpha2 = alpha[i2];
   double y1     = y[i1];
   double y2     = y[i2];
   double L;
   double H;

   if (y1 != y2)
   {
      L = max(0,     alpha2 - alpha1);
      H = min(C[i2], alpha2 - alpha1 + C[i1]);
   }
   else
   {
      L = max(0,     alpha1 + alpha2 - C[i1]);
      H = min(C[i2], alpha1 + alpha2);
   }

   if (L == H)
   {
      return 0;
   }

   /* recompute Lagrange multiplier for pattern i2 */

   double e1;

   if (alpha1 > 0.0 && alpha1 < C[i1])
   {
      e1 = error[i1];
   }
   else
   {
      e1 = fwd(i1) - y1;
   }

   double k11 = cache->fetch(i1, i1);
   double k12 = cache->fetch(i1, i2);
   double k22 = cache->fetch(i2, i2);
   double eta = 2.0*k12-k11-k22;
   double s   = y1*y2;
   double a2  = 0.0;

   if (eta < 0.0)
   {
      a2 = alpha2 - y2*(e1 - e2)/eta;

      /* constrain a2 to lie between L and H */

      if (a2 < L)
      {
         a2 = L;
      }
      else if (a2 > H)
      {
         a2 = H;
      }
   }
   else
   {
      return 0;
   }

   if (fabs(a2-alpha2) < epsilon*(a2+alpha2+epsilon))
   {
      return 0;
   }

   /* recompute Lagrange multiplier for pattern i1 */

   double a1 = alpha1+s*(alpha2-a2);

   /* update vector of Lagrange multipliers */

   alpha[i1] = a1;
   alpha[i2] = a2;

   /* update threshold to reflect change in Lagrange multipliers */

   double w1   = y1*(a1 - alpha1);
   double w2   = y2*(a2 - alpha2);
   double b1   = e1 + w1*k11 + w2*k12;
   double b2   = e2 + w1*k12 + w2*k22;
   double bold = bias;

   bias += 0.5*(b1 + b2);

   /* update error cache->*/

   if (fabs(b1-b2) < epsilon)
   {
      error[i1] = 0.0;
      error[i2] = 0.0;
   }
   else
   {
      if (a1 > 0.0 && a1 < C[i1])
      {
         error[i1] = fwd(i1) - y1;
      }

      if (a2 > 0.0 && a2 < C[i2])
      {
         error[i2] = fwd(i2) - y2;
      }
   }

   if (error[i1] > error[i2])
   {
      minimum = i2;
      maximum = i1;
   }
   else
   {
      minimum = i1;
      maximum = i2;
   }

   for (int i = 0; i < ntp; i++)
   {
      if (alpha[i] > 0.0 && alpha[i] < C[i] && i != i1 && i != i2)
      {
         error[i] += w1*cache->fetch(i1, i)
                  +  w2*cache->fetch(i2, i)
                  +  bold - bias;

         if (error[i] > error[maximum])
         {
            maximum = i;
         }

         if (error[i] < error[minimum])
         {
            minimum = i;
         }
      }
   }

   /* report progress made */

   return 1;
}

int SmoTutor::examineNonBound(int i2, double e2)
{
   int start = rand() % ntp;

   for (int i = 0; i < ntp; i++)
   {
      int i1 = (i + start) % ntp;

      if (alpha[i1] > 0.0 && alpha[i1] < C[i1])
      {
         if (takeStep(i1, i2, e2))
         {
            return 1;
         }
      }
   }

   return 0;
}

int SmoTutor::examineBound(int i2, double e2)
{
   int start = rand() % ntp;

   for (int i = 0; i < ntp; i++)
   {
      int i1 = (i + start) % ntp;

      if (alpha[i1] == 0.0 || alpha[i1] == C[i1])
      {
         if (takeStep(i1, i2, e2))
         {
            return 1;
         }
      }
   }

   return 0;
}

int SmoTutor::examineFirstChoice(int i2, double e2)
{
   if (minimum > -1)
   {
      if (fabs(e2 - error[minimum]) > fabs(e2 - error[maximum]))
      {
         if (takeStep(minimum, i2, e2))
         {
            return 1;
         }
      }
      else
      {
         if (takeStep(maximum, i2, e2))
         {
            return 1;
         }
      }
   }

   return 0;
}

int SmoTutor::examineExample(int i2)
{
   double alpha2 = alpha[i2];
   double y2     = y[i2];
   double e2;

   if (alpha2 > 0.0 && alpha2 < C[i2])
   {
      e2 = error[i2];
   }
   else
   {
      e2 = fwd(i2) - y2;
   }

   double r2 = e2*y2;

   // take action only if i2 violates Karush-Kuhn-Tucker conditions

   if ((r2 < -tolerance && alpha2 < C[i2]) || (r2 > tolerance && alpha2 > 0))
   {
      if (examineFirstChoice(i2, e2))
      {
         return 1;
      }

      if (examineNonBound(i2, e2))
      {
         return 1;
      }

      if (examineBound(i2, e2))
      {
         return 1;
      }
   }

   // no progress possible

   return 0;
}

void SmoTutor::sequentialMinimalOptimisation()
{
   int numberChanged;
   int examineAll    = 0;
   int epoch         = 1;

   do
   {
      numberChanged = 0;

      if (examineAll == 1)
      {
         for (int i = 0; i < ntp; i++)
         {
            numberChanged += examineExample(i);
         }

         examineAll = 0;
      }
      else
      {
         for (int i = 0; i < ntp; i++)
         {
            if (alpha[i] > 0 && alpha[i] < C[i])
            {
               numberChanged += examineExample(i);
            }
         }

         if (numberChanged == 0)
         {
            examineAll = 1;
         }
      }

      /*
      mexPrintf("epoch %d number of changes %d/%d\n",
                epoch++,
                numberChanged,
                nonZeroLagrangeMultipliers());
      */
   }
   while (numberChanged > 0 || examineAll);
}

mxArray *SmoTutor::train()
{
   sequentialMinimalOptimisation();

   mxArray *rhs[4], *lhs[1];

   rhs[0] = kernel;                                   // kernel
   rhs[1] = x;                                        // svs
   rhs[2] = mxCreateDoubleMatrix(1, ntp, mxREAL);     // w
   rhs[3] = mxCreateDoubleMatrix(1, 1,   mxREAL);     // bias

   // set up weight vector

   double *w = mxGetPr(rhs[2]);

   for (int i = 0; i < ntp; i++)
   {
      w[i] = y[i]*alpha[i];
   }

   // set up bias

   *mxGetPr(rhs[3]) = bias;

   // form support vector machine

   mexCallMATLAB(1, lhs, 4, rhs, "svc");

   return lhs[0];
}

/***************************** That's all Folks! *****************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩色视频在线观看| 91亚洲男人天堂| 亚洲国产精品高清| 99国产精品久久久久| 亚洲裸体xxx| 欧美大尺度电影在线| 1区2区3区国产精品| 三级一区在线视频先锋 | 在线视频你懂得一区| 日韩一级大片在线观看| 亚洲人成网站在线| 国产成人aaa| 精品免费视频.| 奇米影视一区二区三区小说| 99久久er热在这里只有精品66| 欧美大胆人体bbbb| 视频一区免费在线观看| 99天天综合性| 国产精品午夜春色av| 久久国产免费看| 一本色道久久综合亚洲精品按摩| 国产精品久久久久久久久免费丝袜 | 日韩精品一卡二卡三卡四卡无卡| 成人激情小说乱人伦| 亚洲精品一区二区三区精华液| 香蕉久久夜色精品国产使用方法| 色哟哟一区二区在线观看| 日本一区二区综合亚洲| 国产精品一区在线观看乱码| 精品精品国产高清a毛片牛牛 | 成人黄色综合网站| 26uuu欧美| 激情伊人五月天久久综合| 精品国产一区a| 韩国av一区二区| 久久天堂av综合合色蜜桃网| 国产九九视频一区二区三区| 精品国产精品网麻豆系列| 蜜乳av一区二区| 精品处破学生在线二十三| 国产精品影视天天线| 中文子幕无线码一区tr| 成a人片国产精品| 亚洲免费观看在线视频| 日本精品一区二区三区四区的功能| 亚洲日本在线天堂| 欧美综合天天夜夜久久| 午夜av电影一区| 日韩欧美亚洲另类制服综合在线| 麻豆传媒一区二区三区| 精品国产免费人成电影在线观看四季| 麻豆成人91精品二区三区| 久久这里都是精品| 成人18视频日本| 亚洲国产精品久久一线不卡| 欧美一卡二卡在线| 99久久婷婷国产| 亚洲免费观看高清| 日韩午夜激情av| 风流少妇一区二区| 亚洲一区二区三区四区在线免费观看 | 成人少妇影院yyyy| 亚洲黄一区二区三区| 欧美放荡的少妇| 国产一区二区三区久久久| 亚洲国产成人私人影院tom| 色欧美日韩亚洲| 久久av资源网| 日韩理论在线观看| 欧美日韩在线精品一区二区三区激情| 日本不卡免费在线视频| 国产精品视频一二| 制服丝袜国产精品| 不卡的av电影在线观看| 婷婷中文字幕综合| 欧美国产精品v| 在线播放中文一区| 波多野结衣在线aⅴ中文字幕不卡| 一区二区三区四区精品在线视频| 日韩一区二区三区四区| 成人动漫一区二区在线| 男女性色大片免费观看一区二区| 中国av一区二区三区| 欧美中文字幕一区二区三区 | 午夜伦欧美伦电影理论片| 欧美国产精品v| 日韩三级免费观看| 欧美亚洲综合一区| 成人综合婷婷国产精品久久蜜臀| 首页国产欧美久久| 国产精品久久久久影院亚瑟| 91精品国产综合久久精品图片| 99精品久久久久久| 国产美女精品在线| 免费av网站大全久久| 亚洲精品免费在线| 日韩一区在线播放| 欧美国产日韩在线观看| 久久综合中文字幕| 91精品国产麻豆国产自产在线 | 亚洲男人的天堂网| 中文一区在线播放| 国产视频在线观看一区二区三区 | 国产欧美精品区一区二区三区| 欧美无人高清视频在线观看| hitomi一区二区三区精品| 国产麻豆视频一区二区| 国产在线国偷精品免费看| 亚洲va国产天堂va久久en| 136国产福利精品导航| 国产精品色哟哟网站| 国产农村妇女毛片精品久久麻豆 | 久久不见久久见免费视频7| 日韩在线一区二区| 香蕉加勒比综合久久| 午夜精品久久久久久| 亚洲3atv精品一区二区三区| 一区二区三区在线播| 一区二区成人在线| 亚洲午夜电影在线观看| 亚洲一二三专区| 天堂午夜影视日韩欧美一区二区| 亚洲一区二区精品视频| 亚洲一区电影777| 亚洲高清免费在线| 视频一区欧美精品| 久久国内精品视频| 国产一区二区三区高清播放| 国产精品一区二区久久精品爱涩 | 亚洲人成精品久久久久| 综合分类小说区另类春色亚洲小说欧美| 久久久久久日产精品| 国产精品午夜电影| 亚洲一二三四在线| 日本va欧美va欧美va精品| 美女视频一区二区三区| 国产高清在线观看免费不卡| 不卡视频免费播放| 欧美日韩国产小视频| 精品国产91乱码一区二区三区| 2022国产精品视频| 成人欧美一区二区三区小说 | 国产午夜精品福利| 亚洲色图欧美激情| 日韩精品每日更新| 国产成人在线视频网站| 色老汉av一区二区三区| 91精品国产高清一区二区三区蜜臀| 日韩精品资源二区在线| 国产精品久久久久精k8| 亚洲国产aⅴ天堂久久| 韩国v欧美v日本v亚洲v| 色先锋资源久久综合| 欧美mv日韩mv国产网站| 亚洲欧洲色图综合| 日韩福利视频网| 国产成人av网站| 欧美日韩在线播放三区四区| 国产日韩欧美精品一区| 亚洲一区二区黄色| 成人午夜av在线| 欧美日本精品一区二区三区| 日本一二三四高清不卡| 亚洲成a人片在线不卡一二三区| 国产毛片精品国产一区二区三区| 色婷婷综合久久久中文字幕| 日韩免费高清视频| 亚洲精品成人天堂一二三| 国产一级精品在线| 91精品国产综合久久久久久久久久| 国产精品国产三级国产aⅴ中文| 日韩精品视频网站| 日本电影欧美片| 中文欧美字幕免费| 激情综合一区二区三区| 日欧美一区二区| 欧美日韩国产另类一区| 91久久人澡人人添人人爽欧美| 91福利国产成人精品照片| 国产日韩精品一区二区三区| 五月天丁香久久| 色哟哟国产精品免费观看| 中文字幕高清不卡| 九九国产精品视频| 91麻豆精品国产91久久久久久| 日韩毛片在线免费观看| 福利一区二区在线| 久久婷婷一区二区三区| 老司机精品视频导航| 欧美日韩国产中文| 亚洲电影一区二区三区| 在线视频一区二区免费| 亚洲欧洲综合另类| 成人午夜视频福利| 国产精品免费久久久久| 懂色av中文字幕一区二区三区| 精品国内二区三区| 国产一区二区三区在线观看免费视频| 欧美一区二区三区免费视频 | 麻豆精品在线看|