# Fitting mixture model of Gaussians and uniform distributions to real data

I have times series of wind direction and velocity. For now, I leave aside the velocity and focus on the distribution of wind directions.

Over there, there is usually three main wind directions, and variations around these directions.

My goal is to quantify these directions as well as the proportion of time associated to each main directions. My first guess was to trying to fit this with Gaussian mixture model:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.mixture import GaussianMixture

gmm = GaussianMixture(n_components = 3).fit(data.reshape(-1, 1))

plt.figure()
plt.hist(data, bins=50, histtype='stepfilled', density=True, alpha=0.5)
plt.xlim(0, 360)
f_axis = data.copy().ravel()
f_axis.sort()
a = []
for weight, mean, covar in zip(gmm.weights_, gmm.means_, gmm.covariances_):
a.append(weight*norm.pdf(f_axis, mean, np.sqrt(covar)).ravel())
plt.plot(f_axis, a[-1])
plt.plot(f_axis, np.array(a).sum(axis =0), 'k-')
plt.xlabel('Variable')
plt.ylabel('PDF')
plt.tight_layout()
plt.show()


The fit is not that good, and we guessed it is because there is also a 'background noise' of uniformly distributed data. In another word, everything below y = 0.17 (or something around this) should not exist.

Is there anyway to take this into account ?

How to fit a mixture of gaussian and uniform distributions ?

Note that these are angular data (periodic), but I did not take this into account. As a result, the half peak around 360 is part of the first main peak at 50.

• Because the range of your variable is $[0,360]$ I would guess you have an angle -- a kind of circular variable. That requires special treatment , especially in this case. Instead of asking for an abstract solution to an abstract problem that might not give you a good answer (or even a correct one), why not disclose the actual problem you are trying to solve? – whuber Dec 3 '20 at 12:18
• How do you know there are three peaks? It seems that the histogram has three peaks with a "half-peak" at the right tail. I am wonder whether it sounds something? – TrungDung Dec 3 '20 at 12:29
• Thanks for these comments ! I'll edit my question based on it. – Liris Dec 3 '20 at 12:56
• I don't see much of a benefit from fitting a Gaussian mixture model, in part because the peaks are not Gaussian (they are too sharp and one of them is too skewed): this enterprise is doomed. But you can readily achieve your objective of estimating the principal directions and proportions of time: the peaks are clearly identifiable--this needs no statistical procedure to achieve--so all that's left is to estimate the boundaries between them. You could use the bottoms of the valleys that separate them, for instance; but the best way will depend on your loss function. – whuber Dec 4 '20 at 14:52