Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we add another parameter representing the hyperedge weight? #2

Open
spagnuolocarmine opened this issue Jan 18, 2019 · 5 comments

Comments

@spagnuolocarmine
Copy link
Collaborator

spagnuolocarmine commented Jan 18, 2019

With more details, that means that the hyperedges (HE) can (also) have a weight associated to an HE. Currently each vertices in an HE have a particular weight.
For this reason is not clear which is the total weight of an HE.

We notice that this new value can also be mapped in the BipartiteView of the HyperGraph (H), as the weight of the node that represents the HE. Obviously this can be achieved (in more generic format) defining a method/function to compute the weight of each HE.

@bkamins
Copy link
Collaborator

bkamins commented Jan 18, 2019

The default was that the weight of the HE is a sum of weights of vertices in this HE. This information can be cached if we would think that it would be good to have it precomputed.

However, if we think that these two things should be decoupled it should be easy to add it.

@pszufe what use-cases for different kinds weights do you see?

@pszufe
Copy link
Owner

pszufe commented Jan 22, 2019

I think that Carmine's proposal is valid for several cases where messages are being exchanged wihin a network. Here is a sample use case scenario for weighted HEs:

Consider a hypergraph where edges represent agents acting on some market (for example making buying and selling decisions).
Consider a hyperedge representing a message (for example, a market report) that was distributed to a set of users.
Vertex-hyperedge weights represent the influence a message has on each particular market agent.
The hyperedge weight represents message sentiment (positive, negative).

The above scenario represents a group of models where on one hand the hypergraph is the most natural representation and on the other hand you need the hyperedge weights.

@bkamins
Copy link
Collaborator

bkamins commented Jan 22, 2019

I would say that positive/negative is an attribute of a hyperedge not a weight. This is then a general question do we want to equip hyperedges and vertices with arbitrary metadata?

Regarding the weight of a hyperedge - I am OK to add it as it does not cost much (but still it would be good to have some use cases in mind).

@pszufe
Copy link
Owner

pszufe commented Jan 24, 2019

It seems the most reasonable solution is to make it possible to attach any values to hyperedges.
Additionally, we have exactly the same situation with vertices - it would also make sense to add some information to them.

Currently we have the following constructor for a Hypergraph:

Hypergraph{T}(n, k) where {T<:Real}

I propose to add the following two constructors

Hypergraph{T, V}(n, k) where {T<:Real}
Hypergraph{T, V, E}(n, k) where {T<:Real}

where

  • T is the type of weights representing hyperedge - vertex relation (and this is available via the Array API)
  • V is the type of information stored at a vertex (note that it can be any Julia type)
  • E is the type of information stored at a hyperedge (note that it can be any Julia type)

In this way we allow any weight system but also other types of information to be stored at hyperedges and vertices.

This means that our main data structure is going to look like this:

struct Hypergraph{T,V,E} <: AbstractMatrix{Union{T, Nothing}}
    v2he::Vector{Dict{Int,T}}
    he2v::Vector{Dict{Int,T}}
    vs::Vector{V}
    hes::Vector{E}
    Hypergraph{T}(n, k) where {T<:Real} =
        new{T,Nothing,Nothing}([Dict{Int,T}() for i in 1:n], [Dict{Int,T}() for i in 1:k], Vector{Nothing}(nothing, n), Vector{Nothing}(nothing, k))
    Hypergraph{T,V}(n, k) where {T<:Real, V} =
        new{T,V,Nothing}([Dict{Int,T}() for i in 1:n], [Dict{Int,T}() for i in 1:k],Vector{V}(undef, n),Vector{Nothing}(nothing, k))
    Hypergraph{T,V,E}(n, k) where {T<:Real, V, E} =
        new{T,V,E}([Dict{Int,T}() for i in 1:n], [Dict{Int,T}() for i in 1:k],Vector{V}(undef,n),Vector{E}(undef,k))    
end

@spagnuolocarmine is this something you had in mind?

@spagnuolocarmine
Copy link
Collaborator Author

I think that is fine for more generic data structure. Moreover, what we can do in several H views (such as bipartite or 2 section) is provide a constructor of the view that takes as argument a weight-function (defined to be able to compute the weight of an HE given as function argument), in this way we allow also to define the weight of an HE not only at struct build time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants