Skip to content

Commit

Permalink
replace Array{Float64, x} with Vector and Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed Jul 23, 2023
1 parent 7d17172 commit fad7df4
Show file tree
Hide file tree
Showing 31 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/asm2000.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function asm2000(setting::RegressionSetting)::Dict
end


function asm2000(X::Array{Float64,2}, y::Array{Float64,1})::Dict
function asm2000(X::Matrix{Float64}, y::Vector{Float64})::Dict
n, p = size(X)
h = floor((n + p - 1) / 2)
ltsreg = lts(X, y)
Expand Down
4 changes: 2 additions & 2 deletions src/atkinson94.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function atkinson94(setting::RegressionSetting; iters = nothing, crit = 3.0)::Di
end

function atkinson94(
X::Array{Float64,2},
y::Array{Float64,1};
X::Matrix{Float64},
y::Vector{Float64};
iters = nothing,
crit = 3.0,
)::Dict
Expand Down
6 changes: 3 additions & 3 deletions src/atkinsonstalactiteplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function atkinsonstalactiteplot(
end

function atkinsonstalactiteplot(
X::Array{Float64,2},
y::Array{Float64,1};
X::Matrix{Float64},
y::Vector{Float64};
iters = nothing,
crit = 3.0,
)::Nothing
Expand All @@ -46,7 +46,7 @@ function atkinsonstalactiteplot(
end

function generate_stalactite_plot(
residuals_matrix::Array{Float64,2},
residuals_matrix::Matrix{Float64},
n::Int64,
p::Int64,
crit,
Expand Down
12 changes: 6 additions & 6 deletions src/bacon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Two methods V1 and V2 are defined in the paper which use Mahalanobis distance or
- `method`: The distance method to use for selecting the points for initial subset
"""
function initial_basic_subset_multivariate_data(
X::Array{Float64,2},
X::Matrix{Float64},
m::Int;
method::String = "mahalanobis",
)
Expand Down Expand Up @@ -53,7 +53,7 @@ It also guarantees that at least m indices are returned and that the selected in
- `m`: The minimum number of points to include in the subset indices.
- `distances`: The distances vector used for selecting minumum distance indices.
"""
function select_subset(X::Array{Float64,2}, m::Int, distances::Array{Float64})
function select_subset(X::Matrix{Float64}, m::Int, distances::Array{Float64})
rank_x = rank(X)
sorted_distances = sortperm(distances)
subset = sorted_distances[1:m]
Expand Down Expand Up @@ -88,7 +88,7 @@ This function performs the outlier detection for multivariate data according to
- `alpha`: The quantile used for cutoff
"""
function bacon_multivariate_outlier_detection(
X::Array{Float64,2},
X::Matrix{Float64},
m::Int;
method::String = "mahalanobis",
alpha::Float64 = 0.025,
Expand Down Expand Up @@ -146,7 +146,7 @@ This function computes the t distance for each point and returns the distance ve
- `y`: The output vector
- `subset`: The vector which denotes the points inside the subset, used to scale the residuals accordingly.
"""
function compute_t_distance(X::Array{Float64,2}, y::Array{Float64}, subset::Array{Int64})
function compute_t_distance(X::Matrix{Float64}, y::Array{Float64}, subset::Array{Int64})

n, p = size(X)

Expand Down Expand Up @@ -187,7 +187,7 @@ This function computes the initial subset having at least m elements which are l
- `alpha`: The quantile used for cutoff
"""
function bacon_regression_initial_subset(
X::Array{Float64,2},
X::Matrix{Float64},
y::Array{Float64},
m::Int;
method::String = "mahalanobis",
Expand Down Expand Up @@ -259,7 +259,7 @@ Billor, Nedret, Ali S. Hadi, and Paul F. Velleman. "BACON: blocked adaptive comp
Computational statistics & data analysis 34.3 (2000): 279-298.
"""
function bacon(
X::Array{Float64,2},
X::Matrix{Float64},
y::Array{Float64};
m::Int,
method::String = "mahalanobis",
Expand Down
16 changes: 8 additions & 8 deletions src/basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end
```julia-repl
julia> setting = createRegressionSetting(@formula(calls ~ year), phones);
julia> designMatrix(setting)
24×2 Array{Float64,2}:
24×2 Matrix{Float64}:
1.0 50.0
1.0 51.0
1.0 52.0
Expand All @@ -160,10 +160,10 @@ julia> designMatrix(setting)
1.0 73.0
```
"""
function designMatrix(setting::RegressionSetting)::Array{Float64,2}
function designMatrix(setting::RegressionSetting)::Matrix{Float64}
mf = ModelFrame(setting.formula, setting.data)
mm = ModelMatrix(mf)
return convert(Array{Float64,2}, mm.m)
return convert(Matrix{Float64}, mm.m)
end


Expand All @@ -182,7 +182,7 @@ end
```julia-repl
julia> setting = createRegressionSetting(@formula(calls ~ year), phones);
julia> responseVector(setting)
24-element Array{Float64,1}:
24-element Vector{Float64}:
4.4
4.7
4.7
Expand All @@ -209,9 +209,9 @@ julia> responseVector(setting)
29.0
```
"""
function responseVector(setting::RegressionSetting)::Array{Float64,1}
function responseVector(setting::RegressionSetting)::Vector{Float64}
mf = ModelFrame(setting.formula, setting.data)
return convert(Array{Float64,1}, setting.data[:, mf.f.lhs.sym])
return convert(Vector{Float64}, setting.data[:, mf.f.lhs.sym])
end


Expand All @@ -233,7 +233,7 @@ julia> X, y = @extractRegressionSetting setting;
julia> size(X)
(24,2)
julia> y
24-element Array{Float64,1}:
24-element Vector{Float64}:
4.4
4.7
4.7
Expand Down Expand Up @@ -313,7 +313,7 @@ julia> find_minimum_nonzero([0.0, 0.0, 5.0, 1.0])
1.0
```
"""
function find_minimum_nonzero(arr::Array{Float64,1})
function find_minimum_nonzero(arr::Vector{Float64})
return minimum(filter(x -> x > 0, arr))
end

Expand Down
6 changes: 3 additions & 3 deletions src/bch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ end


function bch(
Xdesign::Array{Float64,2},
y::Array{Float64,1};
Xdesign::Matrix{Float64},
y::Vector{Float64};
alpha = 0.05,
maxiter = 1000,
epsilon = 0.000001,
Expand All @@ -98,7 +98,7 @@ function bch(
c = (2.0 * (n + 2.0 * p)) / (n - 2.0 * p)

estimatedvariance = 0.0
estimatedvariances = Array{Float64,1}(undef, 0)
estimatedvariances = Vector{Float64}(undef, 0)

# Algorithm 2 - Step 0.a
coordmeds = coordinatwisemedians(X)
Expand Down
4 changes: 2 additions & 2 deletions src/bchplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function bchplot(
end

function bchplot(
Xdesign::Array{Float64,2},
y::Array{Float64,1};
Xdesign::Matrix{Float64},
y::Vector{Float64};
alpha = 0.05,
maxiter = 1000,
epsilon = 0.00001,
Expand Down
8 changes: 4 additions & 4 deletions src/ccf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Perform signed gradient descent for clipped convex functions for a given regress
# Arguments
- `setting::RegressionSetting`: RegressionSetting object with a formula and dataset.
- `starting_lambdas::Array{Float64,1}`: Starting values of weighting parameters used by signed gradient descent.
- `starting_lambdas::Vector{Float64}`: Starting values of weighting parameters used by signed gradient descent.
- `alpha::Float64`: Loss at which a point is labeled as an outlier (points with loss ≥ alpha will be called outliers).
- `max_iter::Int64`: Maximum number of iterations to run signed gradient descent.
- `beta::Float64`: Step size parameter.
Expand Down Expand Up @@ -81,7 +81,7 @@ Perform signed gradient descent for clipped convex functions for a given regress
# Arguments
- `X::Matrix{Float64}`: Design matrix of the linear model.
- `y::Vector{Float64}`: Response vector of the linear model.
- `starting_lambdas::Array{Float64,1}`: Starting values of weighting parameters used by signed gradient descent.
- `starting_lambdas::Vector{Float64}`: Starting values of weighting parameters used by signed gradient descent.
- `alpha::Float64`: Loss at which a point is labeled as an outlier. If unspecified, will be chosen as p*mean(residuals.^2), where residuals are OLS residuals.
- `p::Float64`: Points that have squared OLS residual greater than p times the mean squared OLS residual are considered outliers.
- `max_iter::Int64`: Maximum number of iterations to run signed gradient descent.
Expand All @@ -100,8 +100,8 @@ Barratt, S., Angeris, G. & Boyd, S. Minimizing a sum of clipped convex functions
"""
function ccf(
X::Array{Float64,2},
y::Array{Float64,1};
X::Matrix{Float64},
y::Vector{Float64};
starting_lambdas = nothing,
alpha = nothing,
p = 3,
Expand Down
2 changes: 1 addition & 1 deletion src/cm97.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ end



function cm97(X::Array{Float64,2}, y::Array{Float64,1}; maxiter::Int = 1000)::Dict
function cm97(X::Matrix{Float64}, y::Vector{Float64}; maxiter::Int = 1000)::Dict

n, p = size(X)
pbar::Float64 = p / n
Expand Down
2 changes: 1 addition & 1 deletion src/dataimage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Computational Statistics & Data Analysis 43.4 (2003): 541-552.
"""
function dataimage(
dataMatrix::Array{Float64,2};
dataMatrix::Matrix{Float64};
distance = :mahalanobis,
)::Matrix{RGBX{Float64}}
d = nothing
Expand Down
14 changes: 7 additions & 7 deletions src/diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ end
# Example
```julia-repl
julia> mat = [1.0 2.0; 3.0 4.0; 5.0 6.0]
3×2 Array{Float64,2}:
3×2 Matrix{Float64}:
1.0 2.0
3.0 4.0
5.0 6.0
julia> coordinatwisemedians(mat)
2-element Array{Float64,1}:
2-element Vector{Float64}:
3.0
4.0
```
Expand Down Expand Up @@ -224,7 +224,7 @@ Calculate `dffit` for all observations.
julia> reg = createRegressionSetting(@formula(calls ~ year), phones);
julia> dffits(reg)
24-element Array{Float64,1}:
24-element Vector{Float64}:
2.3008326745719785
1.2189579001467337
0.35535667547543426
Expand Down Expand Up @@ -305,7 +305,7 @@ Calculate Studentized residuals for a given regression setting.
julia> reg = createRegressionSetting(@formula(calls ~ year), phones);
julia> studentizedResiduals(reg)
24-element Array{Float64,1}:
24-element Vector{Float64}:
0.2398783264505892
0.1463945666608097
0.04934549995087145
Expand Down Expand Up @@ -361,7 +361,7 @@ Calculate adjusted residuals for a given regression setting.
```julia-repl
julia> reg = createRegressionSetting(@formula(calls ~ year), phones);
julia> adjustedResiduals(reg)
24-element Array{Float64,1}:
24-element Vector{Float64}:
13.486773572526268
8.2307993473897
2.774371467851612
Expand Down Expand Up @@ -455,7 +455,7 @@ Calculate Cook distances for all observations in a regression setting.
julia> reg = createRegressionSetting(@formula(calls ~ year), phones);
julia> cooks(reg)
24-element Array{Float64,1}:
24-element Vector{Float64}:
0.005344774190779822
0.0017088194691033689
0.00016624914057962608
Expand Down Expand Up @@ -617,7 +617,7 @@ Apply DFBETA diagnostic for a given regression setting and observation index.
```julia-repl
julia> setting = createRegressionSetting(@formula(calls ~ year), phones);
julia> dfbeta(setting, 1)
2-element Array{Float64,1}:
2-element Vector{Float64}:
9.643915678524024
-0.14686166007904422
```
Expand Down
10 changes: 5 additions & 5 deletions src/ga.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Distributions: sample
abstract type Chromosome end

mutable struct RealChromosome <: Chromosome
genes::Array{Float64,1}
genes::Vector{Float64}
cost::Float64
end

Expand Down Expand Up @@ -83,8 +83,8 @@ end
function createPopulation(
popsize::Int,
chsize::Int,
mins::Array{Float64,1},
maxs::Array{Float64,1},
mins::Vector{Float64},
maxs::Vector{Float64},
)::Array{RealChromosome,1}
pop = Array{RealChromosome,1}(undef, popsize)
for i = 1:popsize
Expand Down Expand Up @@ -148,8 +148,8 @@ function ga(
popsize::Int,
chsize::Int,
fcost::Function,
mins::Array{Float64,1},
maxs::Array{Float64,1},
mins::Vector{Float64},
maxs::Vector{Float64},
pcross::Float64,
pmutate::Float64,
elitisim::Int,
Expand Down
4 changes: 2 additions & 2 deletions src/gwlts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ function galts(setting::RegressionSetting)
return galts(X, y)
end

function galts(X::Array{Float64,2}, y::Array{Float64,1})
function galts(X::Matrix{Float64}, y::Vector{Float64})
n, p = size(X)
h = Int(floor((n + p + 1.0) / 2.0))

function fcost(genes::Array{Float64,1})
function fcost(genes::Vector{Float64})
objective, _ = iterateCSteps(X, y, genes, h)
return objective
end
Expand Down
4 changes: 2 additions & 2 deletions src/hadi1992.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Perform the sub-algorithm of handling singularity defined in Hadi (1992).
Hadi, Ali S. "Identifying multiple outliers in multivariate data."
Journal of the Royal Statistical Society: Series B (Methodological) 54.3 (1992): 761-771.
"""
function hadi1992_handle_singularity(S::Array{Float64,2})::Array{Float64,2}
function hadi1992_handle_singularity(S::Matrix{Float64})::Matrix{Float64}
p, _ = size(S)
eigen_structure = eigen(S)
values = eigen_structure.values
Expand Down Expand Up @@ -75,7 +75,7 @@ Dict{Any,Any} with 3 entries:
Hadi, Ali S. "Identifying multiple outliers in multivariate data."
Journal of the Royal Statistical Society: Series B (Methodological) 54.3 (1992): 761-771.
"""
function hadi1992(multivariateData::Array{Float64,2}; alpha = 0.05)
function hadi1992(multivariateData::Matrix{Float64}; alpha = 0.05)
n, p = size(multivariateData)
h = Int(floor((n + p + 1.0) / 2.0))
chi_50_quantile = quantile(Chisq(p), 0.50)
Expand Down
2 changes: 1 addition & 1 deletion src/hadi1994.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Dict{Any,Any} with 3 entries:
Hadi, Ali S. "A modification of a method for the dedection of outliers in multivariate samples"
Journal of the Royal Statistical Society: Series B (Methodological) 56.2 (1994): 393-396.
"""
function hadi1994(multivariateData::Array{Float64,2}; alpha = 0.05)
function hadi1994(multivariateData::Matrix{Float64}; alpha = 0.05)
n, p = size(multivariateData)
h = Int(round((n + p + 1.0) / 2.0))
cnp = (1 + ((2) / (n - 1 - 3p)) + ((p + 1) / (n - p)))^2
Expand Down
10 changes: 5 additions & 5 deletions src/hs93.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function hs93initialset(setting::RegressionSetting)::Array{Int,1}
return hs93initialset(X, y)
end

function hs93initialset(X::Array{Float64,2}, y::Array{Float64,1})::Array{Int,1}
function hs93initialset(X::Matrix{Float64}, y::Vector{Float64})::Array{Int,1}
_, p = size(X)
s = p + 1
dfs = abs.(dffits(X, y))
Expand Down Expand Up @@ -107,8 +107,8 @@ end


function hs93basicsubset(
X::Array{Float64,2},
y::Array{Float64,1},
X::Matrix{Float64},
y::Vector{Float64},
initialindices::Array{Int,1},
)::Array{Int,1}
n, p = size(X)
Expand Down Expand Up @@ -186,8 +186,8 @@ end


function hs93(
X::Array{Float64,2},
y::Array{Float64,1};
X::Matrix{Float64},
y::Vector{Float64};
alpha = 0.05,
basicsubsetindices = nothing,
)
Expand Down
Loading

0 comments on commit fad7df4

Please sign in to comment.