예제 #1
0
void randwater(int astart,int nwater,int nwatom,rvec x[],rvec v[],int *seed)
{
  int  i,j,wi,wj,*tab;
  rvec buf;
  
  snew(tab,nwater);
  for(i=0; (i<nwater); i++)
    tab[i]=i;
  for(j=0; (j<23*nwater); j++) {
    wi = (int) (nwater*rando(seed)) % nwater;
    do {
      wj = (int) (nwater*rando(seed)) % nwater;
    } while (wi == wj);
    wi = astart+wi*nwatom;
    wj = astart+wj*nwatom;
    /* Swap coords for wi and wj */
    for(i=0; (i<nwatom); i++) {
      copy_rvec(x[wi+i],buf);
      copy_rvec(x[wj+i],x[wi+i]);
      copy_rvec(buf,x[wj+i]);
      if (v) {
	copy_rvec(v[wi+i],buf);
	copy_rvec(v[wj+i],v[wi+i]);
	copy_rvec(buf,v[wj+i]);
      }
    }
  }
  sfree(tab);
}
void OneObject::MakeMeSit(){
	if(!(Media==2&&Ref.General->CanFly))return;
	MakeFog((RealX>>2)+(rando()&255)-128,(RealY>>2)+(rando()&255)-128);
	MakeFog((RealX>>2)+(rando()&255)-128,(RealY>>2)+(rando()&255)-128);
	MakeFog((RealX>>2)+(rando()&255)-128,(RealY>>2)+(rando()&255)-128);
	//MakeFog((RealX>>2)+(rando()&255)-128,(RealY>>2)+(rando()&255)-128);
	//MakeFog((RealX>>2)+(rando()&255)-128,(RealY>>2)+(rando()&255)-128);
	MakeFog((RealX>>2)+(rando()&255)-128,(RealY>>2)+(rando()&255)-128);
	if(LLock[y][x]){
		Die();
		return;
	};
	ClearOrders();
	if(InLineCom)FreeAsmLink();
	int cx=x>>2;
	int cy=y>>2;
	FlyCell* FC=&FlyMap[cy][cx];
	for(int pp=0;pp<15;pp++){
		if(FC->FlyList[pp]==Index){
			FC->FlyList[pp]=0xFFFF;
			FC->NFly--;
		};
	};
	Media=0;
	FlyMops[y][x]=0xFFFF;
	Mops[y][x]=Index;
};
예제 #3
0
static void test_q_inel(FILE *fp,int *seed)
{
  int i;
  
  fprintf(fp,"Testing the energy/omega dependent inelastic scattering q tables\n");
  for(i=0; (i<1000); i++) {
    (void) get_q_inel(500*rando(seed),400*rando(seed),seed,fp,NULL);
  }
}
예제 #4
0
파일: nxt.c 프로젝트: daniel974/EV3
//Initialize the neural network
void Initialize_Net()
{
     for( j = 1 ; j <= NumHidden ; j++ ) {    /* initialize WeightIH and DeltaWeightIH */
        for( i = 0 ; i <= NumInput ; i++ ) {
            DeltaWeightIH[i][j] = 0.0 ;
            WeightIH[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
        }
    }
    for( k = 1 ; k <= NumOutput ; k ++ ) {    /* initialize WeightHO and DeltaWeightHO */
        for( j = 0 ; j <= NumHidden ; j++ ) {
            DeltaWeightHO[j][k] = 0.0 ;
            WeightHO[j][k] = 2.0 * ( rando() - 0.5 ) * smallwt ;
        }
    }
}
예제 #5
0
파일: xutils.c 프로젝트: hasagar/gromacs
real value_rand(t_range *r, int *seed)
{
    real logrmin, logrmax;
    real mr;

    if (r->np == 1)
    {
        r->rval = r->rmin;
    }
    else
    {
        mr = rando(seed);
        if ((r->ptype == eseEPSILON) && ff.bLogEps)
        {
            logrmin = log(r->rmin);
            logrmax = log(r->rmax);
            r->rval = exp(logrmin + mr*(logrmax-logrmin));
        }
        else
        {
            r->rval = r->rmin + mr*(r->rmax-r->rmin);
        }
    }
    if (debug)
    {
        fprintf(debug, "type: %s, value: %g\n", esenm[r->ptype], r->rval);
    }
    return r->rval;
}
예제 #6
0
real band_ener(int *seed,FILE *fp,char *fn)
{
  static real *ener  = NULL;
  static real *prob  = NULL;
  static int  nener;
  int  eindex;
  real r;
  
  /* Read data at first call, misuse read_cross function */
  if (prob == NULL)
    nener = read_cross(fn,&ener,&prob,1.0);
  
  r = rando(seed);
  
  if ((eindex = my_bsearch(r,nener,prob,FALSE)) >= 0) {
#ifdef DEBUG
    if (eindex >= nener)
      gmx_fatal(FARGS,"r = %f, prob[0] = %f, prob[%d] = %f",r,
		  prob[0],prob[nener-1]);
#endif

    if (fp)
      fprintf(fp,"%8.3f  %8.3f\n",ener[eindex],r);
    
    return ener[eindex];
  }
  return 0;
}
예제 #7
0
static void pukeit(const char *db,const char *defstring, char *retstring, 
		   int retsize, int *cqnum)
{
  FILE *fp;
  char **help;
  int  i,nhlp;
  int  seed;
 
  if (be_cool() && ((fp = low_libopen(db,FALSE)) != NULL)) {
    nhlp=fget_lines(fp,&help);
    /* for libraries we can use the low-level close routines */
    ffclose(fp);
    seed=time(NULL);
    *cqnum=nhlp*rando(&seed);
    if (strlen(help[*cqnum]) >= STRLEN)
      help[*cqnum][STRLEN-1] = '\0';
    strncpy(retstring,help[*cqnum],retsize);
    f(retstring);
    for(i=0; (i<nhlp); i++)
      sfree(help[i]);
    sfree(help);
  }
  else 
    strncpy(retstring,defstring,retsize);
}
예제 #8
0
real get_theta_el(real ekin,int *seed,FILE *fp,char *fn)
{
  static t_p2Ddata *p2Ddata = NULL;
  real r,theta;
  int  eindex,tindex;
  
  if (p2Ddata == NULL) 
    p2Ddata = read_p2Ddata(fn);
  
  /* Get energy index by binary search */
  if ((eindex = my_bsearch(ekin,p2Ddata->nener,p2Ddata->ener,TRUE)) >= 0) {
  
    /* Start with random number */
    r = rando(seed);
    
    /* Do binary search in the energy table */
    if ((tindex = my_bsearch(r,p2Ddata->n2Ddata,p2Ddata->prob[eindex],FALSE)) >= 0) {
  
      theta = p2Ddata->data[eindex][tindex];
      
      if (fp) 
	fprintf(fp,"%8.3f  %8.3f\n",theta,r);
      
      return theta;
    }
  }
  return 0;
}
예제 #9
0
static void test_omega(FILE *fp,int *seed)
{
  int i;

  fprintf(fp,"Testing the energy loss tables\n");
  for(i=0; (i<1000); i++) {
    (void) get_omega(500*rando(seed),seed,fp,NULL);
  }
}
예제 #10
0
파일: gemm.c 프로젝트: jorgenfar/TDT4200
float* create_random_matrix(int m, int n){
    float* A = ( float*)malloc(sizeof( float)*m*n);

    for(int i = 0; i < m*n; i++){
        A[i] = rando();
    }

    return A;
}
예제 #11
0
double arithGame(int max, int quantity, int op) {
		int penalty = 0;
		double start = time(0);

		int i;
		for (i = 1; i <= quantity; i++) {
				int a = rando(max);
				int b = rando(max);
				int answer, response;

				if (op == 1) {
						answer = a + b;
						printf("What is %d+%d?\n", a, b);
						scanf("%d", &response);

						if (response == answer) {
								printf("Correct, great job!\n");
						} else {
								printf("Sorry, that's incorrect. The answer is %d.\n", answer);
								penalty += 5.0;
						};
				} else if (op == 2) {
						answer = a * b;
						printf("What is %d times %d?\n", a, b);
						scanf("%d", &response);

						if (response == answer) {
								printf("Correct, great job!\n");
						} else {
								printf("Sorry, that's incorrect. The answer is %d.\n", answer);
								penalty += 5.0;
						};
				};
		};

		double end = time(0);
		double timespent = end - start + penalty;
		timespent = timespent / quantity;
		printf("You took an average of %lf seconds per question.\n", timespent);

		return timespent;
};
예제 #12
0
void HugeExplosion::HandleExpl(){
	if(Enabled){
		for(int j=0;j<0;j++){
			byte angl=rando()&255;
			int rad=rando()&511;
			int xx=x+((rad*TSin[angl])>>8);
			int yy=y+((rad*TCos[angl])>>8);
			byte xxx=byte(xx>>7);
			byte yyy=byte(xx>>7);
			word MID=Mops[yyy][xxx];
			if(MID!=0xFFFF&&int(Group[MID]))
				Group[MID]->Life=0;
			CreateExObjD(WPLIST[NUCLUSE[rando()&3]],xx,yy,angl,8,255,NULL);
			r1++;
		};
		int rx=r2;
		if(rx>30)rx=50;
		for(j=0;j<rx;j++){
			byte angl=rando()&255;
			int rr=r2+(rando()&127);
			int xx=x+((rr*TSin[angl])>>8);
			int yy=y+((rr*TCos[angl])>>8);
			byte xxx=byte(xx>>7);
			byte yyy=byte(yy>>7);
			word MID=Mops[yyy][xxx];
			if(MID!=0xFFFF&&int(Group[MID]))
				Group[MID]->Life=0;
			CreateExObjD(WPLIST[NUCLUSE[rando()&3]],xx,yy,angl,16,255,NULL);
			r2++;
		};
		if(r2>Radius2)Enabled=false;
	};
};
예제 #13
0
파일: num_rand.c 프로젝트: great90/gcl
LFD(Lrandom)(void)
{
	int j;
        object x;
	
	j = vs_top - vs_base;
	if (j == 1)
		vs_push(symbol_value(Vrandom_state));
	check_arg(2);
	check_type_random_state(&vs_base[1]);
	x = rando(vs_base[0], vs_base[1]);
	vs_top = vs_base;
	vs_push(x);
}
예제 #14
0
파일: Zad01.c 프로젝트: wdziurdzia/LabJProg
int main(){
	int c_int;
	int h_int;
	int suma = 0;
	int sukces = 0;
	while(suma <= 20){
		printf("czlowiek: ");
		scanf("%i",&h_int);
		suma += h_int;
		c_int = rando();
		printf("komputer: %i ",c_int);
		suma += c_int;
		printf("suma: %i \n",suma);
	}
	printf("KONIEC GRY, WYGRAŁ CZŁOWIEK\n");
}
예제 #15
0
void
Flash_build_complete_key(Flash_Complete_Key CK)
{
	int i;

	init_table_flash(CK->M,/*CK->I,*/CK->M1/*,CK->M2/* /*,CK->M3*/);
	Bij_Aff(CK->S1,CK->IS1,CK->S2,CK->M);
	Bij_Aff(CK->T1,CK->IT1,CK->T2,CK->M);
	priv_pub(CK->Q,CK->L,CK->C,CK->S1,CK->S2,CK->T1,CK->T2,CK->M);

	for(i=0;i<11;i++)
	{
		CK->delta[i] = rando();
	}
	CK->delta[0] = CK->delta[0] & 3;

}
예제 #16
0
real get_omega(real ekin,int *seed,FILE *fp,char *fn)
{
  static t_p2Ddata *p2Ddata = NULL;
  real r,ome,fx,fy;
  int  eindex,oindex;
  
  if (p2Ddata == NULL) 
    p2Ddata = read_p2Ddata(fn);
  
  /* Get energy index by binary search */
  if ((eindex = my_bsearch(ekin,p2Ddata->nener,p2Ddata->ener,TRUE)) >= 0) {
#ifdef DEBUG
    if (eindex >= p2Ddata->nener)
      gmx_fatal(FARGS,"eindex (%d) out of range (max %d) in get_omega",
		  eindex,p2Ddata->nener);
#endif

    /* Start with random number */
    r = rando(seed);
    
    /* Do binary search in the energy table */
    if ((oindex = my_bsearch(r,p2Ddata->n2Ddata,p2Ddata->prob[eindex],TRUE)) >= 0) {
#ifdef DEBUG
      if (oindex >= p2Ddata->n2Ddata)
	gmx_fatal(FARGS,"oindex (%d) out of range (max %d) in get_omega",
		    oindex,p2Ddata->n2Ddata);
#endif

      fy = ((r-p2Ddata->prob[eindex][oindex])/
	    (p2Ddata->prob[eindex][oindex+1]-p2Ddata->prob[eindex][oindex]));
      ome = interpolate2D(p2Ddata->nener,p2Ddata->n2Ddata,p2Ddata->ener,
			  p2Ddata->data,ekin,fy,
			  eindex,oindex);
      /* ome = p2Ddata->data[eindex][oindex];*/
      
      if (fp) 
	fprintf(fp,"%8.3f  %8.3f\n",ome,r);
      
      return ome;
    }
  }
  return 0;
}
예제 #17
0
real get_q_inel(real ekin,real omega,int *seed,FILE *fp,char *fn)
{
  static t_pq_inel *pq = NULL;
  int    eindex,oindex,tindex;
  real   r,theta;
  
  if (pq == NULL)
    pq = read_pq(fn);

  /* Get energy index by binary search */
  if ((eindex = my_bsearch(ekin,pq->nener,pq->ener,TRUE)) >= 0) {
#ifdef DEBUG
    if (eindex >= pq->nener)
      gmx_fatal(FARGS,"eindex out of range (%d >= %d)",eindex,pq->nener);
#endif
      
    /* Do binary search in the energy table */
    if ((oindex = my_bsearch(omega,pq->nomega,pq->omega[eindex],FALSE)) >= 0) {
#ifdef DEBUG
      if (oindex >= pq->nomega)
	gmx_fatal(FARGS,"oindex out of range (%d >= %d)",oindex,pq->nomega);
#endif
      
      /* Start with random number */
      r = rando(seed);
      
      if ((tindex = my_bsearch(r,pq->nq,pq->prob[eindex][oindex],FALSE)) >= 0) {
#ifdef DEBUG
	if (tindex >= pq->nq)
	  gmx_fatal(FARGS,"tindex out of range (%d >= %d)",tindex,pq->nq);
#endif
	
	theta = pq->q[eindex][oindex][tindex];
  
	if (fp)
	  fprintf(fp,"get_q_inel: %8.3f  %8.3f\n",theta,r);
	
	return theta;
      }
    }
  }
  return 0;
}
예제 #18
0
double guessGame(int max) {
		int answer, response = 0, guesses = 0;
		answer = rando(max);
		double start = time(0);
		while (response != answer) {
				printf("Enter your guess!\n");
				scanf("%d", &response);
				guesses++;
				if (response > answer) {
						printf("Your guess is too high, try again.\n");
				} else if (response < answer) {
						printf("Your guess is too low, try again.\n");
				};
		};
		double end = time(0);
		double timespentCorr = (end - start)/(2 * numDigits(max));
		double timespent = end - start;
		printf("Great, you guessed the correct number %d in %d guesses in %lf seconds.\n", answer, guesses, timespent);
		return timespentCorr;
};
예제 #19
0
static void rand_rot(int natoms, rvec x[], rvec v[], vec4 xrot[], vec4 vrot[],
                     int *seed, rvec max_rot)
{
    mat4 mt1, mt2, mr[DIM], mtemp1, mtemp2, mtemp3, mxtot, mvtot;
    rvec xcm;
    real phi;
    int  i, m;

    clear_rvec(xcm);
    for (i = 0; (i < natoms); i++)
    {
        for (m = 0; (m < DIM); m++)
        {
            xcm[m] += x[i][m]/natoms; /* get center of mass of one molecule  */
        }
    }
    fprintf(stderr, "center of geometry: %f, %f, %f\n", xcm[0], xcm[1], xcm[2]);

    translate(-xcm[XX], -xcm[YY], -xcm[ZZ], mt1); /* move c.o.ma to origin */
    for (m = 0; (m < DIM); m++)
    {
        phi = M_PI*max_rot[m]*(2*rando(seed) - 1)/180;
        rotate(m, phi, mr[m]);
    }
    translate(xcm[XX], xcm[YY], xcm[ZZ], mt2);

    /* For mult_matrix we need to multiply in the opposite order
     * compared to normal mathematical notation.
     */
    mult_matrix(mtemp1, mt1, mr[XX]);
    mult_matrix(mtemp2, mr[YY], mr[ZZ]);
    mult_matrix(mtemp3, mtemp1, mtemp2);
    mult_matrix(mxtot, mtemp3, mt2);
    mult_matrix(mvtot, mr[XX], mtemp2);

    for (i = 0; (i < natoms); i++)
    {
        m4_op(mxtot, x[i], xrot[i]);
        m4_op(mvtot, v[i], vrot[i]);
    }
}
예제 #20
0
static char *insert_mols(char *mol_insrt,int nmol_insrt,int ntry,int seed,
			 t_atoms *atoms,rvec **x,real **r,int ePBC,matrix box,
			 gmx_atomprop_t aps,real r_distance,real rshell)
{
  t_pbc   pbc;
  static  char    *title_insrt;
  t_atoms atoms_insrt;
  rvec    *x_insrt,*x_n;
  real    *r_insrt;
  int     ePBC_insrt;
  matrix  box_insrt;
  int     i,mol,onr;
  real    alfa,beta,gamma;
  rvec    offset_x;
  int     try;
   
  set_pbc(&pbc,ePBC,box);
  
  /* read number of atoms of insert molecules */
  get_stx_coordnum(mol_insrt,&atoms_insrt.nr);
  if (atoms_insrt.nr == 0)
    gmx_fatal(FARGS,"No molecule in %s, please check your input\n",mol_insrt);
  /* allocate memory for atom coordinates of insert molecules */
  snew(x_insrt,atoms_insrt.nr);
  snew(r_insrt,atoms_insrt.nr);
  snew(atoms_insrt.resname,atoms_insrt.nr);
  snew(atoms_insrt.atomname,atoms_insrt.nr);
  snew(atoms_insrt.atom,atoms_insrt.nr);
  atoms_insrt.pdbinfo = NULL;
  snew(x_n,atoms_insrt.nr);
  snew(title_insrt,STRLEN);
  
  /* read residue number, residue names, atomnames, coordinates etc. */
  fprintf(stderr,"Reading molecule configuration \n");
  read_stx_conf(mol_insrt,title_insrt,&atoms_insrt,x_insrt,NULL,
		&ePBC_insrt,box_insrt);
  fprintf(stderr,"%s\nContaining %d atoms in %d residue\n",
	  title_insrt,atoms_insrt.nr,atoms_insrt.nres);
  srenew(atoms_insrt.resname,atoms_insrt.nres);  
    
  /* initialise van der waals arrays of insert molecules */
  mk_vdw(&atoms_insrt,r_insrt,aps,r_distance);

  srenew(atoms->resname,(atoms->nres+nmol_insrt));
  srenew(atoms->atomname,(atoms->nr+atoms_insrt.nr*nmol_insrt));
  srenew(atoms->atom,(atoms->nr+atoms_insrt.nr*nmol_insrt));
  srenew(*x,(atoms->nr+atoms_insrt.nr*nmol_insrt));
  srenew(*r,(atoms->nr+atoms_insrt.nr*nmol_insrt));
  
  try=mol=0;
  while ((mol < nmol_insrt) && (try < ntry*nmol_insrt)) {
    fprintf(stderr,"\rTry %d",try++);
    for (i=0;(i<atoms_insrt.nr);i++) {
      if (atoms_insrt.atom[i].resnr!=0) 
	gmx_fatal(FARGS,"more then one residue in insert molecules\n"
		    "program terminated\n");
      copy_rvec(x_insrt[i],x_n[i]);
    }
    alfa=2*M_PI*rando(&seed);
    beta=2*M_PI*rando(&seed);
    gamma=2*M_PI*rando(&seed);
    rotate_conf(atoms_insrt.nr,x_n,NULL,alfa,beta,gamma);
    offset_x[XX]=box[XX][XX]*rando(&seed);
    offset_x[YY]=box[YY][YY]*rando(&seed);
    offset_x[ZZ]=box[ZZ][ZZ]*rando(&seed);
    gen_box(0,atoms_insrt.nr,x_n,box_insrt,offset_x,TRUE);
    if (!in_box(&pbc,x_n[0]) || !in_box(&pbc,x_n[atoms_insrt.nr-1]))
      continue;
    onr=atoms->nr;
    
    add_conf(atoms,x,NULL,r,FALSE,ePBC,box,TRUE,
	     &atoms_insrt,x_n,NULL,r_insrt,FALSE,rshell,0);
    
    if (atoms->nr==(atoms_insrt.nr+onr)) {
      mol++;
      fprintf(stderr," success (now %d atoms)!",atoms->nr);
    }
  }
  srenew(atoms->resname,  atoms->nres);
  srenew(atoms->atomname, atoms->nr);
  srenew(atoms->atom,     atoms->nr);
  srenew(*x,              atoms->nr);
  srenew(*r,              atoms->nr);
  
  fprintf(stderr,"\n");
  /* print number of molecules added */
  fprintf(stderr,"Added %d molecules (out of %d requested) of %s\n",
	  mol,nmol_insrt,*atoms_insrt.resname[0]); 
    
  return title_insrt;
}

static void add_solv(char *fn,t_atoms *atoms,rvec **x,rvec **v,real **r,
		     int ePBC,matrix box,
		     gmx_atomprop_t aps,real r_distance,int *atoms_added,
		     int *residues_added,real rshell,int max_sol)
{
  int     i,nmol;
  ivec    n_box;
  char    filename[STRLEN];
  char    title_solvt[STRLEN];
  t_atoms *atoms_solvt;
  rvec    *x_solvt,*v_solvt=NULL;
  real    *r_solvt;
  int     ePBC_solvt;
  matrix  box_solvt;
  int     onr,onres;

  strncpy(filename,libfn(fn),STRLEN);
  snew(atoms_solvt,1);
  get_stx_coordnum(filename,&(atoms_solvt->nr)); 
  if (atoms_solvt->nr == 0)
    gmx_fatal(FARGS,"No solvent in %s, please check your input\n",filename);
  snew(x_solvt,atoms_solvt->nr);
  if (v) snew(v_solvt,atoms_solvt->nr);
  snew(r_solvt,atoms_solvt->nr);
  snew(atoms_solvt->resname,atoms_solvt->nr);
  snew(atoms_solvt->atomname,atoms_solvt->nr);
  snew(atoms_solvt->atom,atoms_solvt->nr);
  atoms_solvt->pdbinfo = NULL;
  fprintf(stderr,"Reading solvent configuration%s\n",
	  v_solvt?" and velocities":"");
  read_stx_conf(filename,title_solvt,atoms_solvt,x_solvt,v_solvt,
		&ePBC_solvt,box_solvt);
  fprintf(stderr,"\"%s\"\n",title_solvt);
  fprintf(stderr,"solvent configuration contains %d atoms in %d residues\n",
	  atoms_solvt->nr,atoms_solvt->nres);
  fprintf(stderr,"\n");
  
  /* apply pbc for solvent configuration for whole molecules */
  rm_res_pbc(atoms_solvt,x_solvt,box_solvt);
  
  /* initialise van der waals arrays of solvent configuration */
  mk_vdw(atoms_solvt,r_solvt,aps,r_distance);
  
  /* calculate the box multiplication factors n_box[0...DIM] */
  nmol=1;
  for (i=0; (i < DIM);i++) {
    n_box[i] = 1;
    while (n_box[i]*box_solvt[i][i] < box[i][i])
      n_box[i]++;
    nmol*=n_box[i];
  }
  fprintf(stderr,"Will generate new solvent configuration of %dx%dx%d boxes\n",
	  n_box[XX],n_box[YY],n_box[ZZ]);
  
  /* realloc atoms_solvt for the new solvent configuration */
  srenew(atoms_solvt->resname,atoms_solvt->nres*nmol);
  srenew(atoms_solvt->atomname,atoms_solvt->nr*nmol);
  srenew(atoms_solvt->atom,atoms_solvt->nr*nmol);
  srenew(x_solvt,atoms_solvt->nr*nmol);
  if (v_solvt) srenew(v_solvt,atoms_solvt->nr*nmol);
  srenew(r_solvt,atoms_solvt->nr*nmol);
  
  /* generate a new solvent configuration */
  genconf(atoms_solvt,x_solvt,v_solvt,r_solvt,box_solvt,n_box);

#ifdef DEBUG
  print_stat(x_solvt,atoms_solvt->nr,box_solvt);
#endif
  
#ifdef DEBUG
  print_stat(x_solvt,atoms_solvt->nr,box_solvt);
#endif
  /* Sort the solvent mixture, not the protein... */
  sort_molecule(&atoms_solvt,x_solvt,v_solvt,r_solvt);
  
  /* add the two configurations */
  onr=atoms->nr;
  onres=atoms->nres;
  add_conf(atoms,x,v,r,TRUE,ePBC,box,FALSE,
	   atoms_solvt,x_solvt,v_solvt,r_solvt,TRUE,rshell,max_sol);
  *atoms_added=atoms->nr-onr;
  *residues_added=atoms->nres-onres;
  
  sfree(x_solvt);
  sfree(r_solvt);

  fprintf(stderr,"Generated solvent containing %d atoms in %d residues\n",
	  *atoms_added,*residues_added);
}
예제 #21
0
파일: bhamcode-nn.c 프로젝트: EISALab/DBN
main() {
    int    i, j, k, p, np, op, ranpat[NUMPAT+1], epoch;
    int    NumPattern = NUMPAT, NumInput = NUMIN, NumHidden = NUMHID, NumOutput = NUMOUT;
    double Input[NUMPAT+1][NUMIN+1] = { 0, 0, 0,  0, 0, 0,  0, 1, 0,  0, 0, 1,  0, 1, 1 };
    double Target[NUMPAT+1][NUMOUT+1] = { 0, 0,  0, 0,  0, 1,  0, 1,  0, 0 };
    double SumH[NUMPAT+1][NUMHID+1], WeightIH[NUMIN+1][NUMHID+1], Hidden[NUMPAT+1][NUMHID+1];
    double SumO[NUMPAT+1][NUMOUT+1], WeightHO[NUMHID+1][NUMOUT+1], Output[NUMPAT+1][NUMOUT+1];
    double DeltaO[NUMOUT+1], SumDOW[NUMHID+1], DeltaH[NUMHID+1];
    double DeltaWeightIH[NUMIN+1][NUMHID+1], DeltaWeightHO[NUMHID+1][NUMOUT+1];
    double Error, eta = 0.5, alpha = 0.9, smallwt = 0.5;
  
    for( j = 1 ; j <= NumHidden ; j++ ) {    /* initialize WeightIH and DeltaWeightIH */
        for( i = 0 ; i <= NumInput ; i++ ) { 
            DeltaWeightIH[i][j] = 0.0 ;
            WeightIH[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
        }
    }
    for( k = 1 ; k <= NumOutput ; k ++ ) {    /* initialize WeightHO and DeltaWeightHO */
        for( j = 0 ; j <= NumHidden ; j++ ) {
            DeltaWeightHO[j][k] = 0.0 ;              
            WeightHO[j][k] = 2.0 * ( rando() - 0.5 ) * smallwt ;
        }
    }
     
    for( epoch = 0 ; epoch < 100000 ; epoch++) {    /* iterate weight updates */
        for( p = 1 ; p <= NumPattern ; p++ ) {    /* randomize order of individuals */
            ranpat[p] = p ;
        }
        for( p = 1 ; p <= NumPattern ; p++) {
            np = p + rando() * ( NumPattern + 1 - p ) ;
            op = ranpat[p] ; ranpat[p] = ranpat[np] ; ranpat[np] = op ;
        }
        Error = 0.0 ;
        for( np = 1 ; np <= NumPattern ; np++ ) {    /* repeat for all the training patterns */
            p = ranpat[np];
            for( j = 1 ; j <= NumHidden ; j++ ) {    /* compute hidden unit activations */
                SumH[p][j] = WeightIH[0][j] ;
                for( i = 1 ; i <= NumInput ; i++ ) {
                    SumH[p][j] += Input[p][i] * WeightIH[i][j] ;
                }
                Hidden[p][j] = 1.0/(1.0 + exp(-SumH[p][j])) ;
            }
            for( k = 1 ; k <= NumOutput ; k++ ) {    /* compute output unit activations and errors */
                SumO[p][k] = WeightHO[0][k] ;
                for( j = 1 ; j <= NumHidden ; j++ ) {
                    SumO[p][k] += Hidden[p][j] * WeightHO[j][k] ;
                }
                Output[p][k] = 1.0/(1.0 + exp(-SumO[p][k])) ;   /* Sigmoidal Outputs */
/*              Output[p][k] = SumO[p][k];      Linear Outputs */
                Error += 0.5 * (Target[p][k] - Output[p][k]) * (Target[p][k] - Output[p][k]) ;   /* SSE */
/*              Error -= ( Target[p][k] * log( Output[p][k] ) + ( 1.0 - Target[p][k] ) * log( 1.0 - Output[p][k] ) ) ;    Cross-Entropy Error */
                DeltaO[k] = (Target[p][k] - Output[p][k]) * Output[p][k] * (1.0 - Output[p][k]) ;   /* Sigmoidal Outputs, SSE */
/*              DeltaO[k] = Target[p][k] - Output[p][k];     Sigmoidal Outputs, Cross-Entropy Error */
/*              DeltaO[k] = Target[p][k] - Output[p][k];     Linear Outputs, SSE */
            }
            for( j = 1 ; j <= NumHidden ; j++ ) {    /* 'back-propagate' errors to hidden layer */
                SumDOW[j] = 0.0 ;
                for( k = 1 ; k <= NumOutput ; k++ ) {
                    SumDOW[j] += WeightHO[j][k] * DeltaO[k] ;
                }
                DeltaH[j] = SumDOW[j] * Hidden[p][j] * (1.0 - Hidden[p][j]) ;
            }
            for( j = 1 ; j <= NumHidden ; j++ ) {     /* update weights WeightIH */
                DeltaWeightIH[0][j] = eta * DeltaH[j] + alpha * DeltaWeightIH[0][j] ;
                WeightIH[0][j] += DeltaWeightIH[0][j] ;
                for( i = 1 ; i <= NumInput ; i++ ) { 
                    DeltaWeightIH[i][j] = eta * Input[p][i] * DeltaH[j] + alpha * DeltaWeightIH[i][j];
                    WeightIH[i][j] += DeltaWeightIH[i][j] ;
                }
            }
            for( k = 1 ; k <= NumOutput ; k ++ ) {    /* update weights WeightHO */
                DeltaWeightHO[0][k] = eta * DeltaO[k] + alpha * DeltaWeightHO[0][k] ;
                WeightHO[0][k] += DeltaWeightHO[0][k] ;
                for( j = 1 ; j <= NumHidden ; j++ ) {
                    DeltaWeightHO[j][k] = eta * Hidden[p][j] * DeltaO[k] + alpha * DeltaWeightHO[j][k] ;
                    WeightHO[j][k] += DeltaWeightHO[j][k] ;
                }
            }
        }
        if( epoch%100 == 0 ) fprintf(stdout, "\nEpoch %-5d :   Error = %f", epoch, Error) ;
        if( Error < 0.0004 ) break ;  /* stop learning when 'near enough' */
    }
    
    fprintf(stdout, "\n\nNETWORK DATA - EPOCH %d\n\nPat\t", epoch) ;   /* print network outputs */
    for( i = 1 ; i <= NumInput ; i++ ) {
        fprintf(stdout, "Input%-4d\t", i) ;
    }
    for( k = 1 ; k <= NumOutput ; k++ ) {
        fprintf(stdout, "Target%-4d\tOutput%-4d\t", k, k) ;
    }
    for( p = 1 ; p <= NumPattern ; p++ ) {        
    fprintf(stdout, "\n%d\t", p) ;
        for( i = 1 ; i <= NumInput ; i++ ) {
            fprintf(stdout, "%f\t", Input[p][i]) ;
        }
        for( k = 1 ; k <= NumOutput ; k++ ) {
            fprintf(stdout, "%f\t%f\t", Target[p][k], Output[p][k]) ;
        }
    }
    fprintf(stdout, "\n\nGoodbye!\n\n") ;
    return 1 ;
}
예제 #22
0
static int get_replica_exchange(FILE *fplog,const gmx_multisim_t *ms,
                                struct gmx_repl_ex *re,real *ener,real vol,
                                int step,real time)
{
    int  m,i,a,b;
    real *Epot=NULL,*Vol=NULL,*dvdl=NULL,*prob;
    real ediff=0,delta=0,dpV=0,betaA=0,betaB=0;
    gmx_bool *bEx,bPrint;
    int  exchange;

    fprintf(fplog,"Replica exchange at step %d time %g\n",step,time);
  
    switch (re->type)
    {
    case ereTEMP:
        snew(Epot,re->nrepl);
        snew(Vol,re->nrepl);
        Epot[re->repl] = ener[F_EPOT];
        Vol[re->repl]  = vol;
        gmx_sum_sim(re->nrepl,Epot,ms);
        gmx_sum_sim(re->nrepl,Vol,ms);
        break;
    case ereLAMBDA:
        snew(dvdl,re->nrepl);
        dvdl[re->repl] = ener[F_DVDL];
        gmx_sum_sim(re->nrepl,dvdl,ms);
        break;
    }

    snew(bEx,re->nrepl);
    snew(prob,re->nrepl);

    exchange = -1;
    m = (step / re->nst) % 2;
    for(i=1; i<re->nrepl; i++)
    {
        a = re->ind[i-1];
        b = re->ind[i];
        bPrint = (re->repl==a || re->repl==b);
        if (i % 2 == m)
        {
            switch (re->type)
            {
            case ereTEMP:
                /* Use equations from:
                 * Okabe et. al. Chem. Phys. Lett. 335 (2001) 435-439
                 */
                ediff = Epot[b] - Epot[a];
                betaA = 1.0/(re->q[a]*BOLTZ);
                betaB = 1.0/(re->q[b]*BOLTZ);
                delta = (betaA - betaB)*ediff;
                break;
            case ereLAMBDA:
                /* Here we exchange based on a linear extrapolation of dV/dlambda.
                 * We would like to have the real energies
                 * from foreign lambda calculations.
                 */
                ediff = (dvdl[a] - dvdl[b])*(re->q[b] - re->q[a]);
                delta = ediff/(BOLTZ*re->temp);
                break;
            default:
                gmx_incons("Unknown replica exchange quantity");
            }
            if (bPrint)
            {
                fprintf(fplog,"Repl %d <-> %d  dE = %10.3e",a,b,delta);
            }
            if (re->bNPT)
            {
                dpV = (betaA*re->pres[a]-betaB*re->pres[b])*(Vol[b]-Vol[a])/PRESFAC;
                if (bPrint)
                {
                    fprintf(fplog,"  dpV = %10.3e  d = %10.3e",dpV,delta + dpV);
                }
                delta += dpV;
            }
            if (bPrint)
            {
                fprintf(fplog,"\n");
            }
            if (delta <= 0)
            {
                prob[i] = 1;
                bEx[i] = TRUE;
            }
            else
            {
                if (delta > 100)
                {
                    prob[i] = 0;
                }
                else
                {
                    prob[i] = exp(-delta);
                }
                bEx[i] = (rando(&(re->seed)) < prob[i]);
            }
            re->prob_sum[i] += prob[i];    
            if (bEx[i])
            {
                if (a == re->repl)
                {
                    exchange = b;
                }
                else if (b == re->repl)
                {
                    exchange = a;
                }
                re->nexchange[i]++;
            }
        }
        else
        {
            prob[i] = -1;
            bEx[i] = FALSE;
        }
    }
    print_ind(fplog,"ex",re->nrepl,re->ind,bEx);
    print_prob(fplog,"pr",re->nrepl,prob);
    fprintf(fplog,"\n");

    sfree(bEx);
    sfree(prob);
    sfree(Epot);
    sfree(Vol);
    sfree(dvdl);
  
    re->nattempt[m]++;

    return exchange;
}
예제 #23
0
파일: repl_ex.c 프로젝트: hasagar/gromacs
static void
test_for_replica_exchange(FILE                 *fplog,
                          const gmx_multisim_t *ms,
                          struct gmx_repl_ex   *re,
                          gmx_enerdata_t       *enerd,
                          real                  vol,
                          gmx_large_int_t       step,
                          real                  time)
{
    int       m, i, j, a, b, ap, bp, i0, i1, tmp;
    real      ediff = 0, delta = 0, dpV = 0;
    gmx_bool  bPrint, bMultiEx;
    gmx_bool *bEx      = re->bEx;
    real     *prob     = re->prob;
    int      *pind     = re->destinations; /* permuted index */
    gmx_bool  bEpot    = FALSE;
    gmx_bool  bDLambda = FALSE;
    gmx_bool  bVol     = FALSE;

    bMultiEx = (re->nex > 1);  /* multiple exchanges at each state */
    fprintf(fplog, "Replica exchange at step " gmx_large_int_pfmt " time %g\n", step, time);

    if (re->bNPT)
    {
        for (i = 0; i < re->nrepl; i++)
        {
            re->Vol[i] = 0;
        }
        bVol               = TRUE;
        re->Vol[re->repl]  = vol;
    }
    if ((re->type == ereTEMP || re->type == ereTL))
    {
        for (i = 0; i < re->nrepl; i++)
        {
            re->Epot[i] = 0;
        }
        bEpot              = TRUE;
        re->Epot[re->repl] = enerd->term[F_EPOT];
        /* temperatures of different states*/
        for (i = 0; i < re->nrepl; i++)
        {
            re->beta[i] = 1.0/(re->q[ereTEMP][i]*BOLTZ);
        }
    }
    else
    {
        for (i = 0; i < re->nrepl; i++)
        {
            re->beta[i] = 1.0/(re->temp*BOLTZ);  /* we have a single temperature */
        }
    }
    if (re->type == ereLAMBDA || re->type == ereTL)
    {
        bDLambda = TRUE;
        /* lambda differences. */
        /* de[i][j] is the energy of the jth simulation in the ith Hamiltonian
           minus the energy of the jth simulation in the jth Hamiltonian */
        for (i = 0; i < re->nrepl; i++)
        {
            for (j = 0; j < re->nrepl; j++)
            {
                re->de[i][j] = 0;
            }
        }
        for (i = 0; i < re->nrepl; i++)
        {
            re->de[i][re->repl] = (enerd->enerpart_lambda[(int)re->q[ereLAMBDA][i]+1]-enerd->enerpart_lambda[0]);
        }
    }

    /* now actually do the communication */
    if (bVol)
    {
        gmx_sum_sim(re->nrepl, re->Vol, ms);
    }
    if (bEpot)
    {
        gmx_sum_sim(re->nrepl, re->Epot, ms);
    }
    if (bDLambda)
    {
        for (i = 0; i < re->nrepl; i++)
        {
            gmx_sum_sim(re->nrepl, re->de[i], ms);
        }
    }

    /* make a duplicate set of indices for shuffling */
    for (i = 0; i < re->nrepl; i++)
    {
        pind[i] = re->ind[i];
    }

    if (bMultiEx)
    {
        /* multiple random switch exchange */
        for (i = 0; i < re->nex; i++)
        {
            /* randomly select a pair  */
            /* in theory, could reduce this by identifying only which switches had a nonneglibible
               probability of occurring (log p > -100) and only operate on those switches */
            /* find out which state it is from, and what label that state currently has. Likely
               more work that useful. */
            i0 = (int)(re->nrepl*rando(&(re->seed)));
            i1 = (int)(re->nrepl*rando(&(re->seed)));
            if (i0 == i1)
            {
                i--;
                continue;  /* self-exchange, back up and do it again */
            }

            a  = re->ind[i0]; /* what are the indices of these states? */
            b  = re->ind[i1];
            ap = pind[i0];
            bp = pind[i1];

            bPrint = FALSE; /* too noisy */
            /* calculate the energy difference */
            /* if the code changes to flip the STATES, rather than the configurations,
               use the commented version of the code */
            /* delta = calc_delta(fplog,bPrint,re,a,b,ap,bp); */
            delta = calc_delta(fplog, bPrint, re, ap, bp, a, b);

            /* we actually only use the first space in the prob and bEx array,
               since there are actually many switches between pairs. */

            if (delta <= 0)
            {
                /* accepted */
                prob[0] = 1;
                bEx[0]  = TRUE;
            }
            else
            {
                if (delta > PROBABILITYCUTOFF)
                {
                    prob[0] = 0;
                }
                else
                {
                    prob[0] = exp(-delta);
                }
                /* roll a number to determine if accepted */
                bEx[0] = (rando(&(re->seed)) < prob[0]);
            }
            re->prob_sum[0] += prob[0];

            if (bEx[0])
            {
                /* swap the states */
                tmp      = pind[i0];
                pind[i0] = pind[i1];
                pind[i1] = tmp;
            }
        }
        re->nattempt[0]++;  /* keep track of total permutation trials here */
        print_allswitchind(fplog, re->nrepl, re->ind, pind, re->allswaps, re->tmpswap);
    }
    else
    {
        /* standard nearest neighbor replica exchange */
        m = (step / re->nst) % 2;
        for (i = 1; i < re->nrepl; i++)
        {
            a = re->ind[i-1];
            b = re->ind[i];

            bPrint = (re->repl == a || re->repl == b);
            if (i % 2 == m)
            {
                delta = calc_delta(fplog, bPrint, re, a, b, a, b);
                if (delta <= 0)
                {
                    /* accepted */
                    prob[i] = 1;
                    bEx[i]  = TRUE;
                }
                else
                {
                    if (delta > PROBABILITYCUTOFF)
                    {
                        prob[i] = 0;
                    }
                    else
                    {
                        prob[i] = exp(-delta);
                    }
                    /* roll a number to determine if accepted */
                    bEx[i] = (rando(&(re->seed)) < prob[i]);
                }
                re->prob_sum[i] += prob[i];

                if (bEx[i])
                {
                    /* swap these two */
                    tmp       = pind[i-1];
                    pind[i-1] = pind[i];
                    pind[i]   = tmp;
                    re->nexchange[i]++;  /* statistics for back compatibility */
                }
            }
            else
            {
                prob[i] = -1;
                bEx[i]  = FALSE;
            }
        }
        /* print some statistics */
        print_ind(fplog, "ex", re->nrepl, re->ind, bEx);
        print_prob(fplog, "pr", re->nrepl, prob);
        fprintf(fplog, "\n");
        re->nattempt[m]++;
    }

    /* record which moves were made and accepted */
    for (i = 0; i < re->nrepl; i++)
    {
        re->nmoves[re->ind[i]][pind[i]] += 1;
        re->nmoves[pind[i]][re->ind[i]] += 1;
    }
    fflush(fplog); /* make sure we can see what the last exchange was */
}
bool Nation::CreateOnFly(int x,int y,int n){
	int cx=x>>2;
	int cy=y>>2;
	FlyCell* FC=&FlyMap[cy][cx];
	if(FC->NFly>=15)return false;
	int Rex=(x<<9)+256;
	int Rey=(y<<9)+256;
	for(int i=0;i<MaxObj&&int(Group[i]);i++);
	if(i>MaxObj)return false;
	if(n>=NMon) return false;
	if(i>=MAXOBJECT)MAXOBJECT=i+1;
	for(int k=0;FC->FlyList[k]!=0xFFFF;k++);
	FC->NFly++;
	FC->FlyList[k]=i;
	Group[i]=OBJECTS+i;
	LastObject=i;
	Cell8x8* CELL=&TCInf[NNUM][y>>2][x>>2];
	OneObject* G=Group[i];
	GeneralObject* GO=Mon[n];
	AddOrderEffect(x,y,GO->BornSound);
	CELL->UnitsAmount[GO->Kind]++;
	G->DefaultSettings(GO);
	G->Teleport=false;
	G->capTeleport=GO->Teleport;
	G->RealX=Rex;
	G->RealY=Rey;
	G->DestX=Rex;
	G->DestY=Rey;
	G->RealVx=0;
	G->RealVy=0;
	G->RealDir=rando()&255;
	G->Media=2;
	G->OnWater=false;
	G->Kind=GO->Kind;
	G->VisRadius=GO->VisRadius;
	G->VisSpots=GO->VisSpots;
	G->SpotType=GO->SpotType;
	G->SpotSize=GO->SpotSize;
	G->DangerZone=GO->DangerZone;
	G->NoSearchVictim=GO->NoSearchVictim;
	G->NoAnswer=GO->NoAnswer;
	G->NeedNoHelp=GO->NeedNoHelp;
	G->Nat=this;
	G->Ready=true;
	G->wepX=GO->wepX;
	G->wepY=GO->wepY;
	G->MaxDelay=GO->delay;
	G->delay=0;
	G->NearBase=0xFFFF;
	G->capBase=GO->cpbBase;
	G->RStage=0;
	G->RType=0;
	G->RAmount=0;
	G->NNUM=NNUM;
	G->NIndex=n;
	G->AnmStandKind=0;
	G->AnmGoKind=1;
	G->capBuild=GO->cpbBuild;
	G->GroupIndex=NULL;
	G->cpbMoving=GO->cpbMoving;
	if(!GO->SizeX)GO->SizeX=1;
	if(!GO->SizeY)GO->SizeY=1;
	G->Lx=GO->SizeX;
	G->Ly=GO->SizeY;
	G->TempFlag=false;
	G->Mobilised=false;
	G->Wars=NULL;
	G->Index=i;
	//Mops[y][x]=i;
	Visuals* m;
	m=(Visuals*)Mon[n];
	G->Selected=false;
	G->Borg=false;
	G->Life=m->info.Basic.MaxLife;
	G->MaxLife=m->info.Basic.MaxLife;
	G->Ref.Visual=m;
	G->x=x;
	G->y=y;
	G->CrowdRef=NULL;
	G->Push=false;
	//LLock[y][x]=true;
	//IncLock(x,y);
	G->Direction=rando() & 7;
	memset(&(G->ARegs),0,sizeof G->ARegs);
	G->LoadAnimation(0,0,0);
	G->LoadCurAnm(0);
	G->LocalOrder=NULL;
	//G->OrderReport=NULL;
	//G->MessageFlags=0;
	G->PrioryLevel=0;
	//G->MessageKind=0;
	G->InLineCom=NULL;
	G->LineOffset=0;
	G->Ticks=0;
	G->TicksPerChange=10;
	G->Wait=0;
	G->Addx=0;
	G->Addy=0;
//	G->inMotion=false;
	G->Npush=0;
	G->StandTime=100;
	G->Sdoxlo=false;
	G->Weap=Mon[n]->Weap;
	G->NMask=NMask;
	G->Important=false;
	G->EnemyDist=5000;
	G->Attack=false;
	G->EnemyID=0xFFFF;
	G->Egoist=false;
	G->Height=0;
	G->LoadAnimation(0,0,0);//stand=motion animation
	G->LoadAnimation(1,2,0);//attack
	G->LoadAnimation(2,3,0);//death
	G->BestDist=32*16*6;
	G->FlyAttackMode=false;
	NGidot++;
	if(GO->UFO)G->MakeMeUFO();
	return true;
};
예제 #25
0
int gmx_nmens(int argc,char *argv[])
{
  static char *desc[] = {
    "[TT]g_nmens[tt] generates an ensemble around an average structure",
    "in a subspace which is defined by a set of normal modes (eigenvectors).",
    "The eigenvectors are assumed to be mass-weighted.",
    "The position along each eigenvector is randomly taken from a Gaussian",
    "distribution with variance kT/eigenvalue.[PAR]",
    "By default the starting eigenvector is set to 7, since the first six",
    "normal modes are the translational and rotational degrees of freedom." 
  };
  static int  nstruct=100,first=7,last=-1,seed=-1;
  static real temp=300.0;
  t_pargs pa[] = {
    { "-temp",  FALSE, etREAL, {&temp}, 
      "Temperature in Kelvin" },
    { "-seed", FALSE, etINT, {&seed},     
      "Random seed, -1 generates a seed from time and pid" },
    { "-num", FALSE, etINT, {&nstruct},     
      "Number of structures to generate" },
    { "-first", FALSE, etINT, {&first},     
      "First eigenvector to use (-1 is select)" },
    { "-last",  FALSE, etINT, {&last}, 
      "Last eigenvector to use (-1 is till the last)" }
  };
#define NPA asize(pa)
  
  int        out;
  int        status,trjout;
  t_topology top;
  int        ePBC;
  t_atoms    *atoms;
  rvec       *xtop,*xref,*xav,*xout1,*xout2;
  bool       bDMR,bDMA,bFit;
  int        nvec,*eignr=NULL;
  rvec       **eigvec=NULL;
  matrix     box;
  real       *eigval,totmass,*invsqrtm,t,disp;
  int        natoms,neigval;
  char       *grpname,*indexfile,title[STRLEN];
  int        i,j,d,s,v;
  int        nout,*iout,noutvec,*outvec;
  atom_id    *index;
  real       rfac,invfr,rhalf,jr;
  int *      eigvalnr;
  
  unsigned long      jran;
  const unsigned long im = 0xffff;
  const unsigned long ia = 1093;
  const unsigned long ic = 18257;

  t_filenm fnm[] = { 
    { efTRN, "-v",    "eigenvec",    ffREAD  },
    { efXVG, "-e",    "eigenval",    ffREAD  },
    { efTPS, NULL,    NULL,          ffREAD },
    { efNDX, NULL,    NULL,          ffOPTRD },
    { efTRO, "-o",    "ensemble",    ffWRITE }
  }; 
#define NFILE asize(fnm) 

  CopyRight(stderr,argv[0]); 
  parse_common_args(&argc,argv,PCA_BE_NICE,
		    NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL); 

  indexfile=ftp2fn_null(efNDX,NFILE,fnm);

  read_eigenvectors(opt2fn("-v",NFILE,fnm),&natoms,&bFit,
		    &xref,&bDMR,&xav,&bDMA,&nvec,&eignr,&eigvec,&eigval);

  read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xtop,NULL,box,bDMA);
  atoms=&top.atoms;

  printf("\nSelect an index group of %d elements that corresponds to the eigenvectors\n",natoms);
  get_index(atoms,indexfile,1,&i,&index,&grpname);
  if (i!=natoms)
    gmx_fatal(FARGS,"you selected a group with %d elements instead of %d",
		i,natoms);
  printf("\n");
  
  snew(invsqrtm,natoms);
  if (bDMA) {
    for(i=0; (i<natoms); i++)
      invsqrtm[i] = invsqrt(atoms->atom[index[i]].m);
  } else {
    for(i=0; (i<natoms); i++)
      invsqrtm[i]=1.0;
  }
  
  if (last==-1)
      last=natoms*DIM;
  if (first>-1) 
  {
      /* make an index from first to last */
      nout=last-first+1;
      snew(iout,nout);
      for(i=0; i<nout; i++)
          iout[i]=first-1+i;
  }
  else 
  {
      printf("Select eigenvectors for output, end your selection with 0\n");
      nout=-1;
      iout=NULL;
      do {
          nout++;
          srenew(iout,nout+1);
          if(1 != scanf("%d",&iout[nout]))
	  {
	      gmx_fatal(FARGS,"Error reading user input");
	  }
          iout[nout]--;
      } while (iout[nout]>=0);
      printf("\n");
  }
  
  /* make an index of the eigenvectors which are present */
  snew(outvec,nout);
  noutvec=0;
  for(i=0; i<nout; i++)
  {
      j=0;
      while ((j<nvec) && (eignr[j]!=iout[i]))
          j++;
      if ((j<nvec) && (eignr[j]==iout[i]))
      {
          outvec[noutvec] = j;
          iout[noutvec] = iout[i];
          noutvec++;
      }
  }
  
  fprintf(stderr,"%d eigenvectors selected for output\n",noutvec);

  if (seed == -1)
    seed = make_seed();
  fprintf(stderr,"Using seed %d and a temperature of %g K\n",seed,temp);

  snew(xout1,natoms);
  snew(xout2,atoms->nr);
  out=open_trx(ftp2fn(efTRO,NFILE,fnm),"w");
  jran = (unsigned long)((real)im*rando(&seed));
  for(s=0; s<nstruct; s++) {
    for(i=0; i<natoms; i++)
      copy_rvec(xav[i],xout1[i]);
    for(j=0; j<noutvec; j++) {
      v = outvec[j];
      /* (r-0.5) n times:  var_n = n * var_1 = n/12
	 n=4:  var_n = 1/3, so multiply with 3 */
      
      rfac  = sqrt(3.0 * BOLTZ*temp/eigval[iout[j]]);
      rhalf = 2.0*rfac; 
      rfac  = rfac/(real)im;

      jran = (jran*ia+ic) & im;
      jr = (real)jran;
      jran = (jran*ia+ic) & im;
      jr += (real)jran;
      jran = (jran*ia+ic) & im;
      jr += (real)jran;
      jran = (jran*ia+ic) & im;
      jr += (real)jran;
      disp = rfac * jr - rhalf;
      
      for(i=0; i<natoms; i++)
          for(d=0; d<DIM; d++)
              xout1[i][d] += disp*eigvec[v][i][d]*invsqrtm[i];
    }
    for(i=0; i<natoms; i++)
        copy_rvec(xout1[i],xout2[index[i]]);
    t = s+1;
    write_trx(out,natoms,index,atoms,0,t,box,xout2,NULL);
    fprintf(stderr,"\rGenerated %d structures",s+1);
  }
  fprintf(stderr,"\n");
  close_trx(out);
  
  return 0;
}
예제 #26
0
파일: acf.test.c 프로젝트: aeszter/gromacs
int main(int argc,char *argv[])
{
  FILE *fp;
  const char *desc[] = {
    "testac tests the functioning of the GROMACS acf routines"
  };
  static int nframes = 1024;
  static int datatp  = 0;
  static real a=0.02*M_PI;
  output_env_t oenv;
  t_pargs pa[] = {
    { "-np", FALSE, etINT, &nframes,
      "Number of data points" },
    { "-dtp",FALSE, etINT, &datatp,
      "Which data: 0=all 0.0, 1=all 1.0, 2=cos(a t), 3=random, 4=cos(a t)+random, 5=sin(a t)/(a t)" }
  };
  static char *str[] = {
    "all 0.0", 
    "all 1.0",
    "cos(a t)",
    "random", 
    "cos(a t)+random",
    "sin(a t)/(a t)"
  };
  t_filenm fnm[] = {
    { efXVG, "-d", "acf-data", ffWRITE },
    { efXVG, "-c", "acf-corr", ffWRITE },
    { efXVG, "-comb", "acf-comb.xvg", ffWRITE }
  };
#define NFILE asize(fnm)
  int     npargs,i,nlag;
  int     seed=1993;
  real    *data,*data2,x;
  t_pargs *ppa;
  
  CopyRight(stderr,argv[0]);
  npargs = asize(pa);
  ppa    = add_acf_pargs(&npargs,pa);
  parse_common_args_r(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_BE_NICE,
		      NFILE,fnm,npargs,ppa,asize(desc),desc,0,NULL,&oenv);
  snew(data,nframes);
  snew(data2,nframes);
  
  fp = xvgropen(opt2fn("-d",NFILE,fnm),"testac","x","y",oenv);
  for(i=0; (i<nframes); i++) {
    x = a*i;
    switch (datatp) {
    case 1:
      data[i] = 1;
      break;
    case 2:
      data[i] = cos(x);
      break;
    case 3:
      data[i] = 2*rando(&seed)-1.0;
      break;
    case 4:
      data[i] = cos(x)+2*rando(&seed)-1.0;
      break;
    case 5:
      if (i==0)
	data[i] = 1;
      else
	data[i] = sin(x)/(x);
    default:
      /* Data remains 0.0 */
      break;
    }
    fprintf(fp,"%10g  %10g\n",x,data[i]);
    data2[i] = data[i];
  }
  ffclose(fp);
  
  do_autocorr(opt2fn("-c",NFILE,fnm),oenv,str[datatp],
	      nframes,1,&data,a,eacNormal,FALSE);
	      
  nlag = get_acfnout();
  fp = xvgropen(opt2fn("-comb",NFILE,fnm),"testac","x","y",oenv);
  for(i=0; (i<nlag); i++) {
    fprintf(fp,"%10g  %10g  %10g\n",a*i,data2[i],data[i]);
  }
  ffclose(fp);

  do_view(opt2fn("-c",NFILE,fnm),"-nxy");
    
  thanx(stderr);

  return 0;
}
예제 #27
0
static Boolean
mainEventHandler (EventPtr event)
{
    int handled = 0;
    FormPtr form;
    ControlPtr active = 0;

    switch (event->eType) {
    case frmOpenEvent:
	form = FrmGetActiveForm();
	listPtr_races =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, lid_races));

	// clear the list selection
	LstSetSelection(listPtr_races, -1);

	// set up the player and races selection buttons
	buttonPtr_players2 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_players2));
	buttonPtr_players3 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_players3));
	buttonPtr_players4 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_players4));
	buttonPtr_races3 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_races3));
	buttonPtr_races5 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_races5));
	buttonPtr_races7 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_races7));
	buttonPtr_races9 =
	    FrmGetObjectPtr(form, FrmGetObjectIndex(form, pbid_races9));

	// activate the appropriate options
	switch (players) {
	case 2: active = buttonPtr_players2; break;
	case 3: active = buttonPtr_players3; break;
	case 4: active = buttonPtr_players4; break;
	}

	if (active != 0) CtlSetValue(active, 1);

	switch (races) {
	case 3: active = buttonPtr_races3; break;
	case 5: active = buttonPtr_races5; break;
	case 7: active = buttonPtr_races7; break;
	case 9: active = buttonPtr_races9; break;
	}

	if (active != 0) CtlSetValue(active, 1);

	FrmDrawForm(form);
	handled = 1;
	break;

    case ctlSelectEvent:  // a button was pressed and released
	switch (event->data.ctlSelect.controlID) {
	case pbid_players2: players = 2; handled = 1; break;
	case pbid_players3: players = 3; handled = 1; break;
	case pbid_players4: players = 4; handled = 1; break;

	case pbid_races3: races = 3; handled = 1; break;
	case pbid_races5: races = 5; handled = 1; break;
	case pbid_races7: races = 7; handled = 1; break;
	case pbid_races9: races = 9; handled = 1; break;

	case bid_rando: rando(); handled = 1; break;
	}
	break;

    case menuEvent:
	switch (event->data.menu.itemID) {
	case miid_about:
	    FrmAlert(aid_about);
	    break;

	case miid_prefs:
	    FrmGotoForm(fid_prefs);
	    break;
	}
	handled = 1;
	break;

    default:
	break;
    }

    return handled;
}
예제 #28
0
파일: nxt.c 프로젝트: daniel974/EV3
//task main() {
int main() {

    Initialize_Net();
    for( epoch = 0 ; epoch < 100 ; epoch++) {    /* iterate weight updates */
        for( p = 1 ; p <= NumPattern ; p++ ) {    /* randomize order of individuals */
            ranpat[p] = p ;
        }
        for( p = 1 ; p <= NumPattern ; p++) {
            np = p + rando() * ( NumPattern + 1 - p ) ;
            op = ranpat[p] ; ranpat[p] = ranpat[np] ; ranpat[np] = op ;
        }
        Error = 0.0 ;
        for( np = 1 ; np <= NumPattern ; np++ ) {    /* repeat for all the training patterns */
            p = ranpat[np];
            for( j = 1 ; j <= NumHidden ; j++ ) {    /* compute hidden unit activations */
                SumH[p][j] = WeightIH[0][j] ;
                for( i = 1 ; i <= NumInput ; i++ ) {
                    SumH[p][j] += Input[p][i] * WeightIH[i][j] ;
                }
                Hidden[p][j] = 1.0/(1.0 + pow(E, (-SumH[p][j]))) ;
                //Hidden[p][j] = 1.0/(1.0 + E^(-SumH[p][j])) ;
            }
            for( k = 1 ; k <= NumOutput ; k++ ) {    /* compute output unit activations and errors */
                SumO[p][k] = WeightHO[0][k] ;
                for( j = 1 ; j <= NumHidden ; j++ ) {
                    SumO[p][k] += Hidden[p][j] * WeightHO[j][k] ;
                }
                Output[p][k] = 1.0/(1.0 + pow(E, (-SumO[p][k]))) ;   /* Sigmoidal Outputs */
                //Output[p][k] = 1.0/(1.0 + E^(-SumO[p][k])) ;   /* Sigmoidal Outputs */
/*              Output[p][k] = SumO[p][k];      Linear Outputs */
                Error += 0.5 * (Target[p][k] - Output[p][k]) * (Target[p][k] - Output[p][k]) ;   /* SSE */
/*              Error -= ( Target[p][k] * log( Output[p][k] ) + ( 1.0 - Target[p][k] ) * log( 1.0 - Output[p][k] ) ) ;    Cross-Entropy Error */
                DeltaO[k] = (Target[p][k] - Output[p][k]) * Output[p][k] * (1.0 - Output[p][k]) ;   /* Sigmoidal Outputs, SSE */
/*              DeltaO[k] = Target[p][k] - Output[p][k];     Sigmoidal Outputs, Cross-Entropy Error */
/*              DeltaO[k] = Target[p][k] - Output[p][k];     Linear Outputs, SSE */
            }
            for( j = 1 ; j <= NumHidden ; j++ ) {    /* 'back-propagate' errors to hidden layer */
                SumDOW[j] = 0.0 ;
                for( k = 1 ; k <= NumOutput ; k++ ) {
                    SumDOW[j] += WeightHO[j][k] * DeltaO[k] ;
                }
                DeltaH[j] = SumDOW[j] * Hidden[p][j] * (1.0 - Hidden[p][j]) ;
            }
            for( j = 1 ; j <= NumHidden ; j++ ) {     /* update weights WeightIH */
                DeltaWeightIH[0][j] = eta * DeltaH[j] + alpha * DeltaWeightIH[0][j] ;
                WeightIH[0][j] += DeltaWeightIH[0][j] ;
                for( i = 1 ; i <= NumInput ; i++ ) {
                    DeltaWeightIH[i][j] = eta * Input[p][i] * DeltaH[j] + alpha * DeltaWeightIH[i][j];
                    WeightIH[i][j] += DeltaWeightIH[i][j] ;
                }
            }
            for( k = 1 ; k <= NumOutput ; k ++ ) {    /* update weights WeightHO */
                DeltaWeightHO[0][k] = eta * DeltaO[k] + alpha * DeltaWeightHO[0][k] ;
                WeightHO[0][k] += DeltaWeightHO[0][k] ;
                for( j = 1 ; j <= NumHidden ; j++ ) {
                    DeltaWeightHO[j][k] = eta * Hidden[p][j] * DeltaO[k] + alpha * DeltaWeightHO[j][k] ;
                    WeightHO[j][k] += DeltaWeightHO[j][k] ;
                }
            }
        }
        if( epoch%100 == 0 ) //fprintf(stdout, "\nEpoch %-5d :   Error = %f", epoch, Error) ;
        if( Error < 0.0004 ) break ;  /* stop learning when 'near enough' */
    }

    //fprintf(stdout, "\n\nNETWORK DATA - EPOCH %d\n\nPat\t", epoch) ;   /* print network outputs */
    for( i = 1 ; i <= NumInput ; i++ ) {
        //fprintf(stdout, "Input%-4d\t", i) ;

    }
    for( k = 1 ; k <= NumOutput ; k++ ) {
        //fprintf(stdout, "Target%-4d\tOutput%-4d\t", k, k) ;
    }
    for( p = 1 ; p <= NumPattern ; p++ ) {
    //fprintf(stdout, "\n%d\t", p) ;
        for( i = 1 ; i <= NumInput ; i++ ) {
            //fprintf(stdout, "%f\t", Input[p][i]) ;
        }
        for( k = 1 ; k <= NumOutput ; k++ ) {
//            string str=NumToStr(Output[p][k]);
//            TextOut(0,k,str) ;
        }
    }
   Wait(40000);
}
예제 #29
0
static char *insert_mols(const char *mol_insrt, int nmol_insrt, int ntry, int seed,
                         t_atoms *atoms, rvec **x, real **r, int ePBC, matrix box,
                         gmx_atomprop_t aps, real r_distance, real rshell,
                         const output_env_t oenv)
{
    t_pbc            pbc;
    static  char    *title_insrt;
    t_atoms          atoms_insrt;
    rvec            *x_insrt, *x_n;
    real            *r_insrt;
    int              ePBC_insrt;
    matrix           box_insrt;
    int              i, mol, onr;
    real             alfa, beta, gamma;
    rvec             offset_x;
    int              trial;

    set_pbc(&pbc, ePBC, box);

    /* read number of atoms of insert molecules */
    get_stx_coordnum(mol_insrt, &atoms_insrt.nr);
    if (atoms_insrt.nr == 0)
    {
        gmx_fatal(FARGS, "No molecule in %s, please check your input\n", mol_insrt);
    }
    /* allocate memory for atom coordinates of insert molecules */
    snew(x_insrt, atoms_insrt.nr);
    snew(r_insrt, atoms_insrt.nr);
    snew(atoms_insrt.resinfo, atoms_insrt.nr);
    snew(atoms_insrt.atomname, atoms_insrt.nr);
    snew(atoms_insrt.atom, atoms_insrt.nr);
    atoms_insrt.pdbinfo = NULL;
    snew(x_n, atoms_insrt.nr);
    snew(title_insrt, STRLEN);

    /* read residue number, residue names, atomnames, coordinates etc. */
    fprintf(stderr, "Reading molecule configuration \n");
    read_stx_conf(mol_insrt, title_insrt, &atoms_insrt, x_insrt, NULL,
                  &ePBC_insrt, box_insrt);
    fprintf(stderr, "%s\nContaining %d atoms in %d residue\n",
            title_insrt, atoms_insrt.nr, atoms_insrt.nres);
    srenew(atoms_insrt.resinfo, atoms_insrt.nres);

    /* initialise van der waals arrays of insert molecules */
    mk_vdw(&atoms_insrt, r_insrt, aps, r_distance);

    srenew(atoms->resinfo, (atoms->nres+nmol_insrt*atoms_insrt.nres));
    srenew(atoms->atomname, (atoms->nr+atoms_insrt.nr*nmol_insrt));
    srenew(atoms->atom, (atoms->nr+atoms_insrt.nr*nmol_insrt));
    srenew(*x, (atoms->nr+atoms_insrt.nr*nmol_insrt));
    srenew(*r, (atoms->nr+atoms_insrt.nr*nmol_insrt));

    trial = mol = 0;
    while ((mol < nmol_insrt) && (trial < ntry*nmol_insrt))
    {
        fprintf(stderr, "\rTry %d", trial++);
        for (i = 0; (i < atoms_insrt.nr); i++)
        {
            copy_rvec(x_insrt[i], x_n[i]);
        }
        alfa  = 2*M_PI*rando( &seed);
        beta  = 2*M_PI*rando( &seed);
        gamma = 2*M_PI*rando( &seed);
        rotate_conf(atoms_insrt.nr, x_n, NULL, alfa, beta, gamma);
        offset_x[XX] = box[XX][XX]*rando(&seed);
        offset_x[YY] = box[YY][YY]*rando(&seed);
        offset_x[ZZ] = box[ZZ][ZZ]*rando(&seed);
        gen_box(0, atoms_insrt.nr, x_n, box_insrt, offset_x, TRUE);
        if (!in_box(&pbc, x_n[0]) || !in_box(&pbc, x_n[atoms_insrt.nr-1]))
        {
            continue;
        }
        onr = atoms->nr;

        add_conf(atoms, x, NULL, r, FALSE, ePBC, box, TRUE,
                 &atoms_insrt, x_n, NULL, r_insrt, FALSE, rshell, 0, oenv);

        if (atoms->nr == (atoms_insrt.nr+onr))
        {
            mol++;
            fprintf(stderr, " success (now %d atoms)!", atoms->nr);
        }
    }
    srenew(atoms->resinfo,  atoms->nres);
    srenew(atoms->atomname, atoms->nr);
    srenew(atoms->atom,     atoms->nr);
    srenew(*x,              atoms->nr);
    srenew(*r,              atoms->nr);

    fprintf(stderr, "\n");
    /* print number of molecules added */
    fprintf(stderr, "Added %d molecules (out of %d requested) of %s\n",
            mol, nmol_insrt, *atoms_insrt.resinfo[0].name);

    return title_insrt;
}
int main(){

  int i, j, k, p, np, op, game, epoch, NumGame = 81, NumIn = 20;

  char line[1024];
  double num;
  int line_count = 0, target_index = 0, game_index = 0, input_index = 0;

  int hidd1, hidd2, hidd3, best_hidd1, best_hidd2, best_hidd3;
  double min_error = 1000000;
  // for (hidd1 = 10000; hidd1 < 40005; hidd1++){
  //   for (hidd2 = 10000; hidd2 < 45000; hidd2++){
  //     for (hidd3 = 10000; hidd3 < 45000; hidd3++){
        // for (eta = .4; eta < .7; eta = eta + .1){
        //   for (alpha = .7; alpha < 1; alpha = alpha + .1){

      int NumHidd1 = 15, NumHidd2 = 44, NumHidd3 = 35, NumPatt = 100;
      double sumH1[NumHidd1], sumH2[NumHidd2], sumH3[NumHidd3], sumO[NumOut];
      double hidden1[NumHidd1], hidden2[NumHidd2], hidden3[NumHidd3], output[NumOut];
      double weightIn[NumIn][NumHidd1], weightHidd1[NumHidd1][NumHidd2], weightHidd2[NumHidd2][NumHidd3], weightHidd3[NumHidd3][NumOut];
      double deltaWeightIN[NumIn][NumHidd1], deltaWeightH1[NumHidd1][NumHidd2], deltaWeightH2[NumHidd2][NumHidd3], deltaWeightH3[NumHidd3][NumOut];
      double sumBP1[NumHidd1], sumBP2[NumHidd2], sumBP3[NumHidd3];
      double deltaH1[NumHidd1], deltaH2[NumHidd2], deltaH3[NumHidd3], deltaO[NumOut];

      double input[NumGame][NumIn];
      double target[NumGame];
      double output_array[NumGame];
      int output_count = 0;
      double error[NumOut], eta = 0.5, alpha = 0.9, smallwt = 0.5, best_alpha, best_eta, total_error;


      FILE *csvFile = fopen("training set.csv", "r");

      input_index = 0;
      line_count = 0;
      target_index = 0;
      game_index = 0;
      output_count = 0;
      if (csvFile){
        char *token;
        while (fgets(line, 1024, csvFile)){
          token = strtok(&line[0], ",");
          if (!strcmp(token, "eof"))
            break;
          if (!strcmp(token,"\r\n")){
            line_count++;
            input_index = 0;
          }

          while(token){
            num = atof(token);
            if (line_count == 2 && strcmp(token,"\r\n")){
              target[target_index] = num;
              target_index++;
            }
            else if (line_count == 0){
              input[game_index][input_index] = num;
              input_index++;
            }
            token = strtok(NULL, ",");
          }
          if (line_count == 4){
            line_count = 0;
            game_index++;
          }

        }
        fclose(csvFile);
      }

      for (i = 0; i < NumGame; i++){
        // target[i] = log(1 + exp(target[i]));
        target[i] = 30 * (1.0/(1.0 + exp(-.1 * target[i])));
        // target[i] = (exp(target[i]) - exp(-target[i])) / (exp(target[i] + exp(-target[i])));
        // target[i] = target[i]/30;
      }

      int ranpat[NumPatt];

      double error1[NumIn], error2[NumHidd1], error3[NumHidd2], error4[NumHidd3];
      for (i = 0; i < NumIn; i++){
        for (j = 0; j < NumHidd1; j++){
          weightIn[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
          // weightIn[i][j] = .5;
          deltaWeightIN[i][j] = 0.0;
        }
      }

      for (i = 0; i < NumHidd1; i++){
        for (j = 0; j < NumHidd2; j++){
          weightHidd1[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
          // weightHidd1[i][j] = .5;
          deltaWeightH1[i][j] = 0.0;
        }
      }

      for (i = 0; i < NumHidd2; i++){
        for (j = 0; j < NumHidd3; j++){
          weightHidd2[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
          // weightHidd2[i][j] = .5;
          deltaWeightH2[i][j] = 0.0;
        }
      }

      for (i = 0; i < NumHidd3; i++){
        for (j = 0; j < NumOut; j++){
          weightHidd3[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
          // weightHidd3[i] = .5;
          deltaWeightH3[i][j] = 0.0;
        }
      }

      for (epoch = 0; epoch < 10050; epoch++){

        // for( p = 1 ; p <= NumPatt ; p++ ) {    /* randomize order of individuals */
        //     ranpat[p] = p ;
        // }
        // for( p = 1 ; p < NumPatt ; p++) {
        //     np = p + (rand() % NumPatt) / NumPatt;
        //     op = ranpat[p] ; ranpat[p] = ranpat[np] ; ranpat[np] = op ;
        // }
        //
        // output_count = 0;
        // for (np = 1; np < NumPatt; np++){
        //   p = ranpat[np];

          // error = 0.0;
          for (game = 0; game < NumGame; game++){

            for (i = 0; i < NumOut; i++){
              error[i] = 0.0;
            }

            for (i = 0; i < NumHidd1; i++){
              sumH1[i] = 0;
              // sumH1[i] = weightIn[0][i];
              for (j = 0; j < NumIn; j++){
                sumH1[i] += input[game][j] * weightIn[j][i];
              }
              // hidden1[i] = log(1 + exp(sumH1[i]));
              hidden1[i] = 1.0/(1.0 + exp(-sumH1[i]));
              // hidden1[i] = (exp(sumH1[i]) - exp(-sumH1[i])) / (exp(sumH1[i] + exp(-sumH1[i])));
              // hidden1[i] = hidden1[i] / 30;
            }

            for (i = 0; i < NumHidd2; i++){
              sumH2[i] = 0;
              // sumH2[i] = weightHidd1[0][i];
              for (j = 0; j < NumHidd1; j++){
                sumH2[i] += hidden1[j] * weightHidd1[j][i];
              }
              // hidden2[i] = log(1 + exp(sumH2[i]));
              hidden2[i] = 1.0/(1.0 + exp(-sumH2[i]));
              // hidden2[i] = (exp(sumH2[i]) - exp(-sumH2[i])) / (exp(sumH2[i] + exp(-sumH2[i])));
              // hidden2[i] = hidden2[i] / 30;
            }

            for (i = 0; i < NumHidd3; i++){
              sumH3[i] = 0;
              // sumH3[i] = weightHidd2[0][i];
              for (j = 0; j < NumHidd2; j++){
                sumH3[i] += hidden2[j] * weightHidd2[j][i];
              }
              // hidden3[i] = log(1 + exp(sumH3[i]));
              hidden3[i] = 1.0/(1.0 + exp(-sumH3[i]));
              // hidden3[i] = (exp(sumH3[i]) - exp(-sumH3[i])) / (exp(sumH3[i] + exp(-sumH3[i])));
              // hidden3[i] = hidden3[i] / 30;
            }

            for (j = 0; j < NumOut; j++){
              sumO[j] = 0;
              // sumO[j] = weightHidd3[0][j];
              for (i = 0; i < NumHidd3; i++){
                sumO[j] += hidden3[i] * weightHidd3[i][j];
              }

              // output = log(1 + exp(sumO));
              // output[j] = (1.0/(1.0 + exp(-.1*sumO)));
              output[j] = 30 * ( 1.0 / 1.0 + exp(-.1*sumO[j]));
              // output = (exp(sumO) - exp(-sumO)) / (exp(sumO + exp(-sumO)));
              // output = sumO / 30;
              // error += .5 * (target[p][game] - output) * (target[p][game] - output);
              error[j] = ((target[game] - output[j]));
              // error = target[game] - output;
              // total_error += fabs(error);
              deltaO[j] = (target[game] - output[j]) * output[j] * (1.0 - output[j]);

            }

            min_error = 1000000000;
            int index = 0;
            for (i = 0; i < NumOut; i++){
              if (error[i] < min_error)
                index = i;
            }
            printf("Target = %G\n", target[game]);
            printf("Output = %G\n", output[index]);
            printf("SumO = %G\n", sumO[index]);

            for (i = 0; i < NumHidd3; i++){
              for (j = 0; j < NumOut; j++){
                sumBP3[i] = weightHidd3[i][j] * deltaO[j];
                deltaH3[i] = sumBP3[i] * hidden3[i] * (1.0 - hidden3[i]);
              }
            }

            for (i = 0; i < NumHidd2; i++){
              sumBP2[i] = 0.0;
              for(j = 0; j < NumHidd3; j++){
                sumBP2[i] += weightHidd2[i][j] * deltaH3[j];
              }
              deltaH2[i] = sumBP2[i] * hidden2[i] * (1.0 - hidden2[i]);
            }

            for (i = 0; i < NumHidd1; i++){
              sumBP1[i] = 0.0;
              for (j = 0; j < NumHidd2; j++){
                  sumBP1[i] += weightHidd1[i][j] * deltaH2[j];
              }
              deltaH1[i] = sumBP1[i] * hidden1[i] * (1.0 - hidden1[i]);
            }

            for (i = 0; i < NumHidd1; i++){
              deltaWeightIN[0][i] = eta * deltaH1[i] + alpha * deltaWeightIN[0][i];
              weightIn[0][i] += deltaWeightIN[0][i];
              for (j = 0; j < NumIn; j++){
                deltaWeightIN[j][i] = eta * input[game][j] * deltaH1[i] + alpha * deltaWeightIN[j][i];
                weightIn[j][i] += deltaWeightIN[j][i];
              }
            }

            for (i = 0; i < NumHidd2; i++){
              deltaWeightH1[0][i] = eta * deltaH2[i] + alpha * deltaWeightH1[0][i];
              weightHidd1[0][i] += deltaWeightH1[0][i];
              for (j = 0; j < NumHidd1; j++){
                deltaWeightH1[j][i] = eta * hidden1[j] * deltaH2[i] + alpha * deltaWeightH1[j][i];
                weightHidd1[j][i] += deltaWeightH1[j][i];
              }
            }

            for (i = 0; i < NumHidd3; i++){
              deltaWeightH2[0][i] = eta * deltaH3[i] + alpha * deltaWeightH2[0][i];
              weightHidd2[0][i] += deltaWeightH2[0][i];
              for (j = 0; j < NumHidd2; j++){
                deltaWeightH2[j][i] = eta * hidden2[j] * deltaH3[i] + alpha * deltaWeightH2[j][i];
                weightHidd2[j][i] += deltaWeightH2[j][i];
              }
            }

            for (j = 0; j < NumOut; j++){
              deltaWeightH3[0][j] = eta * deltaO[j] + alpha * deltaWeightH3[0][j];
              weightHidd3[0][j] += deltaWeightH3[0][j];
              for (i = 0; i < NumHidd3; i++){
                deltaWeightH3[i][j] = eta * hidden3[i] * deltaO[j] + alpha * deltaWeightH3[i][j];
                weightHidd3[i][j] += deltaWeightH3[i][j];
              }
            }


            // printf("%G\n", output);
          }
        }
        // printf("Epoch = %d\n", epoch);
        // printf("Error = %G\n", error);
        // for (i = 0; i < NumGame; i++){
        //   printf("%G\n", output_array[i]);
        // }
        // if (error < min_error){
        //   min_error = error;
        //   best_hidd1 = hidd1;
        //   best_hidd2 = hidd2;
        //   best_hidd3 = hidd3;
        //   // best_alpha = alpha;
        //   // best_eta = eta;
        // }
        // printf("Min error = %G\n", min_error);
        // printf("Best Hidd1 = %d\n", best_hidd1);
        // printf("Best Hidd2 = %d\n", best_hidd2);
        // printf("Best Hidd3 = %d\n", best_hidd3);
        // // printf("Best alpha = %G ... eta = %G\n", alpha, eta);
        // printf("Current Hidd 1 = %d ... Hidd2 = %d ... Hidd2 = %d\n", hidd1, hidd2, hidd3);
        // if (error < .05)
        //   break;
    //   }
    //
    // }
  // }
  // // if (error < .05)
  // //   break;
  //   }
  //   // if (error < .05)
  //   //   break;
  //   }

    // if (error < .05)
    //   break;

  //}
  //
  // printf("Input weights-------------------\n" );
  // for (i = 0; i < NumIn; i++){
  //   for (j = 0; j < NumHidd1; j++){
  //     printf("%G\n", weightIn[i][j]);
  //   }
  //   printf("\n" );
  // }
  //
  // printf("Hidd1 weights-------------------\n" );
  // for (i = 0; i < NumHidd1; i++){
  //   for (j = 0; j < NumHidd2; j++){
  //     printf("%G\n",weightHidd1[i][j]);
  //   }
  //   printf("\n" );
  // }
  //
  // printf("Hidd2 weights-------------------\n" );
  // for (i = 0; i < NumHidd2; i++){
  //     printf("%G\n", weightHidd2[i]);
  // }

}