public NonlinearFitDocument(NonlinearFitDocument from)
 {
   _fitEnsemble = null == from._fitEnsemble ? null : (FitEnsemble)from._fitEnsemble.Clone();
   _fitEnsemble.Changed += new EventHandler(EhFitEnsemble_Changed);
   _currentParameters = null == from._currentParameters ? null : (ParameterSet)from._currentParameters.Clone();
   // Note that the fit context is not cloned here.
 }
Beispiel #2
0
		public NonlinearFitDocument(NonlinearFitDocument from)
		{
			_fitEnsemble = null == from._fitEnsemble ? null : (FitEnsemble)from._fitEnsemble.Clone();
			_fitEnsemble.ParentObject = this;

			_currentParameters = null == from._currentParameters ? null : (ParameterSet)from._currentParameters.Clone();
			// Note that the fit context is not cloned here.
		}
    public ParameterSetController(ParameterSet doc)
    {
      _doc = doc;
      _doc.InitializationFinished += new EventHandler(EhInitializationFinished);

      base.DescriptionText = "ParameterName                                      Value                     Vary?       Variance\r\n" +
                        "-------------------------------------------------------------------------------------------------------";
      
      EhInitializationFinished(this, EventArgs.Empty);
    }
Beispiel #4
0
		public void CopyParametersBackTo(ParameterSet pset)
		{
			if (pset.Count != this._constantParameters.Length)
				throw new ArgumentException("Length of parameter set pset does not match with cached length of parameter set");
			int varyingPara = 0;
			for (int i = 0; i < pset.Count; i++)
			{
				if (pset[i].Vary)
					varyingPara++;
			}

			if (varyingPara != this._cachedVaryingParameters.Length)
				throw new ArgumentException("Number of varying parameters in pset does not match cached number of varying parameters");

			varyingPara = 0;
			for (int i = 0; i < pset.Count; i++)
			{
				if (pset[i].Vary)
				{
					pset[i].Parameter = this._cachedVaryingParameters[varyingPara];
					pset[i].Variance = _resultingCovariances == null ? 0 : Math.Sqrt(_resultingCovariances[varyingPara + varyingPara * _cachedVaryingParameters.Length]);
					varyingPara++;
				}
				else
				{
					pset[i].Parameter = this._constantParameters[i];
					pset[i].Variance = 0;
				}
			}
			pset.OnInitializationFinished();
		}
Beispiel #5
0
		/// <summary>
		/// Internal function to set up the cached data for the fitting procedure.
		/// </summary>
		/// <param name="paraSet">The set of parameters (the information which parameters are fixed is mainly used here).</param>
		private void CalculateCachedData(ParameterSet paraSet)
		{
			// Preparation: Store the parameter names by name and index, and store
			// all parameter values in _constantParameters
			System.Collections.Hashtable paraNames = new System.Collections.Hashtable();
			System.Collections.Hashtable varyingParaNames = new System.Collections.Hashtable();

			_constantParameters = new double[paraSet.Count];
			int numberOfVaryingParameters = 0;
			for (int i = 0; i < paraSet.Count; ++i)
			{
				paraNames.Add(paraSet[i].Name, i);
				_constantParameters[i] = paraSet[i].Parameter;
				if (paraSet[i].Vary)
					++numberOfVaryingParameters;
			}
			_cachedVaryingParameters = new double[numberOfVaryingParameters];
			for (int i = 0, k = 0; i < paraSet.Count; ++i)
			{
				if (paraSet[i].Vary)
				{
					varyingParaNames.Add(paraSet[i].Name, k);
					_cachedVaryingParameters[k++] = paraSet[i].Parameter;
				}
			}

			_cachedNumberOfData = 0;
			_cachedFitElementInfo = new CachedFitElementInfo[_fitEnsemble.Count];
			for (int i = 0; i < _fitEnsemble.Count; i++)
			{
				CachedFitElementInfo info = new CachedFitElementInfo();
				_cachedFitElementInfo[i] = info;
				FitElement fitEle = _fitEnsemble[i];

				info.ValidRows = fitEle.CalculateValidNumericRows();

				info.Xs = new double[fitEle.NumberOfIndependentVariables];
				info.Parameters = new double[fitEle.NumberOfParameters];
				info.Ys = new double[fitEle.NumberOfDependentVariables];

				// Calculate the number of used variables
				int numVariablesUsed = 0;
				for (int j = 0; j < fitEle.NumberOfDependentVariables; ++j)
				{
					if (fitEle.DependentVariables(j) != null)
						++numVariablesUsed;
				}
				info.DependentVariablesInUse = new int[numVariablesUsed];
				for (int j = 0, used = 0; j < fitEle.NumberOfDependentVariables; ++j)
				{
					if (fitEle.DependentVariables(j) != null)
						info.DependentVariablesInUse[used++] = j;
				}

				// calculate the total number of data points
				_cachedNumberOfData += numVariablesUsed * info.ValidRows.Count;

				// now create the parameter mapping
				info.ParameterMapping = new int[fitEle.NumberOfParameters];

				for (int j = 0; j < info.ParameterMapping.Length; ++j)
				{
					if (!paraNames.Contains(fitEle.ParameterName(j)))
						throw new ArgumentException(string.Format("ParameterSet does not contain parameter {0}, which is used by function[{1}]", fitEle.ParameterName(j), i));

					int idx = (int)paraNames[fitEle.ParameterName(j)];
					if (paraSet[idx].Vary)
					{
						info.ParameterMapping[j] = (int)varyingParaNames[fitEle.ParameterName(j)];
					}
					else
					{
						info.ParameterMapping[j] = -idx - 1;
					}
				}
			}

			_cachedDependentValues = new double[_cachedNumberOfData];
			GetDependentValues(_cachedDependentValues);

			if (this.HasToUseWeights())
			{
				_cachedWeights = new double[_cachedNumberOfData];
				GetWeights(_cachedWeights);
			}
			else
				_cachedWeights = null;
		}
Beispiel #6
0
		/// <summary>
		/// Constructor of the adapter.
		/// </summary>
		/// <param name="ensemble">The fit ensemble, i.e. the functions and data you intend to fit.</param>
		/// <param name="paraSet">The set of initial parameter. Must contain a initial estimation of the parameters. Contains also information which
		/// parameters can vary and which are fixed during the fitting procedure.</param>
		public LevMarAdapter(FitEnsemble ensemble, ParameterSet paraSet)
		{
			_fitEnsemble = ensemble;

			CalculateCachedData(paraSet);
		}
 public NonlinearFitDocument()
 {
   _fitEnsemble = new FitEnsemble();
   _currentParameters = new ParameterSet();
   _fitEnsemble.Changed += new EventHandler(EhFitEnsemble_Changed);
 }
Beispiel #8
0
		public object Clone()
		{
			ParameterSet result = new ParameterSet();
			for (int i = 0; i < Count; ++i)
				result.Add((ParameterSetElement)this[i].Clone());

			return result;
		}
Beispiel #9
0
		public NonlinearFitDocument()
		{
			_fitEnsemble = new FitEnsemble() { ParentObject = this };
			_currentParameters = new ParameterSet();
		}
Beispiel #10
0
        /// <summary>
        /// Internal function to set up the cached data for the fitting procedure.
        /// </summary>
        /// <param name="paraSet">The set of parameters (the information which parameters are fixed is mainly used here).</param>
        private void CalculateCachedData(ParameterSet paraSet)
        {
            // Preparation: Store the parameter names by name and index, and store
            // all parameter values in _constantParameters
            var paraNames        = new System.Collections.Hashtable();
            var varyingParaNames = new System.Collections.Hashtable();

            _constantParameters = new double[paraSet.Count];
            int numberOfVaryingParameters = 0;

            for (int i = 0; i < paraSet.Count; ++i)
            {
                paraNames.Add(paraSet[i].Name, i);
                _constantParameters[i] = paraSet[i].Parameter;
                if (paraSet[i].Vary)
                {
                    ++numberOfVaryingParameters;
                }
            }
            _cachedVaryingParameters = new double[numberOfVaryingParameters];
            for (int i = 0, k = 0; i < paraSet.Count; ++i)
            {
                if (paraSet[i].Vary)
                {
                    varyingParaNames.Add(paraSet[i].Name, k);
                    _cachedVaryingParameters[k++] = paraSet[i].Parameter;
                }
            }

            _cachedNumberOfData   = 0;
            _cachedFitElementInfo = new CachedFitElementInfo[_fitEnsemble.Count];
            for (int i = 0; i < _fitEnsemble.Count; i++)
            {
                var info = new CachedFitElementInfo();
                _cachedFitElementInfo[i] = info;
                FitElement fitEle = _fitEnsemble[i];

                info.ValidRows = fitEle.CalculateValidNumericRows();

                info.Xs         = new double[fitEle.NumberOfIndependentVariables];
                info.Parameters = new double[fitEle.NumberOfParameters];
                info.Ys         = new double[fitEle.NumberOfDependentVariables];

                // Calculate the number of used variables
                int numVariablesUsed = 0;
                for (int j = 0; j < fitEle.NumberOfDependentVariables; ++j)
                {
                    if (fitEle.DependentVariables(j) != null)
                    {
                        ++numVariablesUsed;
                    }
                }
                info.DependentVariablesInUse = new int[numVariablesUsed];
                for (int j = 0, used = 0; j < fitEle.NumberOfDependentVariables; ++j)
                {
                    if (fitEle.DependentVariables(j) != null)
                    {
                        info.DependentVariablesInUse[used++] = j;
                    }
                }

                // calculate the total number of data points
                _cachedNumberOfData += numVariablesUsed * info.ValidRows.Count;

                // now create the parameter mapping
                info.ParameterMapping = new int[fitEle.NumberOfParameters];

                for (int j = 0; j < info.ParameterMapping.Length; ++j)
                {
                    if (!paraNames.Contains(fitEle.ParameterName(j)))
                    {
                        throw new ArgumentException(string.Format("ParameterSet does not contain parameter {0}, which is used by function[{1}]", fitEle.ParameterName(j), i));
                    }

                    int idx = (int)paraNames[fitEle.ParameterName(j)];
                    if (paraSet[idx].Vary)
                    {
                        info.ParameterMapping[j] = (int)varyingParaNames[fitEle.ParameterName(j)];
                    }
                    else
                    {
                        info.ParameterMapping[j] = -idx - 1;
                    }
                }
            }

            _cachedDependentValues = new double[_cachedNumberOfData];
            GetDependentValues(_cachedDependentValues);

            if (HasToUseWeights())
            {
                _cachedWeights = new double[_cachedNumberOfData];
                GetWeights(_cachedWeights);
            }
            else
            {
                _cachedWeights = null;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Constructor of the adapter.
        /// </summary>
        /// <param name="ensemble">The fit ensemble, i.e. the functions and data you intend to fit.</param>
        /// <param name="paraSet">The set of initial parameter. Must contain a initial estimation of the parameters. Contains also information which
        /// parameters can vary and which are fixed during the fitting procedure.</param>
        public LevMarAdapter(FitEnsemble ensemble, ParameterSet paraSet)
        {
            _fitEnsemble = ensemble;

            CalculateCachedData(paraSet);
        }