Skip to content

Commit ea0c6f5

Browse files
committed
(docs) wrote docs for the new simplex_graph_limited function
1 parent 5c549cb commit ea0c6f5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

nimplex.nim

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,18 @@ proc simplex_graph_limited*(
263263
ndiv: int,
264264
limit: seq[seq[int]]
265265
): (Tensor[int], seq[seq[int]]) =
266-
## .. image:: ../assets/small_GI.png
267-
## Generates a simplex graph in a `dim`-component space based on (1) grid of nodes following `ndiv` divisions per dimension (i.e., quantized to `1/ndiv`),
268-
## similar to `simplex_grid`_, and (2) a list of neighbor lists corresponding to edges. The result is a tuple of
269-
## (1) a deterministically allocated Arraymancer `Tensor[int]` of shape `(N_S(dim, ndiv), dim)` containing all possible compositions in the simplex space
270-
## just like in `simplex_grid`_, and (2) a `seq[seq[int]]` containing a list of neighbors for each node. The current implementation utilizes GC-allocated `seq` for neighbors
271-
## to reduce memory footprint in cases where `ndiv` is close to `dim` and not all nodes have the complete set of `dim(dim-1)` neighbors. This is a tradeoff between memory and performance, which can be
272-
## adjusted by switching to a (N_S(dim, ndiv), dim(dim-1)) `Tensor[int]` with `-1` padding for missing neighbors, just like done in `outFunction_graph`_ for NumPy output generation.
266+
## .. image:: ../assets/small_GL.png
267+
## Generates a "limited" simplex graph in up to `dim`-component space represented by (1) grid of nodes quantized to `1/ndiv`, similar to `simplex_grid`_, and (2) a list of
268+
## neighbor lists corresponding to edges, but only for nodes within the specified `limit` sequence of integer pairs denoting maximum and minimum values for each component
269+
## in terms of fractions of `ndiv` (e.g. [[0, 24], [0, 12], [3, 6]] with `ndiv=24` would mean that the first component can take values from 0 to 100%, the second from 0 to
270+
## 50%, and the third from 12.5 to 25%, inclusive). The figure above depicts an example of a 3-component simplex graph with `ndiv=12` and limits of [[1, 8], [1, 8], [1, 8]].
271+
## This implementation iterates over all nodes but only computes neighbors for those within the limits, which then gets prunned to avoid connecting to nodes outside the limits
272+
## (difficult to avoide for more than 3 components). The is rearranged and node indexes are remapped to be a dense uniformly spread grid in a subspace of the simplex, akin to
273+
## the full `simplex_graph`_ but with a smaller number of nodes and more elaborate shapes, such as in the figure below with `ndiv=24` and limits of
274+
## [[0, 24], [0, 24], [0, 12], [0, 3]], resulting in a tetrahedron cut around its base and one corner.
275+
## .. image:: ../assets/small_GL2.png
276+
## The result is a tuple of (1) a runtime allocated Arraymancer `Tensor[int]` of shape `(N<=N_S(dim, ndiv), dim)` containing compositions and (2) a `seq[seq[int]]` containing
277+
## a list of neighbors for each node.
273278

274279
assert len(limit) == dim, "The size of limit sequence put on the simplex grid must match the dimensionality"
275280
for l in limit:
@@ -287,8 +292,10 @@ proc simplex_graph_limited*(
287292
projectedNodes: seq[seq[int]]
288293
projectedNeighbors: seq[seq[int]]
289294

290-
proc checkAgainstLimit(x:Tensor, dim:int, limit:seq[seq[int]]): bool {.inline.} =
291-
## Check if the current composition `x` is within the specified limits.
295+
proc checkAgainstLimit(
296+
x:Tensor, dim:int, limit:seq[seq[int]]
297+
): bool {.inline.} =
298+
## Check if the current composition `x` is within the specified `limit`.
292299
for i in 0..<dim:
293300
if x[i] > limit[i][1]:
294301
return false

0 commit comments

Comments
 (0)