Tube rename to Room

pull/1/head
Yong Zhu 5 years ago
parent 98ba7972db
commit 261576dd14

@ -39,7 +39,7 @@ public class Env extends JPanel {
public static final int FROG_PER_SCREEN = EGG_QTY * FROG_PER_EGG / SCREEN; // 每屏上显示几个青蛙,这个数值由上面三个参数计算得来
/** Frog's brain size is a 3D array of Cube */ // 脑空间是个三维Cube数组,为节约内存,仅在用到数组元素时才去初始化这维,按需分配内存
/** Frog's brain size is a 3D array of Room */ // 脑空间是个三维Room数组,为节约内存,仅在用到数组元素时才去初始化这维,按需分配内存
public static final int FROG_BRAIN_XSIZE = 30; // frog的脑在X方向长度
public static final int FROG_BRAIN_YSIZE = 20; // frog的脑在Y方向长度
public static final int FROG_BRAIN_ZSIZE = 20; // frog的脑在Z方向长度
@ -60,7 +60,7 @@ 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 = 3000;// 每轮测试步数,可调
public static final int STEPS_PER_ROUND = 2000;// 每轮测试步数,可调
public static int step;// 当前测试步数
public static final int FOOD_QTY = 100; // 食物数量, 可调
@ -242,7 +242,7 @@ public class Env extends JPanel {
Application.brainPic.drawBrainPicture(firstFrog);
for (int j = 0; j < FROG_PER_SCREEN; j++) {
Frog f = frogs.get(screen * FROG_PER_SCREEN + j);
f.cubes = null; // 清空frog脑细胞所占用的内存
f.rooms = null; // 清空frog脑细胞所占用的内存
}
Application.mainFrame.setTitle(new StringBuilder("Round: ").append(round).append(", screen:")
.append(screen).append(", ").append(foodFoundCountText()).append(", 用时: ")

@ -18,26 +18,25 @@ import java.util.List;
import javax.imageio.ImageIO;
import com.github.drinkjava2.frog.brain.Cube;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.organ.Organ;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.Room;
import com.github.drinkjava2.frog.egg.Egg;
import com.github.drinkjava2.frog.objects.Material;
/**
* Frog = organs + cubes <br/>
* cubes = brain cells + photon <br/>
* Frog = organs + rooms <br/>
* rooms = brain cells + photons <br/>
* organs = cell parameters + cell actions
*
* Groupcubescube
*
* Organroomsroom
*
* @author Yong Zhu
* @since 1.0
*/
public class Frog {
/** brain cells */
public Cube[][][] cubes;
/** brain rooms */
public Room[][][] rooms;// 一开始不要初始化只在调用getRoom方法时才初始化相关维以节约内存
/** organs */
public List<Organ> organs = new ArrayList<>();
@ -64,9 +63,9 @@ public class Frog {
organs.add(org);
}
public void initFrog() {// 仅在测试之前调用这个方法初始化frog以节约内存测试完成后要清空cubes释放内存
public void initFrog() {// 仅在测试之前调用这个方法初始化frog以节约内存测试完成后要清空units释放内存
try {
cubes = new Cube[Env.FROG_BRAIN_XSIZE][][]; // 为了节约内存先只初始化三维数组的x维另两维用到时再分配
rooms = new Room[Env.FROG_BRAIN_XSIZE][][]; // 为了节约内存先只初始化三维数组的x维另两维用到时再分配
} catch (OutOfMemoryError e) {
System.out.println("OutOfMemoryError found for frog, force it die.");
this.alive = false;
@ -76,32 +75,32 @@ public class Frog {
org.init(this);
}
/** Find a organ in frog by organ's class name */
/** Find a organ in frog by organ's name */
@SuppressWarnings("unchecked")
public <T extends Organ> T findOrganByName(String organName) {// 根据器官类名寻找器官,不常用
public <T extends Organ> T findOrganByName(String organName) {// 根据器官名寻找器官,但不是每个器官都有名字
for (Organ o : organs)
if (organName.equalsIgnoreCase(o.getClass().getSimpleName()))
if (o.organName != null && organName.equalsIgnoreCase(o.organName))
return (T) o;
return null;
}
/** Active all cubes in organ with given activeValue */
/** Set with given activeValue */
public void setCuboidVales(Cuboid o, float active) {// 激活长方体区域内的所有脑区
if (!alive)
return;
for (int x = o.x; x < o.x + o.xe; x++)
for (int y = o.y; y < o.y + o.ye; y++)
for (int z = o.z; z < o.z + o.ze; z++)
getCube(x, y, z).setActive(active);
}
getRoom(x, y, z).setActive(active);
}
/** Calculate organ activity by add all organ cubes' active value together */
public float getCuboidTotalValues(Cuboid o) {// 遍历长方体区域所在cube,将它们的激活值汇总返回
/** Calculate organ activity by add all organ rooms' active value together */
public float getCuboidTotalValues(Cuboid o) {// 遍历长方体区域所在room,将它们的激活值汇总返回
float activity = 0;
for (int x = o.x; x < o.x + o.xe; x++)
for (int y = o.y; y < o.y + o.ye; y++)
for (int z = o.z; z < o.z + o.ze; z++)
activity += this.getCube(x, y, z).getActive();
activity += this.getRoom(x, y, z).getActive();
return activity;
}
@ -125,23 +124,23 @@ public class Frog {
g.drawImage(frogImg, x - 8, y - 8, 16, 16, null);
}
/** Check if cube exist */
public boolean existCube(int x, int y, int z) {// 检查指定坐标Cube是否存在
return cubes[x] != null && cubes[x][y] != null && cubes[x][y][z] != null;
/** Check if room exist */
public boolean existRoom(int x, int y, int z) {// 检查指定坐标room是否存在
return rooms[x] != null && rooms[x][y] != null && rooms[x][y][z] != null;
}
/** Get a cube in position (x,y,z), if not exist, create a new one */
public Cube getCube(int x, int y, int z) {// 获取指定坐标的Cube如果为空则在指定位置新建Cube
if (cubes[x] == null)
cubes[x] = new Cube[Env.FROG_BRAIN_YSIZE][];
if (cubes[x][y] == null)
cubes[x][y] = new Cube[Env.FROG_BRAIN_ZSIZE];
if (cubes[x][y][z] == null) {
Cube cube = new Cube();
cubes[x][y][z] = cube;
return cube;
/** Get a room in position (x,y,z), if not exist, create a new one */
public Room getRoom(int x, int y, int z) {// 获取指定坐标的Room如果为空则在指定位置新建Room
if (rooms[x] == null)
rooms[x] = new Room[Env.FROG_BRAIN_YSIZE][];
if (rooms[x][y] == null)
rooms[x][y] = new Room[Env.FROG_BRAIN_ZSIZE];
if (rooms[x][y][z] == null) {
Room unit = new Room();
rooms[x][y][z] = unit;
return unit;
} else
return cubes[x][y][z];
return rooms[x][y][z];
}
}

@ -1,12 +1,15 @@
package com.github.drinkjava2.frog.brain;
import static java.awt.Color.BLACK;
import static java.awt.Color.BLUE;
import static java.awt.Color.CYAN;
import static java.awt.Color.GREEN;
import static java.awt.Color.MAGENTA;
import static java.awt.Color.ORANGE;
import static java.awt.Color.RED;
import static java.awt.Color.WHITE;
import static java.awt.Color.YELLOW;
//import static java.awt.BLUE;
import static java.lang.Math.cos;
import static java.lang.Math.round;
import static java.lang.Math.sin;
@ -18,7 +21,6 @@ import javax.swing.JPanel;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.organ.Organ;
/**
* BrainPicture show first frog's brain structure, for debug purpose only
@ -28,9 +30,9 @@ import com.github.drinkjava2.frog.brain.organ.Organ;
* @author Yong Zhu
* @since 1.0
*/
@SuppressWarnings("serial")
@SuppressWarnings("all")
public class BrainPicture extends JPanel {
Color color = Color.red;
Color picColor = RED;
int brainDispWidth; // screen display piexls width
float scale; // brain scale
int xOffset = 0; // brain display x offset compare to screen
@ -75,6 +77,11 @@ public class BrainPicture extends JPanel {
drawLine(x, y + ye, z + ze, x, y, z + ze);
}
public void drawCone(Cone c) {// 在脑图上画一个锥体视角是TopView
drawLine(c.x1, c.y1, c.z1, c.x2, c.y2, c.z2);// 画锥体的中心线
//TODO画出锥体的上下面
}
/*-
线topx1,y1x2,y2线
x θ
@ -131,15 +138,15 @@ public class BrainPicture extends JPanel {
y2 = y;
Graphics g = this.getGraphics();
g.setColor(color);
g.setColor(picColor);
g.drawLine((int) round(x1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + xOffset,
(int) round(y1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset,
(int) round(x2) + Env.FROG_BRAIN_DISP_WIDTH / 2 + xOffset,
(int) round(y2) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset);
}
/** 画出Cube的中心点 */
public void drawCubeCenter(float x, float y, float z) {
/** 画出Room的中心点 */
public void drawRoomCenter(float x, float y, float z) {
drawPoint(x + 0.5f, y + 0.5f, z + 0.5f, (int) Math.max(1, Math.round(scale * .7)));
}
@ -168,7 +175,7 @@ public class BrainPicture extends JPanel {
y1 = y;
Graphics g = this.getGraphics();
g.setColor(color);
g.setColor(picColor);
g.fillOval((int) round(x1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + xOffset,
(int) round(y1) + Env.FROG_BRAIN_DISP_WIDTH / 2 + yOffset - diameter / 2, diameter, diameter);
}
@ -184,20 +191,20 @@ public class BrainPicture extends JPanel {
public static Color rainbowColor(float i) {
if (i == 0)
return Color.black;
return BLACK;
if (i == 1)
return Color.RED;
return RED;
if (i <= 3)
return Color.ORANGE;
return ORANGE;
if (i <= 10)
return Color.YELLOW;
return YELLOW;
if (i <= 20)
return Color.GREEN;
return GREEN;
if (i <= 50)
return Color.CYAN;
return CYAN;
if (i <= 100)
return Color.BLUE;
return Color.MAGENTA;
return BLUE;
return MAGENTA;
}
private static Cuboid brain = new Cuboid(0, 0, 0, Env.FROG_BRAIN_XSIZE, Env.FROG_BRAIN_YSIZE, Env.FROG_BRAIN_ZSIZE);
@ -208,28 +215,28 @@ public class BrainPicture extends JPanel {
if (!Env.SHOW_FIRST_FROG_BRAIN)
return;
Graphics g = this.getGraphics();
g.setColor(Color.WHITE);// 先清空旧图
g.setColor(WHITE);// 先清空旧图
g.fillRect(0, 0, brainDispWidth, brainDispWidth);
g.setColor(Color.black); // 画边框
g.setColor(BLACK); // 画边框
g.drawRect(0, 0, brainDispWidth, brainDispWidth);
setPicColor(BLACK);
drawCuboid(brain);// 先把脑的框架画出来
for (Organ organ : f.organs)// 每个器官负责画出自已在脑图中的位置和形状
organ.drawOnBrainPicture(f, this); // each organ draw itself
this.setColor(Color.RED);
setPicColor(RED);
drawLine(0, 0, 0, 1, 0, 0);
drawLine(0, 0, 0, 0, 1, 0);
drawLine(0, 0, 0, 0, 0, 1);
for (int x = 0; x < Env.FROG_BRAIN_XSIZE; x++) {
if (f.cubes[x] != null)
if (f.rooms[x] != null)
for (int y = 0; y < Env.FROG_BRAIN_YSIZE; y++) {
if (f.cubes[x][y] != null)
if (f.rooms[x][y] != null)
for (int z = 0; z < Env.FROG_BRAIN_ZSIZE; z++) {
if (f.existCube(x, y, z) && f.getCube(x, y, z).getActive() > 0) {
setColor(rainbowColor(f.getCube(x, y, z).getActive()));
drawCubeCenter(x, y, z);
if (f.existRoom(x, y, z) && f.getRoom(x, y, z).getActive() > 0) {
setPicColor(rainbowColor(f.getRoom(x, y, z).getActive()));
drawRoomCenter(x, y, z);
}
}
}
@ -270,8 +277,8 @@ public class BrainPicture extends JPanel {
this.zAngle = zAngle;
}
public void setColor(Color color) {
this.color = color;
public void setPicColor(Color color) {
this.picColor = color;
}
public int getxOffset() {

@ -10,8 +10,6 @@
*/
package com.github.drinkjava2.frog.brain;
import com.github.drinkjava2.frog.brain.organ.Organ;
/**
* Cell is the basic unit of frog's brain
*

@ -10,34 +10,33 @@
*/
package com.github.drinkjava2.frog.brain;
import java.io.Serializable;
/**
* Cone represents a cone zone in brain
* Cone represents a cone 3d zone in brain
*
* ConeCuboid.
* Cone()Cuboid.
*
* @author Yong Zhu
* @since 1.0
* @since 2.0.2
*/
public class Cone implements Serializable {
@SuppressWarnings("all")
public class Cone implements Shape {
private static final long serialVersionUID = 1L;
public float x1; // 这6个变量定义了Cone的中心线起点和终点,器官不能拐弯,但拐弯可以用多个立方锥体器官首尾相接演化出来
public float y1;
public float z1;
public float x2;
public float y2;
public float z2;
public int x1; // 这6个变量定义了Cone的中心线起点和终点,器官不能拐弯,但拐弯可以用一个锥体分成两个首尾相接的锥体再进一步变异演化出来
public int y1;
public int z1;
public int x2;
public int y2;
public int z2;
public float r1 = 8; // 起点的半径,为了简化编程,通常是是指起点矩形边长的一半,因为圆形计算麻烦
public float r2 = 8; // 终点的半径
public int r1 = 8; // 起点的半径,为了简化编程,通常是是指起点矩形边长的一半,因为圆形计算麻烦
public int r2 = 8; // 终点的半径
public Cone() {
// 空构造器不能省
}
public Cone(float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2) {// 用x,y,z,r来构造
public Cone(int x1, int y1, int z1, int x2, int y2, int z2, int r1, int r2) {// 用x,y,z,r来构造
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
@ -48,4 +47,9 @@ public class Cone implements Serializable {
this.r2 = r2;
}
@Override
public void drawOnBrainPicture(BrainPicture pic) {
pic.drawCone(this);
}
}

@ -10,17 +10,16 @@
*/
package com.github.drinkjava2.frog.brain;
import java.io.Serializable;
/**
* Cuboid represents a rectangular prism zone in brain
* Cuboid represents a rectangular prism 3d zone in brain
*
* CuboidCone
*
* @author Yong Zhu
* @since 1.0
* @since 2.0.2
*/
public class Cuboid implements Serializable {
@SuppressWarnings("all")
public class Cuboid implements Shape {
private static final long serialVersionUID = 1L;
public int x;// x,y,z是长方体的左下角坐标
@ -43,7 +42,7 @@ public class Cuboid implements Serializable {
this.ze = ze;
}
public Cuboid(Cuboid c) {// 用另一个Cube来构造
public Cuboid(Cuboid c) {// 用另一个Cuboid来构造
this.x = c.x;
this.y = c.y;
this.z = c.z;
@ -52,19 +51,8 @@ public class Cuboid implements Serializable {
this.ze = c.ze;
}
public static void copyXYZ(Cuboid from, Cuboid to) {
to.x = from.x;
to.y = from.y;
to.z = from.z;
}
public static void copyXYZE(Cuboid from, Cuboid to) {
to.x = from.x;
to.y = from.y;
to.z = from.z;
to.xe = from.xe;
to.xe = from.xe;
to.xe = from.xe;
@Override
public void drawOnBrainPicture(BrainPicture pic) {
pic.drawCuboid(this);
}
}

@ -8,17 +8,14 @@
* 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;
package com.github.drinkjava2.frog.brain;
import java.awt.Color;
import java.io.Serializable;
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.Cone;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Synapse;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
* Organ is a cone-cylinder shape zone inside of brain,, organ can be saved in
@ -56,20 +53,18 @@ import com.github.drinkjava2.frog.brain.Synapse;
public class Organ implements Serializable, Cloneable {// 因为要保存在蛋文件里,所以必须支持串行化
private static final long serialVersionUID = 1L;
public float fat = 0;// 细胞活跃多则fat值大在一屏测试完成后如果fat值很低则这个器官被丢弃的可能性加大
public boolean allowBorrow;// 是否允许在精子中将这个器官借出
public float fat = 0;// 细胞活跃多则fat值大如果fat值很低则这个器官被丢弃的可能性加大这个值很重要它使得孤岛器官不存在,保证所有器官都相连
public boolean allowVary;// 是否允许变异,有一些器官是手工创建的,在项目初级阶段禁止它们参与变异和生存竟争。
public boolean allowBorrow;// 是否允许在精子中将这个器官借出,有一些器官是手工创建的,在项目初级阶段禁止它们借出
public String organName;// 器官的名字通常只有手工创建的器官才有名字可以用frog.findOrganByName来查找到这个器官
// 本行以下参数受变异和生存竟争影响,随机有大概率小变异,小概率大变异,极小概率极大变异
// ======= 本行以下所有参数受变异和生存竟争影响 =============
/** If cuboid is not null, then ignore cone setting */
public Cuboid cuboid; // 如果器官是长方体形状,则这个属性非空。器官的形状暂时只能是长方体或锥体
public int type; // 器官类型, 这是个最重要参数,它决定器官的播种行为、脑细胞的形状及行为, 这个字段如果变异,将极大地改变器官的性质
public Cone cone;// 如果器官是锥体,则这个属性非空
public Shape shape; // 器官的形状
public float cellDensity = 1; // 细胞播种密度,目前只有均匀播种这一个方案
public int type; // 脑细胞类型, 不同类型细胞对同一个参数的解释行为可能不同,或根本不会用到某个参数, 这个字段如果变异,将完全改变器官的行为
public float cellDistance; // 细胞播种间隔,它决定了播种密度。目前只有均匀播种这一个方案
public int synapsesLimit;// 细胞允许创建动态触突的数量上限详见Cell类的synapses字段
@ -83,7 +78,7 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
public float inputDoor;// 接收阀值,接收的能量小于这个阀值时,细胞不会吸收这份能量,直接煙灭或以光子的形式转发出去
public float radius;// 细胞即使没有触突也可以处理光子这个radius是细胞的管辖半径局限于角度的信号处理,如穿透和反射,或6个正方向
public float radius;// 细胞即使没有触突也可以处理光子这个radius是细胞的管辖半径处理信号角度只限于穿透和反射或6个正方向
public float dropRate;// 是一个介于0~1的值反映了细胞存的能量下降速率在每一步长中细胞能量都以这个速率损失可以参考遗忘曲线
@ -92,23 +87,49 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
public Synapse[] sides; // 侧面(通常是抑制,是负光子输出)输出触突,从脉冲神经网络学习到有这种侧向抑制
public Synapse[] outputs; // 输出触突
/** Only call once after organ be created by new() method */
public Organ[] vary() { // 器官的变异,返回本身或变异后的一个或多个类似自已的器官放在一个数组里返回
public Organ() {// 缺省构造器,生成具有缺省参数但没有形状的器官
allowVary = true;
allowBorrow = true;
type = 0;
cellDistance = 1;
synapsesLimit = 10;
energyLimit = 100;
outputRate = 30;
outputDoor = 30;
inputRate = 100;
inputDoor = 5;
radius = 1;
dropRate = 95;
inputs = null;
sides = null;
outputs = null;
}
/** Only call once after organ be created */
public Organ[] vary(Frog f) { // 器官变异仅会在青蛙下蛋时即new Egg(frog)中被调用一次,返回本身或变异后的一个或一组类似器官返回
if (!allowVary)
return new Organ[] { this };// 如果不允许变异,器官就把自身返回,存放在蛋里
Organ newOrgan = null;
try {
newOrgan = (Organ) this.clone();// 克隆这个方法名符其实
} catch (Exception e) {
throw new UnknownError("Can not make new Organ copy for " + this);
}
// TODO:这里要添加新器官变异的具体代码,所有器官都共用同一个变异规则,变异包括数量增减、形状及位置、各种可变异参数等
return new Organ[] { newOrgan };
type = RandomUtils.vary(type);// 随机有大概率小变异,小概率大变异,极小概率极大变异
shape = RandomUtils.vary(shape);
cellDistance = RandomUtils.vary(cellDistance);
synapsesLimit = RandomUtils.vary(synapsesLimit);
energyLimit = RandomUtils.vary(energyLimit);
outputRate = RandomUtils.vary(outputRate);
outputDoor = RandomUtils.vary(outputDoor);
inputRate = RandomUtils.vary(inputRate);
inputDoor = RandomUtils.vary(inputDoor);
radius = RandomUtils.vary(radius);
dropRate = RandomUtils.vary(dropRate);
inputs = RandomUtils.vary(inputs);
sides = RandomUtils.vary(sides);
outputs = RandomUtils.vary(outputs);
return new Organ[] { this };
}
/** Only call once when frog created , Child class can override this method */
public void init(Frog f) { // 在青蛙生成时会调用这个方法,进行一些初始化,通常是根据参数来播种脑细胞
// TODO:这里要添加器官播种脑细胞的具体代码,所有器官都共用同一个方法
// 这里是各种形状器官播种脑细胞的具体代码,目前只有长方体和锥体两种形状
}
/** each step will call Organ's active methodd */
@ -120,9 +141,20 @@ public class Organ implements Serializable, Cloneable {// 因为要保存在蛋
public void drawOnBrainPicture(Frog f, BrainPicture pic) { // 把器官的轮廓显示在脑图上
if (!Env.SHOW_FIRST_FROG_BRAIN || !f.alive) // 如果不允许画或青蛙死了,就直接返回
return;
pic.setColor(Color.BLACK); // 缺省是黑色
if (cuboid != null)
pic.drawCuboid(cuboid);// 如果器官是长方体就调用drawCuboid方法画出来
pic.setPicColor(Color.LIGHT_GRAY); // 缺省是黑色
shape.drawOnBrainPicture(pic);
}
public static Organ randomCuboidOrgan() {
Organ o = new Organ();
o.shape = RandomUtils.randomCuboid();
return o;
}
public static Organ randomConeOrgan() {
Organ o = new Organ();
o.shape = RandomUtils.randomCone();
return o;
}
}

@ -13,17 +13,17 @@ package com.github.drinkjava2.frog.brain;
import java.util.Arrays;
/**
* Cube include 0~n cells and 0~n photons
* Room is the smallest unit of brain space, a room can have 0~n cells and 0~n
* photons
*
* Cube(Cell)(Photon)
* CubeCuboidCubeCuboid,
*
* Room(Cell)(Photon)frogrooms
* RoomCube, Room
*
* @author Yong Zhu
* @since 1.0
*/
public class Cube {
/** Activity of current cube */
public class Room {
/** Activity of current room */
private float active = 0; // 这个立方体的激活程度,允许是负值,它反映了在这个小立方体里所有光子的能量汇总值
private Cell[] cells = null;

@ -0,0 +1,26 @@
/*
* 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;
import java.io.Serializable;
/**
* Shape represents a 3d zone in brain
*
* Shape,shape
*
* @author Yong Zhu
* @since 2.0.2
*/
public interface Shape extends Serializable {
/* Draw self on brain picture */
public void drawOnBrainPicture(BrainPicture pic);
}

@ -14,13 +14,17 @@ 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.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Eye can only see env material
* Ear can accept letter information input
* +Unicode
*
* @author Yong Zhu
* @since 2.0.2
*/
public class Ear extends Organ {// 耳朵也是长方体所以它的cuboid不为空
@SuppressWarnings("all")
public class Ear extends Organ {// 耳朵也是长方体,我为什么要用也?
private static final long serialVersionUID = 1L;
public int n = 18; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3)
public Cuboid a = new Cuboid(10, 10, Env.FROG_BRAIN_ZSIZE - 1, 3, 3, 1);
@ -29,7 +33,10 @@ public class Ear extends Organ {// 耳朵也是长方体所以它的cuboid不
public Cuboid d = new Cuboid(15, 15, Env.FROG_BRAIN_ZSIZE - 1, 3, 3, 1);
public Ear() {
this.cuboid = new Cuboid(10, 10, Env.FROG_BRAIN_ZSIZE - 1, 8, 8, 1);
this.shape = new Cuboid(10, 10, Env.FROG_BRAIN_ZSIZE - 1, 8, 8, 1);
this.organName = "ear";
this.allowVary = false;
this.allowBorrow=false;
}
public void drawOnBrainPicture(Frog f, BrainPicture pic) {// 把自已这个器官在脑图上显示出来,子类可以重写这个方法

@ -12,18 +12,22 @@ package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Eye can only see env material
*
* @author Yong Zhu
*/
public class Eye extends Organ {// 眼睛是长方体所以它的cuboid不为空
public class Eye extends Organ {// 眼睛是长方体
private static final long serialVersionUID = 1L;
public int n = 18; // 眼睛有n x n个感光细胞 用随机试错算法自动变异(加1或减1最小是3x3)
public Eye() {
this.cuboid = new Cuboid(0, 5, 5, 1, 10, 10);
this.shape = new Cuboid(0, 5, 5, 1, 10, 10);
this.organName = "eye";
this.allowVary = false;
this.allowBorrow = false;
}
/**
@ -36,12 +40,13 @@ public class Eye extends Organ {// 眼睛是长方体所以它的cuboid不为
return;
int w = pixels.length;
int h = pixels[0].length;
Cuboid c = (Cuboid) shape;
// 在视网膜上产生字母像素点阵,即激活这个脑视网膜所在的cubes区然后由器官播种出的脑细胞负责将激活能量转为光子输送、存贮到其它位置
// 在视网膜上产生字母像素点阵,即激活这个脑视网膜所在的rooms区然后由器官播种出的脑细胞负责将激活能量转为光子输送、存贮到其它位置
for (int px = 0; px < w; px++)
for (int py = 0; py < h; py++)
if (pixels[px][py] > 0)
f.getCube(0, this.cuboid.y + this.cuboid.ye - px, this.cuboid.z + py).setActive(20);
f.getRoom(0, c.y + c.ye - px, c.z + py).setActive(20);
}
}

@ -15,9 +15,9 @@ import java.util.ArrayList;
import java.util.List;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
import com.github.drinkjava2.frog.brain.organ.Ear;
import com.github.drinkjava2.frog.brain.organ.Eye;
import com.github.drinkjava2.frog.brain.organ.Organ;
import com.github.drinkjava2.frog.util.RandomUtils;
/**
@ -31,41 +31,51 @@ import com.github.drinkjava2.frog.util.RandomUtils;
* @since 1.0
*/
public class Egg implements Serializable {
public static int FIXED_ORGAN_QTY = 11;
private static final long serialVersionUID = 1L;
public List<Organ> organs = new ArrayList<>();
public List<Organ> organs = new ArrayList<>();// NOSONAR
public Egg() {// 无中生有,创建一个蛋,先有蛋,后有蛙
organs.add(new Eye()); // 眼是手工创建的,必有
organs.add(new Ear()); // 耳是手工创建的这个是用来测试ABCD字母识别的
organs.add(Organ.randomCuboidOrgan());
}
/** Create egg from frog */
public Egg(Frog frog) { // 青蛙下蛋每个青蛙的器官会创建自已的副本或变异可以是0或多个
for (Organ organ : frog.organs)
for (Organ newOrgan : organ.vary())
for (Organ newOrgan : organ.vary(frog))
organs.add(newOrgan);
}
/**
* Create a egg by join 2 eggs, x+y=zygote XY XY,
* 退,
*
*
* Create a egg by join 2 eggs, x+y=zygote XY
* XY
*/
public Egg(Egg x, Egg y) {
for (Organ organ : x.organs) {
if (!organ.allowVary || organ.fat != 0 || RandomUtils.percent(70)) // 如果器官没用到,fat为0增加丢弃它的机率
organs.add(organ);
}
// x里原来的organ
for (Organ organ : x.organs)
organs.add(organ);
// 从y里借一个organ
if (RandomUtils.percent(70)) // 70%的情况下不作为, x就是受精卵
return;
// 从y里借一个organ替换掉原来位置的organ相当于DNA级别的片段切换它要求一个随机位置的Organ都允许替换allowBorrow
int yOrganSize = y.organs.size();
if (yOrganSize > 0) {
Organ o = y.organs.get(RandomUtils.nextInt(yOrganSize));
if (o.allowBorrow)
organs.add(o);
int i = RandomUtils.nextInt(yOrganSize);
Organ o = y.organs.get(i);
if (o.allowBorrow) {
if (organs.size() > i && organs.get(i).allowBorrow)
organs.set(i, o);// 用y里的organ替换掉x里的organ,模拟受精
}
}
if (RandomUtils.percent(50))// 有50%的机率随机会产生新的器官
organs.add(Organ.randomCuboidOrgan());
if (RandomUtils.percent(organs.size())) {// 器官会随机丢失,并且机率与器官数量成正比,防止器官无限增长
int i = RandomUtils.nextInt(organs.size());
if (organs.get(i).allowBorrow)
organs.remove(i);
}
}

@ -46,8 +46,8 @@ public class LetterTester implements EnvObject {
letter = String.valueOf(STR.charAt(RandomUtils.nextInt(4)));
pixels = StringPixelUtils.getSanserif12Pixels(letter);
}
Frog firstFrog = Env.frogs.get(screen * Env.FROG_PER_SCREEN);
Eye eye = firstFrog.findOrganByName("eye");
Frog firstFrog = Env.frogs.get(screen * Env.FROG_PER_SCREEN);
Eye eye = firstFrog.findOrganByName("eye");
eye.seeImage(firstFrog, pixels);
Ear ear = firstFrog.findOrganByName("ear");

@ -10,8 +10,18 @@
*/
package com.github.drinkjava2.frog.util;
import static com.github.drinkjava2.frog.Env.FROG_BRAIN_XSIZE;
import static com.github.drinkjava2.frog.Env.FROG_BRAIN_YSIZE;
import static com.github.drinkjava2.frog.Env.FROG_BRAIN_ZSIZE;
import java.util.Random;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.brain.Cone;
import com.github.drinkjava2.frog.brain.Cuboid;
import com.github.drinkjava2.frog.brain.Shape;
import com.github.drinkjava2.frog.brain.Synapse;
/**
* Random Utilities used in this project
*
@ -28,10 +38,63 @@ public class RandomUtils {
public static float nextFloat() {
return rand.nextFloat();
}
public static boolean percent(float percent) {
public static boolean percent(float percent) {// 有百分这percent的机率为true
return rand.nextFloat() * 100 < percent;
}
/** Randomly create a Cuboid inside of brain space */
public static Cuboid randomCuboid() {// 随机生成一个位于脑空间内的立方体
Cuboid c = new Cuboid();
c.x = nextInt(FROG_BRAIN_XSIZE) - FROG_BRAIN_XSIZE / 4;// 为了多产生贴边的立方体,超出边界的被裁切
if (c.x < 0)
c.x = 0;
c.y = nextInt(FROG_BRAIN_YSIZE) - FROG_BRAIN_YSIZE / 4;
if (c.y < 0)
c.y = 0;
c.z = nextInt(FROG_BRAIN_ZSIZE) - FROG_BRAIN_ZSIZE / 4;
if (c.z < 0)
c.z = 0;
c.xe = 1 + nextInt(FROG_BRAIN_XSIZE); // 立方体任一个边长至少是1
if (c.xe > (FROG_BRAIN_XSIZE - c.x))// 超出边界的被裁切
c.xe = FROG_BRAIN_XSIZE - c.x;
c.ye = 1 + nextInt(FROG_BRAIN_YSIZE);
if (c.ye > (FROG_BRAIN_YSIZE - c.y))
c.ye = FROG_BRAIN_YSIZE - c.y;
c.ze = 1 + nextInt(FROG_BRAIN_ZSIZE);
if (c.ze > (FROG_BRAIN_ZSIZE - c.z))
c.ze = FROG_BRAIN_ZSIZE - c.z;
return c;
}
/** Randomly create a Cone inside of brain space */
public static Cone randomCone() {// 随机生成一个位于脑空间内的锥体
Cone c = new Cone();
c.x1 = nextInt(Env.FROG_BRAIN_XSIZE);
c.y1 = nextInt(Env.FROG_BRAIN_YSIZE);
c.z1 = nextInt(Env.FROG_BRAIN_ZSIZE);
c.x2 = nextInt(Env.FROG_BRAIN_XSIZE);
c.y2 = nextInt(Env.FROG_BRAIN_YSIZE);
c.z2 = nextInt(Env.FROG_BRAIN_ZSIZE);
c.r1 = nextInt(Env.FROG_BRAIN_ZSIZE / 2);// 暂时以z边长的一半取随机数
c.r2 = nextInt(Env.FROG_BRAIN_ZSIZE / 2);
return c;
}
public static int vary(int i) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
return i;
}
public static float vary(float f) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
return f;
}
public static Shape vary(Shape shape) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
return shape;
}
public static Synapse[] vary(Synapse[] synapses) {// 随机有大概率小变异,小概率大变异,极小概率极大变异
return synapses;
}
}

@ -7,12 +7,10 @@ LongFer
张老湿
王二麻子
封尘
陈秋华
hl330
目前收入总额:148.77元
目前收入总额:118.88元
支出(按时间顺序)
目前支出总额:0元
目前支出总额:0元
目前余额148.77
目前余额118.88

@ -82,4 +82,9 @@ git reset --hard ae34b07e 可以转回到2019-08-04提交的分组测试的找
开始进行3D脑的实际编程。
### 2019-9-09 到 2019-10-06 之间的6次提交
主要进行脑框架的显示和字母试别测试环境的搭建还没开始进行利用器官进行脑细胞播种的工作。这一阶段基本思路是在每一轮的测试过程前半段随机显示ABCD其中的一个字母(即激活视网膜所在的脑区),并同时激活一个任意脑区。在下半段则只激活这个字母的点阵,然后检测对应的这个脑区是否也会激活,如果激活的话,将会增加青蛙的能量值,让它在生存竟争中胜出,这一步是要完成基本的模式识别功能,框架已搭好,但器官的随机生成还没进行,这一步比较复杂,除了器官的大小位置等参数外,神经元的参数也多,比方说输入、输出光子的方向、正负、数量,能量吸收、释放比例,输入输出阀值、疲劳值、疲劳阀值等,这么多参数要利用随机生成器官的方式来筛选,需要的样本数量多,运行时间会比较长。早期是视网膜和识别区在脑长方体的同一侧,后来的提交改为将视网膜移到左侧,也就是说视觉与识别区(对应耳朵的语音区)在物理上呈90度正交以方便观察和编程。
主要进行脑框架的显示和字母试别测试环境的搭建还没开始进行利用器官进行脑细胞播种的工作。这一阶段基本思路是在每一轮的测试过程前半段随机显示ABCD其中的一个字母(即激活视网膜所在的脑区),并同时激活一个任意脑区。在下半段则只激活这个字母的点阵,然后检测对应的这个脑区是否也会激活,如果激活的话,将会增加青蛙的能量值,让它在生存竟争中胜出,这一步是要完成基本的模式识别功能,框架已搭好,但器官的随机生成还没进行,这一步比较复杂,除了器官的大小位置等参数外,神经元的参数也多,比方说输入、输出光子的方向、正负、数量,能量吸收、释放比例,输入输出阀值、疲劳值、疲劳阀值等,这么多参数要利用随机生成器官的方式来筛选,需要的样本数量多,运行时间会比较长。早期是视网膜和识别区在脑长方体的同一侧,后来的提交改为将视网膜移到左侧,也就是说视觉与识别区(对应耳朵的语音区)在物理上呈90度正交以方便观察和编程。
### 2019-10-06 到 2019-10-21 之间的几次提交
正在进行器官的随机生成、变异和脑细胞播种的编码,尚未完成,初步设想是先不要有固定方向的触突,纯粹用动态触突和随机器官生成试试,看看只用一两个器官是否能生成模式识别能力,即模仿出波驻点逆向成像现象。

Loading…
Cancel
Save