I'm using the SimpleHypergraphs.jl library and trying to construct a hypergraph from a text file such as a csv.
For example, I'd like to load a hypergraph from a csv file like this:
0.0, 7.0, 0.0, 0.0
1.3, 2.8, 4.5, 0.0
0.0, 1.3, 3.1, 4.2
1.2, 0.0, 5.6, 5.0
using SimpleHypergraphs
using CSV
df = CSV.read("edge_weights.csv", DataFrame)
m = Matrix{Float64}(df)
h = Hypergraph(m)
I receive the following error: "ERROR: MethodError: no method matching Hypergraph(::Matrix{Float64})"
I'm new to Julia and I would really appreciate an example of how I could accomplish this. Thanks!
The matrix that is passed as a
Hypergraph
constructor should have elements of typeUnion{Nothing, T}
whereT
is some numeric type (e.g.Matrix{Union{Float64,Nothing}}
rather than just be aMatrix{Float64}
.In SimpleHypegraphs.jl, we use
nothing
(rather than0
) to represent that a vertex does not belong to a hyperedge since in many hypergraph algorithms/applications it is possible for a vertex to belong to a hyper-edge with a zero weight.Hence you could read your file with the following code (for reproducibility I put the file content into a text variable):
This matrix can now easily be used as a
Hypergraph
constructor.However, this might be not exactly what you need because zeros (
0.0
) represent a situation where vertices belong to hyperedges with zero weights:Hence, you might actually want to convert zeros to
nothing
s to represent situation where the vertices do not belong to hyperedges:Now you get what you wanted: