java.lang.Math#atan ( )源码实例Demo

下面列出了java.lang.Math#atan ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Llunatic   文件: ArcTangent.java
public Object atan(Object param)
	throws ParseException
{
	if (param instanceof Complex)
	{
		return ((Complex)param).atan();
	}
	else if (param instanceof Number)
	{
		return new Double(Math.atan(((Number)param).doubleValue()));
	}

	throw new ParseException("Invalid parameter type");
}
 
源代码2 项目: GiantTrees   文件: Vector.java
/**
 * Returns the angle of a 2-dimensional vector (u,v) with the u-axis 
 *
 * @param v v-coordinate of the vector
 * @param u u-coordinate of the vector
 * @return a value from (-180..180)
 */
static public double atan2(double v, double u)  {
	if (u==0) {
		if (v>=0) return 90;
		else return -90;
	} 
	if (u>0)  return Math.atan(v/u)*180/Math.PI;
	if (v>=0) return 180 + Math.atan(v/u)*180/Math.PI;
	return Math.atan(v/u)*180/Math.PI-180;
}
 
源代码3 项目: KEEL   文件: AG.java
/** Inicialization of the population */
public void Initialize () {
	int i, j, temp, mitad_Pob;
	double Valor_Inicial_Sigma = 0.001;

	if (prob_mutacion < 1.0)
		Mu_next = ceil (Math.log(Randomize.Rand()) / Math.log(1.0 - prob_mutacion));
	else  Mu_next = 1;

	Trials=0;

	/* Los conjuntos difusos de los antecedentes de las reglas constituyen la
	primera parte del primer cromosoma de la poblacion inicial.
	Se inicializa C1 en el primer cromosoma. */
	New[0].n_e = 1;
	primer_gen_C2 = 0;

	for (i=0; i<base_reglas.n_reglas; i++) {
		for (j=0; j<base_reglas.tabla.n_var_estado; j++) {
			New[0].Gene[primer_gen_C2] = base_reglas.BaseReglas[i].Ant[j].x0;
			New[0].Gene[primer_gen_C2+1] = base_reglas.BaseReglas[i].Ant[j].x1;
			New[0].Gene[primer_gen_C2+2] = base_reglas.BaseReglas[i].Ant[j].x3;
			primer_gen_C2 += 3;
		}
	}

	/* Se establecen los intervalos en los que varia cada gen de la primera
	parte en la primera generacion */
	for (i=0; i<primer_gen_C2; i+=3) {
		intervalos[i].min = New[0].Gene[i] - (New[0].Gene[i+1]-New[0].Gene[i])/2.0;
		intervalos[i].max = New[0].Gene[i] + (New[0].Gene[i+1]-New[0].Gene[i])/2.0;

		intervalos[i+1].min = New[0].Gene[i+1] - (New[0].Gene[i+1]-New[0].Gene[i])/2.0;
		intervalos[i+1].max = New[0].Gene[i+1] + (New[0].Gene[i+2]-New[0].Gene[i+1])/2.0;

		intervalos[i+2].min = New[0].Gene[i+2] - (New[0].Gene[i+2]-New[0].Gene[i+1])/2.0;
		intervalos[i+2].max = New[0].Gene[i+2] + (New[0].Gene[i+2]-New[0].Gene[i+1])/2.0;
	}


	/* Se inicializa la segunda parte del primer cromosoma con los parametros
	de los consecuentes de las reglas de la BC inicial, junto con los inter-
	valos correspondientes */
	for (i=0; i<base_reglas.n_reglas; i++) {
		for (j=0; j<base_reglas.tabla.n_variables; j++) {
			temp = primer_gen_C2 + i * (base_reglas.tabla.n_variables) + j;
			New[0].Gene[temp] = Math.atan (base_reglas.BaseReglas[i].Cons[j]);
			intervalos[temp].min = -(Math.PI/2) + 1E-10;
			intervalos[temp].max = (Math.PI/2) - 1E-10;
		}
	}

	/* Se genera la segunda mitad de la poblacion inicial generando aleatoriamen-
	te C1 y manteniendo C2 */
	mitad_Pob = ceil(long_poblacion/2);
	for (i=1; i<mitad_Pob; i++) {
		for (j=0; j<primer_gen_C2; j++)
			New[i].Gene[j] = Randomize.Randdouble(intervalos[j].min, intervalos[j].max);

		for (j=primer_gen_C2; j<n_genes; j++)
			New[i].Gene[j] = New[0].Gene[j];

		New[i].n_e = 1;
	}


	/* Se genera el resto de la poblacion inicial generando aleatoriamente C1
	a partir de los intervalos anteriores y mutando C2 */
	for (i=mitad_Pob; i<long_poblacion; i++) {
		for (j=0; j<primer_gen_C2; j++)
			New[i].Gene[j] = Randomize.Randdouble(intervalos[j].min,intervalos[j].max);

		for (j=primer_gen_C2; j<n_genes; j++)
		/* Comprobamos que no se salgan del intervalo permitido [-PI/2,PI/2] */
			do
				New[i].Gene[j] = New[0].Gene[j] + ValorNormal (Valor_Inicial_Sigma);
			while (New[i].Gene[j]<=-(Math.PI/2) || New[i].Gene[j]>=(Math.PI/2));

		New[i].n_e=1;
	}
}
 
