Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit e5df2af9 authored by Dahua Lin's avatar Dahua Lin

renamed sample to sample for weighted sampling

parent 337d7fc4
......@@ -124,7 +124,8 @@ export # types
quantile, # inverse of cdf (defined for p in (0,1))
rand, # random sampler
rand!, # replacement random sampler
sample, # another random sampler - not sure why this is here
sample, # sample from a source array
wsample, # weighted sampling from a source array
sampler, # create a Sampler object for efficient samples
skewness, # skewness of the distribution
sprand, # random sampler for sparse matrices
......
......@@ -140,7 +140,7 @@ end
#
################################################################
function sample(a::AbstractArray, w::AbstractArray{Float64}, wsum::Float64)
function wsample(a::AbstractArray, w::AbstractArray{Float64}, wsum::Float64)
n = length(w)
t = rand() * wsum
......@@ -154,9 +154,9 @@ function sample(a::AbstractArray, w::AbstractArray{Float64}, wsum::Float64)
a[i]
end
sample{W<:FloatingPoint}(a::AbstractArray, w::AbstractArray{Float64}) = sample(a, w, sum(w))
wsample{W<:FloatingPoint}(a::AbstractArray, w::AbstractArray{Float64}) = wsample(a, w, sum(w))
function sample!(a::AbstractArray, w::AbstractArray{Float64}, x::AbstractArray;
function wsample!(a::AbstractArray, w::AbstractArray{Float64}, x::AbstractArray;
wsum::Float64=NaN)
n = length(a)
......@@ -166,16 +166,16 @@ function sample!(a::AbstractArray, w::AbstractArray{Float64}, x::AbstractArray;
_wsum::Float64 = isnan(wsum) ? sum(w) : wsum
for i = 1:length(x)
x[i] = sample(a, w, _wsum)
x[i] = wsample(a, w, _wsum)
end
x
end
function sample{T}(a::AbstractArray{T}, w::AbstractArray{Float64}, n::Integer; wsum::Float64=NaN)
sample!(a, w, Array(T, n); wsum=wsum)
function wsample{T}(a::AbstractArray{T}, w::AbstractArray{Float64}, n::Integer; wsum::Float64=NaN)
wsample!(a, w, Array(T, n); wsum=wsum)
end
function sample{T}(a::AbstractArray{T}, w::AbstractArray{Float64}, dims::Dims; wsum::Float64=NaN)
sample!(a, w, Array(T, dims); wsum=wsum)
function wsample{T}(a::AbstractArray{T}, w::AbstractArray{Float64}, dims::Dims; wsum::Float64=NaN)
wsample!(a, w, Array(T, dims); wsum=wsum)
end
......@@ -80,7 +80,7 @@ end
w = [2., 5., 3.]
n = 10^5
x = sample([10,20,30], w, n)
x = wsample([10,20,30], w, n)
h = [sum(x .== 10), sum(x .== 20), sum(x .== 30)]
@test sum(h) == n
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment