Skip to content

Commit f15f943

Browse files
committed
remove inbounds macro
1 parent 53aa87f commit f15f943

14 files changed

Lines changed: 87 additions & 104 deletions

File tree

src/atkinson94.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function atkinson94(
9292
studentized_residuals = zeros(Float64, n, n)
9393
copy_parameters = false
9494

95-
@inbounds for m = p:n
95+
for m = p:n
9696
olsreg = ols(X[m_subset_indices, :], y[m_subset_indices])
9797
betas = coef(olsreg)
9898
e = (y .- X * betas)
@@ -103,7 +103,7 @@ function atkinson94(
103103
XXinv = pinv(X[m_subset_indices, :]'X[m_subset_indices, :])
104104

105105
# scale the residual according to whether it belongs to m_subset_indices or not
106-
@inbounds for index = 1:n
106+
for index = 1:n
107107
if index in m_subset_indices
108108
h_i = X[index, :]' * XXinv * X[index, :]
109109
studentized_residuals[m, index] =

src/bacon.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ function compute_t_distance(X::Array{Float64,2}, y::Array{Float64}, subset::Arra
160160
scale_factor = (X[i, :]') * (covmatrix_inv * X[i, :])
161161
residual = (y[i] - X[i, :]' * betas)
162162
if i in subset
163-
@inbounds t[i] = residual / (sigma * sqrt(1 - scale_factor))
163+
t[i] = residual / (sigma * sqrt(1 - scale_factor))
164164
else
165-
@inbounds t[i] = residual / (sigma * sqrt(1 + scale_factor))
165+
t[i] = residual / (sigma * sqrt(1 + scale_factor))
166166
end
167167
end
168168
return abs.(t)
@@ -207,7 +207,7 @@ function bacon_regression_initial_subset(
207207
basic_subset = select_subset(X, r + 1, t)
208208
r = length(basic_subset)
209209
iter += 1
210-
if iter > n
210+
if iter > n
211211
break
212212
end
213213
end
@@ -271,20 +271,17 @@ function bacon(
271271
r_prev = r
272272
r = length(subset)
273273
iter += 1
274-
if iter > n
274+
if iter > n
275275
break
276276
end
277277
end
278278

279279
outlierindices = setdiff(1:n, subset)
280-
inlierindices = subset
280+
inlierindices = subset
281281
cleanols = ols(X[inlierindices, :], y[inlierindices])
282282
cleanbetas = coef(cleanols)
283283

284-
result = Dict(
285-
"outliers" => outlierindices,
286-
"betas" => cleanbetas
287-
)
284+
result = Dict("outliers" => outlierindices, "betas" => cleanbetas)
288285
return result
289286
end
290287

src/cm97.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function cm97(X::Array{Float64,2}, y::Array{Float64,1}; maxiter::Int = 1000)::Di
6363
iter::Int = 0
6464

6565
# initial weights
66-
@inbounds for i = 1:n
66+
for i = 1:n
6767
w_is[i] = 1.0 / max(hat[i, i], pbar)
6868
end
6969

@@ -75,7 +75,7 @@ function cm97(X::Array{Float64,2}, y::Array{Float64,1}; maxiter::Int = 1000)::Di
7575
r = y - X * betas
7676
medi = median(abs.(r))
7777

78-
@inbounds for i = 1:n
78+
for i = 1:n
7979
w_is[i] = (1.0 - hat[i, i])^2.0 / max(abs(r[i]), medi)
8080
end
8181

src/dataimage.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export dataimage
55
import ..Diagnostics:
66
mahalanobisSquaredMatrix, euclideanDistances, mahalanobisSquaredBetweenPairs
77

8-
import ..RGB
8+
import ..RGB
99

1010
"""
1111
@@ -62,7 +62,7 @@ function dataimage(
6262
colormatrix = Array{RGB{Float64},2}(undef, n, n)
6363
for i = 1:n
6464
for j = 1:n
65-
@inbounds colormatrix[i, j] = RGB(colours[i, j])
65+
colormatrix[i, j] = RGB(colours[i, j])
6666
end
6767
end
6868
return colormatrix

src/diagnostics.jl

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
module Diagnostics
22

33

4-
export dffit,
4+
export dffit,
55
dffits,
66
dfbeta,
77
dfbetas,
88
hatmatrix,
99
studentizedResiduals,
1010
adjustedResiduals,
1111
jacknifedS,
12-
cooks, cooksoutliers,
12+
cooks,
13+
cooksoutliers,
1314
mahalanobisSquaredMatrix,
1415
covratio,
1516
hadimeasure,
16-
diagnose
17+
diagnose
1718

1819
export coordinatwisemedians, mahalanobisBetweenPairs, euclideanDistances
1920

@@ -47,8 +48,8 @@ function euclideanDistances(dataMatrix::Array{Float64,2})::Array{Float64,2}
4748
for i = 1:n
4849
for j = i:n
4950
if i != j
50-
@inbounds d[i, j] = sqrt(sum((dataMatrix[i, :] .- dataMatrix[j, :]) .^ 2.0))
51-
@inbounds d[j, i] = d[i, j]
51+
d[i, j] = sqrt(sum((dataMatrix[i, :] .- dataMatrix[j, :]) .^ 2.0))
52+
d[j, i] = d[i, j]
5253
end
5354
end
5455
end
@@ -66,7 +67,7 @@ function mahalanobisSquaredBetweenPairs(pairs::Matrix; covmatrix = nothing)
6667
try
6768
invm = inv(covmatrix)
6869
for i = 1:n
69-
@inbounds for j = i:n
70+
for j = i:n
7071
newmat[i, j] =
7172
((pairs[i, :] .- pairs[j, :])' * invm * (pairs[i, :] .- pairs[j, :]))
7273
newmat[j, i] = newmat[i, j]
@@ -113,12 +114,12 @@ function mahalanobisBetweenPairs(dataMatrix::Array{Float64,2})::Array{Float64,2}
113114
for i = 1:n
114115
for j = i:n
115116
if i != j
116-
@inbounds d[i, j] = sqrt(
117+
d[i, j] = sqrt(
117118
(dataMatrix[i, :] .- dataMatrix[j, :]) *
118119
covinv *
119120
(dataMatrix[i, :] .- dataMatrix[j, :])',
120121
)
121-
@inbounds d[j, i] = d[i, j]
122+
d[j, i] = d[i, j]
122123
end
123124
end
124125
end
@@ -497,7 +498,7 @@ function cooks(X::Array{Float64,2}, y::Array{Float64,1})::Array{Float64,1}
497498
s2 = sum(res .* res) / (n - p)
498499
d = zeros(Float64, n)
499500
for i = 1:n
500-
@inbounds d[i] = ((res[i]^2.0) / (p * s2)) * (hat[i, i] / (1 - hat[i, i])^2.0)
501+
d[i] = ((res[i]^2.0) / (p * s2)) * (hat[i, i] / (1 - hat[i, i])^2.0)
501502
end
502503
return d
503504
end
@@ -519,21 +520,17 @@ Calculates Cooks distance for a given regression setting and reports the potenti
519520
- `["cutoff"]`: Quantile of the F distribution.
520521
- `["potentials"]`: Vector of indices of potential regression outliers.
521522
"""
522-
function cooksoutliers(setting::RegressionSetting; alpha::Float64 = 0.5)::Dict
523+
function cooksoutliers(setting::RegressionSetting; alpha::Float64 = 0.5)::Dict
523524
X, y = @extractRegressionSetting setting
524525
return cooksoutliers(X, y, alpha = alpha)
525526
end
526527

527-
function cooksoutliers(X::Array{Float64, 2}, y::Array{Float64, 1}; alpha::Float64 = 0.5)::Dict
528+
function cooksoutliers(X::Array{Float64,2}, y::Array{Float64,1}; alpha::Float64 = 0.5)::Dict
528529
n, p = size(X)
529530
d = cooks(X, y)
530531
cutoff = cookscritical(n, p)
531532
potentials = filter(i -> d[i] >= cutoff, 1:n)
532-
return Dict(
533-
"distance" => d,
534-
"cutoff" => cutoff,
535-
"potentials" => potentials
536-
)
533+
return Dict("distance" => d, "cutoff" => cutoff, "potentials" => potentials)
537534
end
538535

539536

@@ -597,14 +594,11 @@ See also: [`dfbeta`](@ref)
597594
"""
598595
function dfbetas(setting)
599596
y = responseVector(setting)
600-
results = map(i -> dfbeta(setting, i), 1:length(y))
597+
results = map(i -> dfbeta(setting, i), 1:length(y))
601598
return mapreduce(permutedims, vcat, results)
602599
end
603600

604-
function dfbetas(
605-
X::Array{Float64,2},
606-
y::Array{Float64,1}
607-
)
601+
function dfbetas(X::Array{Float64,2}, y::Array{Float64,1})
608602
results = map(i -> dfbeta(X, y, i), 1:length(y))
609603
return mapreduce(permutedims, vcat, results)
610604
end
@@ -724,7 +718,7 @@ function hadimeasure(X::Array{Float64,2}, y::Array{Float64,1}; c::Float64 = 2.0)
724718
hat = hatmatrix(X)
725719
H = zeros(Float64, n)
726720
for i = 1:n
727-
@inbounds H[i] =
721+
H[i] =
728722
(p * res2[i]) / ((1 - hat[i, i]) * (sumres - res2[i])) +
729723
(hat[i, i] / (1 - hat[i, i]))
730724
end
@@ -736,23 +730,23 @@ end
736730

737731
function dffitcritical(n::Int, p::Int)::Float64
738732
return 2.0 * sqrt((p + 1) / (n - p - 1))
739-
end
733+
end
740734

741735
function dfbetacritical(n::Int)::Float64
742736
return 2.0 / sqrt(n)
743-
end
737+
end
744738

745-
function covratiocritical(n::Int, p::Int)::Tuple{Float64, Float64}
739+
function covratiocritical(n::Int, p::Int)::Tuple{Float64,Float64}
746740
c = 3.0 * p / n
747741
return (1.0 - c, 1.0 + c)
748-
end
742+
end
749743

750-
function hatcritical(n::Int, p::Int)::Float64
744+
function hatcritical(n::Int, p::Int)::Float64
751745
return 2.0 * sqrt(p / n)
752-
end
746+
end
753747

754-
function cookscritical(n::Int, p::Int; alpha = 0.5)::Float64
755-
return quantile(FDist(p, n-p), alpha)
748+
function cookscritical(n::Int, p::Int; alpha = 0.5)::Float64
749+
return quantile(FDist(p, n - p), alpha)
756750
end
757751

758752

@@ -772,32 +766,32 @@ Diagnose a regression setting and report potential outliers using [`dffits`](@re
772766
function diagnose(setting::RegressionSetting; alpha = 0.5)
773767
X, y = @extractRegressionSetting setting
774768
return diagnose(X, y, alpha = 0.5)
775-
end
769+
end
776770

777771

778-
function diagnose(X::Array{Float64, 2}, y::Array{Float64, 1}; alpha = 0.5)
772+
function diagnose(X::Array{Float64,2}, y::Array{Float64,1}; alpha = 0.5)
779773
n, p = size(X)
780-
resultdffits = dffits(X, y)
781-
resultdfbetas = dfbetas(X, y)
782-
resultcook = cooks(X, y)
783-
hatresult = hatmatrix(X)
774+
resultdffits = dffits(X, y)
775+
resultdfbetas = dfbetas(X, y)
776+
resultcook = cooks(X, y)
777+
hatresult = hatmatrix(X)
784778

785-
dffitcrit = dffitcritical(n, p)
786-
dfbetacrit = dfbetacritical(n)
787-
hatcrit = hatcritical(n, p)
788-
cookscrit = cookscritical(n, p, alpha = alpha)
779+
dffitcrit = dffitcritical(n, p)
780+
dfbetacrit = dfbetacritical(n)
781+
hatcrit = hatcritical(n, p)
782+
cookscrit = cookscritical(n, p, alpha = alpha)
789783

790-
dffitpotential = filter(i -> abs(resultdffits[i]) >= dffitcrit, 1:n)
784+
dffitpotential = filter(i -> abs(resultdffits[i]) >= dffitcrit, 1:n)
791785
dfbetaspotential = filter(i -> any(x -> (abs(x) > dfbetacrit), resultdfbetas), 1:n)
792-
hatpotential = filter(i -> abs(hatresult[i]) > hatcrit, 1:n)
793-
cookpotential = filter(i -> abs(resultcook[i]) > cookscrit, 1:n)
786+
hatpotential = filter(i -> abs(hatresult[i]) > hatcrit, 1:n)
787+
cookpotential = filter(i -> abs(resultcook[i]) > cookscrit, 1:n)
794788

795789
return Dict(
796790
"dffit_potentials" => dffitpotential,
797791
"dfbeta_potentials" => dfbetaspotential,
798792
"hat_potentials" => hatpotential,
799-
"cooks_potentials" => cookpotential
793+
"cooks_potentials" => cookpotential,
800794
)
801-
end
795+
end
802796

803797
end # end of module Diagnostics

src/ga.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ end
5151

5252
function Mutate(c::RealChromosome, prob::Float64)::RealChromosome
5353
genes = copy(c.genes)
54-
@inbounds for i in eachindex(genes)
54+
for i in eachindex(genes)
5555
if rand() < prob
5656
genes[i] += randn()
5757
end
@@ -64,8 +64,8 @@ function TournamentSelection(
6464
)::Tuple{RealChromosome,RealChromosome}
6565
n = length(pop)
6666
indices = sample(1:n, 4, replace = false)
67-
lucky1 :: Chromosome = RealChromosome()
68-
lucky2 :: Chromosome = RealChromosome()
67+
lucky1::Chromosome = RealChromosome()
68+
lucky2::Chromosome = RealChromosome()
6969
if pop[indices[1]].cost < pop[indices[2]].cost
7070
lucky1 = pop[indices[1]]
7171
else
@@ -87,15 +87,15 @@ function createPopulation(
8787
maxs::Array{Float64,1},
8888
)::Array{RealChromosome,1}
8989
pop = Array{RealChromosome,1}(undef, popsize)
90-
@inbounds for i = 1:popsize
90+
for i = 1:popsize
9191
c = RealChromosome(mins .+ rand(chsize) .* (maxs - mins), Inf64)
9292
pop[i] = c
9393
end
9494
return pop
9595
end
9696

9797
function Evaluate(pop::Array{RealChromosome,1}, fcost::Function)::Array{RealChromosome,1}
98-
@inbounds for i in eachindex(pop)
98+
for i in eachindex(pop)
9999
pop[i].cost = fcost(pop[i].genes)
100100
end
101101
return pop
@@ -109,18 +109,18 @@ function Generation(
109109
pmutate::Float64,
110110
)::Array{RealChromosome,1}
111111
popsize = length(pop)
112-
newpop = Array{Chromosome, 1}(undef, popsize)
112+
newpop = Array{Chromosome,1}(undef, popsize)
113113
pop = sort(Evaluate(pop, fcost))
114-
csize :: Int = 0
115-
@inbounds for i = 1:elitism
114+
csize::Int = 0
115+
for i = 1:elitism
116116
csize += 1
117117
newpop[csize] = pop[i]
118118
end
119119

120120
winner1 = RealChromosome()
121121
winner2 = RealChromosome()
122122

123-
@inbounds while csize < popsize
123+
while csize < popsize
124124
parent1, parent2 = TournamentSelection(pop)
125125
if rand() < pcross
126126
offspring1, offspring2, offspring3 = LinearCrossover(parent1, parent2)
@@ -133,11 +133,11 @@ function Generation(
133133
end
134134
if (csize + 1 <= popsize)
135135
csize += 1
136-
newpop[csize] = winner1
136+
newpop[csize] = winner1
137137
end
138138
if (csize + 1 <= popsize)
139139
csize += 1
140-
newpop[csize] = winner2
140+
newpop[csize] = winner2
141141
end
142142
end
143143
return sort(newpop)

src/hadi1992.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function hadi1992_handle_singularity(S::Array{Float64,2})::Array{Float64,2}
3636
lambda_s = find_minimum_nonzero(values)
3737
W = zeros(Float64, p, p)
3838
for i = 1:p
39-
@inbounds W[i, i] = 1 / max(values[i], lambda_s)
39+
W[i, i] = 1 / max(values[i], lambda_s)
4040
end
4141
newS = vectors * W * vectors
4242
return newS

0 commit comments

Comments
 (0)