Class TFitTask

Unit

Declaration

type TFitTask = class(TComponent)

Description

Fits profile interval by model curves. Provides variable parameters and evaluation function for optimization algorithm. It is inherited from TComponent to allow inserting into TComponentList.

Hierarchy

  • TComponent
  • TFitTask

Overview

Fields

Protected FA: double;
Protected FAllDone: boolean;
Protected FB: double;
Protected FBackground: TPointsSet;
Protected FBackgroundVaryingFlag: boolean;
Protected FBackgroundVaryingIndex: longint;
Protected FBackgroundWasSaved: boolean;
Protected FBegIndex: longint;
Protected FC: double;
Protected FCalcProfile: TPointsSet;
Protected FCommonVariableParameters: Curve_parameters;
Protected FCommonVaryingFlag: boolean;
Protected FCommonVaryingIndex: longint;
Protected FCurAbsMin: double;
Protected FCurMin: double;
Protected FCurMinInitialized: boolean;
Protected FCurSqrMin: double;
Protected FCurveExpr: string;
Protected FCurveNum: longint;
Protected FCurvePositions: TPointsSet;
Protected FCurves: TSelfCopiedCompList;
Protected FCurveScalingEnabled: boolean;
Protected FCurveTypeSelector: ICurveTypeSelector;
Protected FDoneProc: TThreadMethod;
Protected FEnableBackgroundVariation: boolean;
Protected FEnableFastMinimizer: boolean;
Protected FEndIndex: longint;
Protected FEndOfCycle: boolean;
Protected FExpProfile: TPointsSet;
Protected FMaxAcceptableRFactor: double;
Protected FMinimizer: TMinimizer;
Protected FParamNum: longint;
Protected FSavedBackground: TPointsSet;
Protected FShowCurMin: TShowCurMin;
Protected FTerminated: boolean;
Protected FUseCurveRanges: boolean;
Protected FUserDefinedParameters: Curve_parameters;
Protected Fx0: double;

Methods

Public constructor Create(AOwner: TComponent; AEnableBackgroundVariation: boolean; ACurveScalingEnabled: boolean); overload;
Public destructor Destroy; override;
Public function GetAllDone: boolean; virtual;
Public function GetCalcProfile: TPointsSet;
Public function GetCurAbsMin: double; virtual;
Public function GetCurMin: double; virtual;
Public function GetCurMinInitialized: boolean; virtual;
Public function GetCurSqrMin: double; virtual;
Public function GetCurvePositions: TPointsSet;
Public function GetCurves: TSelfCopiedCompList;
Public function GetScalingFactor: double;
Protected function CreatePatternInstance(x0: double): TCurvePointsSet;
Protected function DeleteCurvesWithSmallAmplitude: boolean;
Protected function DeleteCurveWithMaxExpDerivative(var Deleted: TCurvePointsSet): boolean;
Protected function DeleteCurveWithMinimalAmplitude(var Deleted: TCurvePointsSet): boolean;
Protected function EndOfCalculation: boolean;
Protected function EndOfCycle: boolean;
Protected function GetAbsRFactor: double;
Protected function GetCalcProfileIntegral: double;
Protected function GetFunc: double;
Protected function GetOptimizingRFactor: double;
Protected function GetParam: double;
Protected function GetProfileIntegral: double;
Protected function GetRFactor: double;
Protected function GetSqrRFactor: double;
Protected function GetVariationStep: double;
Protected function MinimumStepAchieved: boolean;
Public procedure ComputeProfile;
Public procedure InitCurve(TupleList: TMSCRCurveList; Curve: TCurvePointsSet);
Public procedure MinimizeDifference; virtual;
Public procedure MinimizeDifferenceAgain; virtual;
Public procedure MinimizeNumberOfCurves; virtual;
Public procedure RecreateCurves(TupleList: TMSCRCurveList);
Public procedure SetCurvePositions(ACurvePositions: TPointsSet);
Public procedure SetProfilePointsSet(APointsSet: TPointsSet);
Public procedure SetSpecialCurve(ACurveExpr: string; AParams: Curve_parameters);
Public procedure StopAsyncOper; virtual;
Protected procedure AddCurveToProfile(PS: TPointsSet);
Protected procedure AddPointToCurvePositions(XValue: double);
Protected procedure BackupCurveParameters;
Protected procedure CalcInitHash(Curve: TCurvePointsSet);
Protected procedure ComputeCurveSum;
Protected procedure ComputeFunc;
Protected procedure CreateDHSMinimizer;
Protected procedure CreateFastMinimizer;
Protected procedure DeletePoint(var Points: TPointsSet; XValue: double);
Protected procedure DivideVariationStepBy2;
Protected procedure Done; virtual;
Protected procedure InitializeVariationSteps;
Protected procedure MinimizeNumberOfCurvesAlg;
Protected procedure MultiplyVariationStep(Factor: double);
Protected procedure Optimization;
Protected procedure RestoreCurveParameters;
Protected procedure SetFirstParam;
Protected procedure SetNextParam;
Protected procedure SetParam(NewParamValue: double);
Protected procedure SetVariationStep(NewStepValue: double);
Protected procedure ShowCurMin; virtual;
Protected procedure SubbCurveFromProfile(PS: TPointsSet);

