⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cauchyrandomgenerator.java

📁 用java语言写的遗传算法库
💻 JAVA
字号:
/*
 * This file is part of JGAP.
 *
 * JGAP offers a dual license model containing the LGPL as well as the MPL.
 *
 * For licencing information please see the file license.txt included with JGAP
 * or have a look at the top of class org.jgap.Chromosome which representatively
 * includes the JGAP license policy applicable for any file delivered with JGAP.
 */
package org.jgap.impl;

import java.util.*;

import org.jgap.*;

/**
 * Cauchy probability density function (cumulative distribution function)
 *
 * @author Klaus Meffert
 * @since 1.1
 */
public class CauchyRandomGenerator
    implements RandomGenerator {
  /** String containing the CVS revision. Read out via reflection!*/
  private final static String CVS_REVISION = "$Revision: 1.8 $";

  //delta for distinguishing whether a value is to be interpreted as zero
  private static final double DELTA = 0.000001;

  private double m_scale;

  private double m_location;

  private Random rn;

  /**
   * @author Klaus Meffert
   * @since 1.1
   */
  public CauchyRandomGenerator() {
    this(0.0d, 1.0d);
  }

  /**
   * @param a_location double
   * @param a_scale double
   *
   * @author Klaus Meffert
   * @since 1.1
   */
  public CauchyRandomGenerator(double a_location, double a_scale) {
    m_location = a_location;
    m_scale = a_scale;
    rn = new Random();
  }

  public int nextInt() {
    return Math.min(Integer.MAX_VALUE - 1,
                    (int) Math.round(nextCauchy() * Integer.MAX_VALUE));
  }

  public int nextInt(int ceiling) {
    return Math.min(ceiling - 1,
                    (int) Math.round(nextCauchy() * ceiling));
  }

  public long nextLong() {
    return Math.min(Long.MAX_VALUE - 1,
                    Math.round(nextCauchy() * Long.MAX_VALUE));
  }

  public double nextDouble() {
    return nextCauchy();
  }

  public float nextFloat() {
    return Math.min(Float.MAX_VALUE - 1,
                    (float) (nextCauchy() * Float.MAX_VALUE));
  }

  public boolean nextBoolean() {
    return nextCauchy() >= 0.5d;
  }

  /**
   * Calculate Cumulative Cauchy distribution function.
   * @return the probability that a stochastic variable x is less than X
   *
   * @author Klaus Meffert
   * @since 1.1
   */
  public double nextCauchy() {
    return 0.5 + Math.atan( (rn.nextDouble() - m_location) / m_scale) / Math.PI;
  }

  /**
   * @return double
   *
   * @author Klaus Meffert
   * @since 1.1
   */
  public double getCauchyStandardDeviation() {
    return m_scale;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -