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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? svm_struct_api.c

?? svm(支持向量機(jī))分類算法本質(zhì)上是二類分類器
?? C
?? 第 1 頁 / 共 2 頁
字號:
/***********************************************************************/
/*                                                                     */
/*   svm_struct_api.c                                                  */
/*                                                                     */
/*   Definition of API for attaching implementing SVM learning of      */
/*   structures (e.g. parsing, multi-label classification, HMM)        */ 
/*                                                                     */
/*   Author: Thorsten Joachims                                         */
/*   Date: 03.07.04                                                    */
/*                                                                     */
/*   Copyright (c) 2004  Thorsten Joachims - All rights reserved       */
/*                                                                     */
/*   This software is available for non-commercial use only. It must   */
/*   not be modified and distributed without prior permission of the   */
/*   author. The author is not responsible for implications from the   */
/*   use of this software.                                             */
/*                                                                     */
/***********************************************************************/

#include <stdio.h>
#include <string.h>
#include "svm_struct/svm_struct_common.h"
#include "svm_struct_api.h"

SAMPLE      read_struct_examples(char *file, STRUCT_LEARN_PARM *sparm)
{
  /* Reads training examples and returns them in sample. The number of
     examples must be written into sample.n */
  SAMPLE   sample;  /* sample */
  EXAMPLE  *examples;
  long     n;       /* number of examples */
  DOC **docs;       /* examples in original SVM-light format */ 
  double *target;
  long totwords,i;

  /* Using the read_documents function from SVM-light */
  read_documents(file,&docs,&target,&totwords,&n);
  examples=(EXAMPLE *)my_malloc(sizeof(EXAMPLE)*n);
  for(i=0;i<n;i++) {   /* copy docs over into new datastructure */
    examples[i].x.doc=docs[i];
    examples[i].y.class=target[i]+0.1;
  }
  free(target);
  free(docs);
  sample.n=n;
  sample.examples=examples;

  if(struct_verbosity>=0)
    printf(" (%d examples) ",sample.n);
  return(sample);
}

void        init_struct_model(SAMPLE sample, STRUCTMODEL *sm, 
			      STRUCT_LEARN_PARM *sparm)
{
  /* Initialize structmodel sm. The weight vector w does not need to be
     initialized, but you need to provide the maximum size of the
     feature space in sizePsi. This is the maximum number of different
     weights that can be learned. Later, the weight vector w will
     contain the learned weights for the model. */
  long i,totwords=0;
  WORD *w;

  sparm->num_classes=1;
  for(i=0;i<sample.n;i++)     /* find highest class label */
    if(sparm->num_classes < (sample.examples[i].y.class+0.1)) 
      sparm->num_classes=sample.examples[i].y.class+0.1;
  for(i=0;i<sample.n;i++)     /* find highest feature number */
    for(w=sample.examples[i].x.doc->fvec->words;w->wnum;w++) 
      if(totwords < w->wnum) 
	totwords=w->wnum;
  sparm->num_features=totwords;
  if(struct_verbosity>=0)
    printf("Training set properties: %d features, %d classes\n",
	   sparm->num_features,sparm->num_classes);
  sm->sizePsi=sparm->num_features*sparm->num_classes;
  if(struct_verbosity>=2)
    printf("Size of Phi: %ld\n",sm->sizePsi);
}

CONSTSET    init_struct_constraints(SAMPLE sample, STRUCTMODEL *sm, 
				    STRUCT_LEARN_PARM *sparm)
{
  /* Initializes the optimization problem. Typically, you do not need
     to change this function, since you want to start with an empty
     set of constraints. However, if for example you have constraints
     that certain weights need to be positive, you might put that in
     here. The constraints are represented as lhs[i]*w >= rhs[i]. lhs
     is an array of feature vectors, rhs is an array of doubles. m is
     the number of constraints. The function returns the initial
     set of constraints. */
  CONSTSET c;
  long     sizePsi=sm->sizePsi;
  long     i;
  WORD     words[2];

  if(1) { /* normal case: start with empty set of constraints */
    c.lhs=NULL;
    c.rhs=NULL;
    c.m=0;
  }
  else { /* add constraints so that all learned weights are
            positive. WARNING: Currently, they are positive only up to
            precision epsilon set by -e. */
    c.lhs=my_malloc(sizeof(DOC *)*sizePsi);
    c.rhs=my_malloc(sizeof(double)*sizePsi);
    for(i=0; i<sizePsi; i++) {
      words[0].wnum=i+1;
      words[0].weight=1.0;
      words[1].wnum=0;
      /* the following slackid is a hack. we will run into problems,
         if we have move than 1000000 slack sets (ie examples) */
      c.lhs[i]=create_example(i,0,1000000+i,1,create_svector(words,"",1.0));
      c.rhs[i]=0.0;
    }
  }
  return(c);
}

LABEL       classify_struct_example(PATTERN x, STRUCTMODEL *sm, 
				    STRUCT_LEARN_PARM *sparm)
{
  /* Finds the label yhat for pattern x that scores the highest
     according to the linear evaluation function in sm, especially the
     weights sm.w. The returned label is taken as the prediction of sm
     for the pattern x. The weights correspond to the features defined
     by psi() and range from index 1 to index sm->sizePsi. If the
     function cannot find a label, it shall return an empty label as
     recognized by the function empty_label(y). */
  LABEL y;
  DOC doc;
  long class,bestclass=-1,first=1,j;
  double score,bestscore=-1;
  WORD *words;

  doc=*(x.doc);
  words=doc.fvec->words;
  for(j=0;(words[j]).wnum != 0;j++) {       /* Check if feature numbers   */
    if((words[j]).wnum>sparm->num_features) /* are not larger than in     */
      (words[j]).wnum=0;                    /* model. Remove feature if   */
  }                                         /* necessary.                 */
  for(class=1;class<=sparm->num_classes;class++) {
    y.class=class;
    doc.fvec=psi(x,y,sm,sparm);
    score=classify_example(sm->svm_model,&doc);
    free_svector(doc.fvec);
    if((bestscore<score)  || (first)) {
      bestscore=score;
      bestclass=class;
      first=0;
    }
  }
  y.class=bestclass;
  return(y);
}

LABEL       find_most_violated_constraint_slackrescaling(PATTERN x, LABEL y, 
						     STRUCTMODEL *sm, 
						     STRUCT_LEARN_PARM *sparm)
{
  /* Finds the label ybar for pattern x that that is responsible for
     the most violated constraint for the slack rescaling
     formulation. It has to take into account the scoring function in
     sm, especially the weights sm.w, as well as the loss
     function. The weights in sm.w correspond to the features defined
     by psi() and range from index 1 to index sm->sizePsi. Most simple
     is the case of the zero/one loss function. For the zero/one loss,
     this function should return the highest scoring label ybar, if
     ybar is unequal y; if it is equal to the correct label y, then
     the function shall return the second highest scoring label. If
     the function cannot find a label, it shall return an empty label
     as recognized by the function empty_label(y). */
  LABEL ybar;
  DOC doc;
  long class,bestclass=-1,first=1;
  double score,bestscore=-1;

  doc=*(x.doc);
  for(class=1;class<=sparm->num_classes;class++) {
    ybar.class=class;
    doc.fvec=psi(x,ybar,sm,sparm);
    score=classify_example(sm->svm_model,&doc);
    free_svector(doc.fvec);
    if(((bestscore<score)  || (first)) && (y.class!=class)) {
      bestscore=score;
      bestclass=class;
      first=0;
    }
  }
  if(bestclass == -1) 
    printf("ERROR: Only one class\n");
  ybar.class=bestclass;
  if(struct_verbosity>=3)
    printf("[%ld:%.2f] ",bestclass,bestscore);
  return(ybar);
}

LABEL       find_most_violated_constraint_marginrescaling(PATTERN x, LABEL y, 
						     STRUCTMODEL *sm, 
						     STRUCT_LEARN_PARM *sparm)
{
  /* Finds the label ybar for pattern x that that is responsible for
     the most violated constraint for the margin rescaling
     formulation. It has to take into account the scoring function in
     sm, especially the weights sm.w, as well as the loss
     function. The weights in sm.w correspond to the features defined
     by psi() and range from index 1 to index sm->sizePsi. Most simple
     is the case of the zero/one loss function. For the zero/one loss,
     this function should return the highest scoring label ybar, if
     ybar is unequal y; if it is equal to the correct label y, then
     the function shall return the second highest scoring label. If
     the function cannot find a label, it shall return an empty label
     as recognized by the function empty_label(y). */

  /* margin and slack rescaling are equivalent for zero/one loss */
  return(find_most_violated_constraint_slackrescaling(x,y,sm,sparm));
}

int         empty_label(LABEL y)
{
  /* Returns true, if y is an empty label. An empty label might be
     returned by find_most_violated_constraint_???(x, y, sm) if there
     is no incorrect label that can be found for x, or if it is unable
     to label x at all */
  return(y.class<0.9);
}

SVECTOR     *psi(PATTERN x, LABEL y, STRUCTMODEL *sm,
		 STRUCT_LEARN_PARM *sparm)
{
  /* Returns a feature vector describing the match between pattern x and
     label y. The feature vector is returned as an SVECTOR
     (i.e. pairs <featurenumber:featurevalue>), where the last pair has
     featurenumber 0 as a terminator. Featurenumbers start with 1 and end with
     sizePsi. This feature vector determines the linear evaluation
     function that is used to score labels. There will be one weight in
     sm.w for each feature. Note that psi has to match
     find_most_violated_constraint_???(x, y, sm) and vice versa. In
     particular, find_most_violated_constraint_???(x, y, sm) finds that
     ybar!=y that maximizes psi(x,ybar,sm)*sm.w (where * is the inner
     vector product) and the appropriate function of the loss.  */
  SVECTOR *fvec;
  long i;

  fvec=create_svector(x.doc->fvec->words,x.doc->fvec->userdefined,1.0);
  for(i=0;fvec->words[i].wnum;i++) { /* move to weight vector of class y */
    fvec->words[i].wnum+=(y.class-1)*sparm->num_features;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美二区在线观看| 国产成人精品一区二| 在线观看一区不卡| 亚洲精品免费在线观看| 色综合天天综合网天天狠天天| 亚洲欧美综合网| 国产成人在线观看免费网站| 久久午夜色播影院免费高清| 国产jizzjizz一区二区| 国产精品久久久久久一区二区三区| 成人av在线播放网址| 一区二区三区欧美视频| 欧美人伦禁忌dvd放荡欲情| 视频一区中文字幕国产| 欧美精品一区二区三区蜜桃| 国产成人精品www牛牛影视| 国产精品不卡在线观看| 在线观看成人小视频| 久草中文综合在线| 国产精品嫩草影院av蜜臀| 欧美在线观看视频在线| 午夜精品福利一区二区三区av | 亚洲免费在线看| 欧美日韩高清一区二区三区| 美女性感视频久久| 日本一区二区免费在线| 欧美亚男人的天堂| 激情综合色播激情啊| 亚洲视频每日更新| 日韩午夜激情视频| 94-欧美-setu| 老司机一区二区| 亚洲视频狠狠干| 欧美tickling挠脚心丨vk| 成人91在线观看| 视频在线观看一区| 亚洲手机成人高清视频| 日韩三级免费观看| 色久综合一二码| 国产一区二区在线影院| 一级中文字幕一区二区| 国产欧美日韩精品一区| 911国产精品| 94-欧美-setu| 国产成人精品免费网站| 日本不卡123| 亚洲欧美日韩一区二区三区在线观看| 日韩亚洲欧美在线观看| 91福利社在线观看| 国产a级毛片一区| 久久精品国产999大香线蕉| 亚洲精品乱码久久久久久日本蜜臀| www国产成人免费观看视频 深夜成人网| 色猫猫国产区一区二在线视频| 韩国毛片一区二区三区| 亚洲sss视频在线视频| 亚洲少妇中出一区| 日本一区二区电影| 久久中文字幕电影| 日韩一级二级三级精品视频| 欧美揉bbbbb揉bbbbb| 91香蕉视频污在线| 国产99久久精品| 国产剧情一区二区| 另类的小说在线视频另类成人小视频在线 | 日韩va欧美va亚洲va久久| 亚洲女人小视频在线观看| 国产精品无遮挡| 中文字幕欧美激情| 日本一区二区动态图| 久久久精品黄色| 欧美精品一区二区三区在线| 日韩一级视频免费观看在线| 欧美一三区三区四区免费在线看| 欧美人与性动xxxx| 欧美精品丝袜中出| 欧美日韩成人一区二区| 欧美肥大bbwbbw高潮| 日韩一区二区三区精品视频| 91精品在线一区二区| 91麻豆精品国产91久久久更新时间| 欧美视频在线不卡| 7777精品伊人久久久大香线蕉的 | 在线视频一区二区免费| 国产一区美女在线| 国产成人免费视频精品含羞草妖精| 日本一区中文字幕| 午夜激情久久久| 亚洲第一会所有码转帖| 亚洲午夜精品久久久久久久久| 亚洲欧美在线aaa| xf在线a精品一区二区视频网站| 欧美日韩和欧美的一区二区| 色94色欧美sute亚洲线路二| 91在线观看地址| 色婷婷av一区二区三区gif| 99久久综合99久久综合网站| 不卡电影免费在线播放一区| 国产盗摄视频一区二区三区| 免费成人在线观看| 国产精品自拍网站| 粉嫩欧美一区二区三区高清影视| 国产精品一区二区三区四区| 福利电影一区二区三区| 成人激情av网| 色综合久久99| 欧美亚洲精品一区| 欧美一级久久久久久久大片| 精品国产91乱码一区二区三区| 精品久久久久一区二区国产| 国产婷婷一区二区| 国产精品久久夜| 亚洲男人的天堂在线观看| ...av二区三区久久精品| 五月婷婷激情综合网| 久久国产精品露脸对白| 国产在线视频一区二区三区| 成人福利视频网站| eeuss国产一区二区三区| 欧美色综合网站| 精品久久久三级丝袜| 一区二区三区丝袜| 日韩高清不卡在线| 国产成人8x视频一区二区| 91色在线porny| 91精品在线观看入口| 久久久高清一区二区三区| 国产欧美日韩三区| 亚洲欧美日韩一区二区| 日本不卡视频在线观看| 国产激情一区二区三区| 91国偷自产一区二区三区成为亚洲经典 | 久久免费视频一区| 亚洲色图欧美激情| 麻豆精品视频在线观看视频| 成人免费视频视频| 欧美巨大另类极品videosbest| 日韩一区二区中文字幕| 亚洲一区视频在线观看视频| 国产在线精品免费av| 欧美在线影院一区二区| 久久人人97超碰com| 亚洲婷婷国产精品电影人久久| 亚洲一区二区在线播放相泽| 日韩 欧美一区二区三区| 国产91精品一区二区| 91精品国产综合久久久蜜臀粉嫩| 欧美韩国日本综合| 美日韩黄色大片| 91碰在线视频| 中文字幕一区二区三区视频| 蜜乳av一区二区三区| 91美女精品福利| 久久久久亚洲蜜桃| 视频一区欧美精品| 9色porny自拍视频一区二区| 国产日产欧美精品一区二区三区| 亚洲国产精品久久久久婷婷884| 国产精品1024久久| 日韩一区二区视频在线观看| 一区二区三区四区中文字幕| 国产精品69久久久久水密桃 | 日韩限制级电影在线观看| 亚洲欧洲日产国产综合网| 国产精品 欧美精品| 欧美一区二区三区在线观看| 亚洲一区二区不卡免费| 国产精品99久久久久久久vr| 日韩免费高清电影| 日韩精品免费视频人成| 欧美性猛片aaaaaaa做受| 亚洲人成网站精品片在线观看| 国产91高潮流白浆在线麻豆| 久久精品一区二区三区av| 极品少妇xxxx精品少妇| 亚洲精品一区二区三区99 | 亚洲中国最大av网站| 在线观看不卡一区| 亚洲免费观看高清完整版在线观看熊 | 欧美日韩情趣电影| 国产精品久久久久影院| 99精品视频在线观看| 亚洲人成在线播放网站岛国 | 中文字幕精品一区 | 玉足女爽爽91| 91九色最新地址| 亚洲精品成人在线| 色94色欧美sute亚洲线路一ni| 亚洲精品欧美综合四区| 97se亚洲国产综合自在线观| 免费成人在线视频观看| 亚洲国产精品ⅴa在线观看| 日韩精品一区二区三区蜜臀| 国产米奇在线777精品观看| 久久久99精品免费观看| 成人开心网精品视频| 日本一区二区三级电影在线观看| 国产凹凸在线观看一区二区| 久久色成人在线| 丁香五精品蜜臀久久久久99网站|