Properties

Public property BegIndex: longint read FBegIndex write FBegIndex;
Public property EndIndex: longint read FEndIndex write FEndIndex;
Public property MaxAcceptableRFactor: double write FMaxAcceptableRFactor;
Public property ServerDoneProc: TThreadMethod read FDoneProc write FDoneProc;
Public property ServerShowCurMin: TThreadMethod read FShowCurMin write FShowCurMin;

Description

Fields

Protected FA: double;

Background parameters.

Protected FAllDone: boolean;

Flag indicating that asynchronous operation executed as subtask was Terminated. For this class is always True for now because the class does not support asynchronous operations.

Protected FB: double;

Background parameters.

Protected FBackground: TPointsSet;

List of background points.

Protected FBackgroundVaryingFlag: boolean;

Flag indicating that amplitudes of background points are variated at the moment.

Protected FBackgroundVaryingIndex: longint;

Index of background point amplitude of which is variated at the moment.

Protected FBackgroundWasSaved: boolean;
 
Protected FBegIndex: longint;
 
Protected FC: double;

Background parameters.

Protected FCalcProfile: TPointsSet;

The calculated profile. Every value is calculated as a sum of values of corresponding points of every curve (specimen) and background.

Protected FCommonVariableParameters: Curve_parameters;

List of parameters of curves which are common for all the instances.

Protected FCommonVaryingFlag: boolean;

Flag indicating that common parameters are variated at the moment.

Protected FCommonVaryingIndex: longint;

Index of common parameter which is variated at the moment.

Protected FCurAbsMin: double;
 
Protected FCurMin: double;

Current minimum value of R-factor by which maximal acceptable value is set up. Last achived minimum value is stored to avoid redundant computations and locks in multithreaded environment.

Protected FCurMinInitialized: boolean;
 
Protected FCurSqrMin: double;
 
Protected FCurveExpr: string;

Expression defining user curve type.

Protected FCurveNum: longint;

Index of pattern instance (specimen) parameters of which are variated at the moment.

Protected FCurvePositions: TPointsSet;

Contains positions of curves. Only X-coordinates are used.

Protected FCurves: TSelfCopiedCompList;

Set of curves used to model experimental data inside given interval.

Protected FCurveScalingEnabled: boolean;

Enables curve scaling. Generally it should be true, otherwise optimization could stuck in local minimum. However it could be set to false for some special curve types.

Protected FCurveTypeSelector: ICurveTypeSelector;
 
Protected FDoneProc: TThreadMethod;
 
Protected FEnableBackgroundVariation: boolean;

Enables background variation.

Protected FEnableFastMinimizer: boolean;

Enables fast optimization algorithm.

Protected FEndIndex: longint;
 
Protected FEndOfCycle: boolean;
 
Protected FExpProfile: TPointsSet;

Part of experimental profile corresponding to model interval.

Protected FMaxAcceptableRFactor: double;

Maximal acceptable value of R-factor for minimizing number of curves.

Protected FMinimizer: TMinimizer;

======================= dannye dlya optimizatora ====================

Protected FParamNum: longint;

Index of parameter of pattern instance which is variated at the moment.

Protected FSavedBackground: TPointsSet;
 
Protected FShowCurMin: TShowCurMin;
 
Protected FTerminated: boolean;

Flag signalling to terminate all internal loops.

Protected FUseCurveRanges: boolean;

The flag switches on using intervals in calculating R-factors. Using ranges is switched off when they are not given to accelerate computation.

Protected FUserDefinedParameters: Curve_parameters;

Parameters of user defined curve. Parameters are given from the caller. The object is used to construct curve instances.

Protected Fx0: double;

Background parameters.

Methods

Public constructor Create(AOwner: TComponent; AEnableBackgroundVariation: boolean; ACurveScalingEnabled: boolean); overload;
 
Public destructor Destroy; override;
 
Public function GetAllDone: boolean; virtual;
 
Public function GetCalcProfile: TPointsSet;

Returns final calculated profile.

Public function GetCurAbsMin: double; virtual;
 
Public function GetCurMin: double; virtual;

Returns current minimal achived value of R-factor (FCurMin).

Public function GetCurMinInitialized: boolean; virtual;
 
Public function GetCurSqrMin: double; virtual;
 
Public function GetCurvePositions: TPointsSet;

Returns final list of curve positions.

Public function GetCurves: TSelfCopiedCompList;

Returns final set of model curves (pattern instances).

Public function GetScalingFactor: double;

Returns the factor scaling calculated points up to scale of experimental data.

Protected function CreatePatternInstance(x0: double): TCurvePointsSet;
 
Protected function DeleteCurvesWithSmallAmplitude: boolean;

Removes from list of curve positions those points for which calculated curves have zero amplitude.

Protected function DeleteCurveWithMaxExpDerivative(var Deleted: TCurvePointsSet): boolean;

Removes from list of curve positions the point in which experimental profile has maximal derivative.

Protected function DeleteCurveWithMinimalAmplitude(var Deleted: TCurvePointsSet): boolean;

Deletes from list of curve positions the point in which amplitude of curve is minimal.

Protected function EndOfCalculation: boolean;

Returns flag indicating termination of the calculation.

Protected function EndOfCycle: boolean;

Returns True at the end of iteration cycle.

Protected function GetAbsRFactor: double;
 
Protected function GetCalcProfileIntegral: double;
 
Protected function GetFunc: double;

Calculates R-factor.

Protected function GetOptimizingRFactor: double;

Calculates R-factor used for optimization.

Protected function GetParam: double;

Returns variable parameter value.

Protected function GetProfileIntegral: double;
 
Protected function GetRFactor: double;

Calculates R-factor used for comparison with maximal acceptable value.

Protected function GetSqrRFactor: double;
 
Protected function GetVariationStep: double;

Returns initial variation step for current variable parameter.

Protected function MinimumStepAchieved: boolean;
 
Public procedure ComputeProfile;

Recalculates all pattern instances and FBackground. Calculates resulting profile.

Public procedure InitCurve(TupleList: TMSCRCurveList; Curve: TCurvePointsSet);

Searches pattern specimen by hash and sets its parameters from the given list.

Public procedure MinimizeDifference; virtual;

Fits curves starting from given parameter set (initially or repeatedly).

Public procedure MinimizeDifferenceAgain; virtual;
 
Public procedure MinimizeNumberOfCurves; virtual;

Searches set of curves fitting exprerimental data with given accuracy sequentially decreasing number of such curves.

Public procedure RecreateCurves(TupleList: TMSCRCurveList);

Recreates pattern instances (curves). It should be public for initial calculation of R-factor for overall profile.

Public procedure SetCurvePositions(ACurvePositions: TPointsSet);
 
Public procedure SetProfilePointsSet(APointsSet: TPointsSet);

Sets up experimental profile data.

Public procedure SetSpecialCurve(ACurveExpr: string; AParams: Curve_parameters);
 
Public procedure StopAsyncOper; virtual;

Sets up termination flags and returns.

Protected procedure AddCurveToProfile(PS: TPointsSet);
 
Protected procedure AddPointToCurvePositions(XValue: double);
 
Protected procedure BackupCurveParameters;

Low-level methods of algorithms.

Protected procedure CalcInitHash(Curve: TCurvePointsSet);

Calculates hash of initial values of parameters of pattern instance.

Protected procedure ComputeCurveSum;

Sums all pattern instances and FBackground into single calculated profile.

Protected procedure ComputeFunc;

Computes evaluation function.

Protected procedure CreateDHSMinimizer;

Creates downhill simplex algorithm for the 2nd step of 2-stage processing.

Protected procedure CreateFastMinimizer;

Creates fast optimization algorithm for the 1th step of 2-stage processing, by default is disabled. TODO: Make configurable.

Protected procedure DeletePoint(var Points: TPointsSet; XValue: double);

Deletes poins with given X from the list passed via parameter.

Protected procedure DivideVariationStepBy2;

Divides all optimization steps by 2. Iterface method for TSimpleMinimizer2.

Protected procedure Done; virtual;

Notifies service about finishing computation.

Protected procedure InitializeVariationSteps;
 
Protected procedure MinimizeNumberOfCurvesAlg;

Searches for set of curves fitting experimental profile with given accuracy sequentially decreasing number of curves.

Protected procedure MultiplyVariationStep(Factor: double);
 
Protected procedure Optimization;

Executes cycle of fitting of parameters of curves.

Protected procedure RestoreCurveParameters;
 
Protected procedure SetFirstParam;

Sets iteration to the first variable parameter.

Protected procedure SetNextParam;

Moves iteration to next variable parameter.

Protected procedure SetParam(NewParamValue: double);

Sets variable parameter value.

Protected procedure SetVariationStep(NewStepValue: double);

Does nothing. Should be implemented because is used by pointer. See OnSetStep.

Protected procedure ShowCurMin; virtual;

Notifies service about achievement of new minimum value. This method recomputes data if necessary to be in consistent state with minimum R-factor value.

Protected procedure SubbCurveFromProfile(PS: TPointsSet);
 

Properties

Public property BegIndex: longint read FBegIndex write FBegIndex;

Attributes store indexes of begin and end of the task interval for optimal rebuilding overall resulting profile.

Public property EndIndex: longint read FEndIndex write FEndIndex;
 
Public property MaxAcceptableRFactor: double write FMaxAcceptableRFactor;
 
Public property ServerDoneProc: TThreadMethod read FDoneProc write FDoneProc;
 
Public property ServerShowCurMin: TThreadMethod read FShowCurMin write FShowCurMin;

Callback to update information at achieving new minimum.


Generated by PasDoc 0.15.0.