Skip to content

Commit 18e1005

Browse files
committed
zero r/c check in weighting
1 parent d49a17c commit 18e1005

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Weighting.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,30 @@ function generate_weights(
9090
initialise_target_dataframe :: Function = initialise_target_dataframe_scotland_2022,
9191
make_target_row! :: Function = make_target_row_scotland_2022! ) :: Vector
9292

93+
function check_data( d, nrows, ncols )
94+
zrows = Int[]
95+
for r in 1:nrows
96+
if sum( d[r,:] ) == 0
97+
push!(zrows,r)
98+
end
99+
end
100+
zcols = Int[]
101+
@assert length(zrows) == 0 "data has all-zero rows for rows $(zrows)"
102+
for c in 1:ncols
103+
if sum( d[:,c] ) == 0
104+
push!(zcols,c)
105+
end
106+
end
107+
@assert length(zcols) == 0 "data has all-zero cols $(zcols)"
108+
end
109+
93110
data :: Matrix = make_target_dataset(
94111
nhhlds,
95112
initialise_target_dataframe,
96113
make_target_row! )
97114
# println( data )
98-
nrows = size( data )[1]
99-
ncols = size( data )[2]
115+
nrows, ncols = size( data )
116+
check_data( data, nrows, ncols )
100117
## FIXME parameterise this
101118
initial_weights = ones(nhhlds)*household_total/nhhlds
102119
println( "initial_weights $(initial_weights[1])")

0 commit comments

Comments
 (0)