Networks
A network measured with Open Graph: each node's degree, weight, PageRank, betweenness, community, component, k-core and cut point, paths between nodes, and the network in words; and Graph, Open Graph's graph made from the model's rows, with every graph algorithm as a table (Og, every function of Open Graph, is in the Open Graph reference: /docs/reference/open-graph/notebooks/). Graph and Og's methods are the way in; Og.Native, Open Graph's raw C interface, only when that is what you need: a mistake there can crash the notebook's process instead of showing an error, and OpenBI's agent uses it only when you ask for it.
Network
public sealed class Network
A network with its nodes measured (who matters by PageRank and betweenness, the communities, components, k-cores and cut points, and where to draw each node) and its edges. In a step, Network(...) measures one from a table of edges in the model, on the rows the notebook's user may see; Results.Save(name, network) keeps it as a version, whose nodes become a table of the model once it is in use. Shown under a step, it draws itself, coloured by community and sized by PageRank.
Constructors
Network(Table nodes, Table edges, bool directed = false)nodes: A row per node: Node and its measures (PageRank, Betweenness, Degree, Weight, Community, Component, Core, Cut point), and its place X, Y.edges: A row per edge: From, To and Weight.directed: Whether an edge goes from one node to the other only.
Fields
static readonly string[] Palette- The colors of communities 1, 2, 3 … (then grey): told apart by lightness too.
Properties
Table Nodes { get; }- A row per node: Node; PageRank and Betweenness; Degree and Weight; Community (1 is the largest), Component and Core; Cut point; and X, Y to draw it.
Table Edges { get; }- A row per edge: From, To and Weight (the rows that link the same two nodes, summed).
int Communities { get; }- How many communities (Louvain, on the edges' weights).
double Modularity { get; }- How well the communities separate: 0 not at all, 0.3 and above a clear structure, at most 1.
int CutPoints { get; }- How many nodes would split their part of the network if they went.
string? Dax { get; }- The OAX of the network's nodes (as it was measured).
Also: bool Directed { get; }.
Methods
Table Top(int n = 10)- The nodes that matter most (by PageRank).
IReadOnlyList<string> Explain(object? node = null)- The network in words: its size, communities and parts, the most central nodes, the bridges and the cut points. With a node: why it matters (its rank by PageRank and betweenness, its neighbours, the communities it links, what splits without it, its core).
Table Community(int number)- The nodes of one community (1 = the largest).
Table Path(object from, object to)- The shortest path between two nodes in hops, measured again on the model: a row per Step with its Node, and no rows if the nodes are not connected.
JsonObject ToDisplay(int maxNodes = 1500, int maxEdges = 6000)- What a view draws: the nodes that matter most (up to maxNodes, by PageRank) with their place, community and size, and the heaviest edges between them (up to maxEdges).
string ToSvg(int width = 560, int height = 360)- The network drawn as SVG (for notebooks opened elsewhere).
Also: string ToString().
Graph
public sealed class Graph : IDisposable
A graph of Open Graph's (og_t), in a notebook: made from a table of edges the model gives the step (Graph.FromTable(Dax(...), "From", "To", weight: "Weight") - the rows this user may see, row-level security applied), or by a generator (Graph.Famous("Zachary"), Graph.Ring(10)). Its nodes keep their names; every measure comes back as a table with a Node column (graph.PageRank(), graph.Betweenness(), graph.Communities(), graph.MaxFlow(a, b) ...). Every other function of Open Graph takes it too: Og.TransitiveClosure(graph), Og.Motifs... (Og: all 1,000 of them). Built from a table it is what OAX's NETWORK.* functions measure: the same nodes in the same order, rows between two nodes added up, the same seed. Disposable (its memory is native): `using var g = ...`, or the collector frees it.
Fields
const ulong DefaultSeed = 20261014- OpenBI's NETWORK.* seed: Louvain, Leiden, layouts and random graphs start from it unless told otherwise.
Properties
Og.GraphStruct* Pointer { get; }- The og_t this graph holds, for Open Graph's raw C interface when the user asks for it (in an unsafe block; valid while the graph is not disposed). A mistake there can crash the notebook's process instead of showing an error: Og's methods take the Graph itself.
IReadOnlyList<string> Names { get; set; }- Its nodes' names, by vertex id (built from a table: the values of the ends; otherwise "0", "1" ...).
double[]? Weights { get; set; }- Each edge's weight by edge id (from the table's weight column, or the number of rows it joined); null when unweighted.
IReadOnlyList<bool>? Sides { get; }- Each node's side in a two-sided graph (false: the left column's, true: the right's); null for a graph of one kind of node.
Also: long NodeCount { get; }, long EdgeCount { get; }, bool Directed { get; }.
Methods
static Graph FromEdges(long n, long[] edges, bool directed = false, double[]? weights = null, IEnumerable<string>? names = null)- A graph from its edges as pairs of vertex ids (0 .. n - 1): edges = [from0, to0, from1, to1, ...].
static Graph Famous(string name)- A famous graph by name (Zachary's karate club "Zachary", "Petersen", "Krackhardt_Kite", "Coxeter" ...: og_famous).
static Graph Ring(long n, bool directed = false)- A ring of n nodes (a cycle).
static Graph Star(long n, bool directed = false)- A star: node 0 in the middle, n - 1 around it.
static Graph Full(long n, bool directed = false)- The complete graph on n nodes.
static Graph Tree(long n, long children = 2)- A tree where each node has children nodes below it, n nodes in all.
static Graph Lattice(params long[] sizes)- A grid (a lattice) of the given sizes, e.g. Lattice(10, 10).
static Graph Random(long n, double p, ulong seed = 20261014, bool directed = false)- A random graph G(n, p): each pair of the n nodes linked with probability p (seeded: the same seed, the same graph).
static Graph ScaleFree(long n, long m = 2, ulong seed = 20261014)- A scale-free graph (Barabási-Albert): n nodes, each new one linking to m existing ones by their degree (seeded).
static Graph SmallWorld(long n, long nei = 2, double p = 0.1, ulong seed = 20261014)- A small world (Watts-Strogatz): a ring of n nodes each linked to its nei nearest on either side, each edge rewired with probability p (seeded).
Table Nodes()- A row per node: Node, Degree (its edges, both ways), Weight (their weights).
Table Edges()- A row per edge: From, To, Weight (1 without weights).
Table PageRank(double damping = 0.85, bool weighted = true)- PageRank of each node (Open Graph's PRPACK, as NETWORK.NODES: damping 0.85, the weights unless weighted: false).
Table Betweenness(bool weighted = false, bool normalized = false)- Betweenness: how many shortest paths between others run through each node (weighted: the weights as lengths).
Table Closeness(bool weighted = false, bool normalized = true)- Closeness: 1 / the average distance to the nodes it reaches (Open Graph's definition; normalized by default).
Table Harmonic(bool weighted = false, bool normalized = true)- Harmonic centrality: the sum of 1 / distance to every other node.
Table Eigenvector(bool weighted = true)- Eigenvector centrality (the largest is 1).
Table HubsAndAuthorities(bool weighted = true)- Hubs and authorities (Kleinberg; directed graphs): Hub, Authority.
Table Degree(Og.Neimode mode = Neimode.All)- Each node's degree (its edges, both ways unless mode says otherwise) and weight.
Table Cores()- Each node's core number: the highest k for which the node belongs to a subgraph whose nodes all have k or more neighbours within it.
Table Constraint()- Burt's constraint: how much a node's contacts are tied to each other (low: a broker between groups).
Table Centrality()- The usual measures together: Degree, Weight, PageRank, Betweenness, Closeness, Harmonic, Eigenvector, Core.
Table Communities(string method = "louvain", double resolution = 1, ulong seed = 20261014)- Communities: Node, Community (1 = the largest, as NETWORK.COMMUNITIES numbers them). method: louvain unless named, or leiden, labelprop, walktrap, infomap, fastgreedy, edgebetweenness; resolution for louvain and leiden; seeded (the same seed, the same groups: NETWORK.*'s by default). A directed graph is taken undirected, as NETWORK.* takes it.
double Modularity(Table communities, double resolution = 1)double Modularity(long[] membership, double resolution = 1)- The modularity of communities (a table with Node and Community, or a membership by vertex id): 0 none, 0.3 and above a clear structure.
Table Components(bool strong = false)- The parts of the graph not linked to each other: Node, Component (1 = the largest). strong: a directed graph's strongly connected parts.
Table CutPoints()- The cut points (articulation points): the nodes whose going splits their part of the graph. A row per cut point: Node.
Table Bridges()- The bridges: the edges whose going splits their part of the graph. From, To.
Table ShortestPath(object from, object to, bool weighted = false)- A shortest path from one node to another (weighted: the weights as lengths): a row per step (Step, Node), none when the two are not linked.
Table Distances(object from, bool weighted = false)- The distance from a node to every node (in edges, or by the weights as lengths): Node, Distance (infinite when out of reach).
double Diameter(bool weighted = false)- The longest shortest path (in edges, or by the weights as lengths).
double AveragePathLength(bool weighted = false)- The average length of the shortest paths between the pairs that reach each other.
(double Value, Table Edges) MaxFlow(object source, object target)- The maximum flow from source to target, the weights as capacities (1 each without): its value, and a row per edge with From, To, Capacity, Flow and Cut (whether the edge belongs to a minimum cut: what to strengthen, or what stops everything).
(double Value, Table Cut) MinCut(object? source = null, object? target = null)- A minimum cut: the least total weight (1 each without weights) whose removal splits the graph - between source and target when both are given, else anywhere. Its value, and the edges cut (From, To, Weight).
Table Cliques(int min = 3, int max = 0, int limit = 10000)- The maximal cliques (groups where everyone is linked to everyone, none inside a larger one) of at least min nodes: Clique, Node.
Table LargestCliques()- The largest cliques: Clique, Node.
Table Motifs(int size = 3)- Motifs: how often each small pattern of size nodes (3 or 4; directed 3-4, undirected 3-6) occurs as an induced subgraph: Class (Open Graph's isoclass number), Count. Unconnected patterns are counted NaN, as the reference has them.
Table Triads()- The triad census of a directed graph (the 16 kinds of three nodes, 003 to 300): Triad, Count.
bool IsIsomorphic(Graph other)- Whether the two graphs are the same up to the names of their nodes.
long CountPattern(Graph pattern)- How many times a pattern occurs in the graph (subgraph isomorphisms: VF2), each mapping counted.
Table Similar(string method = "jaccard", int top = 100, IEnumerable<object>? among = null)- Pairs of nodes alike by the neighbours they share: A, B, Similarity, highest first (the top pairs, at most top). method: jaccard (shared / together), dice, adamic (Adamic-Adar: shared neighbours weighted by 1 / log of their degree). For a bipartite graph (customers and products) it compares customers by the products they share.
Table PredictLinks(int top = 20, ulong seed = 20261014, int samples = 1000)- Links likely missing (link prediction): a hierarchical random graph is fitted to this graph (Clauset, Moore and Newman), and its From, To, Probability for the pairs not linked yet come most likely first (top). Seeded.
Table Sensitivity(object node, string measure = "pagerank", int top = 20)- How a node's centrality moves when each edge's weight moves (Open Graph's exact Jacobian): the edges that move it most, From, To, Change (d measure / d weight). measure: pagerank, eigenvector, strength, betweenness, closeness, harmonic. NETWORK.SENSITIVITY's numbers.
Table Layout(string method = "fr", ulong seed = 20261014)- Coordinates for drawing the graph, a row per node with X and Y. method: fr (Fruchterman-Reingold, as NETWORK.LAYOUT), kk (Kamada-Kawai), drl, circle. Seeded.
Network ToNetwork()- The graph as a Network (which draws itself under a step): its nodes measured as NETWORK.NODES measures them (degree and weight, PageRank, betweenness, community, component, core, whether a cut point) and placed as NETWORK.LAYOUT places them.
Table Embed(int dimensions = 2, string matrix = "adjacency")- Coordinates for each node (a spectral embedding): Node, D1 ... Dk, for clustering (KMEANS, k-means in a step) or a map of the graph. matrix: adjacency (the default, as NETWORK.EMBED: the adjacency matrix, its diagonal a node's strength divided by one less than the nodes, the largest eigenvalues, scaled) or laplacian (D^-1/2 A D^-1/2, its largest: the normalised Laplacian's smallest). Taken undirected; each dimension's largest coordinate positive.
SirResult Sir(double beta, double gamma, int runs = 100, IEnumerable<object>? seeds = null)- An epidemic (SIR) along the graph's edges, either way: a sick node passes it to a healthy neighbour at the rate beta, and gets well at the rate gamma; runs runs from the seeds (nodes; none: one node at random each run), the same every time (NETWORK.SIR's own seed, 20261018). Its curve over time and each node's chance of being reached, as NETWORK.SIR and NETWORK.SIR.NODES give them for the same rows.
static Graph FromTwoSided(Table rows, string left, string right, string? weight = null)- A two-sided graph (bipartite) from a table: each row links a node of the left column (customers) to one of the right column (products) - the two sides' values are nodes apart even when equal - with an optional weight; a pair's rows added up, as FromTable adds them. The left side's nodes come first, each side in the order of its values. Its Sides say each node's side; Project(side) gives one side linked by what they share, Matching() the best pairs.
long Id(object node, string side)- A node's vertex id on one side of a two-sided graph (side: the left or the right column's name, or "left", "right").
Graph Project(string side)- One side of a two-sided graph linked by what they share (a projection): two customers linked when they bought a product in common, the edge's weight the number of products they share. side: the left or the right column's name.
(long Size, double Weight, Table Pairs) Matching(bool weighted = false)- The best pairs of a two-sided graph (a bipartite matching: each node in one pair at most): the most pairs, or with weighted the largest total weight. Its size, its weight and the pairs (the two sides' columns and Weight).
static Table CompareCommunities(Table first, Table second, string node = "Node", string community = "Community")- How alike two partitions of nodes are (communities of two snapshots, or of two methods): each a table with a node and a community column (Node, Community: what Communities(), NETWORK.NODES and NETWORK.COMMUNITIES give), compared over the nodes in both. One row: how many nodes both have (Nodes) and how many only one (Only in first, Only in second), the communities each has (Communities in first and in second), NMI and ARI (1 the same), VI and Split-join (0 the same), Rand - NETWORK.COMPARE's.
static Table MatchCommunities(Table current, Table reference, string node = "Node", string community = "Community")- A partition's communities numbered as a reference's (snapshots over time: last month's community 3 is still 3), so colours and names carry over: each community takes the reference's number it shares the most nodes with (the best matching over all of them); one without a match gets a number above any of the reference's, bigger communities the lower ones. Node, Community (the new number), Original (as given), Shared (the nodes it shares with its match) - NETWORK.MATCH's.
static Graph FromTable(Table edges, string from = "From", string to = "To", string? weight = null, bool directed = false, bool merge = true, NodeOrder order = NodeOrder.ByValue)- A graph from a table of edges: a row per edge, its two ends in the columns from and to (text, numbers, dates or TRUE/FALSE: equal values are one node, text compared as OAX compares it, "Carol" and "carol" alike) and, optionally, a weight. merge: true (the default) builds it as OAX's NETWORK.* functions do - the nodes numbered by their values (order: NodeOrder.ByValue: rows given in another order still build an identical graph), a pair's rows added up into one edge (undirected: either way round) and the edges sorted by their two ends' numbers, rows joining a node to itself, without an end, or with a weight not above 0 left out (their ends are still nodes); each edge's weight is its rows' total (their count without a weight column). merge: false keeps every row as an edge (parallel edges, self-loops, any weight but a missing one). NodeOrder.AsTheyCome numbers the nodes as they first appear, as earlier versions of NETWORK.* did.
long Id(object node)- A node's vertex id: by its value (a number, a text in any case, a date, TRUE/FALSE) for a graph made from a table, else by its name or its id.
static Table Rollup(Table links, string from, string to, string? weight, Table starts, string start, string? amount = null, string direction = "out", string loops = "refuse", bool byStart = false)- OAX's NETWORK.ROLLUP in a notebook, with the same answers to the last bit (Open Graph's og_rollup): each start's amount travels along every path that leaves it, multiplied by the weight of each link on the way, and whatever reaches a node is summed. links holds one row per link, its two ends in the columns from and to and its weight, a number of either sign (negative for a by-product). With weight null every row weighs 1; a row whose weight is missing makes no link. Rows that join the same two nodes in the same direction are summed exactly, and a row whose two ends are one node is a loop on it. starts holds one row per start, its node in the column start and, if amount is given, its amount there (each start counts 1 otherwise; a row whose start or amount is missing is skipped). A start without links still gets its own row. direction "out" (the default) runs with the links, as when parts are exploded from products or an owner's effective shares are traced; "in" runs against them, as when costs climb from parts into products or a company's ultimate owners are sought. loops "refuse" (the default) turns any loop into an error naming it; "solve" solves loops exactly (cross-holdings, reciprocal cost allocation, input-output tables), and a loop that doesn't converge is an error. byStart gives a row for each start and each node it reaches. The nodes are numbered by value, the links' ends and the starts together, as NETWORK.* numbers them. Returns a table of Start (with byStart), Node, Level and Total, ordered by start, then level, then node. Level is the greatest number of links between a start and the node, a loop counting as one step; inside a loop it is missing (NaN).
Also: string ToString(), void Dispose().
NodeOrder
public enum NodeOrder
How Graph.FromTable numbers a graph's nodes. ByValue (the default, as OAX's NETWORK.* functions number them): by their values - numbers first, the smallest first; then text by its characters (code points), case aside; then dates, the earliest first; then FALSE and TRUE - so rows given in another order still build an identical graph and answers. AsTheyCome: in the order they first appear (From, then To, row by row), as earlier versions of NETWORK.* numbered them.
Values
Its values: ByValue = 0, AsTheyCome = 1.
SirResult
public sealed record SirResult(
Table Curve,
Table Nodes,
double ReachedShare,
int Runs)
What Graph.Sir gives: Curve, the runs' mean on a grid of times (columns Time, Susceptible, Infected, Recovered, then Infected low and Infected high - where 10% and 90% of the runs were - and Reached share), and Nodes, one row a node (Node; Reached, how often of all runs the node fell ill; Mean time, when it did on average; Seed, whether a run started there). The same numbers as NETWORK.SIR and NETWORK.SIR.NODES.
Properties
Its properties: Table Curve { get; init; }, Table Nodes { get; init; }, double ReachedShare { get; init; }, int Runs { get; init; }.
OpenGraphException
public sealed class OpenGraphException : Exception
What Open Graph reported when a function failed: its error code (Og.Error), the function's C name and its own words (og_abi_error_last), e.g. "Open Graph's og_neighbors: Vertex 9 is not in the graph. (OG_EINVVID)".
Constructors
OpenGraphException(Og.Error code, string function, string? reason)- What Open Graph reported when a function failed: its error code (Og.Error), the function's C name and its own words (og_abi_error_last), e.g. "Open Graph's og_neighbors: Vertex 9 is not in the graph. (OG_EINVVID)".
Properties
Og.Error Code { get; }- The error code (Og.Error.Einval, Og.Error.Einvvid ...).
string Function { get; }- The C name of the function that failed (og_pagerank).
string? Reason { get; }- Open Graph's own reason, when it gave one.
SparseMatrix
public sealed record SparseMatrix(
long Rows,
long Columns,
long[] Row,
long[] Column,
double[] Values)
A sparse matrix as triplets: Rows x Columns, entry k at (Row[k], Column[k]) with Values[k] (og_sparsemat_t in C).
Properties
Its properties: long Rows { get; init; }, long Columns { get; init; }, long[] Row { get; init; }, long[] Column { get; init; }, double[] Values { get; init; }.
Methods
double[,] ToDense()- The matrix dense (rows x columns).
HrgModel
public sealed class HrgModel : IDisposable
A hierarchical random graph (og_hrg_t): a dendrogram fitted to a graph, for link prediction (Og.HrgFit, Og.HrgPredict).
Constructors
HrgModel(long n = 0)- An empty model of n vertices (og_hrg_init), for Og.HrgFit to fit.
Properties
long Size { get; }- Its number of vertices (og_hrg_size).
Methods
Its methods: void Dispose().
OgEntry
public sealed record OgEntry(
string Name,
string Area,
string Kind,
string Summary,
string Status,
string? CSharp,
string? Why)
An entry of Open Graph's documentation and where C# reaches it (tools/gen_open_graph_binding.py's entries.json).
Properties
string Name { get; init; }- Its C name (og_pagerank, og_vector_t, OG_ABI_VERSION).
string Area { get; init; }- Its area of the library (centrality, paths, community1 ...).
string Kind { get; init; }- function, type, macro or constant.
string Summary { get; init; }- What it does, in a sentence.
string Status { get; init; }- safe (a method of Og), native (only in Og.Native, as C declares it), type, constant, macro, data, c-only.
string? CSharp { get; init; }- Its C# name, when it has one.
string? Why { get; init; }- For a c-only entry: why, and what to use instead.