Created
May 25, 2021 04:00
-
-
Save richpsharp/e86557e778dc2a652350b1d203530cf1 to your computer and use it in GitHub Desktop.
Find a good C factor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import scipy.optimize | |
evi_vs_c = [ | |
(0.02874, 0.95), | |
(0.18186, 0.25), | |
(0.3643000126, 0.13575), | |
(0.33039, 0.07075), | |
(0.54826, 0.035425), | |
(0.65346, 0.0001), | |
] | |
def c_factor(evi, a, b, c): | |
return numpy.clip( | |
1-a*numpy.exp(-evi**b)**c + | |
0.07075 * (0.65346-evi)/(0.65346-0.33039), | |
0.0001, 1.0) | |
p0, variant = scipy.optimize.curve_fit( | |
c_factor, | |
[x[0] for x in evi_vs_c], | |
[x[1] for x in evi_vs_c], | |
p0=[3, -0.3, 1], | |
method='lm') | |
print(p0, variant) | |
for evi_val, expected in evi_vs_c: | |
print(expected-c_factor(evi_val, *p0)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment