Replies: 3 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Ah. Is the issue because of n_trials = size(X, 1) by any chance? I think this should be |
Beta Was this translation helpful? Give feedback.
0 replies
-
Some other suggested improvements: function my_loss(tree, dataset::Dataset{T,L}, options)::L where {T,L}
X = dataset.X
n_trials = size(X, 2) # <-- WITH FIX APPLIED
Q = ntuple(j -> zero(T), 4) # <-- TUPLES FASTER THAN VECTORS
total_loss = zero(L)
for i in 1:n_trials
a = Int(X[1, i]) +1
r = X[2, i]
q_input = [Q[a]; r;;] # <-- CONSTRUCT 2x1 DIRECTLY
q_update, valid = eval_tree_array(tree, q_input, options)
if !valid # <-- OTHER CHECKS NOT NEEDED
return L(Inf)
end
maximum = argmax(Q)
total_loss += a == maximum ? -log(1 - 0.7) : -log(0.7 / 3) # <-- SIMPLIFIED
Q = ntuple(
let a=a, q_update=q_update, Q=Q # (not 100% needed; but this is a performance hack to avoid boxing in closure)
j -> j == a ? q_update[1] : Q[j]
end,
4
) # <-- CONSTRUCT NEW TUPLE
end
return total_loss / n_trials
end |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm trying to write a custom loss function for the following problem:
I modeled the following dataset: variables
[a, r]
(action and reward). This datasets represents a multi-armed bandit task in which a subject is asked to choose one out of four arms that yield different results from different normal distributions. Their action is the chosen action and their result is the reward. I want to find the subjects' expectation q of the arms and how the expectation is updated based on their last reward. The functions I used to model the dataset look like this: 1)Pt(a_k) = {(1-epsilon) if k == argmax(Q), epsilon/3 else}, 2)q_{t+1,k} = q_{t,k} + alpha * (r_t - q_{t,k})
. This last function I want to find in the dataset using symbolic regression in Pysr. However, since the variables I'm using and predicting are not directly in the dataset, this problem comes with some difficulties. To solve the problem I'm trying to write a custom loss function, but it's not working as I want, since the model is producing only solutions with a complexity of 1. The code I wrote looks like this:I'm not sure why the model only produces solutions with a complexity of 1. I thought it might have something to do with the model being fit to data that is different than the variables I'm using in the eval_tree_array() function, but I don't know any other way to fix it. Hopefully someone can help me with this. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions