📄 result.cpp.bak
字号:
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
//#include <fstream.h>
#include <float.h>
//#include "initializeTraining.h"
//#include "learn.h"
#include "result.h"
typedef struct feature{
int id;
float value;
}Feature;
typedef struct feature * FeaturePtr;
extern FeaturePtr **example;
extern int * target;
extern double * lambda;
extern int *nonZeroFeature;
extern double *error;
extern int *nonBound;
extern double *weight;
extern int numExample;
extern int maxFeature;
extern int numNonBound;
extern int *unBoundIndex;
extern int dataSetSize;
extern int *errorCache;
extern int *nonZeroLambda;
extern double C;
extern double b;
extern int degree;
extern int kernelType;
extern double sigmaSqr;
extern double rbfConstant;
extern double iteration;
extern double totalIteration;
extern int binaryFeature;
void writeModel(FILE * out)
{
int i,j, numSv;
numSv=0; unBoundSv=0;boundSv=0;
//find out the number of support vectors ,both bound and unbound
for(i =1;i<=numExample;i++){
if(lambda[i]>0){
numSv++;
if(lambda[i]<C)
unBoundSv++;
else
boundSv++;
}
}
//write to the model file
if(kernelType ==0)
fprintf(out,"%d #Linear \n",0); //fprintf(stderr,"%d #Linear \n",0);
else if(kernelType ==1)
fprintf(out,"%d %d # Polynomial with degree %d\n",1,degree,degree);
else if (kernelType ==2)
fprintf(out,"%d %f #rbf with variance %f\n",2,sigmaSqr,sigmaSqr);
fprintf(out,"%d # Number of features\n",maxFeature);
if(kernelType ==0){
for(i=1;i<=maxFeature;i++)
fprintf(out,"%f ",weight[i]);
fprintf(out,"#weight vector\n");
}
fprintf(out,"%6.5f #Threshold b\n",b);
fprintf(out,"%6.5f #C parameter\n",C);
fprintf(out,"%d #Number of support vectors\n",numSv);
/***write the value of (class label*lambda)**/
if(numSv !=0){
for(i=1;i<=numExample;i++){
if(lambda[i]>0){
if(target[i]==1)
fprintf(out,"%.5f ",lambda[i]);
else if(target[i]==-1)
fprintf(out,"%.5f ",-lambda[i]);
for (j=0;j<nonZeroFeature[i];j++)
fprintf(out,"%d : %.5f ",example[i][j]->id,example[i][j]->value);
fprintf(out,"\n");
}
}
}
}
double calculateNorm(void)
{
int i;
double n;
n=0;
for(i=1;i<=maxFeature;i++)
n+=weight[i]*weight[i];
return sqrt(n);
}
double getb(void)
{
return b;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -