细胞自动机_神经细胞自动机用于艺术娱乐

细胞自动机

The article will briefly introduce the field of Cellular Automata (CA), along with a Neural Network approach. The outputs of this work are not simply images. They are some form of a virtual organism that, similar to a living body, grows, and responds to changes. This is an experimental work that hopes to encode information in a genome-like fashion.

本文将简要介绍细胞自动机(CA)领域以及神经网络方法。 这项工作的输出不只是图像。 它们是虚拟生物的某种形式,类似于生物体,可以生长并响应变化。 这是一项实验性工作,希望以类似基因组的方式编码信息。

At the end of this article, we won't be able to create a virtual human living in San Junipero (shout-out to Black Mirrors fans). However, we will be able to present a recreation of Keith Haring’s icon series (1990). These icons will grow from a single cell until they reach a saturation point, where the single-cell becomes one multicellular entity.

在本文的最后,我们将无法在San Junipero中创建虚拟人(向Black Mirrors粉丝大喊大叫)。 但是,我们将能够介绍Keith Haring的偶像系列(1990年)。 这些图标将从单个单元格增长到达到饱和点,在该点上,单个单元格将成为一个多细胞实体。

If you are not interested in the technicalities behind the Neural Network architecture feel free to skip sections with titles starting by “CNN:”. I set the code used for this project on a Colab notebook, which can be used to create similar figures and images for user-defined inputs. The notebook is an edited version of Mordvintsev’s work on Growing Neural Cellular Automata [1].

如果您对神经网络体系结构背后的技术不感兴趣,请随时跳过标题以“ CNN: ”开头的部分。 我在Colab 笔记本上设置了用于该项目的代码,该代码可用于为用户定义的输入创建相似的图形和图像。 该笔记本是Mordvintsev关于“神经细胞自动机的成长” [1]的编辑版本。

Public Projects Archive. Bottom image by author) 公共项目档案 。底部图像由作者提供)

In the early 1950s, Rosalind Franklin, Francis Crick, and James Watson’s collaboration led to the discovery of the DNA [2]. This discovery did create not only the most significant milestone in the development of modern biology but also shaped other fields such as computer science.

1950年代初期, 罗莎琳德·富兰克林 ,弗朗西斯·克里克和詹姆斯·沃森 合作导致了DNA的发现[2]。 这一发现不仅创造了现代生物学发展中最重要的里程碑,而且还塑造了计算机科学等其他领域。

Public Domain. 公共领域 。

Although computer science seemed disconnected entirely from biology, computer scientists like John von Neumann, Stanislaw Ulam, and S. Wolfram were impressed by the efficiency and complexity of biological systems [3]. They painted a model that interprets the newly-founded DNA role and translates the molecular biology architecture to serve computing purposes. According to their understanding at that time, a living body is governed by a single algorithm (DNA), and several functionalities (biochemical operations), which enable nature to present a continuous and responsive model (a biological organism). Hence, life has found a way to compress large information and encode complex behaviors only by using these two principles. This understanding is the foundation of Cellular Automata (CA). Hence, CA is an exercise of experimental dynamics in computer science algorithms in the hope of reconstructing information into a genome-encoded cellular form.

尽管计算机科学似乎与生物学完全脱节,但是像约翰·冯·诺依曼,斯坦尼斯瓦夫·乌兰姆和S·沃尔夫拉姆这样的计算机科学家对生物系统的效率和复杂性印象深刻[3]。 他们绘制了一个模型,该模型解释了新近成立的DNA角色并转换了分子生物学体系结构以用于计算目的。 根据他们当时的理解,活体由单一算法(DNA)和多种功能(生化操作)控制,这些功能使自然界能够呈现出连续且ReactSwift的模型(生物体)。 因此,生活找到了一种仅通过使用这两个原理来压缩大量信息并编码复杂行为的方法。 这种了解是细胞自动机(CA)的基础。 因此,CA是计算机科学算法中实验动态的一种练习,希望将信息重构为基因组编码的细胞形式。

细胞自动机简介 (Introduction to Cellular Automaton)

