如何进化生活在计算机中使用Python_第1页
如何进化生活在计算机中使用Python_第2页
如何进化生活在计算机中使用Python_第3页
如何进化生活在计算机中使用Python_第4页
如何进化生活在计算机中使用Python_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

HowtoEvolveLifeinaComputerusingPython

BertChan

BigDataConsultant@ASL

PyConHK/CodeConf2018

Programminginthe1990’s

PC:80286(8MHz,8MBRAM)

OS:MS-DOS(Win3.1tooslow!)

Pascal

Simulatelife

Simulategravity,fractals

Hack&decodegames

Assembly

Mainloop–veryfast!

Directwritetovideocache

Ifyoudidcodingandhackedstuffsinthe90’s,you’rea…

SimulateLife

Conway’sGameofLife

JohnConway1970

CellularAutomata–arrayofcells(0or1)

Neighborhood(8cells,sum)

Simpleif-then-elserule

forcellincells:

ifcell==1andsumin[2,3]:cell=1 #surviveelifcell==0andsumin[3]:cell=1 #bornelse:cell=0 #die

cell:0or1

1

0 0

0

1

1

0

0

0

neighborhood

Conway’sGameofLife

Themovingglider

Greencellssurvive,bluecellsareborn,redcellsdie

Spaceships,glidergun…

Logicgate,clock,computer…

Hackersloveit!

Goodwaytolearnprogramming!

Playwiththerules

Whatifwe…

cell:0or1

0

0 0

0

1

0

0

0

0

neighborhood(n)

sum=σ𝑛

cell=(ifsum…then…else…)

Playwiththerules

Whatifwe…

Usefloatingpoint?

realnumber

0.12

0.02 0.00

0.95

0.36

0.17

0.46

0.53

0.22

neighborhood(n)

sum=σ𝑛

cell=(ifsum…then…else…)

Playwiththerules

Whatifwe…

Usefloatingpoint?

Biggerneighborhood?Circular?

realnumber

0.36

neighborhood(n)

sum=σ𝑛

cell=(ifsum…then…else…)

Playwiththerules

Whatifwe…

Usefloatingpoint?

Biggerneighborhood?Circular?

Weightedsum?

realnumber

*

neighborhood(n) weights(k)

sum=σ𝑛𝑘

cell=(ifsum…then…else…)

Playwiththerules

realnumber

Whatifwe…

Usefloatingpoint?

Biggerneighborhood?Circular?

Weightedsum?

Smoothupdate?

*

neighborhood(n)

weights(k)

sum=σ𝑛𝑘

cell=cell+0.1*f(sum)

Playwiththerules

Whatifwe…

Usefloatingpoint?

Biggerneighborhood?Circular?

Weightedsum?

Smoothupdate?

Spookythingshappened…

OMGWHATISTHIS??

Lenia

NewkindofArtificialLife

Microorganism-likecreatures

Discovered400+species

Studytheiranatomy,behavior,physiology…

Goodprogrammingexercise

JavaScript,C#,MATLAB,Python

Video

Pythonshowcasevideo

/277328815

Kyoto

WonGECCOVirtualCreaturesContest,Kyoto

HonorableMentioninALIFEArtAward,Tokyo

MeetmyAIhero–@hardmaru

DavidHa(GoogleBrainTokyo)

UsingPython

forPyConHK

WhyPython?

Goodperformance

Fastcoding

Nicesyntax(indent,listcomprehension,etc)

Lotsofusefullibraries

Vibrantcommunity(PyCon,GitHub…)

Matplotlib

PythonLibraries

“Rule34”ofPython

NumPy

Arraycalculations

Reikna

PyOpenCL/

PyCUDA

GPU

acceleration

SciPy/

OpenCV

PIL/Pillow

Imageprocessing

Tkinter

InteractiveUI

ffmpeg-python

subprocess+

ffmpeg

Recordvideo

“Ifthereisaneed,thereisaPythonlibraryforit.”

NumPy

Fastarraycalculations

Machinelearning,deeplearning

Basisofimageprocessing,time-series

Cellularautomata(weightedsumusingFFT)

MainloopofLeniain3lines

potential_fft=np.fft.fft2(cells)*kernel_fft

