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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? bayesian.cc

?? 貝葉斯優(yōu)化算法是一種新的演化算法
?? CC
字號:
// ################################################################################
//
// name:          bayesian.cc      
//
// author:        Martin Pelikan
//
// purpose:       functions for construction and use of bayesian networks 
//                (not including the metric related functions and some of more
//                specific functions defined elsewhere)
//
// last modified: February 1999
//
// ################################################################################

#include <string.h>

#include "bayesian.h"
#include "boa.h"
#include "population.h"
#include "graph.h"
#include "memalloc.h"
#include "recomputeGains.h"
#include "checkCycles.h"
#include "utils.h"
#include "computeCounts.h"
#include "binary.h"
#include "random.h"

// ================================================================================
//
// name:          constructTheNetwork
//
// function:      constructs the network for a given population of strings (data
//                set), and stores it into the graph structure, satisfying the
//                maximal number of incoming edges constraint defined in the
//                parameters passed to the BOA; uses a simple greedy algorithm
//                with only edge additions allowed adding edges which increase
//                the network most (positively) and do not violate constraints;
//                starts with an empty network
//
// parameters:    population...the population of strings to model (a data set)
//                G............where the resulting network is to be stored
//                boaParams....the parameters sent to the BOA
//
// returns:       (int) 0
//
// ================================================================================

int constructTheNetwork(Population *population, AcyclicOrientedGraph *G, BoaParams *boaParams)
{
  int   k,l;

  int   maxNumberOfEdges,numberOfNodes,maxNumberOfIncomingEdges;

  int   numAdded;
  char  finito;

  float **gain;
  char  *full;

  int   maxFrom, maxTo;
  float maxGain;
  
  // empty the graph

  G->removeAllEdges();
 
  // if no incoming edges allowed, the empty network is the solution

  if (boaParams->maxIncoming==0)
    return 0;

  // set some variables

  numberOfNodes            = G->size();
  maxNumberOfIncomingEdges = boaParams->maxIncoming;

  // maximal number of edges is determined by the number of nodes and the maximal number of incoming edges
  // into each node

  maxNumberOfEdges = numberOfNodes*maxNumberOfIncomingEdges;

  // allocate the array for the gains with respect to the addition of each of the edges

  gain = (float**) Calloc(numberOfNodes,sizeof(float*));
  for (k=0; k<numberOfNodes; k++)
    gain[k] = (float*) Calloc(numberOfNodes,sizeof(float));

  // allocate memory for the array containing information about the full nodes (no more edge can go in those)

  full = (char*) Malloc(numberOfNodes);

  // a greedy algorithm for the network constrution -----------------------------------------------
  
  finito = 0;

  // recompute the gains for edges into all nodes and set each node as not full yet
  
  for (k=0; k<numberOfNodes; k++)
    {
      full[k] = 0;
      recomputeGains(k,gain,full,G,population);
    }

  for (numAdded=0; (numAdded<maxNumberOfEdges)&&(!finito); numAdded++)
    {
      maxGain = -1;
      maxFrom = 0;
      maxTo   = 0;
 
      // find the best edge addition (from maxFrom to maxTo with the increase of a metric maxGain)
     
      for (k=0; k<numberOfNodes; k++)
	for (l=0; l<numberOfNodes; l++)
	  if (k!=l)
	    {
	      // what about an edge from k to l?
	      
	      if (gain[k][l]>maxGain)
		{
		  maxFrom = k;
		  maxTo   = l;
		  maxGain = gain[k][l];
		};
	    }
     
      // add an edge with the best gain over all edge additions if its gain is positive, in the other case
      // the greedy algorithm stops
      
      if (maxGain>0)
	{
	  // add the new edge
	  
	  G->addEdge(maxFrom,maxTo);
	  
	  // the edge can't be added anymore
	  
	  gain[maxFrom][maxTo] = gain[maxTo][maxFrom] = -1;
	  
	  // edges that would create cycles with the new edge have to be disabled
	  
	  checkCycles(maxFrom,maxTo,gain,G);
	  
	  // is the ending node of the new edge full yet?
	  
	  full[maxTo]=(G->getNumIn(maxTo)==boaParams->maxIncoming);
	  
	  // recompute the gains that are needed
	  
	  recomputeGains(maxTo,gain,full,G,population);
	}
      else
	finito = 1;
    };
  
  // ----------------------------------------------------------------------------------------------

  // free the memory used by the gain array

  for (k=0; k<numberOfNodes; k++)
    Free(gain[k]);
  Free(gain);

  // free memory used by an auxilary array "full"

  Free(full);

  // get back

  return 0;
};

// ================================================================================
//
// name:          generateNewInstances
//
// function:      generates new instances of the variables (strings) according to 
//                the joint distribution encoded by the constructed network and the
//                conditional probabilities in a modeled data set
//
// parameters:    parents......the modeled population
//                offspring....where the new instances should be stored
//                G............the network used as a model
//                boaParams....the parameters sent to the BOA
//
// returns:       (int) 0
//
// ================================================================================

int generateNewInstances(Population *parents, 
			 Population *offspring, 
			 AcyclicOrientedGraph *G, 
			 BoaParams *boaParams)
{
  long  i;
  long  N,M;
  int   k,l;
  int   numberOfNodes;

  int   **group, *groupSize;
  long   *numGroupInstances,*numGroupInstances0,maxNumGroupInstances;
  float **marginalAll, **marginalAllButOne;
  long   *count;  

  char *added;
  int   numAdded;
  char  canAdd;

  char  *x;
  int   where;
  int   position;
  float prob1;

  // set some variables

  numberOfNodes = boaParams->n;
  N             = parents->N;
  M             = offspring->N;

  // allocate the memory for the matrix of groups, their sizes and marginal frequencies
  
  group              = (int**) Calloc(numberOfNodes,sizeof(int*));
  groupSize          = (int*) Calloc(numberOfNodes,sizeof(int));
  numGroupInstances  = (long*) Calloc(numberOfNodes,sizeof(long));
  numGroupInstances0 = (long*) Calloc(numberOfNodes,sizeof(long));
  marginalAll        = (float**) Calloc(numberOfNodes,sizeof(float*));
  marginalAllButOne  = (float**) Calloc(numberOfNodes,sizeof(float*));

  for (k=0; k<numberOfNodes; k++)
    group[k]=(int*) Calloc(numberOfNodes,sizeof(int));

  // allocate the memory for some auxilary array used for ordering vertices topologically

  added = (char*) Malloc(numberOfNodes);

  // create the array of incoming edges numbers for all vartices (with the node
  // on the first position) and the number of them. 
  // + allocate the memory for marginal frequencies

  maxNumGroupInstances = 0;

  for (k=0; k<numberOfNodes; k++)
    {
      // create k-th group (corresponding to the k-th variable)
      
      group[k][0]=k;
      if (G->getNumIn(k)>0)
	memcpy(&(group[k][1]),G->getParentList(k),G->getNumIn(k)*sizeof(int));
      groupSize[k]=G->getNumIn(k)+1;
      
      // compute the number of its instances
      
      numGroupInstances[k] = 1<<groupSize[k];
      numGroupInstances0[k] = numGroupInstances[k]>>1;
      
      // allocate the memory for marginals and counts
      
      marginalAll[k] = (float*) Calloc(numGroupInstances[k],sizeof(float));
      marginalAllButOne[k] = (float*) Calloc(numGroupInstances0[k],sizeof(float));
      
      // update maxNumGroupInstances
      
      if (numGroupInstances[k]>maxNumGroupInstances)
	maxNumGroupInstances=numGroupInstances[k];
    }
  
  count = (long*) Calloc(maxNumGroupInstances,sizeof(long));
  
  // topologically order nodes (and the corresponding groups of the nodes and their parents)
  
  for (k=0; k<numberOfNodes; k++)
    added[k]=0;
  numAdded=0;

  while (numAdded<numberOfNodes)
    {
      for (k=numAdded; k<numberOfNodes; k++)
	{
	  canAdd=1;
	  
	  for (l=1; l<groupSize[k]; l++)
	    if (!added[group[k][l]])
	      canAdd=0;
	  
	  if (canAdd)
	    {
	      added[group[k][0]]=1;
	      if (k!=numAdded)
		{
		  swapPointers((void**) &(group[k]),(void**) &(group[numAdded]));
		  swapInt(&(groupSize[k]), &(groupSize[numAdded]));
		  swapLong(&(numGroupInstances[k]),&(numGroupInstances[numAdded]));
		  swapLong(&(numGroupInstances0[k]),&(numGroupInstances0[numAdded]));
		  swapPointers((void**) &(marginalAll[k]), (void**) &(marginalAll[numAdded]));
		  swapPointers((void**) &(marginalAllButOne[k]), (void**) &(marginalAllButOne[numAdded]));
		}
	      
	      numAdded++;
	    }
	}
    }
  
  // calculate the marginal frequencies for created groups of positions
   
  for (k=0; k<numberOfNodes; k++)
    {
      computeCounts(group[k],groupSize[k],parents,count);
      
      for (l=0; l<numGroupInstances[k]; l++)
	marginalAll[k][l] = (float) count[l]/N;
	     
      for (l=0; l<numGroupInstances0[k]; l++)
	marginalAllButOne[k][l] = marginalAll[k][l]+marginalAll[k][l+numGroupInstances0[k]];
    };
  
  // generate the ith coordinate (chromosome) for all dhildren

  for (i=0; i<M; i++)
    {
      x = offspring->x[i];
      
      for (k=0; k<numberOfNodes; k++)
	{
	  position = group[k][0];
	  
	  if (groupSize[k]==1)
	      prob1 = marginalAll[k][1];
	  else
	    {
	      x[position] = 0;
	      where       = indexedBinaryToInt(x,group[k],groupSize[k]);
	      prob1       = 1-marginalAll[k][where]/marginalAllButOne[k][where];
	    }
	  
	  if (drand()<prob1)
	    x[position]=1;
	  else
	    x[position]=0;
	}
    }

  // free the memory used by marginal frequencies (for groups of bits) and the "count" array

  for (k=0; k<numberOfNodes; k++)
    {
      Free(marginalAll[k]);
      Free(marginalAllButOne[k]);
    };
    
  Free(count);
    
  // free the memory used by the matrix of groups, their sizes and marginal frequencies

  for (k=0; k<numberOfNodes; k++)
    Free(group[k]);

  Free(group);
  Free(groupSize);
  Free(numGroupInstances);
  Free(numGroupInstances0);
  Free(marginalAll);
  Free(marginalAllButOne);

  // get back

  return 0;
};

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区欧美一区| 色老汉一区二区三区| 91麻豆成人久久精品二区三区| 欧美日韩在线电影| 国产亚洲欧美日韩在线一区| 亚洲国产视频a| 福利视频网站一区二区三区| 69av一区二区三区| 亚洲自拍都市欧美小说| 成人免费视频caoporn| 日韩三级av在线播放| 亚洲综合久久久久| 99re在线精品| 国产精品久久久久久久久晋中| 国内精品视频666| 正在播放一区二区| 亚洲成av人片在www色猫咪| 91在线播放网址| 中文字幕一区二区三区在线观看| 国产精品一品二品| 久久久噜噜噜久久中文字幕色伊伊| 国产不卡在线视频| 精品国产1区二区| 美女视频第一区二区三区免费观看网站| 欧美自拍偷拍午夜视频| 亚洲欧美激情在线| 在线观看区一区二| 亚洲自拍偷拍麻豆| 欧美日韩一区不卡| 偷窥少妇高潮呻吟av久久免费| 在线观看亚洲精品| 亚洲电影在线免费观看| 精品污污网站免费看| 五月天亚洲婷婷| 欧美一区二区三区免费视频 | 日韩一级完整毛片| 日韩二区在线观看| 欧美草草影院在线视频| 国产在线观看一区二区| 国产丝袜在线精品| av在线一区二区| 一区二区在线观看av| 在线观看91视频| 蜜臀久久99精品久久久久宅男 | 欧美亚一区二区| 午夜免费久久看| 91精品国产品国语在线不卡| 国内精品视频一区二区三区八戒| 中文字幕成人av| 欧美性大战久久| 日韩在线观看一区二区| 久久久www成人免费毛片麻豆| av一二三不卡影片| 亚洲va中文字幕| 久久噜噜亚洲综合| 色哟哟日韩精品| 蜜臀av一级做a爰片久久| 欧美激情一区二区三区四区| 在线影视一区二区三区| 精品中文字幕一区二区小辣椒| 欧美国产禁国产网站cc| 欧美xxxx在线观看| 成人黄色av网站在线| 亚洲成人av免费| 国产亚洲综合色| 欧美日韩在线播放三区四区| 国产一区二区三区在线观看精品| 日韩毛片在线免费观看| 欧美成人伊人久久综合网| 99久久夜色精品国产网站| 日韩国产欧美在线播放| 国产精品女主播av| 日韩视频免费观看高清在线视频| 成人精品免费看| 久久精品国产精品青草| 一区二区在线观看视频在线观看| 久久综合九色综合欧美亚洲| 欧美性感一区二区三区| 国产精品 日产精品 欧美精品| 亚洲精品欧美在线| 91精品一区二区三区在线观看| 国产精品一品二品| 丝袜美腿高跟呻吟高潮一区| 国产亚洲精久久久久久| 欧美精品一二三四| 91高清在线观看| 豆国产96在线|亚洲| 日本中文一区二区三区| 亚洲最新在线观看| 亚洲欧洲成人精品av97| 久久综合色8888| 日韩欧美电影一二三| 欧美日本高清视频在线观看| 99精品视频在线观看| 国产.精品.日韩.另类.中文.在线.播放| 婷婷成人综合网| 亚洲主播在线播放| 亚洲精品国产a久久久久久| 中日韩免费视频中文字幕| 精品国产乱码久久久久久久| 在线不卡a资源高清| 在线视频欧美区| 97超碰欧美中文字幕| 91网站视频在线观看| 成人av电影在线| 成人免费三级在线| 国产69精品久久久久毛片| 国产成人在线看| 国产成人午夜视频| 丁香六月久久综合狠狠色| 国产福利视频一区二区三区| 国产老妇另类xxxxx| 国产精品18久久久久久久久久久久| 蜜桃精品视频在线| 老司机精品视频一区二区三区| 日本欧美肥老太交大片| 免费观看成人鲁鲁鲁鲁鲁视频| 免费观看30秒视频久久| 韩国女主播成人在线| 国产精品亚洲一区二区三区在线| 国产麻豆精品一区二区| 国产成人精品一区二区三区网站观看| 国产成人在线电影| 97精品久久久久中文字幕| 日韩欧美色综合| 精品国产免费一区二区三区香蕉| 精品国偷自产国产一区| 国产欧美日产一区| 亚洲免费色视频| 三级欧美在线一区| 狠狠色狠狠色合久久伊人| av一区二区三区四区| 欧美系列在线观看| 日韩欧美综合一区| 国产精品女同互慰在线看| 亚洲自拍偷拍综合| 亚洲午夜三级在线| 欧美va在线播放| 精品国产乱子伦一区| 国产欧美精品在线观看| 亚洲欧美日本在线| 蜜桃av一区二区在线观看| 国产精品亚洲人在线观看| 一本久久综合亚洲鲁鲁五月天 | 国产自产2019最新不卡| www.亚洲国产| 欧美情侣在线播放| 国产亚洲综合色| 亚洲国产色一区| 国产成人福利片| 欧美片网站yy| 欧美精品一区二区三区高清aⅴ | 欧美伊人久久久久久久久影院 | 青青草91视频| 国产精品正在播放| 欧美在线999| 久久理论电影网| 日韩在线一区二区| 91一区二区三区在线观看| 欧美成人性福生活免费看| 一区二区视频免费在线观看| 国产在线一区二区| 欧美日韩国产高清一区二区三区 | 国产精品超碰97尤物18| 久久精品免费观看| 在线观看国产一区二区| 欧美国产成人精品| 蜜臀精品一区二区三区在线观看| 色欧美片视频在线观看在线视频| 26uuu久久天堂性欧美| 亚洲成av人综合在线观看| a美女胸又www黄视频久久| 久久众筹精品私拍模特| 午夜视频一区二区| 欧美一区二区三区爱爱| 伊人开心综合网| 99久久精品免费看| 国产亚洲欧美激情| 极品美女销魂一区二区三区| 制服丝袜激情欧洲亚洲| 一卡二卡三卡日韩欧美| 91亚洲大成网污www| 国产人成亚洲第一网站在线播放 | 日韩高清一区二区| 欧美日韩一区二区电影| 亚洲欧美成aⅴ人在线观看| yourporn久久国产精品| 欧美高清在线精品一区| 国产成人在线电影| 国产欧美日韩视频一区二区| 国产一区二区在线观看视频| 欧美成人一区二区三区| 精品一区二区三区av| 精品国产乱子伦一区| 精品一区二区影视| wwwwxxxxx欧美| 国产电影精品久久禁18| 中文字幕免费在线观看视频一区| 国产成人精品三级| 国产精品欧美经典|