下面列出了java.lang.Math#log ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Object log(Object param) throws ParseException
{
if (param instanceof Complex) {
return ((Complex)param).log().div(CLOG10);
}
else if (param instanceof Number)
{
double num = ((Number) param).doubleValue();
if( num >= 0)
return new Double(Math.log(num)/LOG10);
else if(num != num)
return new Double(Double.NaN);
else
{
Complex temp = new Complex(num);
return temp.log().div(CLOG10);
}
}
throw new ParseException("Invalid parameter type");
}
/** Inicialization of the population */
public void Initialize () {
int i, j;
last = (int) ((prob_cruce * long_poblacion) - 0.5);
Trials = 0;
if (prob_mutacion < 1.0) {
Mu_next = (int) (Math.log(Randomize.Rand()) / Math.log(1.0 - prob_mutacion));
Mu_next++;
}
else Mu_next = 1;
for (j=0; j<n_genes; j++) New[0].Gene[j] = '1';
New[0].n_e = 1;
for (i=1; i < long_poblacion; i++) {
for (j=0; j<n_genes; j++)
if (Randomize.RandintClosed(0,1) == 0) New[i].Gene[j] = '0';
else New[i].Gene[j] = '1';
New[i].n_e = 1;
}
}
public Object ln(Object param)
throws ParseException
{
if (param instanceof Complex)
{
return ((Complex)param).log();
}
else if (param instanceof Number)
{
// Now returns Complex if param is <0
double num = ((Number) param).doubleValue();
if( num >= 0)
return new Double(Math.log(num));
else if(num != num)
return new Double(Double.NaN);
else
{
Complex temp = new Complex(num);
return temp.log();
}
}
throw new ParseException("Invalid parameter type");
}
void Mutacion_Uniforme() {
int posiciones, i, j;
double m;
posiciones = n_genes * long_poblacion;
if (prob_mutacion > 0) {
while (Mu_next < posiciones) {
/* we determinate the chromosome and the GeneSel */
i = Mu_next / n_genes;
j = Mu_next % n_genes;
/* we mutate the GeneSel */
if (New[i].GeneSel[j] == '0') {
New[i].GeneSel[j] = '1';
}
else {
New[i].GeneSel[j] = '0';
}
New[i].n_e = 1;
/* we calculate the next position */
if (prob_mutacion < 1) {
m = Randomize.Rand();
Mu_next += (int) (Math.log(m) / Math.log(1.0 - prob_mutacion)) + 1;
}
else {
Mu_next += 1;
}
}
}
Mu_next -= posiciones;
}
/**
* Returns the log-odds for a given probabilitiy.
*
* @param prob the probabilitiy
*
* @return the log-odds after the probability has been mapped to
* [Utils.SMALL, 1-Utils.SMALL]
*/
public static /*@[email protected]*/ double probToLogOdds(double prob) {
if (gr(prob, 1) || (sm(prob, 0))) {
throw new IllegalArgumentException("probToLogOdds: probability must " +
"be in [0,1] "+prob);
}
double p = SMALL + (1.0 - 2 * SMALL) * prob;
return Math.log(p / (1 - p));
}
/**
* Returns the log-odds for a given probabilitiy.
*
* @param prob the probabilitiy
*
* @return the log-odds after the probability has been mapped to
* [Utils.SMALL, 1-Utils.SMALL]
*/
public static /*@[email protected]*/ double probToLogOdds(double prob) {
if (gr(prob, 1) || (sm(prob, 0))) {
throw new IllegalArgumentException("probToLogOdds: probability must " +
"be in [0,1] "+prob);
}
double p = SMALL + (1.0 - 2 * SMALL) * prob;
return Math.log(p / (1 - p));
}
void Mutacion_Uniforme () {
int posiciones, i, j;
double m;
posiciones = n_genes * long_poblacion;
if (prob_mutacion>0) {
while (Mu_next<posiciones) {
/* we determinate the chromosome and the gene */
i = Mu_next / n_genes;
j = Mu_next % n_genes;
/* we mutate the gene */
if (New[i].Gene[j]=='0') New[i].Gene[j]='1';
else New[i].Gene[j]='0';
New[i].n_e=1;
/* we calculate the next position */
if (prob_mutacion<1) {
m = Randomize.Rand();
Mu_next += (int) (Math.log(m) / Math.log(1.0 - prob_mutacion)) + 1;
}
else Mu_next += 1;
}
}
Mu_next -= posiciones;
}
/** Mutation Non Uniform */
public void Mutacion_No_Uniforme (long Gen, long n_generaciones) {
int posiciones, i, j;
double nval, m;
posiciones = n_genes * long_poblacion;
if (prob_mutacion>0) {
while (Mu_next<posiciones) {
/* we determinate the chromosome and the gene */
i = Mu_next / n_genes;
j = Mu_next % n_genes;
/* we mutate the gene */
if (Randomize.Rand()<0.5)
nval = New[i].Gene[j] + delta (Gen, intervalos[j].max-New[i].Gene[j], n_generaciones);
else
nval=New[i].Gene[j] - delta (Gen, New[i].Gene[j]-intervalos[j].min, n_generaciones);
New[i].Gene[j]=nval;
New[i].n_e = 1;
/* we calculate the next position */
if (prob_mutacion<1) {
m = Randomize.Rand();
Mu_next+= (int) (Math.log(m)/Math.log(1.0-prob_mutacion));
Mu_next++;
}
else Mu_next+=1;
}
Mu_next -= posiciones;
}
}
/** Mutation Non Uniform */
public void Mutacion_No_Uniforme (long Gen, long n_generaciones) {
int posiciones, i, j;
double nval, m;
posiciones = n_genes * long_poblacion;
if (prob_mutacion>0) {
while (Mu_next<posiciones) {
/* we determinate the chromosome and the gene */
i = Mu_next / n_genes;
j = Mu_next % n_genes;
/* we mutate the gene */
if (Randomize.Rand()<0.5)
nval = New[i].Gene[j] + delta (Gen, intervalos[j].max-New[i].Gene[j], n_generaciones);
else
nval=New[i].Gene[j] - delta (Gen, New[i].Gene[j]-intervalos[j].min, n_generaciones);
New[i].Gene[j]=nval;
New[i].n_e = 1;
/* we calculate the next position */
if (prob_mutacion<1) {
m = Randomize.Rand();
Mu_next+= (int) (Math.log(m)/Math.log(1.0-prob_mutacion));
Mu_next++;
}
else Mu_next+=1;
}
Mu_next -= posiciones;
}
}
/** Inicialization of the population */
public void Initialize() {
int i, j;
last = (int) ( (prob_cruce * long_poblacion) - 0.5);
Trials = 0;
if (prob_mutacion < 1.0) {
Mu_next = (int) (Math.log(Randomize.Rand()) /
Math.log(1.0 - prob_mutacion));
Mu_next++;
}
else {
Mu_next = 1;
}
for (j = 0; j < n_genes; j++) {
New[0].GeneSel[j] = '1';
}
New[0].n_e = 1;
for (i = 1; i < long_poblacion; i++) {
for (j = 0; j < n_genes; j++) {
if (Randomize.RandintClosed(0, 1) == 0) {
New[i].GeneSel[j] = '0';
}
else {
New[i].GeneSel[j] = '1';
}
}
New[i].n_e = 1;
}
}
/** Inicialization of the population */
public void Initialize() {
int i, j;
last = (int) ( (prob_cruce * long_poblacion) - 0.5);
Trials = 0;
if (prob_mutacion < 1.0) {
Mu_next = (int) (Math.log(Randomize.Rand()) /
Math.log(1.0 - prob_mutacion));
Mu_next++;
}
else {
Mu_next = 1;
}
for (j = 0; j < n_genes; j++) {
New[0].GeneSel[j] = '1';
}
New[0].n_e = 1;
for (i = 1; i < long_poblacion; i++) {
for (j = 0; j < n_genes; j++) {
if (Randomize.RandintClosed(0, 1) == 0) {
New[i].GeneSel[j] = '0';
}
else {
New[i].GeneSel[j] = '1';
}
}
New[i].n_e = 1;
}
}
public static double atanh(double x) throws ArithmeticException {
if ((x > 1.0) || (x < -1.0)) {
throw new ArithmeticException("range exception");
}
return 0.5 * Math.log((1.0 + x) / (1.0 - x));
}
/** Mutation Non Uniform */
public void Mutacion_No_Uniforme(long Gen, long n_generaciones) {
int posiciones, i, j;
double nval, m;
posiciones = n_genes * long_poblacion;
if (prob_mutacion > 0) {
while (Mu_next < posiciones) {
/* we determinate the chromosome and the gene */
i = Mu_next / n_genes;
j = Mu_next % n_genes;
/* we mutate the gene */
if (Randomize.Rand() < 0.5) {
nval = New[i].Gene[j] +
delta(Gen, intervalos[j].max - New[i].Gene[j], n_generaciones);
}
else {
nval = New[i].Gene[j] -
delta(Gen, New[i].Gene[j] - intervalos[j].min, n_generaciones);
}
New[i].Gene[j] = nval;
New[i].n_e = 1;
/* we calculate the next position */
if (prob_mutacion < 1) {
m = Randomize.Rand();
Mu_next += (int) (Math.log(m) / Math.log(1.0 - prob_mutacion));
Mu_next++;
}
else {
Mu_next += 1;
}
}
Mu_next -= posiciones;
}
}
/** Uniform Non Mutation */
public void Mutacion_Thrift_No_Uniforme(long Gen, long n_generaciones,
BaseD base_datos) {
int posiciones, i, j, variable, etiqueta, punto;
double nval, m;
posiciones = n_genes * long_poblacion;
if (prob_mutacion > 0) {
while (Mu_next < posiciones) {
/* we determinate the chromosome and the gene */
i = Mu_next / n_genes;
j = Mu_next % n_genes;
m = Randomize.Rand();
/* the gene is of C1 */
if (j < base_datos.n_variables) {
/* if I'm in the fisrt label */
if ( (m < 0.5 &&
(New[i].Gene[j] != (double) base_datos.n_etiquetas[j] - 1)) ||
New[i].Gene[j] == 0.0) {
nval = New[i].Gene[j] + 1.0;
}
else {
nval = New[i].Gene[j] - 1.0;
}
/* we update the membership function */
variable = j;
etiqueta = (int) nval;
New[i].Gene[base_datos.n_variables +
3 * variable] = base_datos.BaseDatos[variable][etiqueta].x0;
New[i].Gene[base_datos.n_variables + 3 * variable +
1] = base_datos.BaseDatos[variable][etiqueta].x1;
New[i].Gene[base_datos.n_variables + 3 * variable +
2] = base_datos.BaseDatos[variable][etiqueta].x3;
}
/* else the gene is of C2 */
else {
/* we calculate the variable and label of the gene */
variable = (int) (j - base_datos.n_variables) / 3;
etiqueta = (int) New[i].Gene[variable];
punto = (j - base_datos.n_variables) % 3;
/* we mutate the gene */
if (m < 0.5) {
nval = New[i].Gene[j] +
delta(Gen,
base_datos.intervalos[variable][etiqueta][punto].max -
New[i].Gene[j], n_generaciones);
}
else {
nval = New[i].Gene[j] -
delta(Gen,
New[i].Gene[j] -
base_datos.intervalos[variable][etiqueta][punto].min,
n_generaciones);
}
}
New[i].Gene[j] = nval;
New[i].n_e = 1;
/* we calculate the next position */
if (prob_mutacion < 1) {
m = Randomize.Rand();
Mu_next += (int) (Math.log(m) / Math.log(1.0 - prob_mutacion));
Mu_next++;
}
else {
Mu_next += 1;
}
}
Mu_next -= posiciones;
}
}
/**
* Calculate hyperbolic Tangent of value (from https://github.com/maths/dragmath/blob/master/lib/jep/src/org/nfunk/jep/function/ArcTanH.java)
*
* @param x Value to calculate atanh for
*/
private static double atanh(double x){
return Math.log((1+x)/(1-x))/2;
}
/**
* Returns the logarithm of a for base 2.
*
* @param a a double
* @return the log2 of a.
*/
public static double log2(double a) {
return Math.log(a) / log2;
}
/**
* Returns the logarithm of a for base 2.
*
* @param a a double
* @return the logarithm for base 2
*/
public static /*@[email protected]*/ double log2(double a) {
return Math.log(a) / log2;
}
/**
* Returns the logarithm of a for base 2.
*
* @param a a double
* @return the logarithm for base 2
*/
public static /*@[email protected]*/ double log2(double a) {
return Math.log(a) / log2;
}
public static MR_double log ( MR_double n ) { return new MR_double(Math.log(n.get())); }
public static MR_float log ( MR_float n ) { return new MR_float(Math.log(n.get())); }