如何找到最好的人口(gStar)

时间:2018-04-23 10:02:14

标签: python python-3.x machine-learning neural-network evolutionary-algorithm

如何从随机人群中找到最佳人口(gStar),然后从最佳人口中打印权重,我想使用FPA优化最佳人口,对不起,我是新手

#FP Parameters
num_train = len(X_trainNorm)
input_dim = windowSize
output_dim = 1


popSize = 5

#Model of JST
def buildModel(hidden_dim):
    np.random.seed(7)
    pop = []
    for i in range(popSize):
        W1 = np.random.randn(input_dim, hidden_dim) / np.sqrt(input_dim)
        b1 = np.zeros((1, hidden_dim))
        W2 = np.random.randn(hidden_dim, output_dim) / np.sqrt(hidden_dim)
        b2 = np.zeros((1, output_dim))
        pop.append((W1, W2, b1, b2))
    return pop

buildModel(10)

#Find the best population
def gStar(Weight1, Weight2, bias1, bias2):
    z1 = X_trainNorm.dot(Weight1) + bias1
    a1 = np.tanh(z1)
    z2 = a1.dot(Weight2) + bias2
    target = np.reshape(y_trainNorm,(-1,1))
    error = 0
    error = abs(z2-target)
    tot_error = sum(error)
    print (tot_error)

0 个答案:

没有答案