Skip to content

Instantly share code, notes, and snippets.

@denis-bz
denis-bz / lpgen34.py
Created January 17, 2021 16:15
LP sparse testcase generator: 4n^3 x n^4, 4n^4 non0 17 Jan 2021
#!/usr/bin/env python
""" lpgen34.py LP testcase generator
d=3: 3n^2 x n^3, 3 1s in each column
n=55: A 9075 x 166375, 499125 nnz, glpsol simplex 100 minutes
d=4: 4n^3 x n^4, 4 1s in each column, n in each row
n=16: A 2^14 x 2^16, 2^18 nnz, glpsol simplex 10 hours
"""
# keywords: linear programming, test case, generator, Latin-square
# https://stackoverflow.com/questions/57936789/many-vertex-test-problems-for-the-simplex-method
# https://math.stackexchange.com/questions/3370934/3d-permutation-matrices -- 4d too
@denis-bz
denis-bz / 0-Stripy.md
Created January 8, 2021 11:23
Stripy: percentile stripes for scatterplots

Stripy: percentile stripes for scatterplots

Keywords: scatterplot, percentiles, quantiles, visualize, regression, nonparametric

ozone-stripy-4june

What does this show ? Consider a fat vertical line at a given x in one of these plots. The colored bands are, from low to high,

@denis-bz
denis-bz / triangles_in_sparsegraph.py
Created November 17, 2020 10:39
triangles_in_sparsegraph.py triangles_to_edges.py 17 Nov 2020
#!/usr/bin/env python3
""" triangles in a sparse graph """
# Keywords: sparse-graph, sparse-matrix, scipy, mesh, triangles
# w Polygon_mesh Mesh_generation ...
import numpy as np
from scipy import sparse
# https://docs.scipy.org/doc/scipy/reference/sparse.csgraph.html
# some type names --
@denis-bz
denis-bz / 0-invop.md
Last active March 10, 2021 17:46
Inverse operators for scipy.sparse eigs, arpack 15 Nov 2020

Invop() inverse operator for scipy.sparse eigenvalues with ARPACK

Problem: find a few eigenvalues λ and eigenvectors v of
A v = λ v, \ A a scipy.sparse matrix, largest or smallest |λ|
or K v = λ M v with stiffness matrix K and mass matrix M.

Purpose: experiment with different linear solvers, with verbose to track solver calls.
Keywords: scipy.sparse, linear-solvers, eigenvalue, generalized-eigenvalue, Arpack, logging

In the following examples, eigs( A [M] [Minv] [OPinv] [sigma] ... ) \

@denis-bz
denis-bz / 0-Covid19-hospitalized-Germany.md
Last active September 9, 2020 09:13
Covid-19 % cases hospitalized in Germany up to 6 Sept 2020

Covid-19 cases hospitalized in Germany, March up to 6 September 2020

Keywords: Covid-19, hospitalized, Germany, plot, python

This plot shows the number of Covid-19 cases per week, the number hospitalized, and number of deaths, in Germany for weeks 10 to 36 2020:

9sep2020-Covid19-hospitalized-de-8sep

The data is taken from this report: \

@denis-bz
denis-bz / 0-How-to-make-a-Python-package-for-other-people-to-use.md
Last active May 5, 2023 11:22
from Denis-iMac ~bz/py/plot/folium/git Fri 2023-05-05 May 11:20z

How to make a Python package for other people to use

Keywords, tags: python packaging setup.py setuptools

Purpose: describe how to make a "package" of a Python program for other people to use. This introduction builds on the excellent oa-packaging-guide-preview.readthedocs.io — read that first.

@denis-bz
denis-bz / 0-eigvals-numpy-scipy.md
Last active July 16, 2020 16:37
Do numpy and scipy use different LAPACK drivers for eigvalsh ? 3 Jul 2020

Do numpy and scipy use different LAPACK drivers for eigvalsh on macos ?

eigvals-numpy-scipy.py below runs numpy vs scipy eigvalsh on a dense random matrix:

np.linalg.eigvalsh: 201 sec
scipy.linalg.eigvalsh: 83 sec  driver ev
scipy.linalg.eigvalsh: 84 sec  driver evd

Maybe this is only on macos ?

@denis-bz
denis-bz / 0-Shift-invert-in-pictures.md
Created July 2, 2020 16:39
How shift-invert finds eigenvalues, in pictures 2 Jul 2020

How shift-invert finds eigenvalues, in pictures

Keywords: eigenvalues, eigenvectors, shift-invert, ARPACK, scipy, python

Pictures first:

shiftinvert-randomsparse-n100

Background

@denis-bz
denis-bz / 0-Eigplots.md
Last active June 20, 2020 16:20
Plots of some eigenvalues and eigenvectors 20 Jun 2020

Plots of some eigenvalues and eigenvectors

Keywords: eigenvalues, eigenvectors, test-matrix, scipy, python

Eigenvectors of Suitesparse Norris/fv1

27feb2020-Suitesparse-Norris-fv1-evecs

See SuiteSparse Matrix Collection / Norris, "Finite element modelling of human body parts, Laplace equation on a 2D mesh".

@denis-bz
denis-bz / av_sparse_blocks.py
Last active August 21, 2020 15:02
average e.g. 4 x 4 blocks in a sparse matrix A 16 Jun 2020
#!/usr/bin/env python
"""average e.g. 4 x 4 blocks in a sparse matrix A
N x N -> N/4 x N/4, nnz roughly *= blksize
why: reduce big matrices to plot, q+d approximate inverse
Keywords: sparse-matrix, python, scipy, data-compression
"""
# pretty fast -- coo sums duplicate (i,j) entries
from __future__ import division, print_function