首页 > 解决方案 > 没有关于地图功能的信息?(不是地图)

问题描述

我对返回整数的映射函数有问题我不知道这个映射函数是什么或它的操作是什么,当我搜索时,我发现的只是需要数组的映射对象(Array.prototype.map())。///访问它但是这个函数不需要对象或变量来访问那么这个映射函数到底是什么?我觉得它在做某种健身/最大健身

编辑:实际上它确实适合/最大适合度现在我的问题是我的引擎如何知道即使我使用 ctrl + 空格不存在的地图也这样做,当我这样做或我尝试 alert(map.toString()); 查看源代码它返回本机代码,这意味着它确实存在,为什么这么多?

您可以在此链接上的示例中查看它,您会在 Population.js 类中找到它,因为它对我来说没有意义

naturalSelection() {
// Clear the ArrayList
this.matingPool = [];

let maxFitness = 0;
for (let i = 0; i < this.population.length; i++) {
  if (this.population[i].fitness > maxFitness) {
    maxFitness = this.population[i].fitness;
  }
}

// Based on fitness, each member will get added to the mating pool a certain number of times
// a higher fitness = more entries to mating pool = more likely to be picked as a parent
// a lower fitness = fewer entries to mating pool = less likely to be picked as a parent
for (let i = 0; i < this.population.length; i++) {
   alert(map.toString());
 =>: let fitness = map(this.population[i].fitness, 0, maxFitness, 0,1);

  let n = floor(fitness * 100); // Arbitrary multiplier, we can also use monte carlo method
  for (let j = 0; j < n; j++) { // and pick two random numbers
    this.matingPool.push(this.population[i]);
  }
}

}

标签: javascript

解决方案


推荐阅读