public void EhView_EvaluateChiSqr()
 {
   if (true == this._parameterController.Apply())
   {
     LevMarAdapter fitAdapter = new LevMarAdapter(_doc.FitEnsemble, _doc.CurrentParameters);
     this._chiSquare = fitAdapter.EvaluateChiSquare();
     //_doc.FitEnsemble.InitializeParametersFromParameterSet(_doc.CurrentParameters);
     //_doc.FitEnsemble.DistributeParameters();
     OnAfterFittingStep();
   }
   else
   {
     Current.Gui.ErrorMessageBox("Some of your parameter input is not valid!");
   }
 }
示例#2
0
			public NelderMeadCostFunction(LevMarAdapter adapter)
			{
				_adapter = adapter;
			}
    public void EhView_DoFit()
    {
      if (true == this._parameterController.Apply())
      {
        //        _doc.FitEnsemble.InitializeParametersFromParameterSet(_doc.CurrentParameters);

        LevMarAdapter fitAdapter = new LevMarAdapter(_doc.FitEnsemble, _doc.CurrentParameters);

        Current.Gui.ShowBackgroundCancelDialog(10000, new System.Threading.ThreadStart(fitAdapter.Fit), null);

        this._chiSquare = fitAdapter.ResultingChiSquare;

        fitAdapter.CopyParametersBackTo(_doc.CurrentParameters);

        //_doc.FitEnsemble.InitializeParametersFromParameterSet(_doc.CurrentParameters);
        //_doc.FitEnsemble.DistributeParameters();

        OnAfterFittingStep();
      }
      else
      {
        Current.Gui.ErrorMessageBox("Some of your parameter input is not valid!");
      }
    }
示例#4
0
		public void OnSimulation(bool calculateUnusedDependentVariablesAlso)
		{
			// we investigate for every fit element the corresponding table, and add columns to that table
			LevMarAdapter fitAdapter = new LevMarAdapter(_doc.FitEnsemble, _doc.CurrentParameters);

			int numberOfData;

			if (calculateUnusedDependentVariablesAlso)
			{
				numberOfData = 0;
				for (int i = 0; i < _doc.FitEnsemble.Count; i++)
					numberOfData += fitAdapter.GetValidNumericRows(i).Count * _doc.FitEnsemble[i].NumberOfDependentVariables;
			}
			else
			{
				numberOfData = fitAdapter.NumberOfData;
			}

			// calculate the resulting values
			double[] resultingValues = new double[numberOfData];
			fitAdapter.EvaluateFitValues(resultingValues, calculateUnusedDependentVariablesAlso);

			int nextStartOfDependentValues = 0;
			for (int i = 0; i < _doc.FitEnsemble.Count; i++)
			{
				FitElement fitEle = _doc.FitEnsemble[i];
				int startOfDependentValues = nextStartOfDependentValues;
				Collections.IAscendingIntegerCollection validRows = fitAdapter.GetValidNumericRows(i);
				nextStartOfDependentValues += validRows.Count * fitEle.NumberOfUsedDependentVariables;

				Altaxo.Data.DataTable parentTable = fitEle.GetParentDataTable();
				if (parentTable == null)
					continue;

				if (calculateUnusedDependentVariablesAlso)
				{
					// now we have the parent table, we can add columns to it as we need for the independent variables
					int numDependentVars = fitEle.NumberOfDependentVariables;
					for (int k = 0; k < fitEle.NumberOfDependentVariables; k++)
					{
						DoubleColumn col = new DoubleColumn();
						for (int j = 0; j < validRows.Count; j++)
							col[validRows[j]] = resultingValues[startOfDependentValues + k + j * numDependentVars];

						parentTable.DataColumns.Add(col, fitEle.FitFunction.DependentVariableName(k) + ".Sim", ColumnKind.V);
					}
				}
				else // use only the used dependent variables
				{
					int[] inUse = fitAdapter.GetDependentVariablesInUse(i);
					// copy the evaluation result to the output array (interleaved)
					for (int k = 0; k < inUse.Length; ++k)
					{
						DoubleColumn col = new DoubleColumn();
						for (int j = 0; j < validRows.Count; j++)
							col[validRows[j]] = resultingValues[startOfDependentValues + k + j * inUse.Length];

						string name = null;
						int groupNumber = 0;
						if (fitEle.DependentVariables(inUse[k]) is DataColumn)
						{
							var srcCol = (DataColumn)fitEle.DependentVariables(inUse[k]);
							var srcTable = DataColumnCollection.GetParentDataColumnCollectionOf(srcCol);
							if (srcTable != null)
							{
								name = srcTable.GetColumnName(srcCol);
								groupNumber = srcTable.GetColumnGroup(srcCol);
							}
						}
						if (null == name)
							fitEle.FitFunction.DependentVariableName(inUse[k]);

						parentTable.DataColumns.Add(col, name + ".Sim", ColumnKind.V, groupNumber);
					}
				}
			}
		}
