Memoization and function calls

Alex_Tantos
Sun, 20 Jun 2021 07:56:18 +0000
New to Julia

Hi there.

This is a newbie question. I need to call the following function, lexicalgravitypair(), within a for loop, such as the one below the function definition of lexicalgravitypair(), that depends on the output of 3 other function calls, f(x,y,text), g(x, text) and g(x, text, mode = "backward"). Computing each of these 3 outputs are costly in terms of time and I would like to use memoization and call their cached output. I saw that Memoize.jl is one of the options. However, since am inexperienced with using memoization in general and since there are no example of usage like the one am describing, I don’t know how to use memoization in the scenario I describe; meaning I don’t know where and how to use the memoize_cache() function. Any hint or advice will be greatly appreciated.

function lexicalgravitypair(x::String, y::String, text::String)
    log(f(x,y,text)/g(x, text)) + log(f(x,y,text)/g(x, text, mode = "backward"))
end

for ngram in ngrams:
   if lexicalgravitypair(ngram[1], ngram[2], text) >= 5.5
...
end

5 posts - 3 participants