gaussian

Multivariate kernel density estimation in Python

人盡茶涼 提交于 2019-11-28 23:40:54
I am trying to use SciPy's gaussian_kde function to estimate the density of multivariate data. In my code below I sample a 3D multivariate normal and fit the kernel density but I'm not sure how to evaluate my fit. import numpy as np from scipy import stats mu = np.array([1, 10, 20]) sigma = np.matrix([[4, 10, 0], [10, 25, 0], [0, 0, 100]]) data = np.random.multivariate_normal(mu, sigma, 1000) values = data.T kernel = stats.gaussian_kde(values) I saw this but not sure how to extend it to 3D. Also not sure how do I even begin to evaluate the fitted density? How do I visualize this? There are

Random Numbers with Gaussian and Uniform Distributions in matlab

試著忘記壹切 提交于 2019-11-28 22:05:25
I want generate a number in Gaussian and Uniform distributions in matlab. I know this function randi and rand() but all of them are in normal (Gaussian) distribution. How can a generate a random number in uniform distribution? Use rand(dimensions) for a Uniform Distribution between 0 and 1. Use randn(dimensions) * sqrt(sigma) + mu for a Gaussian Distribution with a mean of mu and variance of sigma . randn is the function to generate Gaussian distributed variables ( randi and rand produce uniformly distributed ones). raj You can generate any distribution from rand(). For example , lets say you

Test if a data distribution follows a Gaussian distribution in MATLAB

梦想的初衷 提交于 2019-11-28 21:23:14
I have some data points and their mean point. I need to find whether those data points (with that mean) follows a Gaussian distribution. Is there a function in MATLAB which can do that kind of a test? Or do I need to write a test of my own? I tried looking at different statistical functions provided by MATLAB. I am very new to MATLAB so I might have overlooked the right function. cheers Check this documentation page on all available hypothesis tests . From those, for your purpose you can use: Chi-square goodness-of-fit test Lilliefors test z-test t-test Kolmogorov-Smirnov test ... among others

How to generate 2D gaussian with Python?

此生再无相见时 提交于 2019-11-28 21:06:30
问题 I can generate Gaussian data with random.gauss(mu, sigma) function, but how can I generate 2D gaussian? Is there any function like that? 回答1: Since the standard 2D Gaussian distribution is just the product of two 1D Gaussian distribution, if there are no correlation between the two axes (i.e. the covariant matrix is diagonal), just call random.gauss twice. def gauss_2d(mu, sigma): x = random.gauss(mu, sigma) y = random.gauss(mu, sigma) return (x, y) 回答2: If you can use numpy , there is numpy

How to use a custom SVM kernel?

橙三吉。 提交于 2019-11-28 18:54:40
I'd like to implement my own Gaussian kernel in Python, just for exercise. I'm using: sklearn.svm.SVC(kernel=my_kernel) but I really don't understand what is going on. I expect the function my_kernel to be called with the columns of the X matrix as parameters, instead I got it called with X , X as arguments. Looking at the examples things are not clearer. What am I missing? This is my code: ''' Created on 15 Nov 2014 @author: Luigi ''' import scipy.io import numpy as np from sklearn import svm import matplotlib.pyplot as plt def svm_class(fileName): data = scipy.io.loadmat(fileName) X = data[

Python: two-curve gaussian fitting with non-linear least-squares

↘锁芯ラ 提交于 2019-11-28 17:18:27
My knowledge of maths is limited which is why I am probably stuck. I have a spectra to which I am trying to fit two Gaussian peaks. I can fit to the largest peak, but I cannot fit to the smallest peak. I understand that I need to sum the Gaussian function for the two peaks but I do not know where I have gone wrong. An image of my current output is shown: The blue line is my data and the green line is my current fit. There is a shoulder to the left of the main peak in my data which I am currently trying to fit, using the following code: import matplotlib.pyplot as pt import numpy as np from

Sample from multivariate normal/Gaussian distribution in C++

北城余情 提交于 2019-11-28 16:31:45
问题 I've been hunting for a convenient way to sample from a multivariate normal distribution. Does anyone know of a readily available code snippet to do that? For matrices/vectors, I'd prefer to use Boost or Eigen or another phenomenal library I'm not familiar with, but I could use GSL in a pinch. I'd also like it if the method accepted nonnegative -definite covariance matrices rather than requiring positive-definite (e.g., as with the Cholesky decomposition). This exists in MATLAB, NumPy, and

Implementing Gaussian Blur - How to calculate convolution matrix (kernel)

随声附和 提交于 2019-11-28 15:45:51
问题 My question is very close to this question: How do I gaussian blur an image without using any in-built gaussian functions? The answer to this question is very good, but it doesn't give an example of actually calculating a real Gaussian filter kernel. The answer gives an arbitrary kernel and shows how to apply the filter using that kernel but not how to calculate a real kernel itself. I am trying to implement a Gaussian blur in C++ or Matlab from scratch, so I need to know how to calculate the

Python: finding the intersection point of two gaussian curves

天大地大妈咪最大 提交于 2019-11-28 12:18:15
I have two gaussian plots: x = np.linspace(-5,9,10000) plot1=plt.plot(x,mlab.normpdf(x,2.5,1)) plot2=plt.plot(x,mlab.normpdf(x,5,1)) and I want to find the point at where the two curves intersect. Is there a way of doing this? In particular I want to find the value of the x-coordinate where they meet. You want to find the x's such that both gaussian functions have the same height.(i.e intersect) You can do so by equating two gaussian functions and solve for x. In the end you will get a quadratic equation with coefficients relating to the gaussian means and variances. Here is the final result:

openCV Gaussian blur/smoothing of 3D Matrix/Histogram

我的未来我决定 提交于 2019-11-28 10:18:19
问题 I have a (3D) Histogram which I like to apply Gaussian smoothing on: cv::MatND Hist; In the 1D and 2D cases I blur it via: cv::GaussianBlur(Hist, Hist, cv::Size(1,3), 1.0);// 1D case cv::GaussianBlur(Hist, Hist, cv::Size(3,3), 1.0);// 2D case But I struggle to apply Gaussian blurring in the 3D case. Has anyone got an idea how to attempt this? 回答1: Try use separable kernels like shown here: http://www.programming-techniques.com/2013/03/gaussian-blurring-using-separable.html 来源: https:/