Instantly share code, notes, and snippets.


Scipy cookbook 1d Kalman filter

This is just scipy-cookbook KalmanFiltering plus some print statements, and parameters settable in shell or IPython, e.g.

run  Q=1e-6  plot=1

This plot shows how sensitive tracking is to the value of R, on this contrived example, a 1d square wave:


ABXC nonsmooth optimization problems

ABXC is a range of nonsmooth optimization problems from Curtis et al.; see the problem description and links in below. They're hard to optimize, very noisy near minima, and some are infeasible. Here's a plot of creeping up an infeasible slope:


#!/usr/bin/env python2
""" coord_sketch: k * dim func() values, varying one coordinate at a time,
give a cheap starting point for further optimization
especially if func() is monotone, up or down, in each coordinate.
from __future__ import division
import sys
import numpy as np
# from Surrogate Modeling Toolbox
# Py-BOBYQA example: minimize the Rosenbrock function
# from
# run [dim= lo= hi= ...] in sh or ipython
# sensitive to rhobeg rhoend:
# $nlopt/bobyqa/bobyqa.c --
# Typically, RHOBEG should be about one tenth of the greatest expected change to a variable,
# while RHOEND should indicate the accuracy that is required in the final values of the variables.
from __future__ import print_function

bump2: an optimization problem from A.J.Keane, .

Keywords: optimization, test case, random search, python

Problems in mathematical optimization have several different aspects:

  • contest: whose program reaches minimum __ in cpu time __ and time-to-understand __
  • learning how to explore particular function terrains
  • learning how to constrain.

Minimize trust-constr works well with no constraints and no bounds, so well that it would be nice if bounds worked too -- make trust-constr the method of choice. But constraints=() and bounds -> ValueError in BarrierSubproblem, n_eq 0 -> arrays of shape (0, n_ineq) (I added a couple of debug prints, but a fix is way over my head).

A test case with logs is under


Gish: sharing files on gist.github by name

Keywords: file sharing, gist, github, CLI, python, remote file server

gish is a command-line program to copy files between local computers and, using file names or gist ids. An example:

Alice:  gish put @Alice  # upload a gist with 3 files
#!/usr/bin/env python2
""" A = noisyUSV( n, d, r, noise ): U S V + noise, n x d, rank r """
from __future__ import division
import numpy as np
from numpy.linalg import norm
from etc import znumpyutil as nu
__version__ = "2018-05-15 May denis-bz-py t-online de" # scale noise * S.max

NO2 in Munich 2016: high traffic => high NO2


This plot shows NO2 levels over the day in Munich in June and December 2016. München-Landshuter-Allee on the left has about the highest NO2 levels in all Germany, and a lot of traffic — 120,000 to 150,000 cars and light trucks per day.
Surprise: high traffic => high NO2.