克隆策略
In [1]:
from scipy.optimize import minimize
import numpy as np
In [2]:
matrix = np.array([
    [0,1,2,1,2],
    [0,1,3,2,3],
    [5,2,3,3,5],
    [10,3,3,4,12],
    [20,5,2,5,15],
    [25,8,4,6,20],
    [23,7,2,7,18],
    [20,6,4,8,16],
    [8,4,2,9,12],
    [2,1,3,10,8],
    [0,1,2,11,4],
    [0,1,2,12,3]
])
In [3]:
corrcoef = np.corrcoef(np.transpose(matrix))
relevancy = np.transpose(corrcoef)[0][1:]
In [4]:
#set initial to all dimensions on
x0 = [1,1,1,1]
In [5]:
#minimize the redundancy minus relevancy

fun = lambda x: sum([corrcoef[i+1, j+1] * x[i] * x[j] for i in range(len(x)) for j in range(len(x))]) / (sum(x) ** 2) - (sum(relevancy * x) / sum(x))
    
In [6]:
res = minimize(fun, x0, bounds=((0,1), (0,1), (0,1), (0,1)))
In [7]:
res.x
Out[7]:
array([ 0.99868791,  0.29757473,  0.32868714,  0.        ])