Skip to content

Commit 5bebe4e

Browse files
Merge pull request #241 from StructuralEquationModels/test_warnings
suppress uninformative warnings during package testing
2 parents cd6413b + 8c703d6 commit 5bebe4e

File tree

16 files changed

+83
-93
lines changed

16 files changed

+83
-93
lines changed

ext/SEMProximalOptExt/ProximalAlgorithms.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function ProximalAlgorithms.value_and_gradient(model::AbstractSem, params)
6161
return obj, grad
6262
end
6363

64-
6564
mutable struct ProximalResult
6665
result::Any
6766
end

src/frontend/fit/summary.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
function details(
2-
sem_fit::SemFit;
3-
show_fitmeasures = false,
4-
color = :light_cyan,
5-
digits = 2,
6-
)
1+
function details(sem_fit::SemFit; show_fitmeasures = false, color = :light_cyan, digits = 2)
72
print("\n")
83
println("Fitted Structural Equation Model")
94
print("\n")
@@ -51,7 +46,7 @@ function details(
5146
secondary_color = :light_yellow,
5247
digits = 2,
5348
show_variables = true,
54-
show_columns = nothing
49+
show_columns = nothing,
5550
)
5651
if show_variables
5752
print("\n")
@@ -150,7 +145,8 @@ function details(
150145
check_round(partable.columns[c][regression_indices]; digits = digits) for
151146
c in regression_columns
152147
)
153-
regression_columns[2] = regression_columns[2] == :relation ? Symbol("") : regression_columns[2]
148+
regression_columns[2] =
149+
regression_columns[2] == :relation ? Symbol("") : regression_columns[2]
154150

155151
print("\n")
156152
pretty_table(
@@ -222,7 +218,8 @@ function details(
222218
printstyled("Means: \n"; color = color)
223219

224220
if isnothing(show_columns)
225-
sorted_columns = [:from, :relation, :to, :estimate, :param, :value_fixed, :start]
221+
sorted_columns =
222+
[:from, :relation, :to, :estimate, :param, :value_fixed, :start]
226223
mean_columns = sort_partially(sorted_columns, columns)
227224
else
228225
mean_columns = copy(show_columns)
@@ -256,7 +253,7 @@ function details(
256253
secondary_color = :light_yellow,
257254
digits = 2,
258255
show_variables = true,
259-
show_columns = nothing
256+
show_columns = nothing,
260257
)
261258
if show_variables
262259
print("\n")
@@ -297,7 +294,7 @@ function details(
297294
secondary_color = secondary_color,
298295
digits = digits,
299296
show_variables = false,
300-
show_columns = show_columns
297+
show_columns = show_columns,
301298
)
302299
end
303300

src/frontend/specification/EnsembleParameterTable.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ EnsembleParameterTable(::Nothing; params::Union{Nothing, Vector{Symbol}} = nothi
1919
)
2020

2121
# convert pairs to dict
22-
EnsembleParameterTable(ps::Pair{K, V}...; params = nothing) where {K, V} =
22+
EnsembleParameterTable(ps::Pair{K, V}...; params = nothing) where {K, V} =
2323
EnsembleParameterTable(Dict(ps...); params = params)
2424

2525
# dictionary of SEM specifications
@@ -148,8 +148,6 @@ end
148148
############################################################################################
149149

150150
function Base.:(==)(p1::EnsembleParameterTable, p2::EnsembleParameterTable)
151-
out =
152-
(p1.tables == p2.tables) &&
153-
(p1.params == p2.params)
151+
out = (p1.tables == p2.tables) && (p1.params == p2.params)
154152
return out
155-
end
153+
end

src/frontend/specification/ParameterTable.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ end
128128

129129
# Equality --------------------------------------------------------------------------------
130130
function Base.:(==)(p1::ParameterTable, p2::ParameterTable)
131-
out =
131+
out =
132132
(p1.columns == p2.columns) &&
133133
(p1.observed_vars == p2.observed_vars) &&
134134
(p1.latent_vars == p2.latent_vars) &&

src/frontend/specification/RAMMatrices.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ function RAMMatrices(
133133
@assert length(partable.sorted_vars) == nvars(partable)
134134
vars_sorted = copy(partable.sorted_vars)
135135
else
136-
vars_sorted = [partable.observed_vars
137-
partable.latent_vars]
136+
vars_sorted = [
137+
partable.observed_vars
138+
partable.latent_vars
139+
]
138140
end
139141

140142
# indices of the vars (A/S/M rows or columns)
@@ -216,13 +218,20 @@ function RAMMatrices(
216218
sort!(M_consts, by = first)
217219
end
218220

219-
return RAMMatrices(ParamsMatrix{T}(A_inds, A_consts, (n_vars, n_vars)),
220-
ParamsMatrix{T}(S_inds, S_consts, (n_vars, n_vars)),
221-
sparse(1:n_observed,
222-
[vars_index[var] for var in partable.observed_vars],
223-
ones(T, n_observed), n_observed, n_vars),
224-
!isnothing(M_inds) ? ParamsVector{T}(M_inds, M_consts, (n_vars,)) : nothing,
225-
params, vars_sorted)
221+
return RAMMatrices(
222+
ParamsMatrix{T}(A_inds, A_consts, (n_vars, n_vars)),
223+
ParamsMatrix{T}(S_inds, S_consts, (n_vars, n_vars)),
224+
sparse(
225+
1:n_observed,
226+
[vars_index[var] for var in partable.observed_vars],
227+
ones(T, n_observed),
228+
n_observed,
229+
n_vars,
230+
),
231+
!isnothing(M_inds) ? ParamsVector{T}(M_inds, M_consts, (n_vars,)) : nothing,
232+
params,
233+
vars_sorted,
234+
)
226235
end
227236

228237
Base.convert(
@@ -360,10 +369,7 @@ function append_rows!(
360369
arr_ix = arr_ixs[arr.linear_indices[j]]
361370
skip_symmetric && (arr_ix visited_indices) && continue
362371

363-
push!(
364-
partable,
365-
partable_row(par, arr_ix, arr_name, varnames, free = true),
366-
)
372+
push!(partable, partable_row(par, arr_ix, arr_name, varnames, free = true))
367373
if skip_symmetric
368374
# mark index and its symmetric as visited
369375
push!(visited_indices, arr_ix)

src/implied/abstract.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ function check_acyclic(A::AbstractMatrix; verbose::Bool = false)
2525
# check if non-triangular matrix is acyclic
2626
acyclic = isone(det(I - A))
2727
if acyclic
28-
verbose && @info "The matrix is acyclic. Reordering variables in the model to make the A matrix either Upper or Lower Triangular can significantly improve performance.\n" maxlog =
29-
1
28+
verbose &&
29+
@info "The matrix is acyclic. Reordering variables in the model to make the A matrix either Upper or Lower Triangular can significantly improve performance.\n" maxlog =
30+
1
3031
end
3132
return A
3233
end

src/loss/ML/FIML.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ function ∇F_fiml_outer!(G, JΣ, Jμ, implied, model, semfiml)
161161

162162
∇Σ = P * (implied.∇S + Q * implied.∇A)
163163

164-
∇μ = implied.F⨉I_A⁻¹ * implied.∇M + kron((implied.I_A⁻¹ * implied.M)', implied.F⨉I_A⁻¹) * implied.∇A
164+
∇μ =
165+
implied.F⨉I_A⁻¹ * implied.∇M +
166+
kron((implied.I_A⁻¹ * implied.M)', implied.F⨉I_A⁻¹) * implied.∇A
165167

166168
mul!(G, ∇Σ', JΣ) # actually transposed
167169
mul!(G, ∇μ', Jμ, -1, 1)

src/objective_gradient_hessian.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@ evaluate!(objective, gradient, hessian, loss::SemLossFunction, model::AbstractSe
2828
evaluate!(objective, gradient, hessian, loss, implied(model), model, params)
2929

3030
# fallback method
31-
function evaluate!(obj, grad, hess, loss::SemLossFunction, implied::SemImplied, model, params)
31+
function evaluate!(
32+
obj,
33+
grad,
34+
hess,
35+
loss::SemLossFunction,
36+
implied::SemImplied,
37+
model,
38+
params,
39+
)
3240
isnothing(obj) || (obj = objective(loss, implied, model, params))
3341
isnothing(grad) || copyto!(grad, gradient(loss, implied, model, params))
3442
isnothing(hess) || copyto!(hess, hessian(loss, implied, model, params))
3543
return obj
3644
end
3745

3846
# fallback methods
39-
objective(f::SemLossFunction, implied::SemImplied, model, params) = objective(f, model, params)
40-
gradient(f::SemLossFunction, implied::SemImplied, model, params) = gradient(f, model, params)
47+
objective(f::SemLossFunction, implied::SemImplied, model, params) =
48+
objective(f, model, params)
49+
gradient(f::SemLossFunction, implied::SemImplied, model, params) =
50+
gradient(f, model, params)
4151
hessian(f::SemLossFunction, implied::SemImplied, model, params) = hessian(f, model, params)
4252

4353
# fallback method for SemImplied that calls update_xxx!() methods

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1515
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1616
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1717
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
18+
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
1819
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/examples/multigroup/build_models.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ model_ml_multigroup2 = SemEnsemble(
1717
data = dat,
1818
column = :school,
1919
groups = [:Pasteur, :Grant_White],
20-
loss = SemML
20+
loss = SemML,
2121
)
2222

23-
2423
# gradients
2524
@testset "ml_gradients_multigroup" begin
2625
test_gradient(model_ml_multigroup, start_test; atol = 1e-9)
@@ -206,11 +205,19 @@ end
206205
# GLS estimation
207206
############################################################################################
208207

209-
model_ls_g1 =
210-
Sem(specification = specification_g1, data = dat_g1, implied = RAMSymbolic, loss = SemWLS)
208+
model_ls_g1 = Sem(
209+
specification = specification_g1,
210+
data = dat_g1,
211+
implied = RAMSymbolic,
212+
loss = SemWLS,
213+
)
211214

212-
model_ls_g2 =
213-
Sem(specification = specification_g2, data = dat_g2, implied = RAMSymbolic, loss = SemWLS)
215+
model_ls_g2 = Sem(
216+
specification = specification_g2,
217+
data = dat_g2,
218+
implied = RAMSymbolic,
219+
loss = SemWLS,
220+
)
214221

215222
model_ls_multigroup = SemEnsemble(model_ls_g1, model_ls_g2; optimizer = semoptimizer)
216223

@@ -239,7 +246,7 @@ end
239246
atol = 1e-5,
240247
)
241248

242-
update_se_hessian!(partable, solution_ls)
249+
@suppress update_se_hessian!(partable, solution_ls)
243250
test_estimates(
244251
partable,
245252
solution_lav[:parameter_estimates_ls];
@@ -283,7 +290,7 @@ if !isnothing(specification_miss_g1)
283290
groups = [:Pasteur, :Grant_White],
284291
loss = SemFIML,
285292
observed = SemObservedMissing,
286-
meanstructure = true
293+
meanstructure = true,
287294
)
288295

289296
############################################################################################

0 commit comments

Comments
 (0)