示例#5
0
		public void OnSimulationWithInterval(bool calculateUnusedDependentVariablesAlso, Common.EquallySpacedInterval interval)
		{
			// we investigate for every fit element the corresponding table, and add columns to that table
			LevMarAdapter fitAdapter = new LevMarAdapter(_doc.FitEnsemble, _doc.CurrentParameters);

			int intervalCount = (int)interval.Count;
			for (int i = 0; i < _doc.FitEnsemble.Count; i++)
			{
				FitElement fitEle = _doc.FitEnsemble[i];

				Altaxo.Data.DataTable parentTable = fitEle.GetParentDataTable();
				if (parentTable == null)
					continue;

				double[] X = new double[fitEle.NumberOfIndependentVariables];
				double[] Y = new double[fitEle.NumberOfDependentVariables];
				double[] P = new double[fitEle.NumberOfParameters];
				DoubleColumn[] xCols = new DoubleColumn[fitEle.NumberOfIndependentVariables];
				DoubleColumn[] yCols = new DoubleColumn[fitEle.NumberOfDependentVariables];

				for (int k = 0; k < xCols.Length; k++)
					xCols[k] = new DoubleColumn();
				for (int k = 0; k < yCols.Length; k++)
					yCols[k] = new DoubleColumn();

				fitAdapter.GetParameters(i, P);
				for (int k = 0; k < intervalCount; k++)
				{
					double xx = interval[k];

					for (int j = 0; j < X.Length; j++)
					{
						X[j] = xx;
						xCols[j][k] = xx;
					}
					fitEle.FitFunction.Evaluate(X, P, Y);
					for (int j = 0; j < Y.Length; j++)
						yCols[j][k] = Y[j];
				}

				int newGroup = parentTable.DataColumns.GetUnusedColumnGroupNumber();

				for (int k = 0; k < fitEle.NumberOfIndependentVariables; k++)
					parentTable.DataColumns.Add(xCols[k], fitEle.FitFunction.DependentVariableName(k) + ".Sim", ColumnKind.X, newGroup);

				if (calculateUnusedDependentVariablesAlso)
				{
					// now we have the parent table, we can add columns to it as we need for the independent variables
					for (int k = 0; k < fitEle.NumberOfDependentVariables; k++)
						parentTable.DataColumns.Add(yCols[k], fitEle.FitFunction.DependentVariableName(k) + ".Sim", ColumnKind.V, newGroup);
				}
				else // use only the used dependent variables
				{
					int[] inUse = fitAdapter.GetDependentVariablesInUse(i);
					// copy the evaluation result to the output array (interleaved)
					for (int k = 0; k < inUse.Length; ++k)
						parentTable.DataColumns.Add(yCols[inUse[k]], fitEle.FitFunction.DependentVariableName(inUse[k]) + ".Sim", ColumnKind.V, newGroup);
				}
			}
		}
示例#6
0
		public void EhView_DoSimplex()
		{
			if (true == this._parameterController.Apply(false))
			{
				//        _doc.FitEnsemble.InitializeParametersFromParameterSet(_doc.CurrentParameters);

				LevMarAdapter fitAdapter = new LevMarAdapter(_doc.FitEnsemble, _doc.CurrentParameters);

				var fitThread = new System.Threading.Thread(new System.Threading.ThreadStart(fitAdapter.DoSimplexMinimization));
				fitThread.Start();
				Current.Gui.ShowBackgroundCancelDialog(10000, null, fitThread);
				if (!(fitThread.ThreadState.HasFlag(System.Threading.ThreadState.Aborted)))
				{
					this._chiSquare = fitAdapter.ResultingChiSquare;

					fitAdapter.CopyParametersBackTo(_doc.CurrentParameters);

					//_doc.FitEnsemble.InitializeParametersFromParameterSet(_doc.CurrentParameters);
					//_doc.FitEnsemble.DistributeParameters();

					OnAfterFittingStep();
				}
			}
			else
			{
				Current.Gui.ErrorMessageBox("Some of your parameter input is not valid!");
			}
		}
示例#7
0
		public void EhView_EvaluateChiSqr()
		{
			if (true == this._parameterController.Apply(false))
			{
				LevMarAdapter fitAdapter = new LevMarAdapter(_doc.FitEnsemble, _doc.CurrentParameters);

				var fitThread = new System.Threading.Thread(new System.Threading.ThreadStart(() => this._chiSquare = fitAdapter.EvaluateChiSquare()));
				fitThread.Start();
				Current.Gui.ShowBackgroundCancelDialog(10000, null, fitThread);
				if (!(fitThread.ThreadState.HasFlag(System.Threading.ThreadState.Aborted)))
				{
					OnAfterFittingStep();
				}
			}
			else
			{
				Current.Gui.ErrorMessageBox("Some of your parameter input is not valid!");
			}
		}
示例#8
0
 public NelderMeadCostFunction(LevMarAdapter adapter)
 {
     _adapter = adapter;
 }
示例#9
0
 /// <summary>
 /// Executes the fit. Afterwards, you can get the fit parameters by <see cref="GetParameter"/>, or the resulting Chi².
 /// </summary>
 public void Fit()
 {
     _fitAdapter = new LevMarAdapter(_fitDoc.FitEnsemble, _fitDoc.CurrentParameters);
     _fitAdapter.Fit();
     _fitAdapter.CopyParametersBackTo(_fitDoc.CurrentParameters);
 }
示例#10
0
		/// <summary>
		/// Executes the fit. Afterwards, you can get the fit parameters by <see cref="GetParameter"/>, or the resulting Chi².
		/// </summary>
		public void Fit()
		{
			_fitAdapter = new LevMarAdapter(_fitDoc.FitEnsemble, _fitDoc.CurrentParameters);
			_fitAdapter.Fit();
			_fitAdapter.CopyParametersBackTo(_fitDoc.CurrentParameters);
		}