11"""
22$(TYPEDSIGNATURES)
33
4- Parse the problem instance found in `uai_filepath ` defined in the UAI model
4+ Parse the problem instance found in `model_filepath ` defined in the UAI model
55format.
66
77The UAI file formats are defined in:
88https://personal.utdallas.edu/~vibhav.gogate/uai16-evaluation/uaiformat.html
99"""
10- function read_uai_file (uai_filepath ; factor_eltype = Float64)
10+ function read_model_file (model_filepath ; factor_eltype = Float64)
1111 # Read the uai file into an array of lines
12- str = open (uai_filepath ) do file
12+ str = open (model_filepath ) do file
1313 read (file, String)
1414 end
15- return read_uai_string (str; factor_eltype)
15+ return read_model_string (str; factor_eltype)
1616end
1717
18- function read_uai_string (str; factor_eltype = Float64)
18+ function read_model_string (str; factor_eltype = Float64)
1919 rawlines = split (str, " \n " )
2020 # Filter out empty lines
2121 lines = filter (! isempty, rawlines)
6565"""
6666$(TYPEDSIGNATURES)
6767
68- Return the observed variables and values in `uai_evid_filepath `. If the passed
68+ Return the observed variables and values in `evidence_filepath `. If the passed
6969file path is an empty string, return empty vectors.
7070
7171The UAI file formats are defined in:
7272https://personal.utdallas.edu/~vibhav.gogate/uai16-evaluation/uaiformat.html
7373"""
74- function read_uai_evid_file (uai_evid_filepath :: AbstractString )
75- if isempty (uai_evid_filepath )
74+ function read_evidence_file (evidence_filepath :: AbstractString )
75+ if isempty (evidence_filepath )
7676 # No evidence
7777 return Int64[], Int64[]
7878 else
7979 # Read the last line of the uai evid file
80- line = open (uai_evid_filepath ) do file
80+ line = open (evidence_filepath ) do file
8181 readlines (file)
8282 end |> last
8383
@@ -104,10 +104,10 @@ as in the model
104104The UAI file formats are defined in:
105105https://personal.utdallas.edu/~vibhav.gogate/uai16-evaluation/uaiformat.html
106106"""
107- function read_uai_mar_file (uai_mar_filepath :: AbstractString ; factor_eltype = Float64)
107+ function read_solution_file (solution_filepath :: AbstractString ; factor_eltype = Float64)
108108
109109 # Read the uai mar file into an array of lines
110- rawlines = open (uai_mar_filepath ) do file
110+ rawlines = open (solution_filepath ) do file
111111 readlines (file)
112112 end
113113
@@ -175,31 +175,24 @@ end
175175"""
176176$(TYPEDSIGNATURES)
177177
178- Read a UAI problem from an artifact .
178+ Read a UAI problem instance from a file .
179179"""
180- function read_uai_problem (problem:: AbstractString ; eltype= Float64):: UAIInstance
181- uai_filepath = joinpath (artifact " MAR_prob" , problem * " .uai" )
182- uai_evid_filepath = joinpath (artifact " MAR_prob" , problem * " .uai.evid" )
183- uai_mar_filepath = joinpath (artifact " MAR_sol" , problem * " .uai.MAR" )
184- return uai_problem_from_file (uai_filepath; uai_evid_filepath, uai_mar_filepath, eltype)
185- end
186-
187- """
188- $(TYPEDSIGNATURES)
189-
190- Read a UAI problem from a file.
191- """
192- function uai_problem_from_file (uai_filepath:: String ; uai_evid_filepath= " " , uai_mar_filepath= " " , eltype= Float64):: UAIInstance
193- nvars, cards, ncliques, factors = read_uai_file (uai_filepath; factor_eltype = eltype)
194- obsvars, obsvals = read_uai_evid_file (uai_evid_filepath)
195- reference_marginals = isempty (uai_mar_filepath) ? Vector{eltype}[] : read_uai_mar_file (uai_mar_filepath)
180+ function read_instance (
181+ model_filepath:: AbstractString ;
182+ evidence_filepath:: AbstractString = " " ,
183+ solution_filepath:: AbstractString = " " ,
184+ eltype = Float64
185+ ):: UAIInstance
186+ nvars, cards, ncliques, factors = read_model_file (model_filepath; factor_eltype = eltype)
187+ obsvars, obsvals = read_evidence_file (evidence_filepath)
188+ reference_marginals = isempty (solution_filepath) ? Vector{eltype}[] : read_solution_file (solution_filepath)
196189 return UAIInstance (nvars, ncliques, cards, factors, obsvars, obsvals, reference_marginals)
197190end
198191
199- function uai_problem_from_string (uai:: String ; eltype= Float64):: UAIInstance
200- nvars, cards, ncliques, factors = read_uai_string (uai; factor_eltype = eltype)
192+ function read_instance_from_string (uai:: AbstractString ; eltype = Float64):: UAIInstance
193+ nvars, cards, ncliques, factors = read_model_string (uai; factor_eltype = eltype)
201194 return UAIInstance (nvars, ncliques, cards, factors, Int[], Int[], Vector{eltype}[])
202195end
203196
204197# patch to get content by broadcasting into array, while keep array size unchanged.
205- broadcasted_content (x) = asarray (content .(x), x)
198+ broadcasted_content (x) = asarray (content .(x), x)
0 commit comments