private void initialize(IDensityKernel kernel, double[][] observations, double[] weights, int[] repeats, double[,] smoothing) { if (smoothing == null) { smoothing = SilvermanRule(observations, weights, repeats); } if (kernel == null) { kernel = new GaussianKernel(Dimension); } this.kernel = kernel; this.samples = observations; this.smoothing = smoothing; this.determinant = smoothing.Determinant(); this.weights = weights; this.repeats = repeats; this.chol = new CholeskyDecomposition(smoothing); if (weights != null) { this.type = WeightType.Fraction; this.numberOfSamples = samples.Length; this.sumOfWeights = weights.Sum(); } else if (repeats != null) { this.type = WeightType.Repetition; this.numberOfSamples = repeats.Sum(); this.sumOfWeights = 1.0; } else { this.type = WeightType.None; this.numberOfSamples = samples.Length; this.sumOfWeights = 1.0; } this.mean = null; this.variance = null; this.covariance = null; }
private void initialize(IDensityKernel kernel, double[][] observations, double[,] smoothing) { if (smoothing == null) { smoothing = SilvermanRule(observations); } if (kernel == null) { kernel = new GaussianKernel(Dimension); } this.kernel = kernel; this.samples = observations; this.smoothing = smoothing; this.determinant = smoothing.Determinant(); this.mean = null; this.variance = null; this.covariance = null; }
private void initialize(IDensityKernel kernel, double[][] observations, double[,] smoothing) { if (smoothing == null) { // Silverman's rule // - http://en.wikipedia.org/wiki/Multivariate_kernel_density_estimation double[] sigma = Statistics.Tools.StandardDeviation(observations); double d = sigma.Length; double n = observations.Length; smoothing = new double[sigma.Length, sigma.Length]; for (int i = 0; i < sigma.Length; i++) { double a = Math.Pow(4 / (d + 2), 1 / (d + 4)); double b = Math.Pow(n, -1 / (d + 4)); smoothing[i, i] = a * b * sigma[i]; } } if (kernel == null) { kernel = new GaussianKernel(Dimension); } this.kernel = kernel; this.samples = observations; this.smoothing = smoothing; this.determinant = smoothing.Determinant(); this.mean = null; this.variance = null; this.covariance = null; }
/// <summary> /// Creates a new Empirical Distribution from the data samples. /// </summary> /// /// <param name="kernel">The kernel density function to use. /// Default is to use the <see cref="GaussianKernel"/>.</param> /// <param name="samples">The data samples.</param> /// <param name="weights">The fractional weights to use for the samples. /// The weights must sum up to one.</param> /// <param name="smoothing"> /// The kernel smoothing or bandwidth to be used in density estimation. /// By default, the normal distribution approximation will be used.</param> /// public MultivariateEmpiricalDistribution(IDensityKernel kernel, double[][] samples, double[] weights, double[,] smoothing) : base(samples[0].Length) { this.initialize(kernel, samples, weights, null, smoothing); }
/// <summary> /// Creates a new Empirical Distribution from the data samples. /// </summary> /// /// <param name="kernel">The kernel density function to use. /// Default is to use the <see cref="GaussianKernel"/>.</param> /// <param name="samples">The data samples forming the distribution.</param> /// public MultivariateEmpiricalDistribution(IDensityKernel kernel, double[][] samples) : base(samples[0].Length) { this.initialize(kernel, samples, null, null, null); }
private void initialize(IDensityKernel kernel, double[][] observations, double[,] smoothing) { if (smoothing == null) { // Silverman's rule // - http://en.wikipedia.org/wiki/Multivariate_kernel_density_estimation double[] sigma = Statistics.Tools.StandardDeviation(observations); double d = sigma.Length; double n = observations.Length; smoothing = new double[sigma.Length, sigma.Length]; for (int i = 0; i < sigma.Length; i++) { double a = Math.Pow(4 / (d + 2), 1 / (d + 4)); double b = Math.Pow(n, -1 / (d + 4)); smoothing[i, i] = a * b * sigma[i]; } } if (kernel == null) kernel = new GaussianKernel(Dimension); this.kernel = kernel; this.samples = observations; this.smoothing = smoothing; this.determinant = smoothing.Determinant(); this.mean = null; this.variance = null; this.covariance = null; }
/// <summary> /// Creates a new Empirical Distribution from the data samples. /// </summary> /// /// <param name="kernel">The kernel density function to use. /// Default is to use the <see cref="GaussianKernel"/>.</param> /// <param name="samples">The data samples.</param> /// <param name="smoothing"> /// The kernel smoothing or bandwidth to be used in density estimation. /// By default, the normal distribution approximation will be used.</param> /// public MultivariateEmpiricalDistribution(IDensityKernel kernel, double[][] samples, double[,] smoothing) : base(samples[0].Length) { this.initialize(kernel, samples, smoothing); }