Replies: 2 comments 3 replies
-
Happy to help. I am a bit confused about one thing in your question:
Does this mean you want to find the same |
Beta Was this translation helpful? Give feedback.
-
What I normally do here is just feed in the variables as additional columns of function my_loss_function(tree, dataset::Dataset{T,L}, options)::L where {T,L}
X = copy(dataset.X)
y = copy(dataset.y) # Don't need to copy if you aren't modifying; but just a safer habit
# Ordering (depends how you pass to .fit)
# 'a' - 1; 'k' - 2; 'd' - 3; 'L' - 4; 'w' - 5; 'g' - 6;'o' - 7.
# Thus, say that 'P' is 8 and 'S' is 9
X_without_P_and_S = vcat(
X[1:7, :], # The actual data
X[8:9, :] .* 0, # Pass zeroed version
)
# Need to pass the the full shape,
# as the genetic algorithm will still sometimes use features 8 and 9!
# Thus, we simply hide that information from it.
prediction, complete = eval_tree_array(tree, X_without_P_and_S, options)
if !complete
return L(Inf)
end
mse = sum(i -> (prediction[i] - y[i])^2, eachindex(y)) / length(y)
# Do something with X[8, :] and X[9, :] ?
return loss
end Hopefully this helps you get started! And pass this entire thing as a string to the |
Beta Was this translation helpful? Give feedback.
-
Summary:
I am trying to create a loss function that incorporates multiple variables that are not used in X for Pysr. I'm not sure if this is possible. Essentially I am trying to achieve multi-objective optimization through a custom loss function.
Background:
I have several Gaussian optics equations with multiple variables to choose an intraocular lens for surgery.
I have a training database with measured truths AFTER surgery:
I also have variables that can be measured BEFORE surgery
Back_calculated_e is an variable that can be back calculated based on gaussian optics:
Pysr is used to Predict e based on pre-operative variables:
Following this we can verify how good our Predicted_E is by using it to compare:
Why not just use Back_Calculated_e as y and use MSE as a loss function? This is what I'm currently doing with Back_Calculated e as the y, with a,k,d,L,w,o as X.
However, as there are measurement errors of baseline variables (a in particular), this makes Back_Calculated_e unreliable as a increases, and so it is much better to rely on absolute truths for loss function, e.g. an average of MSE between [Predicted_P and Actual_P], and [Predicted_S and Actual_S].
How can I feed in Actual_S and Actual_P to a custom loss function although they can are not included in the x variables?
Actual_S and Actual_P are just two arrays that I can read from an Excelsheet.
Thank you very much in advance, or if anyone has any ideas of how this could be achieved?
Failing this:
Gaussian Optics equations if of interest:
v is a constant (12).
Equation to calculate P from e, based on a chosen S:
Predicted_P=(1336 / (a - e)) - (1336 / (1336 / ((1000 / (1000 / s - v)) + k) - e)) (function 3)
Equation to calculate S from E, based on a chosen P:
Predicted_S = 1000*(aekp - 1336ak - 1336ap - e^2kp + 1336ep + 1784896)/(aekpv - 1000aep - 1336akv - 1336apv + 1336000a - e^2kpv + 1000e^2p + 1336epv + 1784896v) (function 4)
Cannot get this to work...
Current Code:
Beta Was this translation helpful? Give feedback.
All reactions