Does anybody know if there is a way to make use of python decorators like functools (@cache) for Python tool in Alteryx? Looking to implement a repetitive function evaluation in python and caching the results would save enormously.
I have seen use cases for something like below in Python, but I wonder how would you achieve similar performance in Alteryx using Python.
from functools import lru_cache
import numpy as np
def estimate_error(x):
t = 1 / (1 + 0.33 * abs(x))
pre_erf = (((1.06 * t - 1.45) * t + 1.42) * t - 0.29) * t + 0.25
erf = np.sign(x) * (1 - pre_erf * t * np.exp(- x * x))
return erf
@lru_cache(maxsize=1024)
def fast_ln_sf(x, scale, shape):
return 0.5 - 0.5 * estimate_error(0.7 * (np.log(x) - np.log(scale)) / shape)
I intend to use this function as an objective for my optimization problem, meaning this function gets evaluated at least 1000s of times if I have high number of variables.
The use case for this function is of the type:
def obj(x, *args):
a = args[0].to_numpy()
s = args[1].to_numpy()
c = args[2].to_numpy()
n = args[3]
sum_ = 0
for i in range(n):
sum _ += (a * fast_ln_sf(x[i], s, c))
return -1 * sum_
solution = scipy.optimize.minimize(obj, args = [df.a, df.b, df.s, df.c, df.shape[0]])