Linearization of the kernel functions in SVM

本文探讨了支持向量机(SVM)中特定形式核函数的线性化方法,并提供了一个将二次多项式形式的核函数转换为线性函数的程序实现。通过引入新变量,实现了函数f(x,y,z)的线性化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                        Linearization of the kernel functions in SVM

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.

Input The 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. Output For 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

这个题所揭露的是考虑特殊情况不全面,且写代码能力不强,经常出现编译错误!

该题需注意的地方:1、输出中  第一个不为零的数前面没有加号。2、零不输出,如果所有的数都是零,则只输出一个空行。 3、如果系数为一,则不输出1,除非是最后的常数位。

AC代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
int main()
{
    long long int t,num[15],i,p,j,w;
    char c;
    scanf("%lld",&t);
    for(i=1;i<=t;i++)
    {
        w=0;
        for(j=0;j<10;j++)
            scanf("%lld",&num[j]);
        for(j=0,c='p';j<10;j++,c++)
        {
            if(c=='s')
                c+=2;
            if(num[j]==0)
                continue;
            else if(num[j]>0)
            {
                if(j!=0&&w==1)
                    printf("+");
                if(num[j]!=1||j==9)
                    printf("%lld",num[j]);
                if(j<9)
                    printf("%c",c);
                w=1;
            }
            else if(num[j]<0)
            {
                w=1;
                if(num[j]!=-1||j==9)
                    printf("%lld",num[j]);
                if(num[j]==-1&&j!=9)
                    printf("-");
                if(j<9)
                    printf("%c",c);
            }
        }
        putchar('\n');
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值