<commit_before>package org.broadinstitute.hail.stats

import breeze.linalg.{DenseMatrix, DenseVector, sum}
import breeze.stats.distributions._
import org.apache.commons.math3.random.JDKRandomGenerator
import org.broadinstitute.hail.utils.info
import org.broadinstitute.hail.variant.VariantDataset
import org.apache.spark.SparkContext
import org.broadinstitute.hail.annotations.Annotation
import org.broadinstitute.hail.expr.{TArray, TDouble, TInt, TStruct}

object BaldingNicholsModel {
  // K populations, N samples, M variants
  // popDist is K-vector proportional to population distribution
  // FstOfPop is K-vector of F_st values
  def apply(K: Int, N: Int, M: Int,
    popDistOpt: Option[DenseVector[Double]] = None,
    FstOfPopOpt: Option[DenseVector[Double]] = None,
    seed: Int): BaldingNicholsModel = {

    require(K > 0)
    require(N > 0)
    require(M > 0)
    require(popDistOpt.forall(_.length == K))
    require(popDistOpt.forall(_.forall(_ >= 0d)))
    require(FstOfPopOpt.forall(_.length == K))
    require(FstOfPopOpt.forall(_.forall(f => f > 0d && f < 1d)))

    info(s"baldingnichols: generating genotypes for $K populations, $N samples, and $M variants...")

    val gen = new JDKRandomGenerator()
    gen.setSeed(seed)
    implicit val rand: RandBasis = new RandBasis(gen)

    val popDist_k = popDistOpt.getOrElse(DenseVector.fill[Double](K)(1d))
    popDist_k :/= sum(popDist_k)
    val popDistRV = Multinomial(popDist_k)
    val popOfSample_n = DenseVector.fill[Int](N)(popDistRV.draw())

    val Fst_k = FstOfPopOpt.getOrElse(DenseVector.fill[Double](K)(0.1))
    val Fst1_k = (1d - Fst_k) :/ Fst_k

    val ancestralAF = Uniform(0.1, 0.9)
    val ancestralAF_m = DenseVector.fill[Double](M)(ancestralAF.draw())

    val popAF_km = DenseMatrix.zeros[Double](K, M)
    (0 until K).foreach(k =>
      (0 until M).foreach(m =>
        popAF_km(k,m) = new Beta((1 - ancestralAF_m(m)) * Fst1_k(k), ancestralAF_m(m) * Fst1_k(k)).draw()))

    val unif = rand.uniform
<commit_msg>Fix method not found error due to relocation. (#1086)<commit_after>package org.broadinstitute.hail.stats

import breeze.linalg.{DenseMatrix, DenseVector, sum}
import breeze.stats.distributions._
import org.apache.commons.math3.random.JDKRandomGenerator
import org.broadinstitute.hail.utils.info
import org.broadinstitute.hail.variant.VariantDataset
import org.apache.spark.SparkContext
import org.broadinstitute.hail.annotations.Annotation
import org.broadinstitute.hail.expr.{TArray, TDouble, TInt, TStruct}

import scala.util.Random

object BaldingNicholsModel {
  // K populations, N samples, M variants
  // popDist is K-vector proportional to population distribution
  // FstOfPop is K-vector of F_st values
  def apply(K: Int, N: Int, M: Int,
    popDistOpt: Option[DenseVector[Double]] = None,
    FstOfPopOpt: Option[DenseVector[Double]] = None,
    seed: Int): BaldingNicholsModel = {

    require(K > 0)
    require(N > 0)
    require(M > 0)
    require(popDistOpt.forall(_.length == K))
    require(popDistOpt.forall(_.forall(_ >= 0d)))
    require(FstOfPopOpt.forall(_.length == K))
    require(FstOfPopOpt.forall(_.forall(f => f > 0d && f < 1d)))

    info(s"baldingnichols: generating genotypes for $K populations, $N samples, and $M variants...")

    Rand.generator.setSeed(seed)

    val popDist_k = popDistOpt.getOrElse(DenseVector.fill[Double](K)(1d))
    popDist_k :/= sum(popDist_k)
    val popDistRV = Multinomial(popDist_k)
    val popOfSample_n = DenseVector.fill[Int](N)(popDistRV.draw())

    val Fst_k = FstOfPopOpt.getOrElse(DenseVector.fill[Double](K)(0.1))
    val Fst1_k = (1d - Fst_k) :/ Fst_k

    val ancestralAF = Uniform(0.1, 0.9)
    val ancestralAF_m = DenseVector.fill[Double](M)(ancestralAF.draw())

    val popAF_km = DenseMatrix.zeros[Double](K, M)
    (0 until K).foreach(k =>
      (0 until M).foreach(m =>
        popAF_km(k,m) = new Beta((1 - ancestralAF_m(m)) * Fst1_k(k), ancestralAF_m(m) * Fst1_k(k)).draw()))

    val unif = Rand.uniform

{'fraction_non_alphanumeric': 0.13226452905811623, 'fraction_numerical': 0.011523046092184368, 'mean_word_length': 4.185714285714286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5397313', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1429, 'n_words': 290}