Ejemplo n.º 1
0
static void fill_random_vector(double *x, int n)
{
	double mu = 1000*(random_uniform()-0.5);
	double sigma = 500*random_uniform()+0.1;
	for (int i = 0; i < n; i++)
		x[i] = mu + sigma*random_normal();
}
Ejemplo n.º 2
0
int main()
{
  int i;
  double rands[1000];
  for (i=0; i&lt;1000; i++)
    rands[i] = 1.0 + 0.5*random_normal();
  return 0;
}
Ejemplo n.º 3
0
void fill_random_field(float *f, int w, int h, float sigma, float eta)
{
	for (int i = 0; i < w * h * 2; i++)
		f[i] = sigma*random_normal();

	void gblur(float *y, float *x, int w, int h, int pd, float s);
	gblur(f, f, w, h, 2, eta);

}
Ejemplo n.º 4
0
main()
{
    int i;

    for (i = 0; i < 200000; i++) {
        /*myrandom(1);*/
        printf("%.3f\n", random_normal(1, 2.65, 6.55));
    }
}
/*the srcDim determines the fan-in to the hidden and output units. The weights ae initialised 
to be inversely proportional to the sqrt(fanin)
*/ 
void initialiseWeights(double *weightMat,int length,int srcDim){
	int i;
	double randm;
	srand((unsigned int)time(NULL));
	for ( i = 0; i<(length);i++){
		randm = random_normal();
		weightMat[i] = randm*1/(sqrt(srcDim));
	}
	
}
Ejemplo n.º 6
0
static GnmValue *
gnumeric_randnorm (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
	gnm_float mean  = value_get_as_float (argv[0]);
	gnm_float stdev = value_get_as_float (argv[1]);

	if (stdev < 0)
		return value_new_error_NUM (ei->pos);

        return value_new_float (stdev * random_normal () + mean);
}
void initialiseBias(double *biasVec,int dim, int srcDim){
	int i;
	double randm;
	
	for ( i = 0; i<dim;i++){
		randm = random_normal();
		biasVec[i] = randm*(1/sqrt(srcDim));
	}
	

}
Ejemplo n.º 8
0
int main()
{

  int i;
  double rands[1000];
  for (i=0; i<1000; i++){
  rands[i] = 1.0 + 0.5*random_normal();
  printf("%f\n",rands[i]);
	}
  return 0;

}
Ejemplo n.º 9
0
static gboolean
tool_random_engine_run_normal (data_analysis_output_t *dao,
			       tools_data_random_t *info,
			       normal_random_tool_t *param)
{
	int i, n;
	for (i = 0; i < info->n_vars; i++) {
		for (n = 0; n < info->count; n++) {
			gnm_float v;
			v = param->stdev * random_normal () + param->mean;
			dao_set_cell_float (dao, i, n, v);
		}
	}
	return FALSE;
}
Ejemplo n.º 10
0
static GnmValue *
gnumeric_randsnorm (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
	gnm_float alpha  = 0.;
	gnm_float mean  = 0.;
	gnm_float stdev = 1.;
	gnm_float result;

	if (argv[0]) {
		alpha  = value_get_as_float (argv[0]);
		if (argv[1]) {
			mean  = value_get_as_float (argv[1]);
			if (argv[2])
				stdev = value_get_as_float (argv[2]);
		}
	}

       	if (stdev < 0)
		return value_new_error_NUM (ei->pos);

	result = ((alpha == 0.) ? random_normal () : random_skew_normal (alpha));

        return value_new_float (stdev * result + mean);
}
Ejemplo n.º 11
0
int main(int argc, char** argv){
	
	int seed = getpid();
	int c;
	int option_index = 0;
	int league_id;
	int num_players;
	
	struct argp_option options[] = {
		{"seed",'s', "int", 0, 0},
		{"league-id", 'l', "int", 0, 0},
		{"players", 'n', "int", 0, 0},
		{"hitter-mean",'h', "double", 0, 0},
		{"hitter-sd", 'i', "double", 0, 0},
		{"pitcher-mean", 'p', "double", 0, 0},
		{"pitcher-sd", 'r', "double", 0, 0},
		{0}
	};

	struct arguments args = {&seed, &league_id, &num_players, &HITTER_MEAN,
					&HITTER_SD, &PITCHER_MEAN, &PITCHER_SD};
	struct argp argp = {options, arg_parser, 0, 0, global_child}; 
	argp_parse(&argp, argc, argv, 0, 0, &args);

#ifdef _USEGSL_
	gsl_rng_env_setup();
	const gsl_rng_type *type = gsl_rng_default;
	rng = gsl_rng_alloc(type);
	gsl_rng_set(rng,seed);
#else
	srand(seed);
#endif
	Db_Object db = db_connect(CONFIG_FILE);
	db->begin_transaction(db->conn);
	fprintf(stderr,"Seed: %d\n",seed);

	Array_List first_names = Array_List_create(sizeof(char*));
	Array_List last_names = Array_List_create(sizeof(char*));

	select_names(db,first_names,last_names);
	int i;

	struct player new_player;
	struct hitter_skill hitter_skill;
	struct pitcher_skill pitcher_skill;
	struct fielder_skill fielder_skill;

	for(i=0;i<num_players;i++){
		
		int power= random_normal(HITTER_MEAN,HITTER_SD,MIN_SKILL,MAX_SKILL);
		int contact = random_normal(HITTER_MEAN,HITTER_SD,MIN_SKILL,MAX_SKILL);
		int fielding = random_normal(HITTER_MEAN,HITTER_SD,MIN_SKILL,MAX_SKILL);
		int speed = random_normal(HITTER_MEAN,HITTER_SD,MIN_SKILL,MAX_SKILL);
		int intelligence = random_normal(HITTER_MEAN,HITTER_SD,MIN_SKILL,MAX_SKILL);
		int control = random_normal(PITCHER_MEAN,PITCHER_SD,MIN_SKILL,MAX_SKILL);
		int movement = random_normal(PITCHER_MEAN,PITCHER_SD,MIN_SKILL,MAX_SKILL);
		int velocity = random_normal(PITCHER_MEAN,PITCHER_SD,MIN_SKILL,MAX_SKILL);
		int endurance = 0;
		int bats = (rand()%100)+1;
		int throws = (rand()%100)+1;
		int position = rand()%18;

/*TODO: Make the choosing of names random.*/
		int first_name = 8 * (power + contact + fielding + speed + bats) % first_names->length;
		int last_name = 8 * (first_name + speed + intelligence + control + movement + velocity + bats + throws + control + movement + position) % last_names->length;
		
		if(throws <= PERCENT_THROW_RIGHT){
			new_player.throws = RIGHT;
		}
		else{
			new_player.throws = LEFT;
		}
		
		if(bats<= PERCENT_HIT_SAME){
			new_player.bats = new_player.throws;
		}
		else if(bats<PERCENT_HIT_SAME+PERCENT_HIT_DIFFERENT){
			if(new_player.throws == RIGHT){
				new_player.bats = LEFT;
			}
			else{
				new_player.bats = RIGHT;
			}
		}
		else{
			new_player.bats = SWITCH;
		}
		if(position <= 9 && position > 1){
			new_player. position = position;
			pitcher_skill.end = random_normal(30.0,PITCHER_SD*SD_TWEAK,0,49);
		}
		else if(position>=15 || position == 1){
			new_player.position =1;
			pitcher_skill.end = random_normal(80.0,PITCHER_SD*SD_TWEAK,50,100);
		}
		else{
			new_player.position = 0;
			pitcher_skill.end = random_normal(30.0,PITCHER_SD*SD_TWEAK,0,49);
		}
		int vs_right_mod = 5;
		int vs_left_mod = 5;
		if(new_player.bats == RIGHT){
			vs_right_mod = -5;
		}
		if(new_player.bats ==LEFT){
			vs_left_mod = -5;
		}
		
		new_player.first_name = gget(first_names,first_name);
		new_player.last_name = gget(last_names,last_name);
		
		hitter_skill.cvr = calc_skill(contact+vs_right_mod,HITTER_SD);
		hitter_skill.pvr = calc_skill(power+vs_right_mod,HITTER_SD);
		hitter_skill.cvl = calc_skill(contact+vs_left_mod,HITTER_SD);
		hitter_skill.pvl = calc_skill(power+vs_left_mod,HITTER_SD);
		hitter_skill.spd = speed;	
		
		fielder_skill.range = calc_skill(fielding,HITTER_SD);
		fielder_skill.arm = calc_skill(fielding,HITTER_SD);
		fielder_skill.field = calc_skill(fielding,HITTER_SD);
		
		new_player.intelligence = intelligence;
		
		pitcher_skill.mov = calc_skill(movement,PITCHER_SD);
		pitcher_skill.vel = calc_skill(velocity,PITCHER_SD);
		pitcher_skill.ctrl = calc_skill(control,PITCHER_SD);
		
		insert_player(db,&new_player,&hitter_skill,&pitcher_skill,&fielder_skill,league_id);
		
	}
	db->commit(db->conn);
	db->close_connection(db->conn);	
#ifdef _USEGSL_
	gsl_rng_free(rng);
#endif

	return 0;	
}
Ejemplo n.º 12
0
static int calc_skill(int mean,double sd)
{
	return random_normal(mean*1.0,sd*SD_TWEAK,MIN_SKILL,MAX_SKILL);
}
Ejemplo n.º 13
0
int main()
{
int i , j , k , rni ,error, current , previous , cs , current1 , previous1 , cs1 ;
float tmp,tmp1,rn,V[p],Vspike[p],In[p],rate[p],RT[q] ;
float rn1,V1[p],V1spike[p],In1[p],rate1[p],RT1[q] ;
FILE *frt ;
frt = fopen("Reactiontimeusher.txt","w"); 
FILE *frt1 ;
frt1 = fopen("StopReactiontimeusher.txt","w"); 
FILE *ferror ;
ferror = fopen("Probabilityusher.txt","w"); 
float sum_i,sum1_i,errper ;
double rands[1000];
double rands1[1000];

for(k=1;k<=s;k++) {

   error = 0 ; 
	
    for (i=1; i<=q; i++){
	  rands[i] = 80.0 + 25.0*random_normal();
  }	
  	  
    for (i=1;i<=k;i++){
	rands1[i] = 0;
  }		
    for (;i<=q;i++){
	rands1[i] = 100.0 + 25.0*random_normal();
  }
	
for(j=1;j<=q;j++){

		
		for(i=1;i<=p;i++)
		{
			In[i] = 0 ; 
			In[i] = rands[j] ;
			V[i] = 0 ; 
			Vspike[i] = 0 ; 
		}
		
		for(i=1;i<=p;i++)
		{
			In1[i] = 0 ; 
			In1[i] = rands1[j] ;
			V1[i] = 0 ; 
			V1spike[i] = 0 ; 
		}


sum_i = 0 ; 
current = 0 ; 
previous = 0  ; 
cs=0 ;   

sum1_i = 0 ; 
current1 = 0 ; 
previous1 = 0  ; 
cs1=0 ;   

V[1] = 0 ;
V1[1] = 0 ;

for(i=2;i<=p;i++)
	{
		sum_i = sum_i + (i*In[i])/p ;
		V[i] = V[i-1] + sum_i*dt/(C) -0.8*V1[i-1];
			
		sum1_i = sum1_i + (i*In1[i])/p ;
		V1[i] = V1[i-1] + sum1_i*dt/(C) - 0.1*V[i-1];

			if(V[i] > 10)
				{
					V[i] = 0 ; 
					Vspike[i] = 100 ; 
					
				}
			if(V1[i] > 10)
				{
					V1[i] = 0 ; 
					V1spike[i] = 100 ; 
					
				}
	
}
	

	
	
		cs = 0 ;
		for(i=2;i<=p;i++)
		{
			if (Vspike[i] == 100  ) 
			{
					cs++ ; 
					if(cs>1) {
					current = i ; 
					tmp = current - previous ; 
					rate[i] = 1.0 / tmp;
					previous = i ;
					}
					
			}
			else {rate[i] = rate[i-1];}
		}
		
		cs1 = 0 ;
		for(i=2;i<=p;i++)
		{
			if (V1spike[i] == 100  ) 
			{
					cs1++ ; 
					if(cs1>1) {
					current1 = i ; 
					tmp1 = current1 - previous1; 
					rate1[i] = 1.0 / tmp1;
					previous1 = i ;
					}
					
			}
			else {rate1[i] = rate1[i-1];}
		}
/*		
for(i=2;i<=p;i++){
	if(rate[i] > 0.05){ fprintf(frt,"%d\t %f \t %d \n" , j , In[5] ,  i ) ; RT[j] = i; break; }		
	}
*/
for(i=2;i<=p;i++){
	if(rate1[i] > 0.05){ fprintf(frt1,"%d\t %f \t %d \t %f \n" , j , In1[5] ,  i , rate1[i] ) ; RT1[j] = i; break; }		
	}

if( (rate[r]>rate1[r]) && (rate[r]>0.05) ) { error++ ;
			 fprintf(frt,"%f \t %f \t %d \n",rate[r],rate1[r],error) ;  }
/*if( (rate1[r]>rate[r]) && (rate1[r]>0.05) ) {
			 fprintf(frt1,"%f \t %f \t %d \n",rate[r],rate1[r],error) ;  }
*/
}
errper = (float)error / q ; 
fprintf(ferror," %f \t %d \n " , errper , k ) ; 
}

}
Ejemplo n.º 14
0
Archivo: genhtml.c Proyecto: ICGog/Dron
//return the length in bytes of a document, where length is
// sampled from a normal distribution with mean len_u and
// variance len_var
int doc_len() {
  return (int)((double)len_u + random_normal() * len_var);
}