Instantly share code, notes, and snippets.

View cookbook-kalman1d.md

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 cookbook-kalman1d.py  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:

View 0-Optimize-ABXC.md

ABXC nonsmooth optimization problems

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

20nov-plot-abxc

View 0-mopta08-py.md
View Coord-sketch.py
#!/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 https://github.com/SMTorg/smt Surrogate Modeling Toolbox
View Test-pybobyqa.py
# Py-BOBYQA example: minimize the Rosenbrock function
# from https://github.com/numericalalgorithmsgroup/pybobyqa
# run this.py [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
View Bump.md

bump2: an optimization problem from A.J.Keane, https://www.southampton.ac.uk/~ajk/bump.html .

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.
View Minimize-trustconstr-noconstraints-bounds.md

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 tr_interior_point.py 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 https://gist.github.com/denis-bz:

View Gish.md

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 gist.github.com, using file names or gist ids. An example:

Alice:  gish put @Alice AA.md aa.py bb.py  # upload a gist with 3 files
View noisyUSV.py
#!/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
View Munich-NO2.md

NO2 in Munich 2016: high traffic => high NO2

2016-mu5-hours-junedec

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.