Skip to main content

Counting and sampling non-negative integer matrices given margin sums.

Project description

matrix-count

Documentation Status PyPI version PyPI platforms codecov

Estimating integer matrix counting problems

Maximilian Jerdee

We provide analytic estimates and sampling-based algorithms for a variety of counting problems defined over integer matrices.

For example, we may count the number of non-negative symmetric integer matrices with even diagonal entries and a given row sum. This is the number of (multi-)graphs with a given degree sequence. We can also estimate the number of such matrices under combinations of the further conditions:

  • Binary matrices (only simple graphs).
  • Fixed total sum of diagonal entries (number of self edges).
  • Fixed sum of entries in blocks of matrix. (number of edges between prescribed groups) [Not yet implemented]

We also include methods for estimating the number of non-negative integer matrices with a given row sum and column sum as described in Jerdee, Kirkley, Newman (2022). [Not yet implemented]

These problems can also be generalized as sums over matrices $A$ weighted by a Dirichlet-multinomial factor on their entries

$$w(A) = \prod_{i < j}\binom{A_{ij} + \alpha - 1}{\alpha - 1} \prod_i \binom{A_{ii}/2 + \alpha - 1}{\alpha - 1}.$$

Note that $\alpha = 1$ corresponds to the uniform count. This more general estimate acts as the partition function of a generalized random multigraph model.

Installation

matrix-count may be installed through pip:

pip install matrix-count

or be built locally by cloning this repository and running

pip install .

in the base directory.

Typical usage

Once installed, the package can be imported as

import matrix_count

Note that this is not import matrix-count.

The package can then be used to evaluate rapid analytic estimates of these counting problems, to sample from the space of such matrices, and to converge to the exact number of these matrices.

# Margin of a 8x8 symmetric non-negative integer matrix with even diagonal entries
margin = [10, 9, 8, 7, 6, 5, 4, 3]

# Estimate the logarithm of the number of symmetric matrices with given margin sum
# (number of multigraphs with given degree sequence)
estimate = matrix_count.estimate_log_symmetric_matrices(margin, alpha=1)
print("Estimated log count of symmetric matrices:", estimate)

# Count the number of such matrices
count, count_err = matrix_count.count_log_symmetric_matrices(margin, alpha=1)
print("Log count of symmetric matrices:", count, "+/-", count_err)

# Sample from the space of such matrices
num_samples = 3
for _t in range(num_samples):
    sample, entropy = matrix_count.sample_symmetric_matrix(margin)
    print("Sampled matrix:")
    print(sample)
    print("Minus log probability of sampled matrix:", entropy)

