您的位置:首页 > 其它

Linearization of the kernel functions in SVM

2016-12-06 10:22 489 查看
SVM(Support Vector Machine)is an important classification tool, which has a wide range of applications in cluster analysis, community division and so on. SVM The kernel functions used in SVM have many forms. Here we only discuss the function of the form f(x,y,z)
= ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j. By introducing new variables p, q, r, u, v, w, the linearization of the function f(x,y,z) is realized by setting the correspondence x^2
<-> p, y^2 <-> q, z^2 <-> r, xy
<-> u, yz <-> v, zx <-> w and the function f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j can be written as g(p,q,r,u,v,w,x,y,z) = ap + bq + cr + du + ev + fw + gx + hy + iz + j, which is
a linear function with 9 variables.

Now your task is to write a program to change f into g. InputThe input of the first line is an integer T, which is the number of test data (T<120). Then T data follows. For each data, there are 10 integer numbers on one line, which are the coefficients and constant a, b, c, d, e, f, g, h, i, j of the function f(x,y,z)
= ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j.OutputFor each input function, print its correspondent linear function with 9 variables in conventional way on one line.Sample Input
2
0 46 3 4 -5 -22 -8 -32 24 27
2 31 -5 0 0 12 0 0 -49 12

Sample Output
46q+3r+4u-5v-22w-8x-32y+24z+27
2p+31q-5r+12w-49z+12


模拟:


用的笨方法,由于没考虑那么全,导致WA了好多遍,要注意1,-1,全为0的时候结果是0,为1或-1时,只写字母就行了,1,-1不用显现出来


#include<stdio.h>
long long int a[100];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int sum=0;
int we;
for(int i=1;i<=10;i++)
{
scanf("%lld",&a[i]);
if(a[i]==0)
{
sum++;
}
}
for(int i=1;i<=10;i++)
{
if(a[i]!=0)
{
we=i;
break;
}
}
if(sum==10)
{
printf("0\n");
}
else
{
if(a[1]!=0)
{
if(a[1]==1)
printf("p");
else if(a[1]==-1)
printf("-p");
else
printf("%dp",a[1]);
}
if(a[2]!=0)
{
if(a[2]>1&&2>we)
printf("+%lldq",a[2]);
else if(a[2]==1&&2>we)
printf("+q");
else if(a[2]==1&&2<=we)
printf("q");
else if(a[2]==-1)
printf("-q");
else
printf("%lldq",a[2]);

}

if(a[3]!=0)
{
if(a[3]>1&&3>we)
printf("+%lldr",a[3]);
else if(a[3]==1&&3>we)
printf("+r");
else if(a[3]==1&&3<=we)
printf("r");
else if(a[3]==-1)
printf("-r");
else
printf("%lldr",a[3]);

}

if(a[4]!=0)
{
if(a[4]>1&&4>we)
printf("+%lldu",a[4]);
else if(a[4]==1&&4>we)
printf("+u");
else if(a[4]==1&&4<=we)
printf("u");
else if(a[4]==-1)
printf("-u");
else
printf("%lldu",a[4]);

}

if(a[5]!=0)
{
if(a[5]>1&&5>we)
printf("+%lldv",a[5]);
else if(a[5]==1&&5>we)
printf("+v");
else if(a[5]==1&&5<=we)
printf("v");
else if(a[5]==-1)
printf("-v");
else
printf("%lldv",a[5]);

}

if(a[6]!=0)
{
if(a[6]>1&&6>we)
printf("+%lldw",a[6]);
else if(a[6]==1&&6>we)
printf("+w");
else if(a[6]==1&&6<=we)
printf("w");
else if(a[6]==-1)
printf("-w");
else
printf("%lldw",a[6]);

}

if(a[7]!=0)
{
if(a[7]>1&&7>we)
printf("+%lldx",a[7]);
else if(a[7]==1&&7>we)
printf("+x");
else if(a[7]==1&&7<=we)
printf("x");
else if(a[7]==-1)
printf("-x");
else
printf("%lldx",a[7]);

}
if(a[8]!=0)
{
if(a[8]>1&&8>we)
printf("+%lldy",a[8]);
else if(a[8]==1&&8>we)
printf("+y");
else if(a[8]==1&&8<=we)
printf("y");
else if(a[8]==-1)
printf("-y");
else
printf("%lldy",a[8]);
}
if(a[9]!=0)
{
if(a[9]>1&&9>we)
printf("+%lldz",a[9]);
else if(a[9]==1&&9>we)
printf("+z");
else if(a[9]==1&&9<=we)
printf("z");
else if(a[9]==-1)
printf("-z");
else
printf("%lldz",a[9]);
}

if(a[10]!=0)
{
if(a[10]>1&&10>we)
printf("+%lld",a[10]);
else if(a[10]==1&&10>we)
printf("+1");
else if(a[10]==1&&10<=we)
printf("1");
else if(a[10]==-1)
printf("-1");
else
printf("%lld",a[10]);

}
printf("\n");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: