-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
greta silently ignoring base functions #317
Comments
Wow, that is weird! I would have expected It would be very easy to add a log10 function to greta to resolve this specific situation. But I'd like to understand why this function would silently return its input unevaluated. |
The following also fall in that category, so should be checked: log2, cosh, sinh, tanh, acosh, asinh, atanh, cospi, sinpi, tanpi, gamma, trigamma, cummax, cummin, Im, Re, Arg, Conj, Mod |
Yes, I just noticed that. The source for Also note that: x <- as_data(10)
log10(x) Also shows the weird return the argument behaviour. |
Maybe you can still add some warning/message if a function cannot be exported correctly? I would prefer a solid |
Consider: x <- as_data(10)
log10(x) # returns the argument (or at least appears to)
x <- unclass(x)
log10(x) # works sort of - changes the data in the array but not the node data So I think the issue is that the primitives ignore the node attribute and work on the value stored in the greta array. So it then appears that the they have no effect as the node value is what is exposed to the user. |
That is indeed the behaviour that I experienced in my real-life application - |
Right. It would be good if we could error nicely if a greta array is passed to some arbitrary function that doesn't support it. Unfortunately, erroring is the function's responsibility, there's not much the object can do to trigger an error. Usually a function will error with a message about not being able to work with a greta array. But apparently not here! By the way, you can see the list of functions greta supports here: https://greta-stats.org/reference/functions.html |
I think the 'issue' is the following behaviour: test <- 10
class(test) <- "test"
log10(test)
#> [1] 1
#> attr(,"class")
#> [1] "test" Created on 2019-09-04 by the reprex package (v0.2.1) i.e. that numeric functions ignore the attributes of an object and operate directly on the 'data' Because greta_arrays are really just R array's with a Two ideas to fix this:
All the best! |
Thanks for investigating @jeffreypullin! greta arrays actually used to be lists, but were changed to be arrays fairly recently. In part because other behaviour of having them be lists was problematic (I think concatenation with NULL was one issue). I think a more thorough coverage of numeric functions would probably be the easiest and best option. Most of them will be in TensorFlow anyway, so would only take a couple of lines to implement. |
I was recently debugging an issue with my simulations, where the optimal parameters obtained using
greta
were not actually optimal, so model data, reconstructed usinggreta
output, were systematically offset from the real data. Having checked everything multiple times, I turned to the output ofprint(plot(greta_model))
with the help ofDiagrammeR
. Turned out,greta
silently dropped calls tolog10
function while constructing the model. Check the simplest reprex and the output of theDiagrammeR
as I get on my machine.I am not sure what causes this, because
greta
successfully parsed a complex model containing calls to customR
functions that perform numerical computations, includingexp
,^
and base arithmetics, yetlog10
was dropped.Providing that
greta
models are defined usingR
code and support user-defined functions (e.g. if I definelg <- funciton(x) log(x) / log(10)
, it will be unrolled into two operations), I find it surprising thatlog
s are unsupported (without error or warning).The text was updated successfully, but these errors were encountered: