资源简介
SVM PSO 通过粒群算法择优选择支持向量机的敏感参数
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#define ulong unsigned long // For KISS pseudo random numbers generator
#define RAND_MAX_KISS 4294967295ul // idem
// You don‘t need KISS if you have a good rand() function
double x[100][2] v[100][2] fitness_lbest[100] X_lbest[100][2] X_gbest[2] fitness_X[100];
double fitness_gbest c1 c2r1r2w;
double fitness_gbest_old gamma;
double f_rand();
ulong rand_kiss();
void seed_rand_kiss(ulong seed);
double alea(double adouble b);
double phi s rmax; // Control exploration/exploitation
void main()
{
FILE *chkdsk;
int n nitit i jmax_fitness_indexrt;
double c_min c_max g_min g_maxmax_fitnessvl = 5;
char pr[] = “svmtrain “;
//char fin[] = “ heart_scale“;
//char fin[] = “ train1.scale“;
//char fin[] = “ train2.scale“;
//char fin[] = “ train3.scale“;
char fin[] = “ sptest.scale“;
//char fin[] = “ spect_train.txt“;
c_min = 1 / pow(25); c_max = pow(28);
g_min = 1 / pow(215); g_max = pow(23);
c1 = 1.5; c2 = 1.5;w=0.5;gamma = 0.1;
//c1 = 2; c2 = 2;w=0.8;gamma = 0.1;
srand( (unsigned)time( NULL ) );
//seed_rand_kiss(1); // Initialize KISS
fflush(stdin);
cout<<“Enter the number of particles : “;
cin>>n;
cout<<“Enter the number of iteration is : “;
cin>>it;
cout<<“Enter the number of exactly is is: “;
cin>>gamma;
// Initialize the particle positions and their velocities
for (i=0;i {
//r1 = alea(c_minc_max);
//r2 = f_rand();
//x[i][0] = alea(c_minc_max);
//x[i][1] = alea(g_ming_max);
r1 = f_rand();
r2 = f_rand();
x[i][0] = c_min + (c_max - c_min) * r1;
x[i][1] = g_min + (g_max - g_min) * r2;
v[i][0] = 0;
v[i][1] = 0;
}
int d1d2pq;
d1 = 0; d2 = 1;
s = sqrt(pow(x[d1][0] - x[d2][0]2) + pow(x[d1][1] - x[d2][1]2));
for (p=0; p {
for (q=p+1;q {
if (sqrt(pow(x[p][0] - x[q][0]2) + pow(x[p][1] - x[q][1]2)) > s)
s = sqrt(pow(x[p][0] - x[q][0]2) + pow(x[p][1] - x[q][1]2));
}
}
// Initialize the global and local fitness to the worst possible
fitness_gbest = 0;
for (i = 0; i < n; i++)
{
fitness_lbest[i] = 0;
}
// Loop until convergence in this example a finite number of iterations chosen
nit = 0;
do//for (p = 0; p < nit; p++)
{
//fitness_gbest_old = fitness_gbest;
// evaluate the fitness of each particle
nit +=1;
for (i = 0; i < n;i++)
{
char psBuffer[128];
char cmd[200];
int k;
double cx;
if (x[i][0] >= c_min && x[i][0] <= c_max && x[i][1] >= g_min && x[i][1] <= g_max)
{
k = sprintf(cmd “%s“ pr);
k += sprintf(cmd + k “ -c %f“ x[i][0]);
k += sprintf(cmd + k “ -g %f“ x[i][1]);
k += sprintf(cmd + k “ -v %f“ vl);
k += sprintf(cmd + k “%s“ fin);
if( (chkdsk = _popen(cmd “rt“ )) == NULL )
{// exit( 1 );
- 上一篇:日历记事本C++语言面向对象思想
- 下一篇:Bresenham直线算法的C++实现
相关资源
- libsvm-3.21
- c语言写的svm程序
- PSO算法C++实现
- SVM算法C++代码
- C++实现opencv+yolo+tensorflow+deepsort.txt
- PSO-LS-SVM代码
- Opencv2.4.12 SVM手写数字识别
- svm_smo_多分类_c++
- libsvm工具箱libsvm-3.22版
- libsvm
- 基于SVM与BoW的图片分类的OpenCV实现-
- Opencv3.0 手写数字识别Hog特征+SVM分类器
- 纯C语言 实现SVM,VS工程,亲测可用
- 基于SVM的文本分类源代码,C++
- 人脸识别svm+pcaopencv3
- 协同粒子算法CPSO
- MOPSO算法代码
- OpenCV机器学习SVM支持向量机的分类程
评论
共有 条评论