<commit_before>import Base.Random: rand

export bwmutate, bwmutate!, bsmutate, bsmutate!

mutlocus(v::Int64, ls::Landscape) = setdiff(1:ls.a, v) |> rand

@doc """bwmutate(p::Population, ls::Landscape, mutprob::Float64)

Return a new population such that each locus of the original
population has been mutated with probability `mutprob`.
"""
function bwmutate(p::Population, ls::Landscape, mutprob::Float64)
  np = copy(p)
  bwmutate!(np, ls, mutprob)
  return np
end

@doc """bwmutate!(p::Population, ls::Landscape, mutprob::Float64)

Mutate the population in-place by mutating each locus with probability
`mutprob`.
"""
function bwmutate!(p::Population, ls::Landscape, mutprob::Float64)
  # Use the fact that matrices can be iterated and indexed directly.
  for i = 1:length(p)
    if rand() < mutprob
      p[i] = mutlocus(p[i], ls)
    end
  end
end

@doc """bsmutate(p::Population, ls::Landscape)

Return a new population with a single locus of each bitstring in the original
population mutated (bit flipped if `ls.a == 2`) with probability `mutprob`.
"""
function bsmutate(p::Population, ls::Landscape, mutprob::Float64)
  np = copy(p)
  bsmutate!(np, ls, mutprob)
  return np
end

@doc """bsmutate(p::Population, ls::Landscape)

Mutate a population in-place by mutating up to one locus of each bitstring in
the population.
"""
function bsmutate!(p::Population, ls::Landscape, mutprob::Float64)
  for i = 1:popsize(p)
    if rand() < mutprob
      j = rand(1:ls.n)
      p[j,i] = mutlocus(p[j,i], ls)
    end
  end
end
<commit_msg>Add docs for mutation functions.<commit_after>import Base.Random: rand

export bwmutate, bwmutate!, bsmutate, bsmutate!

mutlocus(v::Int64, ls::Landscape) = setdiff(1:ls.a, v) |> rand

@doc """bwmutate(p::Population, ls::Landscape, mutprob::Float64)

Return a new population such that each locus of the original
population has been mutated with probability `mutprob`.
"""
function bwmutate(p::Population, ls::Landscape, mutprob::Float64)
  np = copy(p)
  bwmutate!(np, ls, mutprob)
  return np
end

@doc """bwmutate(p::MetaPopulation, ls::Landscape, mutprob::Float64)
"""
function bwmutate(p::MetaPopulation, ls::Landscape, mutprob::Float64)
  np = copy(p)
  bwmutate!(np, ls, mutprob)
  return np
end

@doc """bwmutate!(p::Population, ls::Landscape, mutprob::Float64)

Mutate the population in-place by mutating each locus with probability
`mutprob`.
"""
function bwmutate!(p::Population, ls::Landscape, mutprob::Float64)
  # Use the fact that matrices can be iterated and indexed directly.
  for i = 1:length(p)
    if rand() < mutprob
      p[i] = mutlocus(p[i], ls)
    end
  end
end

@doc """bwmutate!(p::MetaPopulation, ls::Landscape, mutprob::Float64)
"""
function bwmutate!(p::MetaPopulation, ls::Landscape, mutprob::Float64)
  for ip = 1:popct(p)
    bwmutate!(p[:,:,ip], ls, mutprob)
  end
end

@doc """bsmutate(p::Population, ls::Landscape)

Return a new population with a single locus of each bitstring in the original
population mutated (bit flipped if `ls.a == 2`) with probability `mutprob`.
"""
function bsmutate(p::Population, ls::Landscape, mutprob::Float64)
  np = copy(p)
  bsmutate!(np, ls, mutprob)
  return np
end

@doc """bsmutate(p::MetaPopulation, ls::Landscape, mutprob::Float64)
"""
function bsmutate(p::MetaPopulation, ls::Landscape, mutprob::Float64)
  np = copy(p)
  bsmutate!(np, ls, mutprob)
  return np
end

@doc """bsmutate(p::Population, ls::Landscape)

Mutate a population in-place by mutating up to one locus of each bitstring in
the population.
"""
function bsmutate!(p::Population, ls::Landscape, mutprob::Float64)
  for i = 1:popsize(p)
    if rand() < mutprob
      j = rand(1:ls.n)
      p[j,i] = mutlocus(p[j,i], ls)
    end
  end
end

@doc """bsmutate!(p::MetaPopulation, ls::Landscape, mutprob::Float64)
"""
function bsmutate!(p::MetaPopulation, ls::Landscape, mutprob::Float64)
  for ip = 1:popct(p)
    bsmutate!(p[:,:,ip], ls, mutprob)
  end
end

{'fraction_non_alphanumeric': 0.14423810735181888, 'fraction_numerical': 0.014245738997710507, 'mean_word_length': 5.261146496815287, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4775207', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1392, 'n_words': 398}