Skip to content

Commit 0ef4c8d

Browse files
committed
formatting fixes
1 parent df5ea75 commit 0ef4c8d

File tree

10 files changed

+55
-69
lines changed

10 files changed

+55
-69
lines changed

src/frontend/fit/fitmeasures/chi2.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Return the χ² value.
1818
(fit.minimum - logdet(obs_cov(observed(model))) - nobserved_vars(observed(model)))
1919

2020
# bollen, p. 115, only correct for GLS weight matrix
21-
χ²(lossfun::SemWLS, fit::SemFit, model::AbstractSemSingle) = (nsamples(fit) - 1) * fit.minimum
21+
χ²(lossfun::SemWLS, fit::SemFit, model::AbstractSemSingle) =
22+
(nsamples(fit) - 1) * fit.minimum
2223

2324
# FIML
2425
function χ²(lossfun::SemFIML, fit::SemFit, model::AbstractSemSingle)

src/frontend/fit/summary.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ function sem_summary(
160160

161161
var_array = reduce(
162162
hcat,
163-
check_round(partable.columns[c][var_indices]; digits = digits) for
164-
c in var_columns
163+
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns
165164
)
166165
var_columns[2] = Symbol("")
167166

src/frontend/specification/ParameterTable.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ sort_vars(partable::ParameterTable) = sort_vars!(deepcopy(partable))
235235
# add a row --------------------------------------------------------------------------------
236236

237237
function Base.push!(partable::ParameterTable, d::Union{AbstractDict{Symbol}, NamedTuple})
238-
issetequal(keys(partable.columns), keys(d)) ||
239-
throw(ArgumentError("The new row needs to have the same keys as the columns of the parameter table."))
238+
issetequal(keys(partable.columns), keys(d)) || throw(
239+
ArgumentError(
240+
"The new row needs to have the same keys as the columns of the parameter table.",
241+
),
242+
)
240243
for (key, val) in pairs(d)
241244
push!(partable.columns[key], val)
242245
end

src/frontend/specification/RAMMatrices.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ function observed_var_indices(ram::RAMMatrices)
3434
return obs_inds
3535
end
3636

37-
latent_var_indices(ram::RAMMatrices) =
38-
[i for i in axes(ram.F, 2) if islatent_var(ram, i)]
37+
latent_var_indices(ram::RAMMatrices) = [i for i in axes(ram.F, 2) if islatent_var(ram, i)]
3938

4039
# observed variables in the order as they appear in ram.F rows
4140
function observed_vars(ram::RAMMatrices)
@@ -145,8 +144,10 @@ function RAMMatrices(
145144
@assert length(partable.sorted_vars) == nvars(partable)
146145
vars_sorted = copy(partable.sorted_vars)
147146
else
148-
vars_sorted = [partable.observed_vars
149-
partable.latent_vars]
147+
vars_sorted = [
148+
partable.observed_vars
149+
partable.latent_vars
150+
]
150151
end
151152

152153
# indices of the vars (A/S/M rows or columns)
@@ -228,13 +229,20 @@ function RAMMatrices(
228229
sort!(M_consts, by = first)
229230
end
230231

231-
return RAMMatrices(ParamsMatrix{T}(A_inds, A_consts, (n_vars, n_vars)),
232-
ParamsMatrix{T}(S_inds, S_consts, (n_vars, n_vars)),
233-
sparse(1:n_observed,
234-
[vars_index[var] for var in partable.observed_vars],
235-
ones(T, n_observed), n_observed, n_vars),
236-
!isnothing(M_inds) ? ParamsVector{T}(M_inds, M_consts, (n_vars,)) : nothing,
237-
params, vars_sorted)
232+
return RAMMatrices(
233+
ParamsMatrix{T}(A_inds, A_consts, (n_vars, n_vars)),
234+
ParamsMatrix{T}(S_inds, S_consts, (n_vars, n_vars)),
235+
sparse(
236+
1:n_observed,
237+
[vars_index[var] for var in partable.observed_vars],
238+
ones(T, n_observed),
239+
n_observed,
240+
n_vars,
241+
),
242+
!isnothing(M_inds) ? ParamsVector{T}(M_inds, M_consts, (n_vars,)) : nothing,
243+
params,
244+
vars_sorted,
245+
)
238246
end
239247

240248
Base.convert(
@@ -372,10 +380,7 @@ function append_rows!(
372380
arr_ix = arr_ixs[arr.linear_indices[j]]
373381
skip_symmetric && (arr_ix visited_indices) && continue
374382

375-
push!(
376-
partable,
377-
partable_row(par, arr_ix, arr_name, varnames, free = true),
378-
)
383+
push!(partable, partable_row(par, arr_ix, arr_name, varnames, free = true))
379384
if skip_symmetric
380385
# mark index and its symmetric as visited
381386
push!(visited_indices, arr_ix)

src/frontend/specification/documentation.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
params(spec::SemSpecification) = spec.params
22

33
# observed + latent
4-
vars(spec::SemSpecification) =
5-
error("vars(spec::$(typeof(spec))) is not implemented")
4+
vars(spec::SemSpecification) = error("vars(spec::$(typeof(spec))) is not implemented")
65
observed_vars(spec::SemSpecification) =
76
error("observed_vars(spec::$(typeof(spec))) is not implemented")
87
latent_vars(spec::SemSpecification) =

src/imply/RAM/generic.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ mutable struct RAM{MS, A1, A2, A3, A4, A5, A6, V2, M1, M2, M3, M4, S1, S2, S3} <
8585
∇S::S2
8686
∇M::S3
8787

88-
RAM{MS}(args...) where {MS <: MeanStructure} =
89-
new{MS, map(typeof, args)...}(args...)
88+
RAM{MS}(args...) where {MS <: MeanStructure} = new{MS, map(typeof, args)...}(args...)
9089
end
9190

9291
############################################################################################
@@ -134,7 +133,11 @@ function RAM(;
134133
# μ
135134
if meanstructure
136135
MS = HasMeanStructure
137-
!isnothing(ram_matrices.M) || throw(ArgumentError("You set `meanstructure = true`, but your model specification contains no mean parameters."))
136+
!isnothing(ram_matrices.M) || throw(
137+
ArgumentError(
138+
"You set `meanstructure = true`, but your model specification contains no mean parameters.",
139+
),
140+
)
138141
M_pre = materialize(ram_matrices.M, rand_params)
139142
∇M = gradient_required ? sparse_gradient(ram_matrices.M) : nothing
140143
μ = zeros(n_obs)
@@ -167,12 +170,7 @@ end
167170
### methods
168171
############################################################################################
169172

170-
function update!(
171-
targets::EvaluationTargets,
172-
imply::RAM,
173-
model::AbstractSemSingle,
174-
params,
175-
)
173+
function update!(targets::EvaluationTargets, imply::RAM, model::AbstractSemSingle, params)
176174
materialize!(imply.A, imply.ram_matrices.A, params)
177175
materialize!(imply.S, imply.ram_matrices.S, params)
178176
if !isnothing(imply.M)

src/imply/abstract.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nparams(imply::SemImply) = nparams(imply.ram_matrices)
1212

1313
function check_acyclic(A::AbstractMatrix)
1414
# check if the model is acyclic
15-
acyclic = isone(det(I-A))
15+
acyclic = isone(det(I - A))
1616

1717
# check if A is lower or upper triangular
1818
if istril(A)
@@ -23,8 +23,9 @@ function check_acyclic(A::AbstractMatrix)
2323
return UpperTriangular(A)
2424
else
2525
if acyclic
26-
@info "Your model is acyclic, specifying the A Matrix as either Upper or Lower Triangular can have great performance benefits.\n" maxlog=1
26+
@info "Your model is acyclic, specifying the A Matrix as either Upper or Lower Triangular can have great performance benefits.\n" maxlog =
27+
1
2728
end
2829
return A
2930
end
30-
end
31+
end

src/observed/covariance.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ function SemObservedCovariance(;
3333
isnothing(obs_mean) || (obs_mean = obs_mean[obs2spec_perm])
3434
end
3535

36-
return SemObservedData(nothing, Symmetric(obs_cov), obs_mean, size(obs_cov, 1), nsamples)
36+
return SemObservedData(
37+
nothing,
38+
Symmetric(obs_cov),
39+
obs_mean,
40+
size(obs_cov, 1),
41+
nsamples,
42+
)
3743
end

test/examples/political_democracy/by_parts.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ model_ridge = Sem(observed, imply_ram, SemLoss(ml, ridge), optimizer_obj)
4040

4141
model_constant = Sem(observed, imply_ram, SemLoss(ml, constant), optimizer_obj)
4242

43-
model_ml_weighted =
44-
Sem(observed, imply_ram, SemLoss(ml; loss_weights = [nsamples(model_ml)]), optimizer_obj)
43+
model_ml_weighted = Sem(
44+
observed,
45+
imply_ram,
46+
SemLoss(ml; loss_weights = [nsamples(model_ml)]),
47+
optimizer_obj,
48+
)
4549

4650
############################################################################################
4751
### test gradients

test/examples/political_democracy/political_democracy.jl

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,7 @@ spec = RAMMatrices(;
7878
S = S,
7979
F = F,
8080
params = x,
81-
vars = [
82-
:x1,
83-
:x2,
84-
:x3,
85-
:y1,
86-
:y2,
87-
:y3,
88-
:y4,
89-
:y5,
90-
:y6,
91-
:y7,
92-
:y8,
93-
:ind60,
94-
:dem60,
95-
:dem65,
96-
],
81+
vars = [:x1, :x2, :x3, :y1, :y2, :y3, :y4, :y5, :y6, :y7, :y8, :ind60, :dem60, :dem65],
9782
)
9883

9984
partable = ParameterTable(spec)
@@ -110,22 +95,7 @@ spec_mean = RAMMatrices(;
11095
F = F,
11196
M = M,
11297
params = [SEM.params(spec); Symbol.("x", string.(32:38))],
113-
vars = [
114-
:x1,
115-
:x2,
116-
:x3,
117-
:y1,
118-
:y2,
119-
:y3,
120-
:y4,
121-
:y5,
122-
:y6,
123-
:y7,
124-
:y8,
125-
:ind60,
126-
:dem60,
127-
:dem65,
128-
],
98+
vars = [:x1, :x2, :x3, :y1, :y2, :y3, :y4, :y5, :y6, :y7, :y8, :ind60, :dem60, :dem65],
12999
)
130100

131101
partable_mean = ParameterTable(spec_mean)

0 commit comments

Comments
 (0)