什么是瞬时速度| 精神出轨是什么意思| 抑制剂是什么| 微信转账为什么要验证码| 什么动物睡觉不闭眼睛| 什么粉一沾就痒还看不出来| 女生安全期是什么意思| 田七和三七有什么区别| 欣喜若狂是什么意思| 榛子是什么树的果实| 酸菜炒什么好吃| 二尖瓣少量反流是什么意思| 迷离的眼神什么意思| 1966年属什么| 什么什么的沙滩| 3岁打什么疫苗| 去台湾需要什么证件| 小龙虾什么季节吃最好| 办理住院手续需要带什么证件| 什么是干股| 广东古代叫什么| 抖腿是什么毛病| 漂流需要带什么| 精工手表什么档次| cp什么意思网络用语| 斑马吃什么| 灯塔是什么意思| 属羊的是什么星座| 锁骨下面的骨头叫什么| 人人有的是什么生肖| 被舔是什么感觉| 为什么不能抠肚脐眼| 小孩咳嗽吃什么药好| 外阴瘙痒是什么情况| 六五年属什么| peaches是什么意思| 为什么姨妈迟迟不来| img是什么意思| 翡翠和和田玉有什么区别| 早上9点到10点是什么时辰| 壶承是什么| 扁桃体肿大有什么症状| 李五行属性是什么| 人和是什么意思| 高血压需要注意什么| 阳春三月指什么生肖| 天龙八部是什么朝代| 眼睛有重影是什么原因| moncler是什么牌子| 1900年属什么生肖| 什么叫有氧运动和无氧运动| 全麻后需要注意什么| 口苦吃什么好得快| 艾滋病初期皮疹是什么样的| 1月25号是什么星座| 经常手淫对身体有什么危害| 脱肛吃什么药最有效| 1991是什么年| 血清铁蛋白高说明什么| 新斯的明是什么药| 米豆腐是什么做的| 什么是权力| 一呼吸胸口疼是什么原因| 辅警政审主要审些什么| 大便的颜色代表什么| 钠偏低是什么原因| 方兴未什么| 十二月八号是什么星座| 扶她是什么意思| 胃热是什么原因引起的| 喝绿豆汤有什么好处| 尿微量白蛋白高吃什么药| 八字不合是什么生肖| 回笼觉是什么意思| 77是什么意思| 红细胞分布宽度偏高是什么意思| 脾胃寒湿吃什么中成药| 为什么做梦| 男人阴茎硬不起来是什么原因| 大禹的爸爸叫什么| 夏天怕冷是什么原因| 陕西的特产有什么| 什么是飞蚊症| lp 什么意思| 什么是答题卡| 血肿不治疗有什么后果| 黄体功能不足吃什么药| 双花是什么中药| 肺不好有什么症状| 口角炎吃什么药| 女人为什么会得霉菌| 什么是半衰期| 7月29号是什么日子| 拔牙什么时候拔最好| 孕妇胃疼吃什么药| 鱿鱼和什么炒好吃| ch4是什么气体| 什么补钾最快| 乙肝病毒表面抗体弱阳性什么意思| 天伦之乐是什么意思啊| 关节积液是什么原因造成的| 幼儿园报名需要什么资料| 包皮炎挂什么科| 什么是飘窗| 引以为傲是什么意思| 四海是什么意思| 为什么有眼袋是什么原因引起的| 喜欢紫色的女人是什么性格| pp材质是什么材质| 七月有什么水果| 验孕棒什么时候测最准| 月经期喝红糖水有什么好处| plt医学上是什么意思| 一根长寿眉预示什么| 自尊心是什么意思| 内分泌代谢科是看什么病的| 男人下面出汗是什么原因| 什么东西越晒越湿| 结节状高密度影是什么意思| 七月二十二什么日子| lmy是什么意思| 饭圈什么意思| 辣条吃多了有什么危害| 牙齿痛吃什么好| 农历11月18日是什么星座| 蜜糖有什么功效和作用| 头晕去医院看什么科| 事业有成是什么意思| 字母圈是什么意思| 什么情况下必须做胃镜| 有人的地方就有江湖什么意思| 裘皮是什么皮| 王八吃什么| 什么情况需要打破伤风针| 梦见好多西瓜是什么意思| 四肢厥逆是什么意思| 入睡困难是什么原因| 甲状腺穿刺是什么意思| 脚干裂用什么药最好| 一什么书桌| 什么医院才是正规医院| 把你的心我的心串一串是什么歌| 什么是健康证| 腰间盘突出吃什么药| 一个口一个且念什么字| 什么葡萄品种最好吃| 唐僧成了什么佛| 嗳气什么意思| 小孩低烧吃什么药| 红薯什么时候种植最好| 梦见偷玉米是什么意思| 宿醉是什么意思| 口疮是什么原因引起的| 浑身发抖是什么原因| 富贵包挂什么科| 麦麸是什么| 拔智齿后要注意什么| 梦见老公不理我是什么意思| 熠熠生辉是什么意思| 什么争鸣成语| 为什么手机会发烫| 235是什么意思| 人体最大的器官是什么| 幸福是什么的经典语录| 病毒性扁桃体发炎吃什么药| 蓝莓什么时候吃最好| puma是什么意思| 猫需要打什么疫苗| 睡觉磨牙齿是什么原因| 心里堵得慌是什么原因| store是什么| pt是什么时间| 眩晕去医院挂什么科室| 泡蛇酒用什么药材最好| 政字五行属什么| 所以然什么意思| 香草是什么| 洒水车的音乐是什么歌| 最小的一位数是什么| 怎么吃都不胖是什么原因| 什么是花青素| 耳闷耳堵是什么原因引起的| 宇宙的尽头是什么| 实证是什么意思| 胃酸胃烧心吃什么药| 天气热适合吃什么| 我靠是什么意思| 雾化用什么药| 梦见好多猫是什么预兆| 上火喝什么茶| 清新的什么| 经常出鼻血是什么原因| 人为什么会得脑梗| 大腿外侧什么经络| 得艾滋病的前兆是什么| 血红蛋白偏低吃什么补| 樱桃补什么| 曲奇饼干为什么不成形| 知音是什么意思| 吞拿鱼是什么鱼| 白子画什么时候爱上花千骨的| 发光免疫是检查什么的| 小茴香是什么| 扇子骨是什么肉| 打2个喷嚏代表什么| 紫河车是什么东西| 人为什么要吃盐| 什么书在书店里买不到| 滴度是什么意思| 冰妹是什么| 社恐是什么意思| 尿失禁吃什么药最好| 八一是什么节| 长情是什么意思| 运费险是什么意思| 天荒地老是什么生肖| 连什么带什么| 50年属什么| 什么叫佛| 老鹰茶是什么茶| 入坑是什么意思| 上海有什么玩的| 排卵试纸强阳说明什么| 兔死狗烹什么意思| 稀松平常是什么意思| 2001年是什么命| 6月13是什么星座| 红枣和枸杞一起泡水喝有什么作用| 蓝牙耳机什么样的好| 咳嗽有绿痰是什么原因| 轻断食什么意思| 叶公好龙的寓意是什么| 上海最高楼叫什么大厦有多少米高| 天五行属什么| 非萎缩性胃窦炎是什么意思| 梦到狗什么意思| 脊髓空洞症是什么病| 控制血糖吃什么食物| 什么人入什么| 彩超无回声是什么意思| 什么的眉毛| 七月十九是什么星座| ushi是什么品牌男装| acth是什么| 杏仁有什么作用和功效| 可可粉是什么东西| 为什么一直拉肚子| 凤五行属性是什么| 肾宝片有什么副作用吗| 不胜感激是什么意思| blk是什么意思| 美女的胸长什么样| 猫头鹰喜欢吃什么| 骨折吃什么恢复快| 灵芝孢子粉治什么病| 肺部钙化是什么意思啊| 什么叫肾阴虚和肾阳虚| 产后拉肚子是什么原因引起的| 此言差矣是什么意思| 梦见棺材什么意思| 梅核气吃什么药能除根| 糗大了是什么意思| 动车是什么| 食管裂孔疝是什么意思| 百度
 

考试资讯--甘肃频道--人民网

百度 目前被广泛应用的深度学习算法即是一例。

In this tutorial, we will see how to apply a Genetic Algorithm (GA) for finding an optimal window size and a number of units in Long Short-Term Memory (LSTM) based Recurrent Neural Network (RNN).



By Aaqib Saeed, University of Twente

Recently, there has been a lot of work on automating machine learning, from a selection of appropriate algorithm to feature selection and hyperparameters tuning. Several tools are available (e.g.?AutoML?and?TPOT), that can aid the user in the process of performing hundreds of experiments efficiently. Likewise, the deep neural network architecture is usually designed by experts; through a trial and error approach. Although, this approach resulted in state-of-the-art models in several domains but is very time-consuming. Lately, due to increase in available computing power, researchers are employing?Reinforcement Learning?and?Evolutionary Algorithms?to automatically search for optimal neural architectures.

In this tutorial, we will see how to apply a Genetic Algorithm (GA) for finding an optimal window size and a number of units in Long Short-Term Memory (LSTM) based Recurrent Neural Network (RNN). For this purpose, we will train and evaluate models for time-series prediction problem using?Keras. For GA, a python package called?DEAP?will be used. The main idea of the tutorial is to familiarize the reader about employing GA, to find optimal settings automatically; hence, only two parameters will be explored. Moreover, reader’s knowledge (theoretical and applied) about RNNs is assumed. If you are unfamiliar with them, please consult following resources?[1]?and?[2].

The ipython netbook with the complete code is available at the following?link.

 

Genetic Algorithm

 
The genetic algorithm is a heuristic search and an optimization method inspired by the process of natural selection. They are widely used for finding a near optimal solution to optimization problems with large parameter space. The process of evolution of species (solutions in our case) is mimicked, by depending on biologically inspired components e.g. crossover. Furthermore, as it doesn’t take auxiliary information into account, (e.g. derivatives) it can be used for both discrete and continuous optimization.

For using a GA, two preconditions have to be fulfilled, a) a solution representation or defining a chromosome and b) a fitness function to evaluate produced solutions. In our case, a binary array is a genetic representation of a solution (see?Figure 1) and model’s Root-Mean-Square Error (RMSE) on validation set will act a fitness value. Moreover, three basic operations that constitute a GA, are as follows:

  1. Selection: It defines which solutions to preserve for further reproduction e.g. roulette wheel selection.
  2. Crossover: It describes how new solutions are created from existing ones e.g. n-point crossover.
  3. Mutation: Its aim is to introduce diversity and novelty into the solution pool by means of randomly swapping or turning-off solution bits e.g. binary mutation.

Genetic representation of a solution

Occasionally, a technique called “Elitism” is also used, which preserve few best solutions from the population, and pass on to next generation.?Figure 2?depicts a complete genetic algorithm, where, initial solutions (population) are randomly generated. Next, they are evaluated according to a fitness function and selection, crossover and mutation are performed afterwards. This process is repeated for a defined number of iteration (called generations in GA terminology). At the end, a solution with highest fitness score is selected as the best solution. To learn more, please check following resources?[3]?and?[4].

Genetic Algorithm

 

Implementation

 
Now, we have a fair understanding of what GA is and how it works. Next, let’s get to coding.

We will use wind power forecast data, which is available at the following?link. It consists of normalized (between zero and one) wind power measurements from seven wind farms. To keep things simple, we will use first wind farm data (column named?wp1) but I encourage the reader to experiment and extend the code to forecast energy for all seven, wind farms.

