亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ga.cc

?? 遺傳算法和神經網絡結合
?? CC
字號:
/*  YAKS, Optann, a Khepera simulator including a separate GA and ANN   (Genetic Algoritm, Artificial Neural Net).  Copyright (C) 2000  Johan Carlsson (johanc@ida.his.se)    This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as published by the Free Software Foundation; either version 2  of the License, or any later version.    This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.    You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include "ga.h"int storre(const void *f2, const void *f1){	  return (int)((*(double*)f1-*(double*)f2)*1000);}int compareF(const void *f2,const void *f1){  double t1,t2;  t1 = (*(FINDEX_T**)f1)->fitness;  t2 = (*(FINDEX_T**)f2)->fitness;  return (int)((t1-t2)*1000);}/** * Mutate the individ of the current generation * @param bitMutateProbability The chance that a bit in an ANN link weight mutates */void Ga::mutateIndivids(int bitMutateProbability){  for(int i=0; i < nrOfIndivids; i++){    individs[i]->mutateNeurons(bitMutateProbability);  }}/** * Creates a new generation without applying any mutation. * New generation is parents * offsprings * @param parents The number of parents * @param offsprings The number of offspring each parent produces */void Ga::createNewGeneration(int parents, int offsprings){  createNewGenerationWithMutation(parents, offsprings, 0);}/** * Creates a new generation using tounament selection. The new individs * are mutaded.  * @attention Note that a individ can be compared with itself. * @attention It is safe to use this method with a GA that uses different ANN architectures * @param bitMutation The probability that a bit in a ANN link weight mutates */void Ga::tournamentSelectionWithMutation(int bitMutation){  int *index;  int i,i1,i2;  Ann **new_individs;  index = (int*)alloca(sizeof(int)*nrOfIndivids);  new_individs = (Ann**)malloc(nrOfIndivids*sizeof(Ann*));     for(i=0; i < nrOfIndivids;i++){    /*  ok we can choose same individ twice - so what ? */    i1 = g_mrand(nrOfIndivids);    i2 = g_mrand(nrOfIndivids);    if(totalFitness[i1] > totalFitness[i2])      index[i] = i1;    else      index[i] = i2;  }  for(i = 0; i < nrOfIndivids; i++){    new_individs[i] = individs[index[i]]->duplicate();    new_individs[i]->mutateNeurons(bitMutation);  }  for(i = 0; i < nrOfIndivids; i++){    delete(individs[i]);  }  free(individs);  individs = new_individs;   /* We uses alloca for index so we dont need to free that memory */}/** * Creates a new generation with weight mutation. * New generation is parents * offsprings. * @attention Individs must have the same ANN architecture * @param parents The number of parents * @param offsprings The number of offspring each parent produces * @param bitMutation The probability that a bit in a ANN link weight mutates */void Ga::createNewGenerationWithWeightMutation(int parents, 					       int offsprings, 					       int bitMutation){  FINDEX_T **index;  Ann *tmp;  int i,p,childIndex;  if(parents*offsprings==nrOfIndivids  || (parents==1 && parents+offsprings-1 == nrOfIndivids)){    /* Make a sorted array in order to map best individs to parents*/    index = (FINDEX_T**)malloc(sizeof(FINDEX_T*)*nrOfIndivids);    for(i=0; i < nrOfIndivids;i++){      index[i]= (FINDEX_T*)alloca(sizeof(FINDEX_T));      index[i]->fitness=totalFitness[i];      index[i]->index=i;    }    qsort(index,nrOfIndivids,sizeof(FINDEX_T*),compareF);    /* move parents to the beginning ot the array */    for(i=0; i < parents; i++){      tmp = individs[i];      individs[i] = individs[index[i]->index];      individs[index[i]->index] = tmp;    }    /* Shall we mutate the offsprings directly ?*/    if(bitMutation>0){      for(p=0;p<parents;p++){	for(i=0;i < offsprings-1; i++){	  childIndex = parents + i*parents + p;	  /* Copy weights from parent */	  individs[childIndex]->copyWeightsFrom(individs[p]);	  /* Mutate offspring */	  individs[childIndex]->mutateNeurons(bitMutation);	}      }    }    else{      for(p=0;p<parents;p++){	for(i=0;i < offsprings-1; i++){	  childIndex = parents + i*parents + p;	  /* Copy weights from parent */	  individs[childIndex]->copyWeightsFrom(individs[p]);	}      }    }    /*We uses alloca for the members (memory allocated on the stack)      so we dont need to free the memory for every individ */     free(index);  }  else{    printf("Parents * offsprings doesn't match number of individs, %i * %i != %i\n",	   parents,offsprings,nrOfIndivids);    exit(-1);  }}/** * Creates a new generation with weight mutation. Saves the best individ. * New generation is parents * offsprings. * @attention Individs must have the same ANN architecture * @param parents The number of parents * @param offsprings The number of offspring each parent produces * @param bitMutation The probability that a bit in a ANN link weight mutates * @param fp A pointer to a filedescriptor where the file is open for writing */void Ga::createNewGenerationWithWeightMutation(int parents, 					       int offsprings, 					       int bitMutation,					       FILE *fp){  FINDEX_T **index;  Ann *tmp;  int i,p,childIndex;  if(parents*offsprings==nrOfIndivids  || (parents==1 && parents+offsprings-1 == nrOfIndivids)){    /* Make a sorted array in order to map best individs to parents*/    index = (FINDEX_T**)malloc(sizeof(FINDEX_T*)*nrOfIndivids);    for(i=0; i < nrOfIndivids;i++){      index[i]= (FINDEX_T*)alloca(sizeof(FINDEX_T));      index[i]->fitness=totalFitness[i];      index[i]->index=i;    }    qsort(index,nrOfIndivids,sizeof(FINDEX_T*),compareF);    /* move parents to the beginning ot the array */    for(i=0; i < parents; i++){      tmp = individs[i];      individs[i] = individs[index[i]->index];      individs[index[i]->index] = tmp;    }    individs[i]->saveWeights(fp);    /* Shall we mutate the offsprings directly ?*/    if(bitMutation>0){      for(p=0;p<parents;p++){	for(i=0;i < offsprings-1; i++){	  childIndex = parents + i*parents + p;	  /* Copy weights from parent */	  individs[childIndex]->copyWeightsFrom(individs[p]);	  /* Mutate offspring */	  individs[childIndex]->mutateNeurons(bitMutation);	}      }    }    else{      for(p=0;p<parents;p++){	for(i=0;i < offsprings-1; i++){	  childIndex = parents + i*parents + p;	  /* Copy weights from parent */	  individs[childIndex]->copyWeightsFrom(individs[p]);	}      }    }    /*We uses alloca for the members (memory allocated on the stack)      so we dont need to free the memory for every individ */     free(index);  }  else{    printf("Parents * offsprings doesn't match number of individs, %i * %i != %i\n",	   parents,offsprings,nrOfIndivids);    exit(-1);  }}/** * Creates a new generation with weight mutation. * New generation is parents * offsprings. * @attention Use createNewGenerationWithWeightMutation if all individs has the same structure. * @attention That method is much faster since we dont have to deallocate and allocate memory. * @param parents The number of parents * @param offsprings The number of offspring each parent produces * @param bitMutation The probability that a bit in a ANN link weight mutates */void Ga::createNewGenerationWithMutation(int parents, int offsprings, int bitMutation){  FINDEX_T **index;  Ann *tmp;  int i,p,childIndex;  if(parents*offsprings==nrOfIndivids || (parents==1 && parents+offsprings-1 == nrOfIndivids)) {    /* Make a sorted array in order to map best individs to parents*/    index = (FINDEX_T**)malloc(sizeof(FINDEX_T*)*nrOfIndivids);    for(i=0; i < nrOfIndivids;i++){      index[i]= (FINDEX_T*)alloca(sizeof(FINDEX_T));      index[i]->fitness=totalFitness[i];      index[i]->index=i;    }    qsort(index,nrOfIndivids,sizeof(FINDEX_T*),compareF);    /* move parents to the beginning ot the array */    for(i=0; i < parents; i++){      tmp = individs[i];      individs[i] = individs[index[i]->index];      individs[index[i]->index] = tmp;    }    /* destroy/remove non parents */    for(i=parents; i < nrOfIndivids; i++){      delete(individs[i]);    }    /* Shall we mutate the offsprings directly ?*/    if(bitMutation>0){      for(p=0;p<parents;p++){	for(i=0;i < offsprings-1; i++){	  childIndex = parents + i*parents + p;	  /* Duplicate parent */	  individs[childIndex] = individs[p]->duplicate();	  /* Mutate offspring */	  individs[childIndex]->mutateNeurons(bitMutation);	}      }    }    else{      for(p=0;p<parents;p++){	for(i=0;i < offsprings-1; i++){	  childIndex = parents + i*parents + p;	  /* Duplicate parent */	  individs[childIndex] = individs[p]->duplicate();	}      }    }    /*We uses alloca for the members (memory allocated on the stack)      so we dont need to free the memory for every individ */     free(index);  }  else{    printf("Parents * offsprings doesn't match number of individs, %i * %i  != %i\n",	   parents,offsprings,nrOfIndivids);    exit(-1);  }}/** * Set fitness for all individs, epochs and total to zero */void Ga::resetFitness(){  int i,u;  for(i = 0; i < nrOfIndivids; i++){    for(u = 0; u < epochs; u++){      fitness[i][u] = 0;    }    totalFitness[i] = 0;  }}/** * Save the average fitness and the fitness for the "nr" best individs to file. * If whished print it to stdout also. * @param nr How many of the best individs to log * @param fp A pointer to a file descriptor which file is open for writing * @param show If show > 0 output, to stdout also */void Ga::saveBestIndividsFitness(int nr,FILE *fp, int show){  double *sort;  double average=0;  sort = (double*) malloc(sizeof(double)*nrOfIndivids);  for(int i=0; i < nrOfIndivids; i++){    sort[i]=totalFitness[i];    average+=totalFitness[i];  }  qsort(sort,nrOfIndivids,sizeof(double),storre);  fprintf(fp,"%.2f ", average / nrOfIndivids);  if(show>0)      printf(" (average %.2f) ", average / nrOfIndivids);  for(int i=0; i < nrOfIndivids && i < nr; i++){    fprintf(fp,"%.2f ",sort[i]);    if(show>0)      printf("%.2f ",sort[i]);  }  if(show>0)    printf("\n");  fprintf(fp,"\n");  free(sort);}/** * Constructor, creates a new GA with iNrOfIndivids and iEpochs * Allocates space for fitness. * @param iNrOfIndivids The number of individs for the GA * @param iEpochs The number of epochs to store fitness for each ANN */Ga::Ga(int iNrOfIndivids, int iEpochs){  fitness = (double**) malloc(iNrOfIndivids*sizeof(double*));  for(int i=0; i < iNrOfIndivids; i++){    fitness[i]= (double*) malloc(iEpochs * sizeof(double));  }  totalFitness = (double*) malloc(iNrOfIndivids*sizeof(double));  nrOfIndivids = iNrOfIndivids;  epochs = iEpochs;  for(int i=0; i < nrOfIndivids; i++){    totalFitness[i] = 0;    for(int e=0; e < epochs; e++){      fitness[i][e] = 0;    }  }}/** *Deconstructor for GA, deallocates all individs and all fitness  */Ga::~Ga(){  if(nrOfIndivids>0){    for(int i=0; i < nrOfIndivids; i++){      delete(individs[i]);    }    free(individs);  }  free(*fitness);  free(fitness);  free(totalFitness);}/** * Create all individs for the GA using original as a template * @attention It is safe to deallocate original after this method * @param orginal Template ANN to duplicate to the new individs */void Ga::createIndivids(const Ann *orginal){  individs = (Ann**)malloc(nrOfIndivids*sizeof(Ann*));  for(int i=0; i < nrOfIndivids; i++){#ifdef GA_DEBUG    cout << "Creating individ " << i << " ANN->duplicate " << endl;#endif    individs[i] = orginal->duplicate();  }}/** *Sets the fitness for iIndivid, iEpoch to newFitness updates the total fitness for that individ *@param iIndivid Which individ *@param iEpoch Which epoch *@param newFitness The new fitness */void Ga::setFitness(int iIndivid, int iEpoch, double newFitness){  if(iIndivid >= 0 && iIndivid < nrOfIndivids && iEpoch >= 0 && iEpoch < epochs){    fitness[iIndivid][iEpoch] = newFitness;    totalFitness[iIndivid] += newFitness;  }  else{    printf("Ga::setFitness(int,int,double) indexes out of range individ %d, epoch %d\n",iIndivid,iEpoch);  }}/** * Get the fitness for iIndivid and iEpoch *@param iIndivid Which individ *@param iEpoch Which epoch *@return The fitness or -1 if iIndivid or iEpoch is out of range */double Ga::getFitness(int iIndivid,int iEpoch){    if(iIndivid >= 0 && iIndivid < nrOfIndivids && iEpoch >= 0 && iEpoch < epochs){    return fitness[iIndivid][iEpoch];  }  else    return(-1);}/** * Get the total fitness for individ n *@param n Which individ *@return The fitness or -1 if n is out of range */double Ga::getTotalFitness(int n){  if(n >= 0 && n < nrOfIndivids)    return totalFitness[n];  else    return (-1);}/** * Get the fitness for the best individ * @return The fitness */int Ga::getBestIndivid(){  int best = 0;  for(int i=0; i < nrOfIndivids; i++){    if(totalFitness[best] < totalFitness[i])      best=i;  }  return best;}/** * Not implemented * */void Ga::addIndivid(){}/** *Saves all individs weights to file *@param fp A pointer to a file descriptor where the file is open for writing * */void Ga::saveAllIndividsWeights(FILE *fp){  for(int i=0; i < nrOfIndivids; i++){    individs[i]->saveWeights(fp);  }}/** *Loads individs from a weight file *@attention The number of individs and the architecture of the individs *@attention must be the same as in the file. *@param fp A pointer to a file descriptor where the file is open for reading */void Ga::loadAllIndividsWeights(FILE *fp){  for(int i=0; i < nrOfIndivids; i++){     individs[i]->loadWeights(fp);  }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色综合一区二区| 日韩成人免费电影| eeuss鲁片一区二区三区在线看| 欧美xxxx在线观看| 国产在线不卡一区| 日本一区二区高清| www.成人在线| 夜夜夜精品看看| 欧美一级欧美三级| 精品中文字幕一区二区| 国产日韩欧美一区二区三区综合 | 国产欧美日韩亚州综合| 国产成人综合自拍| 亚洲色图.com| 日韩欧美中文一区| 国产成人在线观看| 一区二区三区在线免费播放| 91精品国产色综合久久不卡电影| 国产真实乱偷精品视频免| 中文字幕一区在线观看视频| 精品视频在线免费看| 韩国理伦片一区二区三区在线播放 | 欧美日本国产一区| 久久99精品国产麻豆婷婷洗澡| 欧美国产日本视频| 欧美色综合久久| 国产精一区二区三区| 一区二区不卡在线视频 午夜欧美不卡在 | 国产一区二区在线视频| 一区在线观看视频| 欧美日韩精品一区视频| 国产乱人伦偷精品视频不卡 | 丰满岳乱妇一区二区三区| 亚洲美女区一区| 精品少妇一区二区三区日产乱码 | 国产精品一区二区三区四区| 亚洲综合网站在线观看| 久久久久久久久久久黄色| 91久久精品日日躁夜夜躁欧美| 精品一区二区三区在线观看| 亚洲精品高清视频在线观看| 久久午夜羞羞影院免费观看| 欧美无砖专区一中文字| 成人黄色a**站在线观看| 天天影视涩香欲综合网| 国产精品精品国产色婷婷| 欧美一区二区在线视频| 91丨porny丨国产入口| 国产在线精品一区二区夜色| 一区二区三区91| 亚洲欧洲在线观看av| 欧美成人猛片aaaaaaa| 在线观看一区日韩| 成人app软件下载大全免费| 麻豆国产欧美日韩综合精品二区| 亚洲激情男女视频| 国产精品久久久久桃色tv| 精品免费日韩av| 欧美精品乱码久久久久久按摩| jvid福利写真一区二区三区| 国产精品一区二区男女羞羞无遮挡| 免费在线观看一区二区三区| 亚洲va欧美va天堂v国产综合| 国产精品国产自产拍高清av王其| 精品国产区一区| 精品欧美一区二区在线观看| 在线播放中文一区| 欧美日韩国产小视频在线观看| 色呦呦网站一区| 91在线视频免费观看| 成人高清免费观看| 成人精品视频一区| 成人综合婷婷国产精品久久| 国产成人精品免费| 国产做a爰片久久毛片| 麻豆精品一区二区综合av| 日韩精彩视频在线观看| 五月婷婷综合激情| 视频在线观看一区| 日韩中文欧美在线| 免费在线视频一区| 久久99精品国产.久久久久久| 美女性感视频久久| 久草这里只有精品视频| 国产毛片精品视频| 国产成人亚洲综合a∨婷婷图片| 国产综合色在线视频区| 国产精品一二三四区| 国产99久久久精品| www.成人网.com| 欧美在线999| 555夜色666亚洲国产免| 日韩精品中文字幕在线一区| 精品粉嫩超白一线天av| 久久精品一二三| 国产精品久久久久7777按摩| 一区二区三区不卡在线观看| 日韩vs国产vs欧美| 国产精品一级在线| 91成人免费在线| 56国语精品自产拍在线观看| 26uuu久久综合| 成人欧美一区二区三区小说| 亚洲综合久久久| 青椒成人免费视频| 国产成人av电影免费在线观看| 91视频免费看| 欧美一区永久视频免费观看| 国产日韩欧美一区二区三区乱码| 亚洲精品免费一二三区| 奇米综合一区二区三区精品视频| 国产福利一区二区| 欧美怡红院视频| 久久综合精品国产一区二区三区| **欧美大码日韩| 日本不卡的三区四区五区| 成人精品国产免费网站| 欧美精品日韩一本| 中文字幕免费不卡| 午夜精彩视频在线观看不卡| 国产成人av电影在线| 欧美另类videos死尸| 国产日韩欧美精品在线| 亚洲国产视频一区二区| 国产成人久久精品77777最新版本| 91黄色免费看| 久久精子c满五个校花| 午夜av电影一区| av电影一区二区| 日韩欧美一级二级| 亚洲国产日韩一区二区| 国产成人丝袜美腿| 日韩一区国产二区欧美三区| 亚洲色欲色欲www在线观看| 久久99国产精品尤物| 欧美日韩久久久久久| 国产精品成人一区二区三区夜夜夜| 奇米影视一区二区三区| 91久久精品一区二区| 国产日产亚洲精品系列| 日韩一区精品视频| 日本道精品一区二区三区 | 亚洲精品亚洲人成人网在线播放| 精品在线播放午夜| 欧美福利一区二区| 亚洲免费观看高清完整版在线观看熊 | 国产丝袜欧美中文另类| 日韩高清电影一区| 欧美在线视频全部完| 中文字幕中文在线不卡住| 国产最新精品免费| 精品国产电影一区二区| 日本免费新一区视频| 欧美日韩亚洲丝袜制服| 亚洲日本韩国一区| 9i在线看片成人免费| 欧美国产丝袜视频| 成人激情图片网| 国产精品福利在线播放| 粉嫩av一区二区三区在线播放| 久久久亚洲午夜电影| 精品中文字幕一区二区| 精品日韩av一区二区| 免费观看一级欧美片| 欧美大肚乱孕交hd孕妇| 热久久免费视频| 欧美一区二区三区系列电影| 污片在线观看一区二区| 欧美精品九九99久久| 丝袜美腿亚洲一区| 欧美一区二区三区在线| 另类小说一区二区三区| 日韩精品一区二区三区视频在线观看| 亚洲va天堂va国产va久| 欧美一区二区三区日韩视频| 麻豆成人久久精品二区三区红| 欧美一级专区免费大片| 国产尤物一区二区| 欧美激情一二三区| av一本久道久久综合久久鬼色| 中文字幕色av一区二区三区| 欧美影视一区二区三区| 免费成人性网站| 久久色中文字幕| 波多野结衣中文一区| 成人免费在线播放视频| 欧洲国产伦久久久久久久| 日韩精品电影在线观看| 久久色成人在线| 波多野结衣在线aⅴ中文字幕不卡| 亚洲色图欧洲色图| 3atv在线一区二区三区| 国产美女精品一区二区三区| 亚洲婷婷在线视频| 欧美伦理影视网| 国产成人亚洲精品狼色在线| 亚洲精品国产一区二区精华液| 日韩一区二区电影在线| 国产99精品国产| 亚洲在线观看免费|