讲解:MSc、Python、program、PythonHaskell|R

Advanced Aspects of Nature Inspired Search and Optimisation 2019/2020Lab 2 MSc: Time Series Prediction with GPNB! This coursework is only compulsory for MSc students taking the 20cr module.We released a different Lab 2 with an earlier deadline for UG students taking the20cr module.You need to implement one program that solves Exercises 1-3 using any programming language.In Exercise 5, you will run a set of experiments and describe the result using plots and a shortdiscussion.(In the following, replace abc123 with your username.) You need to submit one zip file withthe name niso3-abc123.zip. The zip file should contain one directory named niso3-abc123containing the following files:❼ the source code for your program❼ a Dockerfile (see the appendix for instructions)❼ a PDF file for Exercises 4 and 51In this lab, we will do a simple form of time series prediction. We assume that we are given somehistorical data, (e.g. bitcoin prices for each day over a year), and need to predict the next value inthe time series (e.g., tomorrow’s bitcoin value).We formulate the problem as a regression problem. The training data consists of a set of minput vectors X = (x(0), . . . , x(m−1)) representing historical data, and a set of m output valuesY = (x(0), . . . , x(m−1)), where for each 0 ≤ j ≤ m − 1, x(j) ∈ Rn and y(j) ∈ R. We will use geneticprogramming to evolve a prediction model f : Rn → R, such that f(x(j)) ≈ y(j).Candidate solutions, i.e. programs, will be represented as expressions, where each expression evaluatesto a value, which is considered the output of the program. When evaluating an expression,we assume that we are given a current input vector x = (x0, . . . , xn−1) ∈ Rn. Expressions and evaluationsare defined recursively. Any floating number is an expression which evaluates to the valueof the number. If e1, e2, e3, and e4 are expressions which evaluate to v1, v2, v3 and v4 respectively,then the following are also expressions❼ (add e1 e2) is addition which evaluates to v1 + v2, e.g. (add 1 2)≡ 3❼ (sub e1 e2) is subtraction which evaluates to v1 − v2, e.g. (sub 2 1)≡ 1❼ (mul e1 e2) is multiplication which evaluates to v1v2, e.g. (mul 2 1)≡ 2❼ (div e1 e2) is division which evaluates to v1/v2 if v2 6= 0 and 0 otherwise, e.g., (div 4 2)≡ 2,and (div 4 0)≡ 0,❼ (pow e1 e2) is power which evaluates to vv21, e.g., (pow 2 3)≡ 8❼ (sqrt e1) is the square root which evaluates to √v1, e.g.(sqrt 4)≡ 2❼ (log e1) is the logarithm base 2 which evaluates to log(v1), e.g. (log 8)≡ 3❼ (exp e1) is the exponential function which evaluates to ev1, e.g. (exp 2)≡ e2 ≈ 7.39❼ (max e1 e2) is the maximum which evaluates to max(v1, v2), e.g., (max 1 2)≡ 2❼ (ifleq e1 e2 e3 e4) is a branching statement which evaluates to v3 if v1 ≤ v2, otherwise theexpression evaluates to v4 e.g. (ifleq 1 2 3 4)≡ 3 and (ifleq 2 1 3 4)≡ 4❼ (data e1) is the j-th element xj of the input, where j ≡ |bv1c| mod n.❼ (diff e1 e2) is the difference xk − x` where k ≡ |bv1c| mod n and ` ≡ |bv2c| mod n❼ (avg e1 e2) is the average 1|k−`|Pmax(k,`)−1t=min(k,`)xt where k ≡ |bv1c| mod n and ` ≡ |bv2c|mod nIn all cases where the mathematical value of an expression is undefined or not a real number (e.g.,√−1, 1/0 or (avg 1 1)), the expression should evaluate to 0.We can build large expressions from the recursive definitions. For example, the expression(add (mul 2 3) (log 4))2evaluates to2 · 3 + log(4) = 6 + 2 = 8.To evaluate the fitness of an expression e on a training data (X , Y) of size m, we use the meansquare error is the value of the expression e when evaluated on the input vector x(j).3Exercise 1. (30 % of the marks)Implement a routine to parse and evaluate expressions. You can assume that the input describes asyntactically correct expression. Hint: Make use of a library for parsing s-expressions1, and ensurethat you evaluate expressions exactly as specified on page 2.Input arguments:❼ -expr an expression❼ -n the dimension of the input vector n❼ -x the input vectorOutput:❼ the value of the expressionExample:[pkl@phi ocamlec]$ niso_lab3 -question 1 -n 1 -x 1.0 \-expr (mul (add 1 2) (log 8))9.0[pkl@phi ocamlec]$ niso_lab3 -question 1 -n 2 -x 1.0 2.0 \-expr (max (data 0) (data 1))2.0Exercise 2. (10 % of the marks) Implement a routine which computes the fitness of an expressiongiven a training data set.Input arguments:❼ -expr an expression❼ -n the dimension of the input vector❼ -m the size of the training data (X , Y)❼ -data the name of a file containing the training da代写MSc留学生作业、代做Python编程语言作业、program课程作业代写、Python实验作业代做 帮做Hasketa in the form of m lines, where each linecontains n + 1 values separated by tab characters. The first n elements in a line representsan input vector x, and the last element in a line represents the output value y.Output:❼ The fitness of the expression, given the data.1See e.g. implementations here http://rosettacode.org/wiki/S-Expressions4Exercise 3. (30 % of the marks)Design a genetic programming algorithm to do time series forecasting. You can use any geneticoperators and selection mechanism you find suitable.Input arguments:❼ -lambda population size❼ -n the dimension of the input vector❼ -m the size of the training data (X , Y)❼ -data the name of a file containing training data in the form of m lines, where each linecontains n + 1 values separated by tab characters. The first n elements in a line representsan input vector x, and the last element in a line represents the output value y.❼ -time budget the number of seconds to run the algorithmOutput:❼ The fittest expression found within the time budget.Exercise 4. (10 % of the marks)Describe your algorithm from Exercise 3 in the form of pseudo-code. The pseudo-code should besufficiently detailed to allow an exact re-implementation.Exercise 5. (20 % of the marks)In this final task, you should try to determine parameter settings for your algorithm which lead toas fit expressions as possible.Your algorithm is likely to have several parameters, such as the population size, mutation rates,selection mechanism, and other mechanisms components, such as diversity mechanisms.Choose parameters which you think are essential for the behaviour of your algorithm. Run a set ofexperiments to determine the impact of these parameters on the solution quality. For each parametersetting, run 100 repetitions, and plot box plots of the fittest solution found within the time budget.5A. Docker HowtoFollow these steps exactly to build, test, save, and submit your Docker image. Please replace abc123in the text below with your username.1. Install Docker CE on your machine from the following website:https://www.docker.com/community-edition2. Copy the PDF file from Exercises 4 and 5 all required source files, and/or bytecode to anempty directory named niso2-abc123 (where you replace abc123 with your username).mkdir niso2 - abc123cd niso2 - abc123 /cp ../ exercise . pdf .cp ../ abc123 . py .3. Create a text file Dockerfile file in the same directory, following the instructions below.# Do not change the following line . It specifies the base image which# will be downloaded when you build your image .FROM pklehre / niso2020 - lab2 - msc# Add all the files you need for your submission into the Docker image ,# e . g . source code , Java bytecode , etc . In this example , we assume your# program is the Python code in the file abc123 . py . For simplicity , we# copy the file to the / bin directory in the Docker image . You can add# multiple files if needed .ADD abc123 . py / bin# Install all the software required to run your code . The Docker image# is derived from the Debian Linux distribution . You therefore need to# use the apt - get package manager to install software . You can install# e . g . java , python , ghc or whatever you need . You can also# compile your code if needed .# Note that Java and Python are already installed in the base image .# RUN apt - get update# RUN apt - get -y install python - numpy# The final line specifies your username and how to start your program .# Replace abc123 with your real username and python / bin / abc123 . py# with what is required to start your program .CMD [ - username , abc123 , - submission , python / bin / abc123 . py ]64. Build the Docker image as shown below. The base image pklehre/niso2019-lab3 will bedownloaded from Docker Hubdocker build . -t niso2 - abc1235. Run the docker image to test that your program starts. A battery of test cases will be executedto check your solution.docker run niso2 - abc1236. Once you are happy with your solution, compress the directory containing the Dockerfile asa zip-file. The directory should contain the source code, the Dockerfile, and the PDF file forExercise 4 and 5. The name of the zip-file should be niso2-abc123.zip (again, replace theabc123 with your username).Following the example above, the directory structure contained in the zip file should be asfollows:niso2-abc123/exercise.pdfniso2-abc123/abc123.pyniso2-abc123/DockerfileSubmissions which do not adhere to this directory structure will be rejected!7. Submit the zip file niso2-abc123.zip on Canvas.7转自:http://www.daixie0.com/contents/3/4877.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容

  • By clicking to agree to this Schedule 2, which is hereby ...
    qaz0622阅读 1,419评论 0 2
  • 戴着翡翠戒指腌萝卜干,这种不着调的事情我想也只有我才干得出来。于是这萝卜干的成本就巨大了,差一点就成了翡翠腌...
    苏州的蔷薇花开阅读 459评论 10 3
  • 瘦人碗子阅读 238评论 0 1
  • 晚上给妈妈打电话,妈妈问我什么时候回家,家里的黄皮果还给我留着。说到黄陂皮,我就想起了那金灿灿的颜色,甜酸甜酸的味...
    向行阅读 1,326评论 6 5
  • 田将军出生在一个战争不止,狼烟不熄的年代,但幸运的是田将军的国家还算强大,在近三百年无休止的战争中,依旧保持上风。...
    猫说它很冷阅读 611评论 0 0