A cellular automaton is a continuous state of a set of cells (elements of a grid) starting from a seed that can be either a single cell or several cells. A set of cells at time “t+1” is an update of the set at “t” according to an update “rule”. The update rule involves calculations that depend on neighboring cells. There are three standard definitions of a neighbor cell.

细胞自动机是从种子开始的一组细胞(网格元素)的连续状态,种子可以是单个细胞也可以是多个细胞。 在时间“ t + 1”的一组小区是根据更新“ 规则”在“ t”的一组小区的更新 更新规则涉及取决于相邻小区的计算。 邻居小区有三个标准定义。

Figure 3: Examples for the different neighborhood, (Photo by the author) 图3:不同邻域的示例,(作者提供的照片)

According to each different type of neighborhood, a varied selection of cells (colored grey) contributes to the update of a specific cell (colored black). Thus, the state or values a cell holds directly affects the other cells. Hence, a cellular automaton evolves as a continuous entity. The influence of neighbors on a cell differs according to the type of grid. The best way to illustrate this is by considering a 1-dimensional grid. In the animation below, all the cells occupy one line. Each cell can only have a value of 0 or 1.

根据每种不同的邻域类型,单元格(灰色)的变化选择有助于特定单元格(黑色)的更新。 因此,一个单元格保持的状态或值直接影响其他单元格。 因此,细胞自动机发展成为一个连续的实体。 邻居对小区的影响根据网格的类型而不同。 最好的说明方法是考虑一维网格。 在下面的动画中,所有单元格都占据一行。 每个单元格只能具有0或1的值。

Public Domain) 公共领域 )

Therefore, The rule determines how one generation changes to the next generation with respect to its neighbors. The cases numbered from 0 to 7 represent the different situations that can exist in this 1-D grid. For example, case 2 indicates that if a cell (the center block is the current cell) is currently 1 and has two 0-neighbors, then it will remain 1 (the outcome is shown as the bottom block). There are 256 different combinations since each of the 8 cases can be either 0 or 1. Hence, for a 1-dimensional binary cellular automaton, there can be 256 different rules that will govern the evolution of a system.

因此, 规则确定相对于其邻居,下一代如何改变为下一代。 从0到7编号的个案代表了该1-D网格中可能存在的不同状况。 例如,情况2指示如果一个单元格(中心块是当前单元格)当前为1并且具有两个0邻居,那么它将保持为1(结果显示为底部块)。 由于8种情况中的每一种可以为0或1,因此存在256种不同的组合。因此,对于一维二进制元胞自动机,可以有256种不同的规则来控制系统的演化。

Figure 5: Amazingly simple and effective Elementary Cellular Automaton simulator made by Devin Acker, 2010. (Gif made by author) 图5: Devin Acker制作的惊人简单有效的 基本 元胞 自动机模拟器 ,2010年 。 (由作者制作的Gif)

These systems are generally referred to as Elementary Cellular Automata (ECA)[4]. Despite their simplicity, some rules produce intricate patterns over several generations, such as Rule 30, Rule 90, Rule 110, and Rule 184. There are awards dedicated to ECA research, such as the Rule 30 Prize. Here, Devin Acker has created a simple ECA simulator where a user can set the update rule and the initial conditions, and as shown, distinctive patterns can be produced.

这些系统通常称为基本元胞自动机(ECA) [4]。 尽管它们很简单,但是某些规则在几代人中仍然产生复杂的模式,例如规则30 , 规则90 , 规则110和规则184 。 有专门用于ECA研究的奖项,例如Rule 30 Prize 。 在这里,Devin Acker创建了一个简单的ECA仿真器 ,用户可以在其中设置更新规则和初始条件,并且可以显示出独特的图案。

细胞自动机的现状 (Current State of Cellular Automata)

The field of CA quickly evolved from simple ECA models and is capable of creating more complex patterns. A lot of work has been done on creating 2-dimensional and higher-dimension grids. The interaction between cells, “the update rules”, also has taken the form of highly complicated mathematical expressions.

CA领域Swift从简单的ECA模型发展而来,并且能够创建更复杂的模式。 在创建二维和更高维度的网格方面,已经完成了大量工作。 单元之间的交互(“更新规则”)也采用了高度复杂的数学表达式的形式。

link to read more about some advance and exciting Cyclic Cellular Automata models. This 链接以阅读更多有关一些先进的和令人兴奋的循环细胞自动机模型的信息。 该 blog does an amazing job of exploring such concepts (Reposted 博客在探索这样的概念方面做得非常出色(经许可, from, with permission). 从 ,转贴)。

Unfortunately, Cellular Automata researchers are still far from creating a functional biological organism in the virtual, some might consider this to be a relief :). The generated patterns are generally amorphous and with no explicit representation of shape. These patterns attracted a lot of attention due to their aesthetic value. Some researches focus on discovering artistic CA models that are built on top of computer science and mathematics, hence, questioning the relation between data science and Arts.

不幸的是,Cellular Automata研究人员离在虚拟环境中创建功能性生物有机体还很远,有些人可能认为这是一种缓解:)。 生成的图案通常是无定形的,没有明确的形状表示。 这些图案由于其美学价值而引起了很多关注。 一些研究着重于发现建立在计算机科学和数学之上的艺术CA模型,因此对数据科学与艺术之间的关系提出了质疑。

ToWuensche, p. 13, Designing Beauty: The Art of Cellular Automata [5]

Wuensche,p。 13,设计美:细胞自动机的艺术[5]

However, this project aims to recreate artworks starting from a seed cell. To do so, we will employ a supervised Neural Network to find the best update rule that can successfully recreate an image after several steps.

但是,该项目旨在从种子细胞开始重新创作艺术品。 为此,我们将使用受监督的神经网络来找到最佳的更新规则,该规则可以在几个步骤后成功地重新创建图像。

神经网络创建最佳的细胞自动机 (Neural Networks to create an optimal Cellular Automaton)

One of the biggest challenges facing this field is “how to correctly tell a call when to build? What to build? And when to stop?”. Biology seems to have figured this out. It optimized its use of physics and computation laws after millions of years of evolution. Unfortunately, as biologists are still struggling in solving the puzzle of life, we do not have a clear recipe for how to recreate similar systems virtually. In CA terms, the problem lies in finding the update rule that will transform a single cell into a highly compact body. Hence, instead of finding the optimal update rule in biology, one can employ a Neural Network algorithm that finds this rule over several generations. A Neural Network can go through several trials as some form of a virtual evolution that organisms go through. Therefore, one can use neural network architecture to create a targeted image form a seed cell [1].

该领域面临的最大挑战之一是“如何正确告知呼叫何时建立? 要建什么? 什么时候停止?”。 生物学似乎已经弄清楚了。 经过数百万年的发展,它优化了对物理和计算定律的使用。 不幸的是,由于生物学家们仍在努力解决生活中的难题,因此对于如何虚拟地重建相似的系统,我们没有明确的配方。 用CA而言,问题在于找到将单个单元转换为高度紧凑的主体的更新规则。 因此,代替寻找生物学上的最佳更新规则,可以采用一种神经网络算法,该算法可以在多个世代中找到该规则。 神经网络可以作为有机体经历的某种形式的虚拟进化而经历几次试验。 因此,可以使用神经网络体系结构从种子细胞创建目标图像[1]。

Growing Neural Cellular Automata, (licensed under 生长中的神经细胞自动机检索到的图(根据 CC-BY 4.0) CC-BY 4.0许可)

CNN:元胞自动机模型状态 (CNN: Cellular Automata Model Sates)

The input image here has a 40 by 40 matrix of cells. Each cell has 16 states (channels). The first three channels are RGB, and the forth is the alpha-channel (transparency), while the other channels are invisible and do not necessarily have a predetermined meaning. They can be considered to be a representation of chemical and physical interactions that biological cells experience. The update rule will learn how to make use of these channels to reach the targeted image. The cells interact, according to Moore (r=2) neighborhood (shown in Figure 3).

这里的输入图像具有40 x 40的单元矩阵。 每个单元具有16个状态(通道)。 前三个通道是RGB,第四个通道是alpha通道(透明度),而其他通道是不可见的,不一定具有预定含义。 它们可以被认为是生物细胞经历的化学和物理相互作用的代表。 更新规则将学习如何利用这些渠道到达目标图像。 细胞根据Moore(r = 2)邻域进行交互(如图3所示)。

Growing Neural Cellular Automata, (licensed under 生长的神经细胞自动机检索到的图,(根据 CC-BY 4.0) CC-BY 4.0许可)

Moreover, the alpha-channel will be used to demarcate living cells. Cells with values of alpha > 0.1 are “mature” cells, and their neighbors are “growing” cells. In contrast, cells with alpha<0.1 and with no “mature” cells in their neighborhood are dead cells.

此外,alpha通道将用于划分活细胞。 值> 0.1的单元格是“ 成熟”单元格,而它们的邻居是“ 成长”单元格。 相反,α<0.1且附近没有“ 成熟”细胞的细胞是死细胞。

CNN:反馈环 (CNN: Feedback Loop)

Finally, the feedback loop is set by using the L2 loss function. The loss value is calculated by comparing the visible channels of the recreated image to those channels of the targeted image. In other words, the different channels that contribute to the other channels are only in finding the correct update rule through the perception vectors. They are flexible and will be tailored by the Neural Network architecture to optimize the update rule. While the loss in the visible channel will be calculated using Mean Square Error (MSE) to guide the training.

最后,通过使用L2损失函数来设置反馈环路。 通过将重新创建的图像的可见通道与目标图像的可见通道进行比较来计算损耗值。 换句话说,贡献给其他信道的不同信道只是在通过感知向量找到正确的更新规则。 它们非常灵活,将由神经网络体系结构进行定制以优化更新规则。 而可见光通道的损耗将使用均方误差(MSE)来计算,以指导训练。

Equation 1: Mean Squared Error formula used in the Neural Network. (Image by author) 公式1:神经网络中使用的均方误差公式。 (图片由作者提供)

CNN:卷积层 (CNN: Convolution Layer)

Depthwise separable convolutions for machine learning, 2018. Reposted with permission 深度学习机器学习的卷积可分解卷积的插图,2018年。经许可重新发布

At the heart of the convolutional neural networks (CNN), and what gives them their names, are the convolution layers. Explicitly designed to deal with images, CNNs are inspired by the way humans see. Unlike traditional neural networks that vectorize images, CNNs take the 2D form of an image. This process has a remarkable advantage over conventional neural networks; it maintains the spatial locality of pixels. Since the image is not vectorized, the 2d features of the image are correctly fed to the network.

卷积神经网络是卷积神经网络(CNN)的核心,并为其命名。 CNN专门设计用于处理图像,其灵感来自人类的观看方式。 与将图像矢量化的传统神经网络不同,CNN采用图像的2D形式。 与传统的神经网络相比,该过程具有明显的优势。 它保持像素的空间局部性。 由于未对图像进行矢量化处理,因此图像的2d特征已正确馈送到网络。

Here, Sobel filters — shown in Figure 7 above — are convolved with each of the 16 channels in the two convolution layers. The resulting matrix is then linearized into perception vectors and fed into a final linear neural layer, which gives 128 output nodes where a ReLU activation function then feeds them into a linear layer that produces 16 values. Each value represents an update rule for one of the 16 original channels.

在这里,Sobel滤波器(如上面的图7所示)与两个卷积层中的16个通道中的每一个卷积。 然后将生成的矩阵线性化为感知向量,并馈入最终的线性神经层,该层将提供128个输出节点,其中ReLU激活函数会将其馈入产生16个值的线性层。 每个值代表16个原始通道之一的更新规则。

CNN:ReLU激活 (CNN: ReLU Activation)

Public Domain) Public Domain )

These layers of the architecture are where the update rule is tested and changed. Each cell applies a series of operations to the perception vector, such as convolution operations and ReLU nonlinearities. These operations are the update rule of the system. The network is parametrizing this update rule into 8,000 parameters. Then examines the signals from ReLU functions before it applies the suitable changes to update rule. The changes come in the form of addition or subtraction of values from different states in the perception vector. Moreover, these changes are directed by the weights and values the ReLU function indicates.

在体系结构的这些层中可以测试和更改更新规则。 每个单元对感知向量应用一系列运算,例如卷积运算和ReLU非线性。 这些操作是系统的更新规则。 网络正在将该更新规则参数化为8,000个参数。 然后,在将适当的更改应用于更新规则之前,检查来自ReLU函数的信号。 变化以感知向量中不同状态的值相加或相减的形式出现。 此外,这些变化由ReLU函数指示的权重和值指示。

