遗传算法中的突变:反转位时的错误

时间:2018-01-16 07:28:34

标签: python genetic-algorithm mutation

我在遗传算法中构建突变过程以进行特征选择。 这是代码:

pm

突变过程正在扭转这一局面。位1表示选定的功能,位0表示未选择的功能。

sum_mut是变异概率,total是变异的总和,2393是所有个体的总和加上来自交叉过程的后代。数字offspring是要素的总和。 KeyError Traceback (most recent call last) <ipython-input-38-6f4580f1221c> in <module>() 8 mut_col = int(random.random()*2393) 9 offspring[mut_col][mut_row] ^= 1 ---> 10 mutation(0.05) 11 offspring <ipython-input-38-6f4580f1221c> in mutation(pm) 7 mut_row = int(random.random()*total) 8 mut_col = int(random.random()*2393) ----> 9 offspring[mut_col][mut_row] ^= 1 10 mutation(0.05) 11 offspring C:\Users\HEWLETT PACKARD\Anaconda2\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key) 1962 return self._getitem_multilevel(key) 1963 else: -> 1964 return self._getitem_column(key) 1965 1966 def _getitem_column(self, key): C:\Users\HEWLETT PACKARD\Anaconda2\lib\site-packages\pandas\core\frame.pyc in _getitem_column(self, key) 1969 # get column 1970 if self.columns.is_unique: -> 1971 return self._get_item_cache(key) 1972 1973 # duplicate columns & possible reduce dimensionality C:\Users\HEWLETT PACKARD\Anaconda2\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item) 1643 res = cache.get(item) 1644 if res is None: -> 1645 values = self._data.get(item) 1646 res = self._box_item_values(item, values) 1647 cache[item] = res C:\Users\HEWLETT PACKARD\Anaconda2\lib\site-packages\pandas\core\internals.pyc in get(self, item, fastpath) 3588 3589 if not isnull(item): -> 3590 loc = self.items.get_loc(item) 3591 else: 3592 indexer = np.arange(len(self.items))[isnull(self.items)] C:\Users\HEWLETT PACKARD\Anaconda2\lib\site-packages\pandas\core\indexes\base.pyc in get_loc(self, key, method, tolerance) 2442 return self._engine.get_loc(key) 2443 except KeyError: -> 2444 return self._engine.get_loc(self._maybe_cast_indexer(key)) 2445 2446 indexer = self.get_indexer([key], method=method, tolerance=tolerance) pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item() pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item() KeyError: 2392L 是一个数据框,由所有个人和来自交叉过程的后代组成。

那段代码不起作用。这是错误的追溯:

var _enemy:Enemy; 
_enemy = new Enemy(350,500);
addChild(_enemy);
enemyArray.push(_enemy);

for(var i:int = 0; i < enemyArray.length; i++)
{`enter code here`}

var _enemyFire:EnemyFire; 
_enemyFire = new EnemyFire(_enemy.x, _enemy.y);
addChild(_enemyFire);
enemyAmmoArray.push(_enemyFire);

for(var ef:int = 0; ef < enemyAmmoArray.length; ef++)
{
 _enemyFire = enemyAmmoArray[ef];
 _enemyFire.enemyBulletMOV(0,5);
}
你能帮帮我吗?提前谢谢。

0 个答案:

没有答案