Exp
Simples example
>>> from ffit.funcs.exp import Exp
# Call the fit method with x and y data.
>>> fit_result = Exp().fit(x, y)
# The result is a FitResult object that can be unpacked.
>>> res, res_func = fit_result.res_and_func()
# The parameters can be accessed as attributes.
>> amplitude = fit_result.amplitude
# One can combine multiple calls in one line.
>>> res = Exp().fit(x, y, guess=[1, 2, 3, 4]).plot(ax)
Final parameters
Exponential function parameters.
Attributes:
Name | Type | Description |
---|---|---|
amplitude |
float
|
The amplitude of the exponential function. |
rate |
float
|
The rate of the exponential function. |
offset |
float
|
The offset of the exponential function. |
Additional attributes
tau (float): The time constant of the exponential function, calculated as -1 / rate.
Source code in ffit/funcs/exp.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
Exp function.
Function
f(x) = amplitude * np.exp(rate * x) + offset
Final parameters
The final parameters are given by ExpParam
dataclass.
Source code in ffit/funcs/exp.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
fit
fit(x, data, *, mask=None, guess=None, method='leastsq', maxfev=10000, **kwargs)
Fit the data using the specified fitting function.
This function returns FitResult see the documentation for more information what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_ARRAY
|
The dependent variable. |
required |
mask
|
Optional[_ARRAY]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, tuple, list]]
|
The initial guess for fit parameters (optional). |
None
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use. Valid options are "least_squares", "leastsq", and "curve_fit" (default: "leastsq"). |
'leastsq'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the fit, including the fitted parameters and the fitted function. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid fitting method is provided. |
Source code in ffit/fit_logic.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
async_fit
async
async_fit(x, data, *, mask=None, guess=None, method='leastsq', maxfev=10000, **kwargs)
Asynchronously fits the model to the provided data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable data. |
required |
data
|
_ARRAY
|
The dependent variable data to fit. |
required |
mask
|
Optional[Union[_ARRAY, float]]
|
An optional mask to apply to the data. Defaults to None. |
None
|
guess
|
Optional[_T]
|
An optional initial guess for the fitting parameters. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments to pass to the fitting function. |
{}
|
Returns:
Type | Description |
---|---|
_T
|
FitWithErrorResult[_T]: The result of the fitting process, including the fitted parameters and associated errors. |
Source code in ffit/fit_logic.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
guess
classmethod
guess(x, data, mask=None, guess=None, **kwargs)
Guess the initial fit parameters.
This function returns an object of the class FitResult
.
See its documentation for more information on what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
The independent variable. |
required | |
data
|
The dependent variable. |
required | |
mask
|
Optional[_ARRAY]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[_T]
|
The initial guess for the fit parameters (optional). |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The guess, including the guess parameters and the function based on the guess. |
Examples:
>>> x = [1, 2, 3, 4, 5]
>>> data = [2, 4, 6, 8, 10]
>>> fit_guess = FitLogic.guess(x, data)
>>> fit_guess.plot()
Source code in ffit/fit_logic.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
|
bootstrapping
bootstrapping(x, data, mask=None, guess=None, method='leastsq', num_of_permutations=None, maxfev=_DEFAULT_MAXFEV, **kwargs)
Fit the data using the specified fitting function.
This function returns FitResult see the documentation for more information what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_ARRAY
|
The dependent variable. |
required |
mask
|
Optional[_ARRAY]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, _ANY_LIST_LIKE]]
|
The initial guess for fit parameters (optional). |
None
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use. Valid options are "least_squares", "leastsq", and "curve_fit" (default: "leastsq"). |
'leastsq'
|
num_of_permutations
|
Optional[int]
|
The number of permutations to use for the bootstrapping. |
None
|
maxfev
|
int
|
The maximum number of function evaluations. |
_DEFAULT_MAXFEV
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the fit, including the fitted parameters and the fitted function. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid fitting method is provided. |
Source code in ffit/fit_logic.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
|
array_bootstrapping
array_bootstrapping(x, data, *, mask=None, guess=None, axis=-1, method='leastsq', maxfev=10000, num_of_permutations=None, **kwargs)
Perform array bootstrapping in parallel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_2DARRAY
|
The dependent variable. |
required |
mask
|
Optional[_ARRAY]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, tuple, list]]
|
The initial guess for fit parameters (optional). |
None
|
axis
|
int
|
The axis along which to perform the fit (default: -1). |
-1
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use (default: "leastsq"). |
'leastsq'
|
maxfev
|
int
|
Maximum number of function evaluations (default: 10000). |
10000
|
num_of_permutations
|
Optional[int]
|
Number of bootstrap iterations. |
None
|
**kwargs
|
Additional keyword arguments passed to _fit. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the bootstrapping. |
Source code in ffit/fit_logic.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
|
bootstrapping2D
bootstrapping2D(x, data, mask=None, guess=None, method='leastsq', num_of_permutations=None, **kwargs)
Fit the data using the specified fitting function.
This function returns FitResult see the documentation for more information what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_2DARRAY
|
The 2D dependent variable (data, batches). |
required |
mask
|
Optional[_ARRAY]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, tuple, list]]
|
The initial guess for fit parameters (optional). |
None
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use. Valid options are "least_squares", "leastsq", and "curve_fit" (default: "leastsq"). |
'leastsq'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the fit, including the fitted parameters and the fitted function. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid fitting method is provided. |
Source code in ffit/fit_logic.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
|
mp_array_fit
mp_array_fit(x, data, *, mask=None, guess=None, axis=-1, method='leastsq', maxfev=10000, n_jobs=None, **kwargs)
Perform array fitting in parallel using multiprocessing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_2DARRAY
|
The dependent variable. |
required |
mask
|
Optional[Union[_ARRAY, float]]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, tuple, list]]
|
The initial guess for fit parameters (optional). |
None
|
axis
|
int
|
The axis along which to perform the fit (default: -1). |
-1
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use (default: "leastsq"). |
'leastsq'
|
maxfev
|
int
|
Maximum number of function evaluations (default: 10000). |
10000
|
n_jobs
|
Optional[int]
|
Number of processes to use. If None, uses cpu_count(). |
None
|
**kwargs
|
Additional keyword arguments passed to _fit. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the fit. |
Source code in ffit/fit_logic.py
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 |
|