线性和高斯kernel 计算函数

使用示例:

kparam.kernel_type = 'gaussian';
[K, param] = getKernel(features, kparam);

%features: 500*100;

%labels:100*1


摘自:

% This is an example code in
%Wen LI, Lixin DUAN, Dong XU and Ivor W. Tsang,
%"Learning with Augmented Features for Supervised and Semi-supervised Heterogeneous Domain Adaptation," T-PAMI 2013.


kernel 主函数: (其他函数请去资源页面下载:http://download.csdn.net/detail/yihaizhiyan/7125615)Thanks~

function [kernel param] = getKernel(featuresA, featuresB, param)

% compute a kernel, it can be K(A, A) or K(A, B)
% Usage:
%  1. Compute the kernel between different examples, e.g. in testing:
%   [kernel param] = getKernel(featuresA, featuresB, param)
%  2. Compute the kernel between the sample exaples, e.g. in training:

%   [kernel param] = getKernel(features, param)

%
% Input:
%   featuresA: d-by-m matrix, d is feature dimension, m is the number of
%   samples
%   featuresB: d-by-n matrix, d is feature dimension, m is the number of
%   samples
%   param:  -kernel_type:
%               'linear', 'gaussian'
%           -(gaussian)ratio, sigma, gamma
%
% Output:
%   kernel: m-by-n or m-by-m matrix
%   param: depends on the kernel type
%
%  by LI Wen on Jan 04, 2012
%


if (nargin < 2)
    error('Not enough inputs!\n');
elseif (nargin < 3)
    param = featuresB;
    featuresB = featuresA;
end


if(~isfield(param, 'kernel_type'))
    error('Please specify the kernel_type!\n');
end


kernel  = [];
kt      = lower(param.kernel_type);
if(strcmp(kt, 'linear'))
    kernel = return_LinearKernel(featuresA, featuresB);
elseif(strcmp(kt, 'gaussian'))
    [kernel param] = return_GaussianKernel(featuresA, featuresB, param);
else
    error('Unknown type of kernel: %s.\n', param.kernel_type);
end
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值