源代码4 项目: KEEL   文件: Est_evol.java
/** Generates the initial population of fathers */
public void InicializaPadres () {
	int i, j, y, Mu_primer_grupo, pos_ep, total_mayor;
	double y_med, y_min, y_max, h_max, h_exigido, x;
	double imagen;

	/* we calculate the average, maximum and minimum high, and the matching with which a example is considerated in the initial population */
	y_med = y_min = y_max = tabla.datos[indices_ep[0]].ejemplo[tabla.n_var_estado];
	h_max = tabla.datos[indices_ep[0]].nivel_cubrimiento;

	for (i=1; i<fun_adap.n_ejemplos_positivos; i++) {
		if (tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado] > y_max)
			y_max = tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado] < y_min)
			y_min = tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado];
		
		y_med += tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[indices_ep[i]].nivel_cubrimiento > h_max)
			h_max = tabla.datos[indices_ep[i]].nivel_cubrimiento;
	}

	y_med /= fun_adap.n_ejemplos_positivos;
	h_exigido = porcentaje_h * h_max;

	/* Inicialization of a individual with 'b' value same as the average high and with the 'a' values to 0 */
	for (j=0; j<tabla.n_var_estado; j++)  Padres[0].Gene[j] = 0;
	Padres[0].Gene[tabla.n_var_estado] = Math.atan(y_med);

	/* Inicialization of the porcentaje_Mu * Mu individuals with 'b' value equal to a random value in the rank [y_min,y_max] and with the 'a' values to 0 */
	Mu_primer_grupo = (int) (porcentaje_Mu * Mu + 1);
	for (i=1; i<Mu_primer_grupo; i++) {
		for (j=0; j<tabla.n_var_estado; j++)  Padres[i].Gene[j] = 0;
		Padres[i].Gene[tabla.n_var_estado] = Math.atan(Randomize.Randdouble (y_min,y_max));
	}

	/* Inicialization of the remaining individuals with the random 'a' values and with a the 'b' value for any to example is in the plane */
	for (i=Mu_primer_grupo; i<Mu; i++) {
		for (j=0; j<tabla.n_var_estado; j++) {
			if (Randomize.Rand ()<.5)  y = -1;
			else  y=1;

			x = Randomize.Rand ();
			Padres[i].Gene[j] = f(x,y);
		}
		
		/* we select randomly a example with a matching more high than "h_exigido" */
		for (total_mayor=pos_ep=0; pos_ep<fun_adap.n_ejemplos_positivos; pos_ep++)
			if (tabla.datos[indices_ep[pos_ep]].nivel_cubrimiento >= h_exigido)
				ind_mayor[total_mayor++] = pos_ep;
		
		if (total_mayor==0) {
			System.out.println("Error: The matching, with which a example is considerated in the initial population, isn't surmounted");
		}
		
		pos_ep = ind_mayor[Randomize.RandintClosed (0,total_mayor-1)];
		for (imagen=0.0,j=0; j<tabla.n_var_estado; j++)
			imagen += Math.tan (Padres[i].Gene[j]) * tabla.datos[indices_ep[pos_ep]].ejemplo[j];
		
		Padres[i].Gene[tabla.n_var_estado] = Math.atan(tabla.datos[indices_ep[pos_ep]].ejemplo[tabla.n_var_estado]-imagen);
	}


	/* Inicialization of the vector of tipical desviations */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables; j<tabla.n_variables+n_sigma; j++)  Padres[i].Gene[j] = Valor_Inicial_Sigma;

	/* Inicialization of the vector of angles: arcotangente of 1.0 */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables + n_sigma; j<tabla.n_variables+n_sigma+n_alfa; j++)  
			Padres[i].Gene[j] = Math.atan (1.0);
}
 
源代码5 项目: KEEL   文件: Est_evol_M2TSK.java
/** Generates the initial population of fathers */
public void InicializaPadres () {
	int i, j, y, Mu_primer_grupo, pos_ep, total_mayor;
	double y_med, y_min, y_max, h_max, h_exigido, x;
	double imagen;

	/* we calculate the average, maximum and minimum high, and the matching with which a example is considerated in the initial population */
	y_med = y_min = y_max = tabla.datos[fun_adap.indices_ep[0]].ejemplo[tabla.n_var_estado];
	h_max = tabla.datos[fun_adap.indices_ep[0]].nivel_cubrimiento;


	for (i=1; i<fun_adap.n_ejemplos_positivos; i++) {
		if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] > y_max)  y_max = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] < y_min)  y_min = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];

		y_med += tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento > h_max)  h_max = tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento;
	    
	}

	y_med /= fun_adap.n_ejemplos_positivos;
	h_exigido = porcentaje_h * h_max;



	/* Inicialization of a individual with 'b' value same as the average high and with the 'a' values to 0 */
	for (j=0; j<tabla.n_var_estado; j++)  Padres[0].Gene[j] = 0;
	Padres[0].Gene[tabla.n_var_estado] = Math.atan(y_med);

	/* Inicialization of the porcentaje_Mu * Mu individuals with 'b' value equal to a random value in the rank [y_min,y_max] and with the 'a' values to 0 */
	Mu_primer_grupo = (int) (porcentaje_Mu * Mu + 1);
	for (i=1; i<=Mu_primer_grupo; i++) {
		for (j=0; j<tabla.n_var_estado; j++)  Padres[i].Gene[j] = 0;
		Padres[i].Gene[tabla.n_var_estado] = Math.atan(Randomize.Randdouble (y_min,y_max));
	}

	/* Inicialization of the remaining individuals with the random 'a' values and with a the 'b' value for any to example is in the plane */
	for (i=Mu_primer_grupo+1; i<Mu; i++) {
		for (j=0; j<tabla.n_var_estado; j++) {
			if (Randomize.Rand () < 0.5)  y = -1;
			else  y=1;

			x = Randomize.Rand ();
			Padres[i].Gene[j] = f(x,y);
		}

		/* we select randomly a example with a matching more high than "h_exigido" */
		for (total_mayor=pos_ep=0; pos_ep<fun_adap.n_ejemplos_positivos; pos_ep++)
			if (tabla.datos[fun_adap.indices_ep[pos_ep]].nivel_cubrimiento >= h_exigido)  ind_mayor[total_mayor++] = pos_ep;

		if (total_mayor==0) {
			System.out.println("Error: The matching, with which a example is considerated in the initial population, isn't surmounted");
		}

		pos_ep = ind_mayor[Randomize.RandintClosed (0,total_mayor-1)];
		for (imagen=0.0,j=0; j<tabla.n_var_estado; j++)
			imagen += Math.tan (Padres[i].Gene[j]) * tabla.datos[fun_adap.indices_ep[pos_ep]].ejemplo[j];

		Padres[i].Gene[tabla.n_var_estado] = Math.atan(tabla.datos[fun_adap.indices_ep[pos_ep]].ejemplo[tabla.n_var_estado]-imagen);
	}


	/* Inicialization of the vector of tipical desviations */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables; j<tabla.n_variables+n_sigma; j++)  Padres[i].Gene[j] = Valor_Inicial_Sigma;

	/* Inicialization of the vector of angles: arcotangente of 1.0 */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables + n_sigma; j<tabla.n_variables+n_sigma+n_alfa; j++)
			Padres[i].Gene[j] = Math.atan (1.0);
}
 
源代码6 项目: KEEL   文件: AG_Tun.java
/** Inicialization of the population */
public void Initialize() {
  int i, j, temp, mitad_Pob;
  double Valor_Inicial_Sigma = 0.001;


  if (prob_mutacion < 1.0) {
    Mu_next = (int) Math.ceil(Math.log(Randomize.Rand()) / Math.log(1.0 - prob_mutacion));
  }
  else {
    Mu_next = 1;
  }

  Trials = 0;

  /* Los conjuntos difusos de los antecedentes de las reglas constituyen la
     primera parte del primer cromosoma de la poblacion inicial.
     Se inicializa C1 en el primer cromosoma. */
  New[0].n_e = 1;
  primer_gen_C2 = 0;

  for (i = 0; i < base_reglas.n_reglas; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      New[0].Gene[primer_gen_C2] = base_reglas.BaseReglas[i].Ant[j].x0;
      New[0].Gene[primer_gen_C2 + 1] = base_reglas.BaseReglas[i].Ant[j].x1;
      New[0].Gene[primer_gen_C2 + 2] = base_reglas.BaseReglas[i].Ant[j].x3;
      primer_gen_C2 += 3;
    }
  }

  /* Se establecen los intervalos en los que varia cada gen de la primera
     parte en la primera generacion */
  for (i = 0; i < primer_gen_C2; i += 3) {
    intervalos[i].min = New[0].Gene[i] - (New[0].Gene[i + 1] - New[0].Gene[i]) / 2.0;
    intervalos[i].max = New[0].Gene[i] + (New[0].Gene[i + 1] - New[0].Gene[i]) / 2.0;

    intervalos[i + 1].min = New[0].Gene[i + 1] - (New[0].Gene[i + 1] - New[0].Gene[i]) / 2.0;
    intervalos[i + 1].max = New[0].Gene[i + 1] + (New[0].Gene[i + 2] - New[0].Gene[i + 1]) / 2.0;

    intervalos[i + 2].min = New[0].Gene[i + 2] - (New[0].Gene[i + 2] - New[0].Gene[i + 1]) / 2.0;
    intervalos[i + 2].max = New[0].Gene[i + 2] + (New[0].Gene[i + 2] - New[0].Gene[i + 1]) / 2.0;
  }

  /* Se inicializa la segunda parte del primer cromosoma con los parametros
     de los consecuentes de las reglas de la BC inicial, junto con los inter-
     valos correspondientes */
  for (i = 0; i < base_reglas.n_reglas; i++) {
    for (j = 0; j < tabla.n_variables; j++) {
      temp = primer_gen_C2 + i * (tabla.n_variables) + j;
      New[0].Gene[temp] = Math.atan(base_reglas.BaseReglas[i].Cons[j]);
      intervalos[temp].min = (-1.0 * PI / 2.0) + 1E-10;
      intervalos[temp].max = (PI / 2.0) - 1E-10;
    }
  }

  /* Se genera la segunda mitad de la poblacion inicial generando aleatoriamen-
     te C1 y manteniendo C2 */
  mitad_Pob = (int) Math.ceil(long_poblacion / 2.0);
  for (i = 1; i < mitad_Pob; i++) {
    for (j = 0; j < primer_gen_C2; j++) {
      New[i].Gene[j] = intervalos[j].min + Randomize.Randdouble(intervalos[j].min, intervalos[j].max);
    }

    for (j = primer_gen_C2; j < n_genes; j++) {
      New[i].Gene[j] = New[0].Gene[j];
    }

    New[i].n_e = 1;
  }

  /* Se genera el resto de la poblacion inicial generando aleatoriamente C1
     a partir de los intervalos anteriores y mutando C2 */
  for (i = mitad_Pob; i < long_poblacion; i++) {
    for (j = 0; j < primer_gen_C2; j++) {
      New[i].Gene[j] = intervalos[j].min + Randomize.Randdouble(intervalos[j].min, intervalos[j].max);
    }

    for (j = primer_gen_C2; j < n_genes; j++) {
      /* Comprobamos que no se salgan del intervalo permitido [-PI/2,PI/2] */
      do {
        New[i].Gene[j] = New[0].Gene[j] + ValorNormal(Valor_Inicial_Sigma);
      }
      while (New[i].Gene[j] <= (-1.0 * PI / 2.0) || New[i].Gene[j] >= (PI / 2.0));
    }

    New[i].n_e = 1;
  }
}
 
源代码7 项目: KEEL   文件: Est_mu_landa.java
/** Generates the initial population of fathers */
public void InicializaPadres() {
  int i, j, y, Mu_primer_grupo, pos_ep, total_mayor;
  double y_med, y_min, y_max, h_max, h_exigido, x;
  double imagen;

  /* we calculate the average, maximum and minimum high, and the matching with which a example is considerated in the initial population */
  y_med = y_min = y_max = tabla.datos[fun_adap.indices_ep[0]].ejemplo[tabla.
      n_var_estado];
  h_max = tabla.datos[fun_adap.indices_ep[0]].nivel_cubrimiento;

  for (i = 1; i < fun_adap.n_ejemplos_positivos; i++) {
    if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] > y_max) {
      y_max = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
    }
    if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] < y_min) {
      y_min = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
    }

    y_med += tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
    if (tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento > h_max) {
      h_max = tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento;
    }
  }

  if (fun_adap.n_ejemplos_positivos > 0) {
    y_med /= fun_adap.n_ejemplos_positivos;
  }
  else {
    y_med = Double.MAX_VALUE;
  }
  h_exigido = porcentaje_h * h_max;

  /* Inicialization of a individual with 'b' value same as the average high and with the 'a' values to 0 */
  for (j = 0; j < tabla.n_var_estado; j++) {
    Padres[0].Gene[j] = 0;
  }
  Padres[0].Gene[tabla.n_var_estado] = Math.atan(y_med);

  /* Inicialization of the porcentaje_Mu * Mu individuals with 'b' value equal to a random value in the rank [y_min,y_max] and with the 'a' values to 0 */
  Mu_primer_grupo = (int) (porcentaje_Mu * Mu + 1);
  for (i = 1; i <= Mu_primer_grupo; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      Padres[i].Gene[j] = 0;
    }
    Padres[i].Gene[tabla.n_var_estado] = Math.atan(Randomize.Randdouble(y_min,
        y_max));
  }

  /* Inicialization of the remaining individuals with the random 'a' values and with a the 'b' value for any to example is in the plane */
  for (i = Mu_primer_grupo + 1; i < Mu; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      if (Randomize.Rand() < 0.5) {
        y = -1;
      }
      else {
        y = 1;
      }

      x = Randomize.Rand();
      Padres[i].Gene[j] = f(x, y);
    }

    /* we select randomly a example with a matching more high than "h_exigido" */
    for (total_mayor = pos_ep = 0; pos_ep < fun_adap.n_ejemplos_positivos;
         pos_ep++) {
      if (tabla.datos[fun_adap.indices_ep[pos_ep]].nivel_cubrimiento >= h_exigido) {
        ind_mayor[total_mayor++] = pos_ep;
      }
    }

    if (total_mayor == 0) {
      System.out.println("Error: The matching, with which a example is considerated in the initial population, isn't surmounted");
    }

    pos_ep = ind_mayor[Randomize.RandintClosed(0, total_mayor - 1)];
    for (imagen = 0.0, j = 0; j < tabla.n_var_estado; j++) {
      imagen += Math.tan(Padres[i].Gene[j]) *
          tabla.datos[fun_adap.indices_ep[pos_ep]].ejemplo[j];
    }

    Padres[i].Gene[tabla.n_var_estado] = Math.atan(tabla.datos[fun_adap.indices_ep[
        pos_ep]].ejemplo[tabla.n_var_estado] - imagen);
  }

  /* Inicialization of the vector of tipical desviations */
  for (i = 0; i < Mu; i++) {
    for (j = tabla.n_variables; j < tabla.n_variables + n_sigma; j++) {
      Padres[i].Gene[j] = Valor_Inicial_Sigma;
    }
  }

  /* Inicialization of the vector of angles: arcotangente of 1.0 */
  for (i = 0; i < Mu; i++) {
    for (j = tabla.n_variables + n_sigma;
         j < tabla.n_variables + n_sigma + n_alfa; j++) {
      Padres[i].Gene[j] = Math.atan(1.0);
    }
  }
}
 
源代码8 项目: incubator-retired-mrql   文件: SystemFunctions.java
public static MR_double atan ( MR_double x ) { return new MR_double(Math.atan(x.get())); }