protected override System.Collections.Generic.IEnumerable <Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName() { if (null != _fitDocument) { yield return(new Main.DocumentNodeAndName(_fitDocument, () => _fitDocument = null, "FitDocument")); } }
public static string ShowFitDialog(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl) { var tuple = SelectFitDocument(ctrl); if (!string.IsNullOrEmpty(tuple.Item1)) { return(tuple.Item1); } var fitDocument = tuple.Item2; var fitDocumentIdentifier = tuple.Item3; var activeLayer = tuple.Item4; // we assume we have a fit document by now if (null == tuple.Item2) { throw new InvalidProgramException("At this place, fit document should always be != null"); } if (!string.IsNullOrEmpty(fitDocumentIdentifier)) { var answer = Current.Gui.YesNoCancelMessageBox( "At least one fit function plot item was found in the document from which the fit document could be retrieved.\r\n" + "When changing the fit or the parameters, these fit function plot items would be changed, too.\r\n" + "Sometimes, you might want to keep the previous fit function plot items, e.g. in order to compare them with the new ones.\r\n" + "\r\n" + "Do you want to keep the previous fit function plot item(s) ?", "Keep previous fit function plot items?", false); if (null == answer) { return(null); } if (true == answer) { fitDocumentIdentifier = null; // by setting the identifier to null, we will keep the old fit functions } } var fitController = (Gui.IMVCANController)Current.Gui.GetControllerAndControl(new object[] { fitDocument, fitDocumentIdentifier, activeLayer }, typeof(Gui.IMVCANController)); // before showing the fit dialog, deselect all objects selected if (!ctrl.SelectedObjects.IsReadOnly) // with some graph tools, this is a read-only collection, which can not be cleared { ctrl.SelectedObjects.Clear(); } if (true == Current.Gui.ShowDialog(fitController, "Non-linear fitting")) { var localdoc = fitController.ModelObject as NonlinearFitDocument; // store the fit document in the graphs property ctrl.Doc.SetGraphProperty(FitDocumentPropertyName, localdoc); _lastFitDocument = (Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument)localdoc.Clone(); } return(null); }
public NonlinearFitController(NonlinearFitDocument doc) { _doc = doc; _parameterController = (IMVCAController)Current.Gui.GetControllerAndControl(new object[] { _doc.CurrentParameters }, typeof(IMVCAController)); _fitEnsembleController = (IFitEnsembleController)Current.Gui.GetControllerAndControl(new object[] { _doc.FitEnsemble }, typeof(IFitEnsembleController)); _funcselController = new FitFunctionSelectionController(_doc.FitEnsemble.Count == 0 ? null : _doc.FitEnsemble[0].FitFunction); Current.Gui.FindAndAttachControlTo(_funcselController); _doc.FitEnsemble.Changed += new EventHandler(EhFitEnsemble_Changed); }
/// <summary> /// Initializes a new instance of the <see cref="XYNonlinearFitFunctionPlotData"/> class. /// </summary> /// <param name="fitDocumentIdentifier">The fit document identifier.</param> /// <param name="fitDocument">The fit document. The document will be cloned before stored in this instance.</param> /// <param name="fitElementIndex">Index of the fit element.</param> /// <param name="dependentVariableIndex">Index of the dependent variable of the fit element.</param> /// <param name="dependentVariableTransformation">Transformation, which is applied to the result of the fit function to be then shown in the plot. Can be null.</param> /// <param name="independentVariableIndex">Index of the independent variable of the fit element.</param> /// <param name="independentVariableTransformation">Transformation, which is applied to the x value before it is applied to the fit function. Can be null.</param> public XYNonlinearFitFunctionPlotData(string fitDocumentIdentifier, NonlinearFitDocument fitDocument, int fitElementIndex, int dependentVariableIndex, IVariantToVariantTransformation dependentVariableTransformation, int independentVariableIndex, IVariantToVariantTransformation independentVariableTransformation) { if (null == fitDocumentIdentifier) { throw new ArgumentNullException(nameof(fitDocumentIdentifier)); } if (null == fitDocument) { throw new ArgumentNullException(nameof(fitDocument)); } ChildCloneToMember(ref _fitDocument, fitDocument); // clone here, because we want to have a local copy which can not change. _fitDocumentIdentifier = fitDocumentIdentifier; _fitElementIndex = fitElementIndex; _dependentVariableIndex = dependentVariableIndex; Function = new FitFunctionToScalarFunctionDDWrapper(_fitDocument.FitEnsemble[fitElementIndex].FitFunction, dependentVariableIndex, dependentVariableTransformation, independentVariableIndex, independentVariableTransformation, _fitDocument.GetParametersForFitElement(fitElementIndex)); }
/// <summary> /// Initializes a new instance of the <see cref="XYNonlinearFitFunctionPlotItem"/> class. /// </summary> /// <param name="fitDocumentIdentifier">The fit document identifier.</param> /// <param name="fitDocument">The fit document. The document will be cloned before stored in this instance.</param> /// <param name="fitElementIndex">Index of the fit element.</param> /// <param name="dependentVariableIndex">Index of the dependent variable of the fit element.</param> /// <param name="dependentVariableTransformation">Transformation, which is applied to the result of the fit function to be then shown in the plot. Can be null.</param> /// <param name="ps">The ps.</param> public XYNonlinearFitFunctionPlotItem(string fitDocumentIdentifier, NonlinearFitDocument fitDocument, int fitElementIndex, int dependentVariableIndex, IVariantToVariantTransformation dependentVariableTransformation, int independentVariableIndex, IVariantToVariantTransformation independentVariableTransformation, G2DPlotStyleCollection ps) : base() { if (null == fitDocumentIdentifier) { throw new ArgumentNullException(nameof(fitDocumentIdentifier)); } if (null == fitDocument) { throw new ArgumentNullException(nameof(fitDocument)); } if (null == ps) { throw new ArgumentNullException(nameof(ps)); } ChildSetMember(ref _plotData, new XYNonlinearFitFunctionPlotData(fitDocumentIdentifier, fitDocument, fitElementIndex, dependentVariableIndex, dependentVariableTransformation, independentVariableIndex, independentVariableTransformation)); Style = ps; }
/// <summary> /// Initializes a new instance of the <see cref="XYNonlinearFitFunctionConfidenceBandPlotData"/> class. /// </summary> /// <param name="isPredictionBand">If true, the prediction band is displayed instead of the confidence band. The prediction band is a little wider, because the sigma of the data points give an additional contribution.</param> /// <param name="isLowerBand">True if this data present the lower confidence (or prediction) band; true if the data represent the upper confidence (or prediction) band.</param> /// <param name="confidenceLevel">A number greater than 0 and less than 1 representing the confidence level. Usual values are e.g. 0.95, 0.99, 0.999.</param> /// <param name="fitDocumentIdentifier">The fit document identifier.</param> /// <param name="fitDocument">The fit document. The document will be cloned before stored in this instance.</param> /// <param name="fitElementIndex">Index of the fit element.</param> /// <param name="dependentVariableIndex">Index of the dependent variable of the fit element.</param> /// <param name="dependentVariableTransformation">Transformation, which is applied to the result of the fit function to be then shown in the plot. Can be null.</param> /// <param name="independentVariableIndex">Index of the independent variable of the fit element.</param> /// <param name="independentVariableTransformation">Transformation, which is applied to the x value before it is applied to the fit function. Can be null.</param> /// <param name="numberOfFittedPoints">Number of points that were used for fitting. Needed to calculate the Student's distribution quantile.</param> /// <param name="sigmaSquare">Mean square difference between data points and fitting curve = sumChiSquare/(n-r).</param> /// <param name="covarianceMatrixTimesSigmaSquare">A matrix, representing sigma²(A*At)^-1, which are the covariances of the parameter.</param> public XYNonlinearFitFunctionConfidenceBandPlotData( bool isPredictionBand, bool isLowerBand, double confidenceLevel, string fitDocumentIdentifier, NonlinearFitDocument fitDocument, int fitElementIndex, int dependentVariableIndex, IVariantToVariantTransformation dependentVariableTransformation, int independentVariableIndex, IVariantToVariantTransformation independentVariableTransformation, int numberOfFittedPoints, double sigmaSquare, double[] covarianceMatrixTimesSigmaSquare) { if (null == fitDocumentIdentifier) { throw new ArgumentNullException(nameof(fitDocumentIdentifier)); } if (null == fitDocument) { throw new ArgumentNullException(nameof(fitDocument)); } if (!(confidenceLevel > 0 && confidenceLevel < 1)) { throw new ArgumentOutOfRangeException("Confidence level must be > 0 and < 1", nameof(confidenceLevel)); } if (!(sigmaSquare >= 0)) { throw new ArgumentOutOfRangeException("SigmaSquare must be >=0", nameof(sigmaSquare)); } IsLowerBand = isLowerBand; _confidenceLevel = confidenceLevel; _sigmaSquare = sigmaSquare; ChildCloneToMember(ref _fitDocument, fitDocument); // clone here, because we want to have a local copy which can not change. _fitDocumentIdentifier = fitDocumentIdentifier; _fitElementIndex = fitElementIndex; _dependentVariableIndex = dependentVariableIndex; _dependentVariableTransformation = dependentVariableTransformation; _independentVariableTransformation = independentVariableTransformation; _numberOfFitPoints = numberOfFittedPoints; var(allVaryingParameterNames, indicesOfThisFitElementsVaryingParametersInAllVaryingParameters) = CreateCachedMembers(); // the covariance matrix should have the dimensions of allVaryingParameters.Count x allVaryingParameters.Count if (!(covarianceMatrixTimesSigmaSquare.Length == allVaryingParameterNames.Count * allVaryingParameterNames.Count)) { throw new InvalidProgramException("Covariance matrix dimension does not match with number of varying parameters"); } for (int i = 0; i < _cachedIndicesOfVaryingParametersOfThisFitElement.Length; ++i) { int iRowOriginalCovMat = indicesOfThisFitElementsVaryingParametersInAllVaryingParameters[i]; int iRowThisCovMat = _cachedIndicesOfVaryingParametersOfThisFitElement[i]; for (int j = 0; j < _cachedIndicesOfVaryingParametersOfThisFitElement.Length; ++j) { int jColOriginalCovMat = indicesOfThisFitElementsVaryingParametersInAllVaryingParameters[j]; int jColThisCovMat = _cachedIndicesOfVaryingParametersOfThisFitElement[j]; _covarianceMatrix[iRowThisCovMat, jColThisCovMat] = covarianceMatrixTimesSigmaSquare[iRowOriginalCovMat * allVaryingParameterNames.Count + jColOriginalCovMat]; // TODO is covariance matrix column major or row major } } }