Skip to content

Commit

Permalink
Update sampwsp.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesnoff committed Jun 13, 2024
1 parent 0dbeb5a commit 7204760
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/sampwsp.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
sampwsp(X, dmin; maxit = nro(X))
sampwsp(X, dmin; recod = false, maxit = nro(X))
Build training vs. test sets by WSP sampling.
* `X` : X-data (n, p).
* `dmin` : Distance "dmin" (Santiago et al. 2012).
Keyword arguments:
* `recod` : Boolean indicating if `X` is recoded or not
before the sampling (see below).
* `maxit` : Maximum number of iterations.
Two outputs (= row indexes of the data) are returned:
Expand All @@ -14,6 +16,13 @@ Output `test` is built from the "Wootton, Sergent, Phan-Tan-Luu" (WSP)
algorithm, assumed to generate samples uniformely distributed in the `X` domain
(Santiago et al. 2012).
If `recod = true`, each column x of `X` is recoded within [0, 1] and the center of
the domain is the vector `repeat([.5], p)`. Column x is recoded such as:
* vmin = minimum(x)
* vmax = maximum(x)
* vdiff = vmax - vmin
* x .= 0.5 .+ (x .- (vdiff / 2 + vmin)) / vdiff
## References
Béal A. 2015. Description et sélection de données en grande dimensio. Thèse de doctorat.
Expand All @@ -36,7 +45,7 @@ pnames(res)
plotxy(X[s.test, 1], X[s.test, 2]).f
```
"""
function sampwsp(X, dmin; recod = true, maxit = nro(X))
function sampwsp(X, dmin; recod = false, maxit = nro(X))
X = ensure_mat(X)
n, p = size(X)
indX = collect(1:n)
Expand All @@ -50,8 +59,8 @@ function sampwsp(X, dmin; recod = true, maxit = nro(X))
xmeans = repeat([.5], p)
else
zX = copy(X)
#xmeans = colmean(zX)
xmeans = repeat([.5], p)
xmeans = colmean(zX)
#xmeans = repeat([.5], p)
end
s = getknn(zX, xmeans'; k = 1).ind[1][1]
x .= vrow(zX, s:s)
Expand Down

2 comments on commit 7204760

@mlesnoff
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108876

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.2 -m "<description of version>" 7204760a26a8c5f9d7f7b9b66b6dd0c83e5407f5
git push origin v0.4.2

Please sign in to comment.