コード例 #1
0
        /// <summary>
        ///Ctor. In the LMA fit N is the number of data points, M is the number of fit parameters.
        ///Call <code>fit()</code> to start the actual fitting.
        /// </summary>
        /// <param name="function">The model function to be fitted. Must be able to take M input parameters.</param>
        /// <param name="parameters">The initial guess for the fit parameters, length M.</param>
        /// <param name="dataPoints">The data points in an array, <code>double[0 = x, 1 = y][point index]</code>. Size must be <code>double[2][N]</code>.</param>
        /// <param name="weights">The weights, normally given as: <code>weights[i] = 1 / sigma_i^2</code>.
        /// If you have a bad data point, set its weight to zero. If the given array is null,
        /// a new array is created with all elements set to 1.</param>
        /// <param name="alpha">A Matrix instance. Must be initiated to (M x M) size.
        /// In this case we are using the GeneralMatrix type from the open source JAMA library</param>
        /// <param name="argDeltaChi2">delta chi square</param>
        /// <param name="argMaxIter">maximum number of iterations</param>
        public LMA(LMAFunction function, double[] parameters,
                   double[][] dataPoints, double[] weights,
                   GeneralMatrix alpha,
                   double argDeltaChi2, int argMaxIter)
        {
            if (dataPoints[0].Length != dataPoints[1].Length)
            {
                throw new ArgumentException("Data must have the same number of x and y points.");
            }

            if (dataPoints.Length != 2)
            {
                throw new ArgumentException("Data point array must be 2 x N");
            }

            this.function              = function;
            this.parameters            = parameters;
            this.dataPoints            = dataPoints;
            this.weights               = CheckWeights(dataPoints[0].Length, weights);
            this.incrementedParameters = new double[parameters.Length];
            this.alpha    = alpha;
            this.beta     = new double[parameters.Length];
            this.da       = new double[parameters.Length];
            minDeltaChi2  = argDeltaChi2;
            maxIterations = argMaxIter;
            lambda        = Constants.lambda;
        }
コード例 #2
0
ファイル: LMA.cs プロジェクト: danieleRocha/Momentos
        /// <summary>
        ///Ctor. In the LMA fit N is the number of data points, M is the number of fit parameters.
        ///Call <code>fit()</code> to start the actual fitting.
        /// </summary>
        /// <param name="function">The model function to be fitted. Must be able to take M input parameters.</param>
        /// <param name="parameters">The initial guess for the fit parameters, length M.</param>
        /// <param name="dataPoints">The data points in an array, <code>double[0 = x, 1 = y][point index]</code>. Size must be <code>double[2][N]</code>.</param>
        /// <param name="weights">The weights, normally given as: <code>weights[i] = 1 / sigma_i^2</code>. 
        /// If you have a bad data point, set its weight to zero. If the given array is null,
        /// a new array is created with all elements set to 1.</param>
        /// <param name="alpha">A Matrix instance. Must be initiated to (M x M) size. 
        /// In this case we are using the GeneralMatrix type from the open source JAMA library</param>
        /// <param name="argDeltaChi2">delta chi square</param>
        /// <param name="argMaxIter">maximum number of iterations</param>
        public LMA( LMAFunction function, double[] parameters, 
			double[][] dataPoints, double[] weights, 
			GeneralMatrix alpha,
			double argDeltaChi2, int argMaxIter)
        {
            if (dataPoints[0].Length != dataPoints[1].Length)
                throw new ArgumentException("Data must have the same number of x and y points.");

            if (dataPoints.Length != 2)
                throw new ArgumentException("Data point array must be 2 x N");

            this.function = function;
            this.parameters = parameters;
            this.dataPoints = dataPoints;
            this.weights = CheckWeights(dataPoints[0].Length, weights);
            this.incrementedParameters = new double[parameters.Length];
            this.alpha = alpha;
            this.beta = new double[parameters.Length];
            this.da = new double[parameters.Length];
            minDeltaChi2 = argDeltaChi2;
            maxIterations = argMaxIter;
            lambda = Constants.lambda;
        }