CNN:随机过滤器和状态更新 (CNN: Stochastic Filter and State Update)

The rule is continuously altered according to the results of one Neural Network step. However, the update rule is not directly applied. Unlike traditional Cellular Automata models, cells will not be updated simultaneously. This probabilistic approach resembles self-organizing biological systems because cells do not work in global synchrony. In this model, each update is applied to each cell with a random waiting time. We relax this requirement by assuming that each cell performs an update independently, waiting for a random time interval between updates.

该规则根据一个神经网络步骤的结果不断更改。 但是,更新规则不会直接应用。 与传统的Cellular Automata模型不同,单元不会同时更新。 这种概率方法类似于自组织的生物系统,因为细胞无法整体同步工作。 在此模型中,每次更新都会以随机等待时间应用于每个单元。 通过假设每个单元独立执行更新,并等待更新之间的随机时间间隔,我们可以放宽此要求。

结果 (Results)

To test this system, we tried to recreate Keith Haring’s works initially and some other symbols as well. The results can be compared visually, by merely looking at the targeted image and the best CA corresponding to the picture. It can also be examined by using the Loss History graph, where the best Cellular automaton model has the lowest Log Loss score. This also indicates the complexity of the targeted images. A highly complicated target image will not be easily reproduced after 80,000 steps. It will generally have a higher Log Loss value.

为了测试该系统,我们尝试首先重新创建Keith Haring的作品以及其他一些符号。 通过仅查看目标图像和与图片相对应的最佳CA即可在视觉上比较结果。 也可以使用“丢失历史记录”图进行检查,其中最佳的元胞自动机模型的对数丢失得分最低。 这也表明目标图像的复杂性。 80,000步后,高度复杂的目标图像将不容易再现。 通常它将具有较高的对数丢失值。

2-飞行恶魔: (2-Flying Devil:)

Public Projects Archive). Right: the Log of the Loss of the CA models when compared to the targeted image (figure by author). Public Projects Archive )。 右:与目标图像相比,CA模型的损失日志(作者提供的图)。
Figure 12: Four different CA with different update rules. The first one with the most ineffective update rule, and the last one to the right with the most accurate update rule (Figure by author). 图12:具有不同更新规则的四个不同的CA。 第一个具有最无效的更新规则,而最后一个具有最精确的更新规则(作者提供的图)。

3-辐射婴儿: (3-Radiant Baby:)

Public Projects Archive). Left: the Log of the Loss of the CA models when compared to the targeted image. Public Projects Archive )。 左:与目标图像相比,CA模型的损失日志。
Figure 14: Four different CA with different update rules. The first one with the most ineffective update rule, and the last one to the right with the most accurate update rule (Figure by author) 图14:具有不同更新规则的四个不同的CA。 第一个具有最无效的更新规则,而最后一个具有最准确的更新规则(作者提供的图)

讨论区 (Discussion)

The project was able to recreate these icons with high accuracy. However, the process has several limitations that can be improved. For example, the project is done on a free Colab subscription with constraints on computing power. Hence, we were forced to shrink the images to 40 by 40 pixels. This made the targeted image lose some of its quality and appear to be pixilated.

该项目能够高精度地重新创建这些图标。 但是,该过程具有一些可以改进的局限性。 例如,该项目是在免费的Colab订阅上完成的,但对计算能力有限制。 因此,我们不得不将图像缩小到40 x 40像素。 这使目标图像失去了某些质量,并且看起来像是像素化。

Public Projects Archive). 公共项目档案 )。

Furthermore, the Neural Network Architecture is designed to iterate over 80,000 CA versions with different update rules. This number of iterations simply was not enough to get an exact recreation of some targeted images such as “Three-Eyed Monster” By Keith Haring, due to its complexity.

此外,神经网络体系结构旨在使用不同的更新规则来迭代80,000个CA版本。 由于其复杂性,此迭代次数根本不足以精确再现某些目标图像,例如Keith Haring的“三眼怪物”。

