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 override bool CopyFrom(object obj)
        {
            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            if (!base.CopyFrom(obj))
            {
                return(false);
            }

            if (obj is XYNonlinearFitFunctionConfidenceBandPlotData from)
            {
                _fitDocumentIdentifier = from._fitDocumentIdentifier;
                ChildCopyToMember(ref _fitDocument, from._fitDocument);
                _fitElementIndex                   = from._fitElementIndex;
                _independentVariableIndex          = from._independentVariableIndex;
                _independentVariableTransformation = from._independentVariableTransformation;
                _dependentVariableIndex            = from._dependentVariableIndex;
                _dependentVariableTransformation   = from._dependentVariableTransformation;
                _numberOfFitPoints                 = from._numberOfFitPoints;
                _sigmaSquare = from._sigmaSquare;

                IsLowerBand      = from.IsLowerBand;
                IsPredictionBand = from.IsPredictionBand;
                _confidenceLevel = from._confidenceLevel;
                CreateCachedMembers();
                // covariance matrix must be cloned after CreateCachedMembers, because it's allocated there
                _covarianceMatrix = (double[, ])from._covarianceMatrix.Clone();
                return(true);
            }
            return(false);
        }
		// This type has not serialization.
		// Serialization should be done via the corresponding Proxy type.

		#endregion Serialization

		public TransformedReadableColumn(IReadableColumn column, IVariantToVariantTransformation transformation)
		{
			if (null == column)
				throw new ArgumentNullException(nameof(column));

			if (null == transformation)
				throw new ArgumentNullException(nameof(transformation));

			_originalColumn = column;
			_transformation = transformation;
		}
Example #4
0
 /// <summary>
 /// Adds a transformation to a flattened list. If the provided transformation is a <see cref="CompoundTransformation"/>, the transformation is unpacked before added to the list.
 /// </summary>
 /// <param name="transformation">The transformation.</param>
 /// <param name="list">The list.</param>
 private static void AddTransformationToFlattenedList(IVariantToVariantTransformation transformation, List <IVariantToVariantTransformation> list)
 {
     if (transformation is CompoundTransformation ct)
     {
         foreach (var trans in ct._transformations)
         {
             AddTransformationToFlattenedList(trans, list);
         }
     }
     else if (transformation != null)
     {
         list.Add(transformation);
     }
 }
        // This type has not serialization.
        // Serialization should be done via the corresponding Proxy type.

        #endregion Serialization

        public TransformedReadableColumn(IReadableColumn column, IVariantToVariantTransformation transformation)
        {
            if (null == column)
            {
                throw new ArgumentNullException(nameof(column));
            }

            if (null == transformation)
            {
                throw new ArgumentNullException(nameof(transformation));
            }

            _originalColumn = column;
            _transformation = transformation;
        }
 public ITransformedReadableColumn WithTransformation(IVariantToVariantTransformation transformation)
 {
     if (object.Equals(_transformation, transformation))
     {
         return(this);
     }
     else
     {
         if (null == transformation)
         {
             throw new ArgumentNullException(nameof(transformation));
         }
         var result = (TransformedReadableColumn)MemberwiseClone();
         result._transformation = transformation;
         return(result);
     }
 }
Example #7
0
        public CompoundTransformation WithPrependedTransformation(IVariantToVariantTransformation transformation)
        {
            if (null == transformation)
            {
                throw new ArgumentNullException(nameof(transformation));
            }

            var result = new CompoundTransformation
            {
                _transformations = new List <IVariantToVariantTransformation>(_transformations)
            };

            if (transformation is CompoundTransformation)
            {
                result._transformations.AddRange(((CompoundTransformation)transformation)._transformations);
            }
            else
            {
                result._transformations.Add(transformation);
            }
            return(result);
        }
		/// <summary>
		/// Constructor by giving a numeric column.
		/// </summary>
		/// <param name="column">The numeric column to hold.</param>
		protected TransformedReadableColumnProxyForStandaloneColumns(ITransformedReadableColumn column)
		{
			_underlyingColumn = column.UnderlyingReadableColumn;
			_transformation = column.Transformation;
			_cachedResultingColumn = column;
		}
        /// <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;
        }
Example #10
0
        /// <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="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
                }
            }
        }
Example #12
0
 /// <summary>
 /// Cloning constructor.
 /// </summary>
 /// <param name="from">Object to clone from.</param>
 public TransformedReadableColumnProxy(TransformedReadableColumnProxy from)
     : base(from)
 {
     _transformation = from._transformation; // transformation is immutable
 }
		/// <summary>
		/// Cloning constructor.
		/// </summary>
		/// <param name="from">Object to clone from.</param>
		public TransformedReadableColumnProxy(TransformedReadableColumnProxy from)
			: base(from)
		{
			_transformation = from._transformation; // transformation is immutable
		}
		protected TransformedReadableColumnProxy(ITransformedReadableColumn column)
			: base((IDocumentLeafNode)column.UnderlyingReadableColumn)
		{
			_transformation = column.Transformation;
		}
		public ITransformedReadableColumn WithTransformation(IVariantToVariantTransformation transformation)
		{
			if (object.Equals(_transformation, transformation))
			{
				return this;
			}
			else
			{
				if (null == transformation)
					throw new ArgumentNullException(nameof(transformation));
				var result = (TransformedReadableColumn)this.MemberwiseClone();
				result._transformation = transformation;
				return result;
			}
		}
Example #16
0
 protected TransformedReadableColumnProxy(ITransformedReadableColumn column)
     : base((IDocumentLeafNode)column.UnderlyingReadableColumn)
 {
     _transformation = column.Transformation;
 }
 public FitFunctionToScalarFunctionDDWrapper(IFitFunction fitFunction, int dependentVariable, IVariantToVariantTransformation dependentVariableTransformation, double[] parameter)
 {
     Initialize(fitFunction, dependentVariable, dependentVariableTransformation, 0, null, parameter);
 }
Example #18
0
 /// <summary>
 /// Constructor by giving a numeric column.
 /// </summary>
 /// <param name="column">The numeric column to hold.</param>
 protected TransformedReadableColumnProxyForStandaloneColumns(ITransformedReadableColumn column)
 {
     _underlyingColumn      = column.UnderlyingReadableColumn;
     _transformation        = column.Transformation;
     _cachedResultingColumn = column;
 }