<commit_before># solver should contain all algorithm-specific parameters and methods.
# at a minimum, we need to be able to compute the weight updates for a layer

type DropoutStrategy
  on::Bool 
  pInput::Float64  # the probability that a node is used for the weights from inputs
  pHidden::Float64  # the probability that a node is used for hidden layers
end

DropoutStrategy(; on=false, pInput=0.8, pHidden=0.5) = DropoutStrategy(on, pInput, pHidden)



# -------------------------------------


abstract ErrorModel

"typical sum of squared errors"
immutable L2ErrorModel <: ErrorModel end

"returns M from the equation δ = M .* f'(Σ) ... used in the gradient update"
errorMultiplier(::L2ErrorModel, y::Float64, yhat::Float64) = yhat - y

"cost function"
cost(::L2ErrorModel, y::Float64, yhat::Float64) = 0.5 * (y - yhat) ^ 2
cost(::L2ErrorModel, y::AVecF, yhat::AVecF) = 0.5 * sumabs2(y - yhat)

#-------------

"""
Typical sum of squared errors, but scaled by ρ*y.  We implicitly assume that y ∈ {0,1}.
"""
immutable WeightedL2ErrorModel <: ErrorModel
  ρ::Float64
end
errorMultiplier(model::WeightedL2ErrorModel, y::Float64, yhat::Float64) = (yhat - y) * model.ρ * y
cost(model::WeightedL2ErrorModel, y::Float64, yhat::Float64) = 0.5 * (y - yhat) ^ 2 * model.ρ * y

#-------------

"""<commit_msg>working on ErrorModels<commit_after># solver should contain all algorithm-specific parameters and methods.
# at a minimum, we need to be able to compute the weight updates for a layer

type DropoutStrategy
  on::Bool 
  pInput::Float64  # the probability that a node is used for the weights from inputs
  pHidden::Float64  # the probability that a node is used for hidden layers
end

DropoutStrategy(; on=false, pInput=0.8, pHidden=0.5) = DropoutStrategy(on, pInput, pHidden)



# -------------------------------------


abstract ErrorModel

"typical sum of squared errors"
immutable L2ErrorModel <: ErrorModel end

"returns M from the equation δ = M .* f'(Σ) ... used in the gradient update"
errorMultiplier(::L2ErrorModel, y::Float64, yhat::Float64) = yhat - y

"cost function"
cost(::L2ErrorModel, y::Float64, yhat::Float64) = 0.5 * (y - yhat) ^ 2
cost(::L2ErrorModel, y::AVecF, yhat::AVecF) = 0.5 * sumabs2(y - yhat)

#-------------

"""
Typical sum of squared errors, but scaled by ρ*y.  We implicitly assume that y ∈ {0,1}.
"""
immutable WeightedL2ErrorModel <: ErrorModel
  ρ::Float64
end
errorMultiplier(model::WeightedL2ErrorModel, y::Float64, yhat::Float64) = (yhat - y) * (y > 0 ? model.ρ : 1)
cost(model::WeightedL2ErrorModel, y::Float64, yhat::Float64) = 0.5 * (y - yhat) ^ 2 * (y > 0 ? model.ρ : 1)

#-------------

"""
{'fraction_non_alphanumeric': 0.16761471368979902, 'fraction_numerical': 0.034888130451270385, 'mean_word_length': 3.5561312607944733, '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': '5243044', 'n_tokens_mistral': 938, 'n_tokens_neox': 891, 'n_words': 288}