Let’s import required packages, load the dataset and define two helper functions. The first method?prepare_dataset?will segment the data into chunks to create?X,?Y?pair for model training. The?X?will the wind power values from the past (e.g.?1?to?t-1) and?Y?will be future value at time?t. The second method?train_evaluate?perform three things, 1) decoding GA solution to get window size and number of units. 2) Prepare the dataset using window size found by GA and divide into train and validation set, and 3) train LSTM model, calculate RMSE on validation set and return it as a fitness score of the current GA solution.

import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split as split

from keras.layers import LSTM, Input, Dense
from keras.models import Model

from deap import base, creator, tools, algorithms
from scipy.stats import bernoulli
from bitstring import BitArray

np.random.seed(1120)


data = pd.read_csv('train.csv')
data = np.reshape(np.array(data['wp1']),(len(data['wp1']),1))

# Use first 17,257 points as training/validation and rest of the 1500 points as test set.
train_data = data[0:17257]
test_data = data[17257:]


def prepare_dataset(data, window_size):
    X, Y = np.empty((0,window_size)), np.empty((0))
    for i in range(len(data)-window_size-1):
        X = np.vstack([X,data[i:(i + window_size),0]])
        Y = np.append(Y,data[i + window_size,0])   
    X = np.reshape(X,(len(X),window_size,1))
    Y = np.reshape(Y,(len(Y),1))
    return X, Y

def train_evaluate(ga_individual_solution):   
    # Decode GA solution to integer for window_size and num_units
    window_size_bits = BitArray(ga_individual_solution[0:6])
    num_units_bits = BitArray(ga_individual_solution[6:]) 
    window_size = window_size_bits.uint
    num_units = num_units_bits.uint
    print('\nWindow Size: ', window_size, ', Num of Units: ', num_units)
    
    # Return fitness score of 100 if window_size or num_unit is zero
    if window_size == 0 or num_units == 0:
        return 100, 
    
    # Segment the train_data based on new window_size; split into train and validation (80/20)
    X,Y = prepare_dataset(train_data,window_size)
    X_train, X_val, y_train, y_val = split(X, Y, test_size = 0.20, random_state = 1120)
    
    # Train LSTM model and predict on validation set
    inputs = Input(shape=(window_size,1))
    x = LSTM(num_units, input_shape=(window_size,1))(inputs)
    predictions = Dense(1, activation='linear')(x)
    model = Model(inputs=inputs, outputs=predictions)
    model.compile(optimizer='adam',loss='mean_squared_error')
    model.fit(X_train, y_train, epochs=5, batch_size=10,shuffle=True)
    y_pred = model.predict(X_val)
    
    # Calculate the RMSE score as fitness score for GA
    rmse = np.sqrt(mean_squared_error(y_val, y_pred))
    print('Validation RMSE: ', rmse,'\n')
    
    return rmse,


Next, use DEAP package to define things to run GA. We will use a binary representation for the solution of length ten. It will be randomly initialized using Bernoulli distribution. Likewise, ordered crossover, shuffle mutation and roulette wheel selection is used. The GA parameter values are initialized arbitrarily; I will suggest you, to play around with different settings.

population_size = 4
num_generations = 4
gene_length = 10

# As we are trying to minimize the RMSE score, that's why using -1.0. 
# In case, when you want to maximize accuracy for instance, use 1.0
creator.create('FitnessMax', base.Fitness, weights = (-1.0,))
creator.create('Individual', list , fitness = creator.FitnessMax)

toolbox = base.Toolbox()
toolbox.register('binary', bernoulli.rvs, 0.5)
toolbox.register('individual', tools.initRepeat, creator.Individual, toolbox.binary, 
n = gene_length)
toolbox.register('population', tools.initRepeat, list , toolbox.individual)

toolbox.register('mate', tools.cxOrdered)
toolbox.register('mutate', tools.mutShuffleIndexes, indpb = 0.6)
toolbox.register('select', tools.selRoulette)
toolbox.register('evaluate', train_evaluate)

population = toolbox.population(n = population_size)
r = algorithms.eaSimple(population, toolbox, cxpb = 0.4, mutpb = 0.1, 
ngen = num_generations, verbose = False)


The K best-found solution via GA can be seen easily seen using?tools.selBest(population,k = 1). Afterward, the optimal configuration can be used to train on the complete training set and test it on holdout test set.

# Print top N solutions - (1st only, for now)
best_individuals = tools.selBest(population,k = 1)
best_window_size = None
best_num_units = None

for bi in best_individuals:
    window_size_bits = BitArray(bi[0:6])
    num_units_bits = BitArray(bi[6:]) 
    best_window_size = window_size_bits.uint
    best_num_units = num_units_bits.uint
    print('\nWindow Size: ', best_window_size, ', Num of Units: ', best_num_units)


# Train the model using best configuration on complete training set 
#and make predictions on the test set
X_train,y_train = prepare_dataset(train_data,best_window_size)
X_test, y_test = prepare_dataset(test_data,best_window_size)

inputs = Input(shape=(best_window_size,1))
x = LSTM(best_num_units, input_shape=(best_window_size,1))(inputs)
predictions = Dense(1, activation='linear')(x)
model = Model(inputs = inputs, outputs = predictions)
model.compile(optimizer='adam',loss='mean_squared_error')
model.fit(X_train, y_train, epochs=5, batch_size=10,shuffle=True)
y_pred = model.predict(X_test)

rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print('Test RMSE: ', rmse)


In this tutorial, we saw how to employ GA to automatically find optimal window size (or lookback) and a number of units to use in RNN. For further learning, I would suggest you, to experiment with different GA parameter configurations, extend genetic representation to include more parameters to explore and share your findings and questions below in the comment section below.

 
References:

  1. Understanding LSTM Networks, by Christopher Olah
  2. Recurrent Neural Networks in Tensorflow I, by R2RT
  3. Genetic Algorithms: Theory and Applications, by Ulrich Bodenhofer
  4. Chapter 9, Genetic Algorithms of Machine Learning book, by Tom M. Mitchell

 
AuthorBio: Aaqib Saeed is a graduate student of Computer Science (specializing in Data Science and Smart Services) at University of Twente (The Netherlands).

Original. Reposted with permission.

Related:



脑动脉硬化是什么意思 嗓子不舒服吃什么水果 小腿麻木是什么原因 手球是什么运动 扁平疣用什么药
梦见手机坏了是什么意思 虾米吃什么 两岁宝宝不会说话但什么都知道 烂嘴角是缺什么维生素 红花泡水喝有什么功效
什么样的人死后还会出现 育红班是什么意思 医学cr是什么意思 红花是什么 玫瑰和月季有什么区别
破关是什么意思 梦见做饭是什么意思 嘌呤是什么东西 落花生是什么意思 吃马齿苋有什么好处
懒散是什么意思hcv8jop5ns4r.cn 桃花像什么hcv9jop2ns4r.cn 相亲为什么不能拖太久hcv7jop5ns2r.cn 97年什么生肖hcv9jop6ns8r.cn 什么时候洗头最好beikeqingting.com
医院特需号是什么意思hcv8jop7ns9r.cn 出cos是什么意思sscsqa.com 208是什么意思imcecn.com 鱼喜欢吃什么hcv8jop5ns4r.cn 什么症状需要做肠镜hcv8jop6ns1r.cn
受精卵发育成什么hcv9jop1ns2r.cn 寒包火感冒吃什么药hcv9jop8ns0r.cn 黄体酮吃多了有什么副作用hcv7jop6ns2r.cn 失心疯是什么意思hcv7jop6ns9r.cn 非什么意思hcv7jop9ns1r.cn
雷声什么hcv8jop9ns3r.cn 来袭是什么意思hcv8jop4ns1r.cn 什么是晶体hcv9jop2ns1r.cn 囟门凹陷是什么原因cl108k.com 特别出演什么意思hcv7jop6ns1r.cn
百度