Figure 16: The Neural Network failed to find the correct update rule, cells are growing in a chaotic fashion (figure by author). 图16:神经网络未能找到正确的更新规则,细胞正在以混乱的方式生长(作者提供的图)。

It is also worth mentioning that we tried different Neural Network Architectures by adding more convolutional layers and operators. However, that only increased the run time and did not yield significantly better results.

还值得一提的是,我们通过添加更多卷积层和运算符尝试了不同的神经网络体系结构。 但是,这只会增加运行时间,而不会产生明显更好的结果。

结论 (Conclusion)

It is essential to consider alternative ways to develop Cellular Automaton models. The goal of finding the correct settings to create highly complex structures from a seed cell should not only be approached from a mathematical perspective. Numerical methods, such as neural networks, can help guide this search. Indeed, using Neural Network might not reveal the recipe for creating biological structure; however, it may give a glimpse of where to search for this recipe and what to expect.

必须考虑开发蜂窝自动机模型的替代方法。 寻找正确的设置以从种子细胞创建高度复杂的结构的目标不仅应从数学角度出发。 数值方法(例如神经网络)可以帮助指导此搜索。 确实,使用神经网络可能无法揭示创建生物结构的方法。 但是,它可以让您一目了然地找到该食谱的内容以及期望的内容。

This work is dedicated to the great artist, Keith Haring. If you do not know about Haring, he is a street artist who, in his short life, shaped the contemporary pop art, advocated for queer rights and continuously raised awareness on AIDS [8].

这项工作是献给伟大的艺术家Keith Haring的 。 如果您不了解Haring,他就是街头艺术家,他在短短的时间里塑造了当代波普艺术,倡导同性恋权利并不断提高对艾滋病的认识[8]。

Public Domain) Public Domain )

To read more in detail about Neural Cellular Automata, check this outstanding article explaining in great detail the concept. This article is the basis of this work and I strongly recommend it for further knowledge.

要了解有关神经细胞自动机的更多详细信息,请查看这篇出色的文章,详细介绍该概念。 本文是这项工作的基础,我强烈建议您进一步了解它。

[1] Mordvintsev, et al., Growing Neural Cellular Automata (2020), Distill.

[1] Mordvintsev等人, 《神经细胞自动机的增长》 (2020年),Distill。

[2] Pray, L., Discovery of DNA structure and function: Watson and Crick (2008), Nature

[2] Pray,L., DNA结构和功能的发现:Watson和Crick (2008),自然

[3] Wolfram, Stephen, A New Kind of Science (2002), Wolfram Media.

[3] Wolfram,Stephen,《 一种新的科学》 (2002年),Wolfram Media。

[4] Weisstein, Eric W, Elementary Cellular Automaton, From MathWorld — A Wolfram Web Resource.

[4] Weisstein,Eric W,《 基本细胞自动机》 ,来自MathWorld-Wolfram Web资源。

[5] Adamatzky, Andrew, and Genaro J Martínez, editors. DESIGNING BEAUTY: the Art of Cellular Automata (2018), SPRINGER.

[5] Adamatzky,Andrew和Genaro JMartínez,编辑。 设计美容:细胞自动机的艺术 (2018),SPRINGER。

[6] V, Avinash Sharma. Understanding Activation Functions in Neural Networks (2017). Medium, The Theory Of Everything.

[6] V,阿维纳什·夏尔马(Avinash Sharma)。 了解神经网络中的激活功能 (2017)。 媒介 ,万物理论。

[8] Brownlee, Jason, A Gentle Introduction to the Rectified Linear Unit (ReLU)(2019), Deep Learning Performance.

[8] Brownlee,Jason, 《整流线性单元(ReLU)的温和介绍》 (2019),深度学习性能。

[9] Yarrow, Andrew, Keith Haring, Artist, Dies at 31; Career Began in Subway Graffiti (1990), The New York Times.

[9] Yarrow,安德鲁, 基思·哈林(Keith Haring),艺术家,享年31岁; 在 《纽约时报》的《 地铁涂鸦》 (1990年)中开始了职业生涯 。

翻译自: https://towardsdatascience.com/neural-cellular-automata-for-art-recreation-6d9fb61afb37

细胞自动机

你可能感兴趣的:(java)