/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (weights != null) { throw new NotSupportedException("Weighted estimation is not supported."); } if (options != null) { throw new ArgumentException("No options may be specified."); } // The maximum likelihood estimator for p is the // number of successes over the number of trials int successes = 0; for (int i = 0; i < observations.Length; i++) { if (observations[i] == 1) { successes++; } } this.probability = successes / (double)numberOfTrials; }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { // R. Kolar, R. Jirik, J. Jan (2004) "Estimator Comparison of the // Nakagami-m Parameter and Its Application in Echocardiography", // Radioengineering, 13 (1), 8–12 double[] xsquared = Matrix.ElementwisePower(observations, 2); double mean, var; if (weights == null) { mean = Statistics.Tools.Mean(xsquared); var = Statistics.Tools.Variance(xsquared); } else { mean = Statistics.Tools.WeightedMean(xsquared, weights); var = Statistics.Tools.WeightedVariance(xsquared, weights); } double shape = (mean * mean) / var; double spread = mean; init(shape, spread); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (weights != null) { throw new NotSupportedException(); } initialize((double[])observations.Clone(), null); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (options != null) { throw new ArgumentException("No options may be specified."); } a = (int)observations.Min(); b = (int)observations.Max(); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[][] observations, double[] weights, Fitting.IFittingOptions options) { HiddenMarkovOptions normalOptions = options as HiddenMarkovOptions; if (options != null && normalOptions == null) { throw new ArgumentException("The specified options' type is invalid.", "options"); } Fit(observations, weights, normalOptions); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { double sum = 0; for (int i = 0; i < observations.Length; i++) { sum += observations[i] * observations[i]; } sigma = Math.Sqrt(1.0 / (2.0 * observations.Length) * sum); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (weights != null) { throw new ArgumentException("This distribution does not support weighted samples."); } if (options != null) { throw new ArgumentException("This method does not accept fitting options."); } initialize((double[])observations.Clone(), null); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (immutable) throw new InvalidOperationException("This object can not be modified."); if (options != null) throw new ArgumentException("This method does not accept fitting options."); if (weights != null) throw new ArgumentException("This distribution does not support weighted samples."); a = observations.Min(); b = observations.Max(); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (options != null) { throw new ArgumentException("No options may be specified."); } if (weights != null) { throw new ArgumentException("This distribution does not support weighted samples."); } a = (int)observations.Min(); b = (int)observations.Max(); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { if (immutable) { throw new InvalidOperationException("This object can not be modified."); } if (options != null) { throw new ArgumentException("No options may be specified."); } a = observations.Min(); b = observations.Max(); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// /// <remarks> /// Although both double[] and double[][] arrays are supported, /// providing a double[] for a multivariate distribution or a /// double[][] for a univariate distribution may have a negative /// impact in performance. /// </remarks> /// public override void Fit(int[] observations, double[] weights, Fitting.IFittingOptions options) { if (weights != null) { throw new NotSupportedException("Weighted estimation is not supported."); } if (options != null) { throw new ArgumentException("No options may be specified."); } double sum = 0; for (int i = 0; i < observations.Length; i++) { sum += observations[i] / (double)numberOfTrials; } this.probability = sum / observations.Length; }
/// <summary> /// Not supported. /// </summary> /// public override void Fit(double[] observations, double[] weights, Fitting.IFittingOptions options) { throw new NotSupportedException(); }
/// <summary> /// Fits the underlying distribution to a given set of observations. /// </summary> /// /// <param name="observations">The array of observations to fit the model against. The array /// elements can be either of type double (for univariate data) or /// type double[] (for multivariate data).</param> /// <param name="weights">The weight vector containing the weight for each of the samples.</param> /// <param name="options">Optional arguments which may be used during fitting, such /// as regularization constants and additional parameters.</param> /// public override void Fit(double[][] observations, double[] weights, Fitting.IFittingOptions options) { Fit(observations, weights, options as EmpiricalOptions); }