Further usage examples can be found in the examples directory of the repository and the package documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrix_count-0.1.5.tar.gz (803.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

matrix_count-0.1.5-pp310-pypy310_pp73-macosx_11_0_arm64.whl (144.2 kB view details)

Uploaded PyPymacOS 11.0+ ARM64

matrix_count-0.1.5-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (163.1 kB view details)

Uploaded PyPymacOS 10.15+ x86-64

matrix_count-0.1.5-pp39-pypy39_pp73-macosx_11_0_arm64.whl (144.2 kB view details)

Uploaded PyPymacOS 11.0+ ARM64

matrix_count-0.1.5-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (163.1 kB view details)

Uploaded PyPymacOS 10.15+ x86-64

matrix_count-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (148.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

matrix_count-0.1.5-cp313-cp313-macosx_10_13_x86_64.whl (166.4 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

matrix_count-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (147.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

matrix_count-0.1.5-cp312-cp312-macosx_10_9_x86_64.whl (166.8 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

matrix_count-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (146.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

matrix_count-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl (165.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

matrix_count-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (144.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

matrix_count-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl (162.6 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

matrix_count-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (144.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

matrix_count-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl (162.8 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file matrix_count-0.1.5.tar.gz.

File metadata

  • Download URL: matrix_count-0.1.5.tar.gz
  • Upload date:
  • Size: 803.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for matrix_count-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ccd5e840be2d9d09988252473be75d52b45abe1d6c1576ee47604cba2cefa543
MD5 f8c9221622552f94081d7dc37e2bc184
BLAKE2b-256 a02eb8f2ba74fbc77d76de915f0d496b5195c6a69a4d13b87b3fdc534b6c4119

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-pp310-pypy310_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b71a16bc41797a95fb1850b6e53164167d0faa58c5c4d69ed77d81d973b20388
MD5 56919d643f9b5e9ae2a4042a745d418c
BLAKE2b-256 1fc7f8ebae91fa49fb1fdb6a7b8da542cb5b6fb0cdf23cc7632b0361c3c7eae0

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-pp310-pypy310_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-pp310-pypy310_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9b83291f208008209c7a4c9bd8dfa0f1da07029bf7214373f81e9862a84c8099
MD5 f3e57f7b2a85c99bbd6080dd417925fe
BLAKE2b-256 59bd391c563c5816ddca501a4b81682c1d4d64fa8df99a8a17a7d12de40bcd40

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-pp39-pypy39_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-pp39-pypy39_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4768150c301bc308f1be31a6de0bcabb84baa6d4b360d0d7353dcfbf74392b0
MD5 7f7d3cd3c164b7ac8c3bdaa2764bd4f8
BLAKE2b-256 12762e534165ae0ca26c05cc6521b519afc2a3c130c049b0d2a002118ce51ee8

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-pp39-pypy39_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-pp39-pypy39_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c6bc7dee0d8d1ed6bfddb33dd575b9480f52ade58d34b6058f85c3a7b12d0d81
MD5 2d56ea85b29b06a908cea16ce72a786f
BLAKE2b-256 505e5ec1e2b7ddc4b84ab4989ce5c4b27d90be9c06f9374b5987ea79dd3e6857

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 380b22de66eb2a0278765daf2639c861ec91d9e58fe42946f2341f7984434884
MD5 6544863d1dc4db67114ef96750bd50f2
BLAKE2b-256 eb724914b21a7c3129456d842a543bee1c24c03cb23fce571ea30d323f411968

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 ad08dd90dd39726daf336e51665e4b410b06e7146b192b31a15bd718289b3539
MD5 380c493bc780052d793795fd80ec7308
BLAKE2b-256 abbf5d4ad93a56b65faaa70c3cf69f7e44f2b9fb3ef773d2087cc8c27cb3c036

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c75dd38cb6afc4ddc2362aa6451c5d7d4eadbfba6f7f2fd67d089c71fcca31a8
MD5 b28bcd5e24be206d317c0f4769d74949
BLAKE2b-256 439374ffa8a386f50a39fc44d4938806de9214ebf7977de0880abd771a3ecace

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8eedbf7444804d6bcded1436554204754c9e0712fc2878290553874406e98bfe
MD5 46550354e195a68165a4b124e3b664ce
BLAKE2b-256 94ac6eaf10d1b81ee2ddb17a57fa6d81eb5f9b7459072a3ec5a7ab3bfca80150

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fc3de8d8d15950de99fb24843f7d36a4f14a6d17c059274b4b0af7ea6e033e2
MD5 75190dfc371d0256d23d4dbae8314414
BLAKE2b-256 415238ab9a163a93b91871d66af405a3654b45114d2f4e46b2f390e1153274bc

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 db823eadf870bd602e5ecae36e153eb1395726ea75ac0b884d0a9d3b3bd4c9b9
MD5 435b17776c9c2e72d0b2bea51317f58b
BLAKE2b-256 b9ad3ad082da1a6ab7bc94842b38c6cd6704f88a03347b514d8cd107ff46506a

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0406a1445d4ab60ed81063d1284143f70ab9a5438666f17e455e9bba9a4a8264
MD5 1e6817c0659fa7a845135af1a9b0151a
BLAKE2b-256 ad72d6d355ef5f272137dabb55da414ce974633ef211ac5cb0bf765af7dcc632

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0da5452b55c02f2fc09e4a4250ba5287ec25caef289d5b29bee88aea367a74d1
MD5 ad153bc35cb90486548e58269b32b162
BLAKE2b-256 3b8b56e4a6fb3db514fd844d3b99e0b2fe79e4fa71fce17bb2aaac4a6a548c2e

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8eeaeacf316d85180fe11bd41a1ae8ea241b3c2f77da15a0a4d53d63ea1a15bc
MD5 abd6d60351e5042c1793e3ac6928df47
BLAKE2b-256 cf11efdbe0f9a01153327d6068d51e101f163dd491eafcd2da242e50f645feb0

See more details on using hashes here.

File details

Details for the file matrix_count-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for matrix_count-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9e1c6593d540849c8d78553d5eaf5c0b0520b4cb6145aaebe5caecf06259b25c
MD5 79f8c0b95865ed28eb1f812dc4a8f1bf
BLAKE2b-256 c5522021046eb7de4d3b35d089cfd231d53cefd74a2be89b8e4fc3987c1c2ca5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page