potential=np.fft.fftshift(np.real(np.fft.ifft2(potential_fft))

cells_new=np.clip(cells+dt*g(potential,m,s),0,1)

PyOpenCL/PyCUDA+Reikna

GPUacceleration

(NVIDIA)CUDAPyCUDA

(Apple)OpenCLPyOpenCL

Reikna

PyOpenCL/PyCUDAwrapper

CompilestheGPUcodeforyou

GPUacceleratedFFTinafewlines

gpu_thr=reikna.cluda.any_api().Thread.create()

gpu_fft=reikna.fft.FFT(cells.astype(plex64)).compile(gpu_thr)op_dev=gpu_thr.to_device(cells.astype(plex64))gpu_fft(op_dev,op_dev,**kwargs)

cells=op_dev.get()

PIL/Pillow,SciPy,OpenCV

Imagehandling

PIL(PythonImageLib)pillow

Createimage,drawlines/texts,saveGIF…

img=PIL.Image.frombuffer('P',buffer.shape,buffer,…)

draw=PIL.ImageDraw.Draw(img)

img[0].save(path,format='GIF',append_images=self.gif[1:],loop=0…)

Imageprocessing

SciPy

scipy.ndimage.rotate(A,reshape=False,order=0,mode='wrap’)

OpenCV-Python

TkintervsMatplotlib

InteractiveUI

Real-time2Dimagedisplay

Menu,keyboardbinding,clipboard

Matplotlib

Fordatavisualization

Powerfulbutslow…

Tkinter(Toolkitinterface)

Basicandfast

Others:wxPython,PyQt,PyGTK…

InteractiveUI

win=tk.Tk()tk.Canvas()tk.Menu()

win.bind('<Key>',key_press_event)

win.clipboard_get()

Python3

importtkinterastk

subprocess+ffmpeg

PythonicFFmpegwrappers

ffmpeg-python,ffmpy,etc.

Pipevideotoffmpeg

cmd=['/usr/local/bin/ffmpeg’,'-f','rawvideo',…]

video=subprocess.Popen(cmd,stdin=subprocess.PIPE)forimginimgs:

video.stdin.write(img.convert('RGB').tobytes())video.stdin.close()

AboutALifeandAI

forHKCodeConf

Lenia

Notjustfunnycreatures

UsingAItocreateALife

AboutALife

ArtificialLife

Simulatebiologicallifeorcreatenewlifeforms

Createabody

WetALife=biochemistry,syntheticlife

Artificialcell,expandedgeneticcode…

HardALife=hardware,robots&machines

Humanoids,Strandbeest…

SoftALife=software,simulations

Cellularautomata,virtualcreatures…

WetALife=biochemistry,syntheticlife

Artificialcell,expandedgeneticcode…

HardALife=hardware,robots&machines

Humanoids,Strandbeest…

Syntheticcell(JCVI,2010)

SoftALife=software,simulations

Cellularautomata,virtualcreatures…

ExpandedDNA(TSRI,2014)

WetALife=biochemistry,syntheticlife

Artificialcell,expandedgeneticcode…

HardALife=hardware,robots&machines

Humanoids,Strandbeest…

SoftALife=software,simulations

Cellularautomata,virtualcreatures…

Strandbeest(TheoJansen,1990)

Atlas(BostonDynamics,2017)

SoftALife=software,simulations

Cellularautomata,virtualcreatures…

HardALife=hardware,robots&machines

Humanoids,Strandbeest…

WetALife=biochemistry,syntheticlife

Artificialcell,expandedgeneticcode…

Virtualcreatures(KarlSims,1994)

Softrobots(NickCheney,2014)

AboutAI

EA=EvolutionaryAlgorithms

Neuro-evolution,novelty,etc

ArtificialIntelligence

Machinesdo:learning,planning,vision,language,emotion,art

ML=MachineLearning

Supervised,unsupervised,reinforced

DL=DeepLearning

Deepneuralnets+bigdata+manyGPU

GOFAI=Goodold-fashionedAI

Symbolic,expertsystems

Createamind

GOFAI=Goodold-fashionedAI

Symbolic,expertsystems

ML=MachineLearning

Supervised,unsupervised,reinforced

DL=DeepLearning

Deepneuralnets+bigdata+manyGPU

DeepBluevs.Kasparov(IBM,1997)

EA=EvolutionaryAlgorithms

Neuro-evolution,novelty,etc

WatsoninJeopardy!(IBM,2011)

GOFAI=Goodold-fashionedAI

Symbolic,expertsystems

AlphaGovs.LeeSedol(DeepMind,2016)

ML=MachineLearning

Supervised,unsupervised,reinforced

DL=DeepLearning

Deepneuralnets+bigdata+manyGPU

EA=EvolutionaryAlgorithms

Neuro-evolution,novelty,etc

Autopilot(Tesla,2014)

BigGAN(AndrewBrock,2018)

GOFAI=Goodold-fashionedAI

Symbolic,expertsystems

ML=MachineLearning

Supervised,unsupervised,reinforced

DL=DeepLearning

Deepneuralnets+bigdata+manyGPU

PicBreeder(EPlex,2007)

EA=EvolutionaryAlgorithms

Neuro-evolution,novelty,etc

Evolut

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论