ORTHOGONAL POLYNOMIAL DENSITY ESTIMATION

Preliminaries

Imports


In [1]:
from numpy import seterr
from mkl import set_num_threads
from uuid import uuid4

from lpde.geometry import WidthOf, Window, PointAt, BoundingBox, Mapper, Grid
from lpde.estimators import ParallelEstimator
from lpde.estimators.datatypes import Degree
from lpde.producers import MockParams
from lpde.producers.distributions import gaussian
from lpde.visualizers import Visualize

Notebook settings


In [2]:
%matplotlib qt5

_ = seterr(over='ignore')

set_num_threads(1)

Density Estimation

Initialize


In [3]:
legendre_width = WidthOf(1.8)

center = PointAt(51.375, 35.675)
window = Window(0.55, 0.35)
bounds = BoundingBox(center, window)

mapper = Mapper(bounds, legendre_width)

degree = Degree(20, 20)
params = MockParams(100, 1000, gaussian)
demand = ParallelEstimator(degree, mapper, params)

Start, check, and stop


In [4]:
demand.controller.start(16, 1.0)

In [5]:
demand.controller.alive


Out[5]:
{'Datagate': True,
 'Minimizers': (True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True,
  True),
 'Producer': True,
 'Smoother': True}

In [6]:
demand.controller.open


Out[6]:
{'Coefficients': True, 'Events in': True, 'Events out': True, 'Points': True}

In [9]:
demand.controller.qsize


Out[9]:
{'Coefficients': 0, 'Points': 0}

In [10]:
demand.controller.stop()

Query density at a specific point


In [ ]:
point = PointAt(51.4, 35.7)

demand.at(point)

Plot the density

With the default settings ...

In [ ]:
visulization = Visualize(demand)
animation = visulization.show(cartopy=True, zoom=11)
... and with a different grid.

In [ ]:
demand.grid = Grid(50, 150)

visulization = Visualize(demand)
animation = visulization.show(cartopy=True)

Plot the gradient of the density


In [ ]:
import matplotlib.pyplot as plt

demand.grid = Grid(50, 50)

fig, ax = plt.subplots(figsize=(5.5, 5),)
ax.quiver(*demand.grid, *demand.gradient_on_grid, demand.on_grid, angles='xy', pivot='middle')
fig.tight_layout()

Query density gradient at a specific point


In [ ]:
demand.gradient_at(PointAt(51.4, 35.7))

In [ ]: