资源简介
核典型相关分析python实现,
代码片段和文件信息
import numpy
from numpy import dot eye ones zeros
import scipy.linalg
from kernel_icd import kernel_icd
from kernels import LinearKernel
class KCCA(object):
“““An implementation of Kernel Canonical Correlation Analysis.
“““
def __init__(self kernel1 kernel2 regularization method = ‘kettering_method‘
decomp = ‘full‘ lrank = None
scaler1 = None
scaler2 = None
max_variance_ratio = 1.0):
if decomp not in (‘full‘ ‘icd‘):
raise ValueError(“Error: valid decom values are full or icd received: “+str(decomp))
self.kernel1 = kernel1
self.kernel2 = kernel2
self.reg = regularization
self.method = getattr(self decomp + “_“ + method)
self.decomp = decomp
self.lrank = lrank
self.alpha1 = None
self.alpha2 = None
self.trainX1 = None
self.trainX2 = None
self.max_variance_rato = max_variance_ratio
if scaler1 is not None:
if hasattr(scaler1 “transform“): #sklearn scaler
self.scaler1 = scaler1.transform
else: #assume callable function
self.scaler1 = scaler1
else:
self.scaler1 = None
if scaler2 is not None:
if hasattr(scaler2 “transform“): #sklearn scaler
self.scaler2 = scaler2.transform
else: #assume callable function
self.scaler2 = scaler2
else:
self.scaler2 = None
def full_standard_hardoon_method(self K1 K2 reg):
N = K1.shape[0]
I = eye(N)
Z = numpy.zeros((NN))
R1 = numpy.c_[Z dot(K1 K2)]
R2 = numpy.c_[dot(K2 K1) Z]
R = numpy.r_[R1 R2]
D1 = numpy.c_[dot(K1 K1 + reg*I) Z]
D2 = numpy.c_[Z dot(K2 K2 + reg*I)]
D = 0.5*numpy.r_[D1 D2]
return (R D)
def full_simplified_hardoon_method(self K1 K2 reg):
N = K1.shape[0]
I = eye(N)
Z = numpy.zeros((NN))
R1 = numpy.c_[Z K2]
R2 = numpy.c_[K1 Z]
R = numpy.r_[R1 R2]
D1 = numpy.c_[K1 + reg*I Z]
D2 = numpy.c_[Z K2 + reg*I]
D = numpy.r_[D1 D2]
return (R D)
def full_kettering_method(self K1 K2 reg):
N = K1.shape[0]
I = eye(N)
Z = numpy.zeros((NN))
R1 = numpy.c_[K1 K2]
R2 = R1
R = 1./2 * numpy.r_[R1 R2]
D1 = numpy.c_[K1 + reg*I Z]
D2 = numpy.c_[Z K2 + reg*I]
D = numpy.r_[D1 D2]
return (R D)
#def kcca(self K1 K2):
##remove the mean in features space
#N = K1.shape[0]
#N0 = eye(N) - 1./N * ones(N)
#if self.scaler1 is None:
#K1 = dot(dot(N0K1)N0)
#if self.scaler2 is None:
#K2 = dot(dot(N0K2)N0)
#R D = self.method(K1 K2 self.reg)
##solve generalized eigenvalues problem
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-16 01:34 PyKCCA-master\
文件 303 2019-01-16 01:34 PyKCCA-master\.gitignore
文件 77 2019-01-16 01:34 PyKCCA-master\README.md
文件 66 2019-01-16 01:34 PyKCCA-master\__init__.py
文件 13528 2019-01-16 01:34 PyKCCA-master\kcca.py
文件 2763 2019-01-16 01:34 PyKCCA-master\kernel_icd.py
文件 2758 2019-01-16 01:34 PyKCCA-master\kernels.py
评论
共有 条评论