public void Initialize(IFitFunction fitFunction, int dependentVariable, IVariantToVariantTransformation dependentVariableTransformation, int independentVariable, IVariantToVariantTransformation independentVariableTransformation, double[] parameter) { _fitFunction = fitFunction; if (_fitFunction != null) { _x = new double[_fitFunction.NumberOfIndependentVariables]; _y = new double[_fitFunction.NumberOfDependentVariables]; _parameter = new double[Math.Max(_fitFunction.NumberOfParameters, parameter.Length)]; if (_fitFunction is Main.IDocumentLeafNode && !(_fitFunction is Altaxo.Scripting.FitFunctionScript)) { ((Main.IDocumentLeafNode)fitFunction).ParentObject = this; } } else { _x = new double[1]; _y = new double[1]; _parameter = new double[parameter.Length]; } _dependentVariable = dependentVariable; _dependentVariableTransformation = dependentVariableTransformation; _independentVariable = independentVariable; _independentVariableTransformation = independentVariableTransformation; int len = Math.Min(_parameter.Length, parameter.Length); for (int i = 0; i < len; i++) { _parameter[i] = parameter[i]; } }
public void EditItemOrItemCopy(IFitFunctionInformation selectedtag, bool editItemCopy) { IFitFunction func = null; if (selectedtag is DocumentFitFunctionInformation) { func = selectedtag.CreateFitFunction(); } else if (selectedtag is FileBasedFitFunctionInformation) { func = Altaxo.Main.Services.FitFunctionService.ReadUserDefinedFitFunction(selectedtag as Altaxo.Main.Services.FileBasedFitFunctionInformation); } if (null != func) { var editedFunc = Edit(func, editItemCopy); if (null != editedFunc) { var selNode = SelectFitFunction(editedFunc); if (null != selNode) { FitFunctionSelected((IFitFunctionInformation)selNode.Tag); } } } }
public void Initialize(IFitFunction fitFunction, int dependentVariable, int independentVariable, double[] parameter) { _fitFunction = fitFunction; if (_fitFunction != null) { _x = new double[_fitFunction.NumberOfIndependentVariables]; _y = new double[_fitFunction.NumberOfDependentVariables]; _parameter = new double[Math.Max(_fitFunction.NumberOfParameters, parameter.Length)]; } else { _x = new double[1]; _y = new double[1]; _parameter = new double[parameter.Length]; } _dependentVariable = dependentVariable; _independentVariable = independentVariable; int len = Math.Min(_parameter.Length, parameter.Length); for (int i = 0; i < len; i++) { _parameter[i] = parameter[i]; } }
public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info) { FitFunctionScript s = (FitFunctionScript)obj; // Update the user defined paramter names if (s.m_ScriptObject != null && s.IsUsingUserDefinedParameterNames) { IFitFunction ff = (IFitFunction)s.m_ScriptObject; if (s._UserDefinedParameterNames == null || s._UserDefinedParameterNames.Length != ff.NumberOfParameters) { s._UserDefinedParameterNames = new string[ff.NumberOfParameters]; } for (int i = 0; i < ff.NumberOfParameters; ++i) { s._UserDefinedParameterNames[i] = ff.ParameterName(i); } } info.AddValue("Category", s.FitFunctionCategory); info.AddValue("Name", s.FitFunctionName); info.AddValue("CreationTime", s._fitFunctionCreationTime); info.AddValue("Description", s.FitFunctionName); info.AddBaseValueEmbedded(s, typeof(AbstractScript)); info.AddValue("NumberOfParameters", s.NumberOfParameters); info.AddValue("UserDefinedParameters", s.IsUsingUserDefinedParameterNames); if (s.IsUsingUserDefinedParameterNames) { info.AddArray("UserDefinedParameterNames", s._UserDefinedParameterNames, s._UserDefinedParameterNames.Length); } info.AddArray("IndependentVariableNames", s._IndependentVariablesNames, s._IndependentVariablesNames.Length); info.AddArray("DependentVariableNames", s._DependentVariablesNames, s._DependentVariablesNames.Length); }
public GravitationalSearchAlgorithm(IFitFunction function, OptimizationType optimizationType, int numAgents, int numDimensions, int maxIteration, double minSearchValue, double maxSearchValue) { MaxIteration = maxIteration; NumAgents = numAgents; NumDimensions = numDimensions; MinSearchValue = minSearchValue; MaxSearchValue = maxSearchValue; Function = function; OptimizationType = optimizationType; }
public GasesBrownianMotionOptimization(IFitFunction function, OptimizationType optimizationType, int numAgents, int numDimensions, int maxIteration, double minSearchValue, double maxSearchValue) { MaxIteration = maxIteration; NumAgents = numAgents; NumDimensions = numDimensions; MinSearchValue = minSearchValue; MaxSearchValue = maxSearchValue; Function = function; OptimizationType = optimizationType; }
void Select(IFitFunction func) { bool changed = false; if (_doc.FitEnsemble.Count == 0) // Fitting is fresh, we can add the function silently { FitElement newele = new FitElement(); newele.FitFunction = func; _doc.FitEnsemble.Add(newele); _doc.SetDefaultParametersForFitElement(0); changed = true; } else if (_doc.FitEnsemble.Count > 0 && _doc.FitEnsemble[_doc.FitEnsemble.Count - 1].FitFunction == null) { _doc.FitEnsemble[_doc.FitEnsemble.Count - 1].FitFunction = func; _doc.SetDefaultParametersForFitElement(_doc.FitEnsemble.Count - 1); changed = true; } else // Count>0, and there is already a fit function, we { // have to ask the user whether he wants to discard the old functions or keep them System.Enum selchoice = _lastSelectionChoice; if (Current.Gui.ShowDialog(ref selchoice, "As only or as additional?")) { _lastSelectionChoice = (SelectionChoice)selchoice; if (_lastSelectionChoice == SelectionChoice.SelectAsAdditional) { FitElement newele = new FitElement(); newele.FitFunction = func; _doc.FitEnsemble.Add(newele); _doc.SetDefaultParametersForFitElement(_doc.FitEnsemble.Count - 1); changed = true; } else // select as only { _doc.FitEnsemble[0].FitFunction = func; _doc.SetDefaultParametersForFitElement(0); for (int i = _doc.FitEnsemble.Count - 1; i >= 1; --i) { _doc.FitEnsemble.RemoveAt(i); } changed = true; } } } if (changed) { // _doc.FitEnsemble.InitializeParameterSetFromEnsembleParameters(_doc.CurrentParameters); this._fitEnsembleController.Refresh(); } }
private double zeta = 0.02; // Total Cost of Empire = Cost of Imperialist + Zeta * mean(Cost of All Colonies) //https://www.researchgate.net/post/Can-anyone-help-me-with-the-Imperialist-Competitive-Algorithm public ImperialistCompetitiveAlgorithm(IFitFunction function, OptimizationType optimizationType, int numCountry, int numImperialist, int numDimensions, int maxIteration, double minSearchValue, double maxSearchValue) { MaxIteration = maxIteration; NumCountry = numCountry; NumDimensions = numDimensions; MinSearchValue = minSearchValue; MaxSearchValue = maxSearchValue; Function = function; NumImperialist = numImperialist; OptimizationType = optimizationType; }
private FitFunctionLeafNode SelectFitFunction(IFitFunction func) { var selNode = (FitFunctionLeafNode)TreeNodeExtensions.AnyBetweenHereAndLeaves(_fitFunctionsRoot, (node) => node is FitFunctionLeafNode dln && dln.FunctionType is DocumentFitFunctionInformation dffi && func.Equals(dffi.FitFunction)); if (null != selNode) { selNode.IsExpanded = true; selNode.IsSelected = true; } return(selNode); }
public void EhView_EditItem(IFitFunctionInformation selectedtag) { if (selectedtag is DocumentFitFunctionInformation) { EditItem(selectedtag.CreateFitFunction()); } else if (selectedtag is FileBasedFitFunctionInformation) { IFitFunction func = Altaxo.Main.Services.FitFunctionService.ReadUserDefinedFitFunction(selectedtag as Altaxo.Main.Services.FileBasedFitFunctionInformation); EditItem(func); } }
public FitElement(FitElement from) { if (from._fitFunction is ICloneable fromFitFunc1) { _fitFunction = (IFitFunction)fromFitFunc1.Clone(); if (_fitFunction is Main.IDocumentLeafNode thisFitFunc1) { thisFitFunc1.ParentObject = this; } } else { _fitFunction = from._fitFunction; } if (null != _fitFunction) { _fitFunction.Changed += EhFitFunctionChanged; } ChildCopyToMember(ref _dataTable, from._dataTable); _groupNumber = from._groupNumber; ChildCloneToMember(ref _rangeOfRows, from._rangeOfRows); _independentVariables = new IReadableColumnProxy[from._independentVariables.Length]; for (int i = 0; i < _independentVariables.Length; ++i) { ChildCloneToMember(ref _independentVariables[i], from._independentVariables[i]); } _dependentVariables = new IReadableColumnProxy[from._dependentVariables.Length]; for (int i = 0; i < _dependentVariables.Length; ++i) { ChildCloneToMember(ref _dependentVariables[i], from._dependentVariables[i]); } _errorEvaluation = new IVarianceScaling[from._errorEvaluation.Length]; for (int i = 0; i < _errorEvaluation.Length; ++i) { if (from._errorEvaluation[i] != null) { _errorEvaluation[i] = (IVarianceScaling)from._errorEvaluation[i].Clone(); } } _parameterNames = (string[])from._parameterNames.Clone(); _parameterNameStart = from._parameterNameStart; }
/// <summary> /// This reads a fit function, that is stored in xml format onto disc. /// </summary> /// <param name="info">The fit function information (only the file name is used from it).</param> /// <returns>The fit function, or null if the fit function could not be read.</returns> public static IFitFunction ReadFileBasedFitFunction(Main.Services.FileBasedFitFunctionInformation info) { IFitFunction func = null; try { Altaxo.Serialization.Xml.XmlStreamDeserializationInfo str = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); str.BeginReading(new FileStream(info.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)); func = (IFitFunction)str.GetValue(null); str.EndReading(); return(func); } catch (Exception ex) { Current.Console.WriteLine("Error reading fit function from file {0}, error details: {1}", info.FileName, ex.ToString()); } return(null); }
public bool Apply(bool disposeController) { if (_tempdoc == null) // nothing selected, so return the original doc { return(true); } try { _doc = _tempdoc.CreateFitFunction(); return(true); } catch (Exception ex) { Current.Gui.ErrorMessageBox("Can not create fit function. An exception was thrown: " + ex.Message); } return(false); }
void EditItem(IFitFunction func) { if (null != func) { object[] args = new object[] { func }; if (Current.Gui.ShowDialog(args, "Edit fit function script")) { if (args[0] is FitFunctionScript) { Altaxo.Gui.Scripting.FitFunctionNameAndCategoryController ctrl = new Altaxo.Gui.Scripting.FitFunctionNameAndCategoryController((FitFunctionScript)args[0]); if (Current.Gui.ShowDialog(ctrl, "Store?")) { // Note: category and/or name can have changed now, so it is more save to // completely reinitialize the fit function tree Initialize(); } } } } }
private (List <string> allVaryingParameterNames, int[] indicesOfThisFitElementsVaryingParametersInAllVaryingParameters) CreateCachedMembers() { var fitElement = _fitDocument.FitEnsemble[_fitElementIndex]; _cachedFitFunction = fitElement.FitFunction; _cachedParameters = _fitDocument.GetParametersForFitElement(_fitElementIndex); _cachedParametersForJacobianEvaluation = _fitDocument.GetParametersForFitElement(_fitElementIndex); _cachedJacobian = new double[_cachedParameters.Length]; _functionValues = new double[_cachedFitFunction.NumberOfDependentVariables]; // CovarianceMatrix: we have to pick exactly the varying parameters of this fitelement! // next line retrieves all varying parameters of all fitelements, this corresponds to the rows of the provided covariance matrix var allVaryingParameterNames = new List <string>(_fitDocument.CurrentParameters.Where(x => x.Vary).Select(x => x.Name)); // Indices of the varying parameters of this fit element (with respect to the parameter set of this fitelement) _cachedIndicesOfVaryingParametersOfThisFitElement = Enumerable.Range(0, fitElement.NumberOfParameters).Where(i => allVaryingParameterNames.IndexOf(fitElement.ParameterName(i)) >= 0).ToArray(); // Indices in allVaryingParameters of the parameters in this fitlement, which are varying var indicesOfThisFitElementsVaryingParametersInAllVaryingParameters = Enumerable.Range(0, _cachedIndicesOfVaryingParametersOfThisFitElement.Length).Select(i => allVaryingParameterNames.IndexOf(fitElement.ParameterName(_cachedIndicesOfVaryingParametersOfThisFitElement[i]))).ToArray(); // now we are able to pick the values out of the covariance matrix if (!(_numberOfFitPoints > _cachedIndicesOfVaryingParametersOfThisFitElement.Length)) { _cachedQuantileOfStudentsDistribution = double.NaN; // 0 degrees of freedom } else { // for a given confidence interval, e.g. 0.95, we need to make 0.975 out of it _cachedQuantileOfStudentsDistribution = Altaxo.Calc.Probability.StudentsTDistribution.Quantile(1 - (0.5 * (1 - _confidenceLevel)), _numberOfFitPoints - _cachedIndicesOfVaryingParametersOfThisFitElement.Length); } // for convenience, we let this covariance matrix to be of dimension NumberOfParameters x NumberOfParameters, but we // don't set the elements corresponding to the non-varying parameters, thus they remain zero _covarianceMatrix = new double[fitElement.NumberOfParameters, fitElement.NumberOfParameters]; return(allVaryingParameterNames, indicesOfThisFitElementsVaryingParametersInAllVaryingParameters); }
protected void CollectParameterNames() { _ParametersSortedByName = new System.Collections.SortedList(); int nameposition = 0; for (int i = 0; i < InnerList.Count; i++) { if (null == this[i].FitFunction) { continue; } IFitFunction func = this[i].FitFunction; FitElement ele = this[i]; for (int k = 0; k < func.NumberOfParameters; k++) { if (!(_ParametersSortedByName.ContainsKey(ele.ParameterName(k)))) { _ParametersSortedByName.Add(ele.ParameterName(k), nameposition++); } } } // now sort the items in the order of the namepositions System.Collections.SortedList sortedbypos = new System.Collections.SortedList(); foreach (DictionaryEntry en in _ParametersSortedByName) { sortedbypos.Add(en.Value, en.Key); } _parameterNames = new string[sortedbypos.Count]; for (int i = 0; i < _parameterNames.Length; i++) { _parameterNames[i] = (string)sortedbypos[i]; } }
public FitElement(FitElement from) { this._fitFunction = from._fitFunction; if (_fitFunction is ICloneable) { this._fitFunction = (IFitFunction)((ICloneable)from.FitFunction).Clone(); } _rangeOfRows = PositiveIntegerRange.NewFromFirstAndCount(from._rangeOfRows.First, from._rangeOfRows.Count); _independentVariables = new NumericColumnProxy[from._independentVariables.Length]; for (int i = 0; i < _independentVariables.Length; ++i) { if (from._independentVariables[i] != null) { _independentVariables[i] = (NumericColumnProxy)from._independentVariables[i].Clone(); } } _dependentVariables = new NumericColumnProxy[from._dependentVariables.Length]; for (int i = 0; i < _dependentVariables.Length; ++i) { if (from._dependentVariables[i] != null) { _dependentVariables[i] = (NumericColumnProxy)from._dependentVariables[i].Clone(); } } _errorEvaluation = new IVarianceScaling[from._errorEvaluation.Length]; for (int i = 0; i < _errorEvaluation.Length; ++i) { if (from._errorEvaluation[i] != null) { _errorEvaluation[i] = (IVarianceScaling)from._errorEvaluation[i].Clone(); } } _parameterNames = (string[])from._parameterNames.Clone(); _parameterNameStart = from._parameterNameStart; }
public override bool Compile() { bool success = base.Compile(); if (success && (this.m_ScriptObject is IFitFunction)) { IFitFunction ff = (IFitFunction)m_ScriptObject; this._NumberOfParameters = ff.NumberOfParameters; this._fitFunctionCreationTime = DateTime.Now; if (this.IsUsingUserDefinedParameterNames) { if (_UserDefinedParameterNames == null || _UserDefinedParameterNames.Length != ff.NumberOfParameters) { _UserDefinedParameterNames = new string[ff.NumberOfParameters]; } for (int i = 0; i < ff.NumberOfParameters; ++i) { _UserDefinedParameterNames[i] = ff.ParameterName(i); } } this._IndependentVariablesNames = new string[ff.NumberOfIndependentVariables]; for (int i = 0; i < this._IndependentVariablesNames.Length; ++i) { this._IndependentVariablesNames[i] = ff.IndependentVariableName(i); } this._DependentVariablesNames = new string[ff.NumberOfDependentVariables]; for (int i = 0; i < this._DependentVariablesNames.Length; ++i) { this._DependentVariablesNames[i] = ff.DependentVariableName(i); } } return(success); }
private FitFunctionScript Edit(IFitFunction func, bool editItemCopy) { if (null != func) { if (func is FitFunctionScript) { editItemCopy = true; // for scripts, we always edit a copy } object[] args = new object[] { (editItemCopy && func is ICloneable cfunc) ? cfunc.Clone() : func }; if (Current.Gui.ShowDialog(args, "Edit fit function script")) { if (args[0] is FitFunctionScript editedScript) { var ctrl = new Altaxo.Gui.Scripting.FitFunctionNameAndCategoryController(); ctrl.InitializeDocument(editedScript); if (Current.Gui.ShowDialog(ctrl, "Store?")) { // add the new script to the list var editedScript2 = Current.Project.FitFunctionScripts.Add(editedScript); if (!object.ReferenceEquals(editedScript, editedScript2)) { Current.Gui.InfoMessageBox("Edited fit function was not added because exactly the same fit function already exists.", "To your information"); } // Note: category and/or name can have changed now, so it is more save to // completely reinitialize the fit function tree Initialize(true); return(editedScript2); } } } } return(null); }
private void EditItem(IFitFunction func, bool editCopy) { if (null != func) { object[] args = new object[] { (editCopy && (func is ICloneable)) ? ((ICloneable)func).Clone() : func }; if (Current.Gui.ShowDialog(args, "Edit fit function script")) { if (args[0] is FitFunctionScript) { var ctrl = new Altaxo.Gui.Scripting.FitFunctionNameAndCategoryController(); ctrl.InitializeDocument((FitFunctionScript)args[0]); if (Current.Gui.ShowDialog(ctrl, "Store?")) { // add the new script to the list Current.Project.FitFunctionScripts.Add((FitFunctionScript)args[0]); // Note: category and/or name can have changed now, so it is more save to // completely reinitialize the fit function tree Initialize(); } } } } }
protected override System.Collections.Generic.IEnumerable <Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName() { if (_fitFunction is Main.IDocumentLeafNode && object.ReferenceEquals(((Main.IDocumentLeafNode)_fitFunction).ParentObject, this)) { yield return(new Main.DocumentNodeAndName((Main.IDocumentLeafNode)_fitFunction, () => _fitFunction = null, "WrappedFitFunction")); } }
public FitFunctionToScalarFunctionDDWrapper(IFitFunction fitFunction, int dependentVariable, double[] parameter) { Initialize(fitFunction, dependentVariable, null, 0, null, parameter); }
public FitElement(FitElement from) { this._fitFunction = from._fitFunction; if (_fitFunction is ICloneable) this._fitFunction = (IFitFunction)((ICloneable)from.FitFunction).Clone(); if (null != _fitFunction) _fitFunction.Changed += EhFitFunctionChanged; ChildCopyToMember(ref _dataTable, from._dataTable); this._groupNumber = from._groupNumber; ChildCloneToMember(ref _rangeOfRows, from._rangeOfRows); _independentVariables = new IReadableColumnProxy[from._independentVariables.Length]; for (int i = 0; i < _independentVariables.Length; ++i) { if (from._independentVariables[i] != null) _independentVariables[i] = (IReadableColumnProxy)from._independentVariables[i].Clone(); } _dependentVariables = new IReadableColumnProxy[from._dependentVariables.Length]; for (int i = 0; i < _dependentVariables.Length; ++i) { if (from._dependentVariables[i] != null) _dependentVariables[i] = (IReadableColumnProxy)from._dependentVariables[i].Clone(); } _errorEvaluation = new IVarianceScaling[from._errorEvaluation.Length]; for (int i = 0; i < _errorEvaluation.Length; ++i) { if (from._errorEvaluation[i] != null) _errorEvaluation[i] = (IVarianceScaling)from._errorEvaluation[i].Clone(); } _parameterNames = (string[])from._parameterNames.Clone(); _parameterNameStart = from._parameterNameStart; }
public FitFunctionSelectionController(IFitFunction doc) { _doc = doc; _tempdoc = null; Initialize(true); }
public void Initialize(IFitFunction fitFunction, int dependentVariable, int independentVariable, double[] parameter) { _fitFunction = fitFunction; if (_fitFunction != null) { _x = new double[_fitFunction.NumberOfIndependentVariables]; _y = new double[_fitFunction.NumberOfDependentVariables]; _parameter = new double[Math.Max(_fitFunction.NumberOfParameters, parameter.Length)]; if (_fitFunction is Main.IDocumentLeafNode && !(_fitFunction is Altaxo.Scripting.FitFunctionScript)) ((Main.IDocumentLeafNode)fitFunction).ParentObject = this; } else { _x = new double[1]; _y = new double[1]; _parameter = new double[parameter.Length]; } _dependentVariable = dependentVariable; _independentVariable = independentVariable; int len = Math.Min(_parameter.Length, parameter.Length); for (int i = 0; i < len; i++) _parameter[i] = parameter[i]; }
public FitFunctionToScalarFunctionDDWrapper(IFitFunction fitFunction, int dependentVariable, int independentVariable, double[] parameter) { Initialize(fitFunction,dependentVariable, independentVariable, parameter); }
public void Initialize(IFitFunction fitFunction, int dependentVariable, int independentVariable, double[] parameter) { _fitFunction = fitFunction; if(_fitFunction!=null) { _x = new double[_fitFunction.NumberOfIndependentVariables]; _y = new double[_fitFunction.NumberOfDependentVariables]; _parameter = new double[Math.Max(_fitFunction.NumberOfParameters,parameter.Length)]; } else { _x = new double[1]; _y = new double[1]; _parameter = new double[parameter.Length]; } _dependentVariable = dependentVariable; _independentVariable = independentVariable; int len = Math.Min(_parameter.Length,parameter.Length); for(int i=0;i<len;i++) _parameter[i]=parameter[i]; }
public FitFunctionSelectionController(IFitFunction doc) { _doc = doc; _tempdoc = null; Initialize(); }
public FitFunctionToScalarFunctionDDWrapper(IFitFunction fitFunction, int dependentVariable, IVariantToVariantTransformation dependentVariableTransformation, int independentVariable, IVariantToVariantTransformation independentVariableTransformation, double[] parameter) { Initialize(fitFunction, dependentVariable, dependentVariableTransformation, independentVariable, independentVariableTransformation, parameter); }
protected override System.Collections.Generic.IEnumerable<Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName() { if (null != _independentVariables) { for (int i = 0; i < _independentVariables.Length; ++i) { if (null != _independentVariables[i]) yield return new Main.DocumentNodeAndName(_independentVariables[i], "IndependentVariable" + i.ToString(System.Globalization.CultureInfo.InvariantCulture)); } } if (null != _dependentVariables) { for (int i = 0; i < _dependentVariables.Length; ++i) { if (null != _dependentVariables[i]) yield return new Main.DocumentNodeAndName(_dependentVariables[i], "DependentVariable" + i.ToString(System.Globalization.CultureInfo.InvariantCulture)); } } if (_fitFunction is Main.IDocumentLeafNode) yield return new Main.DocumentNodeAndName((Main.IDocumentLeafNode)_fitFunction, () => _fitFunction = null, "FitFunction"); }
public bool Apply(bool disposeController) { if (_tempdoc == null) // nothing selected, so return the original doc return true; try { _doc = _tempdoc.CreateFitFunction(); return true; } catch (Exception ex) { Current.Gui.ErrorMessageBox("Can not create fit function. An exception was thrown: " + ex.Message); } return false; }
void Select(IFitFunction func) { bool changed = false; if (_doc.FitEnsemble.Count == 0) // Fitting is fresh, we can add the function silently { FitElement newele = new FitElement(); newele.FitFunction = func; _doc.FitEnsemble.Add(newele); _doc.SetDefaultParametersForFitElement(0); changed = true; } else if (_doc.FitEnsemble.Count > 0 && _doc.FitEnsemble[_doc.FitEnsemble.Count - 1].FitFunction == null) { _doc.FitEnsemble[_doc.FitEnsemble.Count - 1].FitFunction = func; _doc.SetDefaultParametersForFitElement(_doc.FitEnsemble.Count - 1); changed = true; } else // Count>0, and there is already a fit function, we { // have to ask the user whether he wants to discard the old functions or keep them System.Enum selchoice = _lastSelectionChoice; if (Current.Gui.ShowDialog(ref selchoice, "As only or as additional?")) { _lastSelectionChoice = (SelectionChoice)selchoice; if (_lastSelectionChoice == SelectionChoice.SelectAsAdditional) { FitElement newele = new FitElement(); newele.FitFunction = func; _doc.FitEnsemble.Add(newele); _doc.SetDefaultParametersForFitElement(_doc.FitEnsemble.Count - 1); changed = true; } else // select as only { _doc.FitEnsemble[0].FitFunction = func; _doc.SetDefaultParametersForFitElement(0); for (int i = _doc.FitEnsemble.Count - 1; i >= 1; --i) _doc.FitEnsemble.RemoveAt(i); changed = true; } } } if (changed) { // _doc.FitEnsemble.InitializeParameterSetFromEnsembleParameters(_doc.CurrentParameters); this._fitEnsembleController.Refresh(); } }
public FitElement(FitElement from) { this._fitFunction = from._fitFunction; if (_fitFunction is ICloneable) this._fitFunction = (IFitFunction)((ICloneable)from.FitFunction).Clone(); _rangeOfRows = PositiveIntegerRange.NewFromFirstAndCount(from._rangeOfRows.First, from._rangeOfRows.Count); _independentVariables = new NumericColumnProxy[from._independentVariables.Length]; for (int i = 0; i < _independentVariables.Length; ++i) { if(from._independentVariables[i]!=null) _independentVariables[i] = (NumericColumnProxy)from._independentVariables[i].Clone(); } _dependentVariables = new NumericColumnProxy[from._dependentVariables.Length]; for (int i = 0; i < _dependentVariables.Length; ++i) { if (from._dependentVariables[i] != null) _dependentVariables[i] = (NumericColumnProxy)from._dependentVariables[i].Clone(); } _errorEvaluation = new IVarianceScaling[from._errorEvaluation.Length]; for (int i = 0; i < _errorEvaluation.Length; ++i) { if (from._errorEvaluation[i] != null) _errorEvaluation[i] = (IVarianceScaling)from._errorEvaluation[i].Clone(); } _parameterNames = (string[])from._parameterNames.Clone(); _parameterNameStart = from._parameterNameStart; }
protected override System.Collections.Generic.IEnumerable<Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName() { if (_fitFunction is Main.IDocumentLeafNode && object.ReferenceEquals(((Main.IDocumentLeafNode)_fitFunction).ParentObject, this)) yield return new Main.DocumentNodeAndName((Main.IDocumentLeafNode)_fitFunction, () => _fitFunction = null, "WrappedFitFunction"); }