Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize computation in distancebased.jl #11

Closed
thevolatilebit opened this issue Dec 2, 2023 · 0 comments
Closed

Optimize computation in distancebased.jl #11

thevolatilebit opened this issue Dec 2, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@thevolatilebit
Copy link
Collaborator

  • There is no need to compute the variance each time in:
    QuadraticDistance(; λ = 1, standardize = true) =
    function (x, col; prior = ones(length(col)))
    σ = standardize ? var(col, Weights(prior); corrected = false) : 1
    return λ * (x .- col) .^ 2 / σ
    end
  • It might be better to preallocate the vectors in
    vec_evidence = map(colname -> get(evidence, colname, 0), non_targets)
    distances = map(eachrow(data)) do row
    vec_row = map(
    colname -> haskey(evidence, colname) ? row[colname] : 0,
    non_targets,
    )
    z = vec_evidence - vec_row
    dot(z, Λ * z)
    end
@thevolatilebit thevolatilebit added the enhancement New feature or request label Dec 2, 2023
@thevolatilebit thevolatilebit self-assigned this Dec 2, 2023
thevolatilebit added a commit that referenced this issue Dec 3, 2023
- Implemented a variant of sq. Mahalanobis distance
with missing entries, see https://www.jstor.org/stable/3559861
on page 285, fixes #12
- Renamed `MahalanobisDistance` to `SquaredMahalanobisDistance`
- Minor adjustments to tutorials
- Removed extra dependencies
- Incremented version

Fixes #11 and #12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant