8

I am working with random graphs a lot. It's quite easy to describe random graph using, adjacency matrix or just a list of edges. However I am thinking that I might benefit from describing random graphs with something similar to graph distributions already presented in Mathematica.

Here is the question:

  • how to implement a custom distribution?
  • does it makes sense at all to do such a thing?
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Alexander
  • 305
  • 1
  • 4

2 Answers2

5

tl;dr Currently, this part of Mathematica is not designed to be extensible.


A few months ago I looked into how GraphPropertyDistribution and related functions are implemented, and whether they are extensible. As you may know, there are some limited ways to read the definition of some built-in symbols.

My goal was to integrate IGraph/M with functions such as RandomGraph, GraphPropertyDistribution, etc. I expected that at least automated numerical computation with graph property distribution may work, and I hoped that I would be able to add symbolic definitions for special cases.

What I found is this:

  • There are internal checks on what is a proper graph distribution or graph property. Therefore it is not sufficient to add on extra definitions to top-level symbols. It would be necessary to "register" new distributions/properties internally.

  • Much of the internal implementation of this functionality is not only ReadProtected, but also Locked (and therefore unmodifiable).

Conclusion: I do not think it is worth bothering (or safe) to extend these symbols.

Instead, define your own functions for each sub-functionality that you need. For example, IGraph/M has functions for sampling from certain random graph models (e.g. IGDegreeSequenceGame). These do only sampling and nothing else.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
1

With regard to custom distribution, see something about ProbabilityDistribution in the documentation.

Here is an example of what can be done:

pd = ProbabilityDistribution[Sqrt[2]/Pi/(1 + x^4), {x, -Infinity, Infinity}]; 
Plot[PDF[pd, x], {x, -4, 4}, Filling -> Axis]

plot

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
LCarvalho
  • 9,233
  • 4
  • 40
  • 96
  • 7
    The OP is talking about implementing custom distributions on graphs (e.g. BernoulliGraphDistribution[] or PriceGraphDistribution[]) and not probability distributions proper. I'm not sure why this has upvotes... – J. M.'s missing motivation Aug 05 '17 at 12:57