Artificial intelligence 如何确定基因组的特征?
在人工智能中,有没有简单和/或非常直观的例子来说明如何将基因组应用到模拟中 基本上,我要做的是一个简单的演练(不是教程,而是总结性质的东西),其中详细介绍了如何实现一个基因组,从而改变一个群体中“个体”的特征 这些基因应该而不是是这样的:Artificial intelligence 如何确定基因组的特征?,artificial-intelligence,simulation,genetic-algorithm,genome,Artificial Intelligence,Simulation,Genetic Algorithm,Genome,在人工智能中,有没有简单和/或非常直观的例子来说明如何将基因组应用到模拟中 基本上,我要做的是一个简单的演练(不是教程,而是总结性质的东西),其中详细介绍了如何实现一个基因组,从而改变一个群体中“个体”的特征 这些基因应该而不是是这样的: 弥撒 力量 长度 等等 但是,它们应该是定义上述事物的事物,从模拟居民的实际特征中提取基因组 我清楚我想要什么吗 不管怎么说,如果有什么方法你已经尝试过了,那更好,并且它以一种类似的形式实现了进化,那么无论如何,继续并发布它吧!灵感越有趣越好:)如果你自己
- 弥撒
- 力量
- 长度
- 等等
不管怎么说,如果有什么方法你已经尝试过了,那更好,并且它以一种类似的形式实现了进化,那么无论如何,继续并发布它吧!灵感越有趣越好:)如果你自己实现你的“个体”,那么任何物体都可以充当你的基因组 特性 进一步简化的一种方法是将您的特征转换为枚举。通过这种方式,您可以通过从父代基因中选择特征来进行简单的重组,并通过随机选择特征的一个枚举值来进行基因突变 一旦这项工作开始,您可以对值范围进行更细致的处理,但使用枚举可以帮助我在一开始就保持清楚 健身 然后,为了赋予这些特征含义,您需要一个描述性能的适应度函数。特征之间的关系取决于你,因此你可以用任何有意义的方式来描述它。这为比较两个基因组提供了一种一致的方法 模拟 然后,运行一个模拟,只需从几个家长开始,生成一组孩子,然后彼此完成。这当然可以自动化,但为了清晰起见,这里有一个明确的示例 Java示例
import java.util.PriorityQueue;
class Genome implements Comparable<Genome> {
public enum Mass {
LIGHT(1),
AVERAGE(2),
HEAVY(3);
final Integer value;
Mass(Integer value) {
this.value = value;
}
}
public enum Strength {
WEAK(1),
AVERAGE(2),
STRONG(3);
final Integer value;
Strength(Integer value) {
this.value = value;
}
}
public enum Length {
SHORT(1),
AVERAGE(2),
LONG(3);
final Integer value;
Length(Integer value) {
this.value = value;
}
}
private final Mass mass;
private final Strength strength;
private final Length length;
public Genome(Mass mass, Strength strength, Length length) {
this.mass = mass;
this.strength = strength;
this.length = length;
}
private Integer fitness() {
return strength.value * length.value - mass.value * mass.value;
}
@Override public int compareTo(Genome that) {
// notice the fitter is less in precedence
if(this.fitness() > that.fitness())
return -1;
else if(this.fitness() < that.fitness())
return 1;
else // this.fitness() == that.fitness()
return 0;
}
public static Genome recombine(Genome... parents) {
if(parents.length < 1)
return null;
// Select parents randomly and then characteristics from them
Mass mass = parents[(int)(Math.random() * parents.length)].mass;
Strength strength = parents[(int)(Math.random() * parents.length)].strength;
Length length = parents[(int)(Math.random() * parents.length)].length;;
return new Genome(mass, strength, length);
}
public static Genome mutate(Genome parent) {
// Select characteristics randomly
Mass mass = Mass.values()[(int)(Math.random() * Mass.values().length)];
Strength strength = Strength.values()[(int)(Math.random() * Strength.values().length)];
Length length = Length.values()[(int)(Math.random() * Length.values().length)];
return new Genome(mass, strength, length);
}
public static void main() {
PriorityQueue<Genome> population = new PriorityQueue<Genome>();
Genome parent1 = new Genome(Mass.LIGHT, Strength.STRONG, Length.SHORT);
Genome parent2 = new Genome(Mass.AVERAGE, Strength.AVERAGE, Length.AVERAGE);
Genome parent3 = new Genome(Mass.HEAVY, Strength.WEAK, Length.LONG);
population.add(parent1);
population.add(parent2);
population.add(parent3);
Genome child1 = Genome.recombine(parent1, parent2);
Genome child2 = Genome.recombine(parent1, parent2);
Genome child3 = Genome.recombine(parent1, parent3);
Genome child4 = Genome.recombine(parent1, parent3);
Genome child5 = Genome.recombine(parent2, parent3);
Genome child6 = Genome.recombine(parent2, parent3);
Genome child7 = Genome.recombine(parent1, parent2, parent3);
Genome child8 = Genome.recombine(parent1, parent2, parent3);
Genome child9 = Genome.recombine(parent1, parent2, parent3);
child1 = Genome.mutate(child1);
child2 = Genome.mutate(child2);
child4 = Genome.mutate(child4);
child8 = Genome.mutate(child8);
population.add(child1);
population.add(child2);
population.add(child3);
population.add(child4);
population.add(child5);
population.add(child6);
population.add(child7);
population.add(child8);
population.add(child9);
// and the winner is...
Genome fittest = population.peek();
}
}
import java.util.PriorityQueue;
class Genome implements Comparable<Genome> {
private final Integer sequence;
private static final Integer bitmaskChunk = 3; // ...0011
private static final Integer shiftMass = 0; // ...00XX
private static final Integer shiftLength = 2; // ...XX00
private static final Integer shiftModulus = 4; // ...0000
private Integer getMass() {
return (sequence >>> shiftMass) & bitmaskChunk;
}
private Integer getLength() {
return (sequence >>> shiftLength) & bitmaskChunk;
}
public Integer getStrength() {
return getMass() * getLength();
}
public Genome(Integer sequence) {
this.sequence = sequence % (1 << Genome.shiftModulus);
}
private Integer fitness() {
// Some performance measure
return getStrength() * getLength() - getMass() * getMass();
}
@Override public int compareTo(Genome that) {
// notice the fitter is less in precedence
if(this.fitness() > that.fitness())
return -1;
else if(this.fitness() < that.fitness())
return 1;
else // this.fitness() == that.fitness()
return 0;
}
public static Genome recombine(Genome... parents) {
if(parents.length < 1)
return null;
Integer sequence = 0;
// Select parents randomly and then characteristics from them
sequence += parents[(int)(Math.random() * parents.length)].getMass() << Genome.shiftMass;
sequence += parents[(int)(Math.random() * parents.length)].getLength() << Genome.shiftLength;
return new Genome(sequence);
}
public static Genome mutate(Genome parent) {
Integer sequence = parent.sequence;
// Randomly change sequence in some way
sequence *= (int)(Math.random() * (1 << Genome.shiftModulus));
return new Genome(sequence);
}
public static void main() {
PriorityQueue<Genome> population = new PriorityQueue<Genome>();
Genome parent1 = new Genome((int)(Math.random() * (1 << Genome.shiftModulus)));
Genome parent2 = new Genome((int)(Math.random() * (1 << Genome.shiftModulus)));
Genome parent3 = new Genome((int)(Math.random() * (1 << Genome.shiftModulus)));
population.add(parent1);
population.add(parent2);
population.add(parent3);
Genome child1 = Genome.recombine(parent1, parent2);
Genome child2 = Genome.recombine(parent1, parent2);
Genome child3 = Genome.recombine(parent1, parent3);
Genome child4 = Genome.recombine(parent1, parent3);
Genome child5 = Genome.recombine(parent2, parent3);
Genome child6 = Genome.recombine(parent2, parent3);
Genome child7 = Genome.recombine(parent1, parent2, parent3);
Genome child8 = Genome.recombine(parent1, parent2, parent3);
Genome child9 = Genome.recombine(parent1, parent2, parent3);
child1 = Genome.mutate(child1);
child2 = Genome.mutate(child2);
child4 = Genome.mutate(child4);
child8 = Genome.mutate(child8);
population.add(child1);
population.add(child2);
population.add(child3);
population.add(child4);
population.add(child5);
population.add(child6);
population.add(child7);
population.add(child8);
population.add(child9);
// and the winner is...
Genome fittest = population.peek();
}
}
import java.util.PriorityQueue;
类实现了可比较的{
公共枚举质量{
灯(1),
平均(2),
重型(3);
最终整数值;
质量(整数值){
这个值=值;
}
}
公众人数{
弱(1),
平均(2),
强(3);
最终整数值;
强度(整数值){
这个值=值;
}
}
公共枚举长度{
短(1),
平均(2),
长(3);
最终整数值;
长度(整数值){
这个值=值;
}
}
私人最终质量;
私人最终实力;
私人最终长度;
公共基因组(质量、强度、长度){
这个质量=质量;
力量=力量;
这个长度=长度;
}
私有整数适应度(){
返回strength.value*length.value-mass.value*mass.value;
}
@覆盖公共int compareTo(基因组){
//请注意,装配工的优先级较低
if(this.fitness()>that.fitness())
返回-1;
else if(this.fitness()
编码
因为听起来你想把这些特征编码成一个序列,其中一些特征在序列中是显式的,而另一些特征在序列中是显式的