Add 003b_simple folder

pull/2/head
drinkjava2 5 years ago
parent 10c0193411
commit e7b33a3b16

@ -92,6 +92,7 @@ Frog: 这是人工生命的主体,目前起名叫青蛙(Frog),其实叫什
![result6](https://gitee.com/drinkjava2/frog/raw/master/result6_letter.gif)
2019-11-26 优化了一下程序用8个汉字来进行模式识别原理演示但容错性依然没有变形、变位后的文字识别率很差。以后要考虑借签算法中的侧抑制、卷积、分层等原理来提高它的容错性这方面算法已经很成熟了目前只需要拿来主义用图形化模拟的方式来实现。但总体上算法和图形化模拟是两条路算法通常可以用模拟的方式来表达但不是所有模拟都可以归纳成算法因为模拟(或者说软件本身)有时会非常复杂,不容易总结出规律。也就是说模拟的表现力比算法更强,但模拟的缺点是资源消耗大。
2019-12-27 在history\003a_legs目录下依然是2维脑)尝试给青蛙加两条腿看它能不能自动学会走路。一条腿位于下方负责左右移动一条腿位于右侧负责上下移动每条腿有抬腿、落腿、转动和相应的感觉细胞。只有当腿落下且转动而且另一条脚抬起来时青蛙才会位移具体什么时候抬腿、什么时候转动腿完全由随机数决定。经过一段时间的生存汰淘之后青蛙会进化出会利用两条腿走路了但需要的时间非常长约几个小时之后才达到最高吃食率50%左右,走路风格也比较诡异,是小碎步而不是大踏步。但至少这是青蛙第一次利用两条腿来走路,还是有点意义的,这证明生命进化中就算神经元随机排布,进化出眼睛和腿也是非常简单自然的事。
2020-05-04 在进行3维脑改造过程中发现找食率很低发现自己也看不懂以前的程序怎么编的了所以又添加一个history\003b_simple目录把2维脑简化一下去掉不重要的器官好仔细分析它的逻辑。
## 运行方式 | Run
运行core或history各个子目录下的run.bat批处理文件即可启动运行history下有多个子目录按时间顺序按列存放着这个项目演化过程中的主要历史版本供演示。

@ -30,11 +30,11 @@ public class Env extends JPanel {
/** Delete eggs at beginning of each run */
public static final boolean DELETE_EGGS = true;// 每次运行是否先删除保存的蛋
public static final int EGG_QTY = 50; // 每轮下n个蛋可调只有最优秀的前n个青蛙们才允许下蛋
public static final int EGG_QTY = 25; // 每轮下n个蛋可调只有最优秀的前n个青蛙们才允许下蛋
public static final int FROG_PER_EGG = 4; // 每个蛋可以孵出几个青蛙
public static final int SCREEN = 4; // 分几屏测完
public static final int SCREEN = 1; // 分几屏测完
public static final int FROG_PER_SCREEN = EGG_QTY * FROG_PER_EGG / SCREEN; // 每屏上显示几个青蛙,这个数值由上面三个参数计算得来
@ -59,10 +59,10 @@ public class Env extends JPanel {
public static final int FROG_BRAIN_DISP_WIDTH = 600; // Frog的脑图在屏幕上的显示大小,可调
/** Steps of one test round */
public static final int STEPS_PER_ROUND = 2000;// 每轮测试步数,可调
public static final int STEPS_PER_ROUND = 4000;// 每轮测试步数,可调
public static int step;// 当前测试步数
public static final int FOOD_QTY = 2000; // 食物数量, 可调
public static final int FOOD_QTY = 1500; // 食物数量, 可调
// 以下是程序内部变量,不要手工修改它们
public static boolean pause = false; // 暂停按钮按下将暂停测试

@ -24,6 +24,7 @@ import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.organ.Line;
import com.github.drinkjava2.frog.egg.Egg;
import com.github.drinkjava2.frog.objects.Material;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Frog = cells <br/>
@ -34,6 +35,7 @@ import com.github.drinkjava2.frog.objects.Material;
* cellscell
*
* @author Yong Zhu
*
* @since 1.0
*/
public class Frog {// 这个程序大量用到public变量而不是getter/setter主要是为了编程方便和简洁但缺点是编程者需要小心维护各个变量
@ -45,7 +47,7 @@ public class Frog {// 这个程序大量用到public变量而不是getter/setter
public int x; // frog在Env中的x坐标
public int y; // frog在Env中的y坐标
public long energy = 1000000; // 青蛙的能量为0则死掉
public long energy = 100000; // 青蛙的能量为0则死掉
public boolean alive = true; // 设为false表示青蛙死掉了将不参与计算和显示以节省时间
public int ateFood = 0; // 青蛙曾吃过的食物总数,下蛋时如果两个青蛙能量相等,可以比数量
@ -65,9 +67,26 @@ public class Frog {// 这个程序大量用到public变量而不是getter/setter
organs.add(org);
}
public void initFrog() {
public void initFrog() { // 初始化frog,通常只是调用每个organ的init方法
for (int orgNo = 0; orgNo < organs.size(); orgNo++) {
organs.get(orgNo).init(this, orgNo);
// energy -= 1; // organ 增多需要消耗能量
}
// Cell c1 = this.findFirstCellByClass(Active.class);
// Cell c2 = this.findFirstCellByClass(MoveUp.class);
// organs.add(new Line(c1, c2));
}
public void addRandomLines() {// 有一定机率在器官间生成随机的神经连线
if (RandomUtils.percent(0.2f)) {
Cell c1 = RandomUtils.getRandomCell(this);
if (c1 == null)
return;
Cell c2 = RandomUtils.getRandomCell(this);
if (c2 == null || c1 == c2)
return;
organs.add(new Line(c1, c2));
}
}
@ -82,6 +101,7 @@ public class Frog {// 这个程序大量用到public变量而不是getter/setter
// 依次调用每个器官的active方法每个器官各自负责调用各自区域通常是Cuboid)内的细胞的行为
for (Organ o : organs)
o.active(this);
addRandomLines(); // 有一定机率在器官间生成随机的神经连线
return alive;
}

@ -264,6 +264,10 @@ public class BrainPicture extends JPanel {
}
public void drawText(float px1, float py1, float pz1, String text) {
drawText(px1, py1, pz1, text, 1);
}
public void drawText(float px1, float py1, float pz1, String text, float textSize) {
double x1 = px1 - Env.FROG_BRAIN_XSIZE / 2;
double y1 = -py1 + Env.FROG_BRAIN_YSIZE / 2;// 屏幕的y坐标是反的显示时要正过来
double z1 = pz1 - Env.FROG_BRAIN_ZSIZE / 2;
@ -286,7 +290,8 @@ public class BrainPicture extends JPanel {
x1 = x;
y1 = y;
g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, (int) round(scale * .3)));
g.setColor(picColor);
g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, (int) round(textSize * scale * .3)));
g.drawString(text, (int) round(x1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + xOffset,
(int) round(y1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset);

@ -39,7 +39,7 @@ public class Cell implements Serializable {
public int x;
public int y;
public int z;
public float energy=0;
public float energy = 0;
public Cell(int x, int y, int z) {
this.x = x;
@ -59,10 +59,18 @@ public class Cell implements Serializable {
organs[organs.length - 1] = orgNo;
}
public boolean inActive() {
if (energy > 30) {
energy -= 30;
return true;
}
return false;
}
public void addEnergy(float e) {
energy += e;
if (energy > 100)
energy = 100;
if (energy > 1000)
energy = 1000;
}
public void subEnergy(float e) {

@ -15,8 +15,6 @@ import java.io.Serializable;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.organ.Line;
import com.github.drinkjava2.frog.brain.organ.Lines;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
@ -70,8 +68,8 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
/** each step will call Organ's active methodd */
public void active(Frog f) {// 每一步测试都会调用active方法它通常遍历每个细胞调用它们的cellAct方法
// 这里是缺省的方法体,子类可以重写这个方法
if (!f.alive || shape == null)
// 这里是缺省的方法体,只针对最常见的形状为长方体的器官,子类可以重写这个方法
if (!f.alive || shape == null || shape.getClass() != Cuboid.class)
return;
Cuboid c = (Cuboid) shape;
for (int px = 0; px < c.xe; px++)
@ -91,35 +89,26 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
return;
pic.setPicColor(Color.LIGHT_GRAY); // 缺省是灰色
shape.drawOnBrainPicture(pic);
pic.setPicColor(Color.RED); // 缺省是灰色
if (this.organName != null && this.shape.getClass() == Cuboid.class) {
int x = ((Cuboid) shape).x;
int y = ((Cuboid) shape).y;
int z = ((Cuboid) shape).z;
pic.drawText(x, y, z, this.organName);
}
}
public boolean getLineEnergy(Frog f, Cell c) {
Lines ls = f.findOrganByClass(Lines.class);
for (Line l : ls.lines) {
if (l == null || l.energy < 30)
continue;
if (l.x2 == c.x && l.y2 == c.y && l.z2 == c.z) {
l.energy -= 30;
return true;
}
pic.setPicColor(Color.RED);
if (this.shape.getClass() == Cuboid.class) { // 显示每个细胞的能量
Cuboid c = (Cuboid) shape;
for (int px = 0; px < c.xe; px++)
for (int py = 0; py < c.ye; py++)
for (int pz = 0; pz < c.ze; pz++) {
Cell cell = f.getCell(c.x + px, c.y + py, c.z + pz);
if (cell != null) {
pic.drawText(c.x + px, c.y + py, c.z + pz, "" + cell.energy, 1.5f);
}
}
}
return false;
}
public static void addLineEnergy(Frog f, Cell c, float energy) {
Lines ls = f.findOrganByClass(Lines.class);
for (Line l : ls.lines) {
if (l == null || l.energy > 100)
continue;
if (l.x1 == c.x && l.y1 == c.y && l.z1 == c.z) // 如果线的输入端位于视网膜上,增加线的能量
l.energy += energy;
}
}
}

@ -16,7 +16,6 @@ import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Active always active
@ -25,19 +24,25 @@ import com.github.drinkjava2.frog.util.RandomUtils;
*/
public class Active extends Organ {// 这个器官的作用总是激活一个固定区,它有可能会被自然选择选中
private static final long serialVersionUID = 1L;
public int actEngery = 5;
public int actEngery = 2;
public Active() {
this.shape = new Cuboid(15, 10, FROG_BRAIN_ZSIZE / 2 + 3, 1, 1, 1);
}
public Organ[] vary(Frog f) {// 重写器官的very方法
actEngery = RandomUtils.varyInLimit(actEngery, 1, 500);
// actEngery = RandomUtils.varyInLimit(actEngery, 1, 5);
// if (RandomUtils.percent(3f)) {
// Active a = new Active();
// Cuboid c = (Cuboid) a.shape;
// c.y--;
// return new Organ[] { this, a };
// }
return new Organ[] { this };
}
@Override
public void cellAct(Frog f, Cell c) {
addLineEnergy(f, c, actEngery);
c.energy -= actEngery;
}
}

@ -10,34 +10,25 @@
*/
package com.github.drinkjava2.frog.brain.organ;
import static com.github.drinkjava2.frog.Env.FROG_BRAIN_ZSIZE;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Happy active after ate food
*/
public class Eat extends Organ { // Eat器官的作用就是如果位置与食物重合增加frog的能量
private static final long serialVersionUID = 1L;
public int actEngery = 1000;
public Eat() {
this.shape = new Cuboid(15, 13, FROG_BRAIN_ZSIZE / 2 + 3, 1, 1, 1);
}
public Organ[] vary(Frog f) {// 重写器官的very方法
actEngery = RandomUtils.varyInLimit(actEngery, 1, 5000);
return new Organ[] { this };
}
@Override
public void active(Frog f) {
if (Env.foundAndAteFood(f.x, f.y)) {
f.ateFood++;
f.energy += actEngery;
}
}

@ -35,11 +35,13 @@ public class Eye {// 这个眼睛是从青蛙视角来观察,因为青蛙生
public static class SeeUp extends Organ {// 这个感光细胞只能看到上方有没有物体
private static final long serialVersionUID = 1L;
public int seeDistance = 10;
public int addEyeEnergy = 6;
public int addEng = 30;
public int subEng = 2;
public Organ[] vary(Frog f) {// 重写器官的very方法允许眼睛看到的距离随机进化
seeDistance = RandomUtils.varyInLimit(seeDistance, 1, 50);
addEyeEnergy = RandomUtils.varyInLimit(addEyeEnergy, 1, 200);
seeDistance = RandomUtils.varyInLimit(seeDistance, 5, 15);
addEng = RandomUtils.varyInLimit(addEng, 10, 30);
subEng = RandomUtils.varyInLimit(subEng, 1, 30);
return new Organ[] { this };
}
@ -50,8 +52,10 @@ public class Eye {// 这个眼睛是从青蛙视角来观察,因为青蛙生
public void cellAct(Frog f, Cell c) {// 如果上方有物体就激活视网膜细胞
for (int i = 1; i <= seeDistance; i++)
if (Env.foundAnyThing(f.x, f.y - i)) {
addLineEnergy(f, c, addEyeEnergy);
c.addEnergy(addEng);
return;
}
c.subEnergy(subEng);
}
}
@ -62,11 +66,13 @@ public class Eye {// 这个眼睛是从青蛙视角来观察,因为青蛙生
shape = new Cuboid(cx, cy - 2, cz, 1, 1, 1);
}
public void cellAct(Frog f, Cell c) {// 如果上方有物体就激活视网膜细胞
public void cellAct(Frog f, Cell c) {
for (int i = 1; i <= seeDistance; i++)
if (Env.foundAnyThing(f.x, f.y + i)) {
addLineEnergy(f, c, addEyeEnergy);
c.addEnergy(addEng);
return;
}
c.subEnergy(subEng);
}
}
@ -77,11 +83,13 @@ public class Eye {// 这个眼睛是从青蛙视角来观察,因为青蛙生
shape = new Cuboid(cx - 2, cy, cz, 1, 1, 1);
}
public void cellAct(Frog f, Cell c) {// 如果上方有物体就激活视网膜细胞
public void cellAct(Frog f, Cell c) {
for (int i = 1; i <= seeDistance; i++)
if (Env.foundAnyThing(f.x - i, f.y)) {
addLineEnergy(f, c, addEyeEnergy);
c.addEnergy(addEng);
return;
}
c.subEnergy(subEng);
}
}
@ -92,11 +100,13 @@ public class Eye {// 这个眼睛是从青蛙视角来观察,因为青蛙生
shape = new Cuboid(cx + 2, cy, cz, 1, 1, 1);
}
public void cellAct(Frog f, Cell c) {// 如果上方有物体就激活视网膜细胞
public void cellAct(Frog f, Cell c) {
for (int i = 1; i <= seeDistance; i++)
if (Env.foundAnyThing(f.x + i, f.y)) {
addLineEnergy(f, c, addEyeEnergy);
c.addEnergy(addEng);
return;
}
c.subEnergy(subEng);
}
}

@ -10,9 +10,11 @@
*/
package com.github.drinkjava2.frog.brain.organ;
import java.io.Serializable;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Line is a line from cell1 to cell2
@ -20,16 +22,13 @@ import com.github.drinkjava2.frog.brain.Cell;
* @author Yong Zhu
* @since 2020-04-18
*/
public class Line implements Serializable {// Line代表一个从cell1到cell2的神经元连接,energy表示连接能量
public class Line extends Organ {// Line代表一个从cell1到cell2的神经元连接,energy表示连接能量
private static final long serialVersionUID = 1L;
public float energy;
public int eng = 30;
public int fat = 0;
public int x1, y1, z1, x2, y2, z2;
public Line() {
// 缺省构造器必有, 因为从磁盘上反序列化要先调用这个构造器
}
public Line(Cell c1, Cell c2) {
this.x1 = c1.x;
this.y1 = c1.y;
@ -39,4 +38,37 @@ public class Line implements Serializable {// Line代表一个从cell1到cell2
this.z2 = c2.z;
}
public void active(Frog f) {// 重写active方法,line的作用就是在细胞c1,c2间传送能量(即信息)
if (!f.alive)
return;
if (RandomUtils.percent(5))
eng = RandomUtils.varyInLimit(eng, 1, 70);// 传输的能量也参与进化
Cell c1 = f.getCell1(this);
if (c1 == null)
return;
Cell c2 = f.getCell2(this);
if (c2 == null)
return;
if (c1.energy > eng) { // 为了保证能量(即熵)守恒,传出的能量要不大于输入能量
fat++;
c1.subEnergy(eng);
c2.addEnergy(eng);
}
}
@Override
public Organ[] vary(Frog f) {
if (fat <= 0)// 如果胖值为0表示这个组的细胞没有用到可以小概率丢掉它了
if (RandomUtils.percent(30))
return new Organ[] {};
if (RandomUtils.percent(3)) // 有3%的几率丢掉它,防止这个器官数量只增不减
return new Organ[] {};
return new Organ[] { this };
}
public void drawOnBrainPicture(Frog f, BrainPicture pic) {
pic.drawLine(this);
pic.drawPoint(this.x2 + .5f, this.y2 + .5f, this.z2 + .5f, 5);
pic.drawText((x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2, "" + eng, 1);
}
}

@ -1,96 +0,0 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain.organ;
import java.awt.Color;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.BrainPicture;
import com.github.drinkjava2.frog.brain.Cell;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* If move cell active, frog will move
*
* Move便
*
* @author Yong Zhu
*/
public class Lines extends Organ {// Lines器官很重要它是神经元之间的连线由随机生成由生存竟争淘汰
private static final long serialVersionUID = 1L;
private static final int LINE_QTY = 100;// 总共允许最多有多少根线条
public Line[] lines;
public Lines() {
shape = null;
organName = null;
if (lines == null)
lines = new Line[LINE_QTY];
}
public void init(Frog f, int orgNo) { // 在青蛙生成时会调用这个方法,进行一些初始化
if (RandomUtils.percent(3f)) // 生成线
addLine(f);
if (RandomUtils.percent(3f)) // 丢弃线
discardLine(f);
}
/**
* 1.线 2.线
*/
public void active(Frog f) {
for (Line line : lines) {
if (line == null)
continue;
f.energy -= 1; //线不是越多越好,线越多,所需能量越多
}
}
public void addLine(Frog f) {// 随机生成线
Cell c1 = RandomUtils.getRandomCell(f);
if (c1 == null)
return;
Cell c2 = RandomUtils.getRandomCell(f);
if (c2 == null)
return;
for (int i = 0; i < lines.length; i++) {// 找空位插入新的线
if (lines[i] == null) {
lines[i] = new Line(c1, c2);
return;
}
}
// 没找到? 随便找个位置顶替原来的线
lines[RandomUtils.nextInt(LINE_QTY)] = new Line(c1, c2);
}
public void discardLine(Frog f) {// 随机丢弃线
lines[RandomUtils.nextInt(LINE_QTY)] = null;
}
/** Child class can override this method to drawing picture */
public void drawOnBrainPicture(Frog f, BrainPicture pic) { // 把器官的轮廓显示在脑图上
if (!Env.SHOW_FIRST_FROG_BRAIN || !f.alive) // 如果不允许画或青蛙死了,就直接返回
return;
for (Line line : lines) {
if (line == null)
continue;
if (line.energy > 0) // 正值用兰色,负值用红色表示
pic.setPicColor(Color.RED);
else
pic.setPicColor(Color.GRAY);
pic.drawLine(line);
pic.drawPoint(line.x2 + .5f, line.y2 + .5f, line.z2 + .5f, 10);
}
}
}

@ -39,7 +39,7 @@ public class Move {// 因为青蛙生活在二次元所以只有上下左右4
@Override
public void cellAct(Frog f, Cell c) {
if (getLineEnergy(f, c))
if (c.inActive())
f.y--;
}
}
@ -53,7 +53,7 @@ public class Move {// 因为青蛙生活在二次元所以只有上下左右4
@Override
public void cellAct(Frog f, Cell c) {
if (getLineEnergy(f, c))
if (c.inActive())
f.y++;
}
}
@ -67,7 +67,7 @@ public class Move {// 因为青蛙生活在二次元所以只有上下左右4
@Override
public void cellAct(Frog f, Cell c) {
if (getLineEnergy(f, c))
if (c.inActive())
f.x--;
}
}
@ -81,7 +81,7 @@ public class Move {// 因为青蛙生活在二次元所以只有上下左右4
@Override
public void cellAct(Frog f, Cell c) {
if (getLineEnergy(f, c))
if (c.inActive())
f.x++;
}
}

@ -17,10 +17,10 @@ import java.util.List;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.organ.Active;
import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.brain.organ.Eat;
import com.github.drinkjava2.frog.brain.organ.Lines;
import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.brain.organ.Move;
import com.github.drinkjava2.frog.brain.organ.Move.MoveUp;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
@ -50,7 +50,6 @@ public class Egg implements Serializable {
organs.add(new Move.MoveRight());
organs.add(new Active()); // 始终激活
organs.add(new Eat()); // 没有什么比吃到东西更愉快的了
organs.add(new Lines()); // 连线
}
/** Create egg from frog */

@ -109,15 +109,29 @@ public class RandomUtils {
return v;
}
// public static int vary(int v) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
// if (percent(40))
// v *= .98 + .04 * nextFloat(); // 0.98~1.02
// if (percent(10))
// v *= .95 + .103 * nextFloat(); // 0.95~1.053
// else if (percent(5))
// v *= .08 + 0.45 * nextFloat(); // 0.8~1.25
// else if (percent(1))
// v *= .05 + 1.5 * nextFloat(); // 0.5~2
// return v;
// }
public static int vary(int v) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
if (percent(40))
v *= .98 + .04 * nextFloat(); // 0.98~1.02
v += v * .04 * (nextFloat() - 0.5); // v=v+-.04
if (percent(10))
v *= .95 + .103 * nextFloat(); // 0.95~1.053
v += v * .103 * (nextFloat() - 0.5); // v=v+-0.1
else if (percent(5))
v *= .08 + 0.45 * nextFloat(); // 0.8~1.25
else if (percent(1))
v *= .05 + 1.5 * nextFloat(); // 0.5~2
v += v * 1 * (nextFloat() - 0.5); // v=v+-0.4
else if (percent(2))
v += v * 4 * (nextFloat() - 0.5); // v=v+-2
else if (percent(1f))
v += v * 8 * (nextFloat() - 0.5); // v=v+-6
return v;
}
@ -136,15 +150,29 @@ public class RandomUtils {
return v;
}
// public static float vary(float v) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
// if (percent(40))
// v *= .98 + .04 * nextFloat(); // 0.98~1.02
// if (percent(10))
// v *= .95 + .103 * nextFloat(); // 0.95~1.053
// else if (percent(5))
// v *= .08 + 0.45 * nextFloat(); // 0.8~1.25
// else if (percent(1))
// v *= .05 + 1.5 * nextFloat(); // 0.5~2
// return v;
// }
public static float vary(float v) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
if (percent(40))
v *= .98 + .04 * nextFloat(); // 0.98~1.02
v += v * .04 * (nextFloat() - 0.5); // v=v+-.04
if (percent(10))
v *= .95 + .103 * nextFloat(); // 0.95~1.053
v += v * .103 * (nextFloat() - 0.5); // v=v+-0.1
else if (percent(5))
v *= .08 + 0.45 * nextFloat(); // 0.8~1.25
else if (percent(1))
v *= .05 + 1.5 * nextFloat(); // 0.5~2
v += v * 1 * (nextFloat() - 0.5); // v=v+-0.4
else if (percent(2))
v += v * 4 * (nextFloat() - 0.5); // v=v+-2
else if (percent(1f))
v += v * 8 * (nextFloat() - 0.5); // v=v+-6
return v;
}

@ -0,0 +1,3 @@
## history\001分支简介
2019.03.11 这是frog项目第一个版本虚拟环境初步建立可以模拟低等生命的遗传、繁殖、变异、进化现象但只能往一个方向运动相当于一个最简单的单细胞生物还不具备视觉能力不具备主动找食能力。
运行run.bat可以查看演示需要安装Java8和Maven

@ -0,0 +1,3 @@
## history\002分支简介
2019-04-12 添加一个简单的眼睛(只有四个感光细胞),自然选择的结果是眼睛被选中,但是和运动区短路了,谈不上智能。但有眼睛后找食效率明显提高了。
这个分支的意义在于它证明了完全随机分布的神经元可以进化成眼睛。

@ -0,0 +1,6 @@
## history\003分支简介
2019-07-28 有以下改动:
1.在Env区中间加了一个陷阱区Trap以增加趣味性自然选择的结果是青蛙会自动绕开陷阱区。
2.增加一个Active器官它的作用是一直保持激活发现比Hungry器官驱动更能提高找食效率。
3.增加一个Chance器官,它的作用是引入随机扰动,打破青蛙有时候围着一个食物打转就是吃不着的死循环。目前进食奖励信号没用到,白白浪费了。
另外Chance和Eye类里也再次运用了随机试错原理去确定关键参数

@ -0,0 +1,2 @@
## 简介
2019-12-27 在history\003a_legs目录下依然是2维脑)尝试给青蛙加两条腿看它能不能自动学会走路。一条腿位于下方负责左右移动一条腿位于右侧负责上下移动每条腿有抬腿、落腿、转动和相应的感觉细胞。只有当腿落下且转动而且另一条脚抬起来时青蛙才会位移具体什么时候抬腿、什么时候转动腿完全由随机数决定。经过一段时间的生存汰淘之后青蛙会进化出会利用两条腿走路了但需要的时间非常长约几个小时之后才达到最高吃食率50%左右,走路风格也比较诡异,是小碎步而不是大踏步。但至少这是青蛙第一次利用两条腿来走路,还是有点意义的,这证明生命进化中就算神经元随机排布,进化出眼睛和腿也是非常简单自然的事。

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ -0,0 +1,5 @@
## 这个分支是基于003_trap基础上简化得来的意义不是很大只是为了方便我整理一下思路
说明本人在作3D脑结构时发现找食率始终很难提高到40%以上原因是没有忠实地照搬2维脑的逻辑但一时找不到问题所在。原来的2维脑器官太多因此这在个分支里先去除不需要的器官和逻辑把2维脑精简到能进化出眼睛的最简结构以便于为下一步转化到3D模式作准备。
在实验中发现Active中的organOutputEnergy参数对进化影响非常大最合适的值为1~3之间吃食率最高可达80%,其它的值吃食率极低。

@ -0,0 +1,2 @@
call mvn eclipse:eclipse
call pause

@ -0,0 +1,102 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.drinkjava2</groupId>
<artifactId>frog003b</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>frog</name>
<description>An artificial life test project</description>
<url>https://gitee.com/drinkjava2/jsqlbox/frog</url>
<issueManagement>
<system>gitee Issue</system>
<url>https://gitee.com/drinkjava2/jsqlbox/frog/issues</url>
</issueManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>Yong Zhu</name>
<email>yong9981@gmail.com</email>
<url>https://gitee.com/drinkjava2/</url>
</developer>
</developers>
<scm>
<connection>scm:git@gitee.com:drinkjava2/frog.git</connection>
<developerConnection>scm:git@gitee.com:drinkjava2/frog.git</developerConnection>
<url>git@gitee.com:drinkjava2/frog.git</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<!-- Release on Java8 -->
<version.java>1.8</version.java>
<version.javadoc>6</version.javadoc>
<version.compiler-plugin>3.3</version.compiler-plugin>
<version.war-plugin>2.6</version.war-plugin>
<version.clean-plugin>3.0.0</version.clean-plugin>
<version.resources-plugin>2.7</version.resources-plugin>
<version.surefire-plugin>2.19</version.surefire-plugin>
<version.jar-plugin>2.6</version.jar-plugin>
<version.source-plugin>2.4</version.source-plugin>
<version.javadoc-plugin>2.10.3</version.javadoc-plugin>
<version.gpg-plugin>1.6</version.gpg-plugin>
</properties>
<dependencies>
<!--dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler-plugin}</version>
<configuration>
<source>${version.java}</source>
<target>${version.java}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.github.drinkjava2.frog.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
</profiles>
</project>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save