You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've made some geometric inspired operators to take advantage of these below that have proven very powerful! @MilesCranmer if only using a maximum of binary operators, is it faster to just keep the traditional structure (unary and binary operators)?
# ---------------- CORE GEOMETRY OPERATORS ----------------# Hypotenusepythag_pos(x, y) =sqrt(x^2+ y^2)
# Safe difference of squarespythag_neg(x, y) = (d = x^2- y^2; d <0.0?NaN:sqrt(d))
# 2D dot productdot2d(x1, y1, x2, y2) = x1*x2 + y1*y2
# 2D cross productcross2d(x1, y1, x2, y2) = x1*y2 - y1*x2
# CosAngle between two vectorsfunctionangle_cos2d(x1, y1, x2, y2)
denom =pythag_pos(x1, y1) *pythag_pos(x2, y2)
denom ==0.0?NaN:dot2d(x1, y1, x2, y2) / denom
end# Law of Cosinesfunctionlaw_of_cosines(a, b, cosC)
safe_cosC =max(-1.0, min(1.0, cosC))
val = a^2+ b^2-2.0* a * b * safe_cosC
val <0.0?NaN:sqrt(val)
end# Inverse law of cosines: cos(C) given sides a, b, cfunctioninverse_loc(a, b, c)
if a <=0|| b <=0|| c <=0|| (a+b <= c) || (a+c <= b) || (b+c <= a) #check valid trianglereturnNaNend
cosval = (a^2+ b^2- c^2) / (2.0* a * b)
returnmax(-1.0, min(1.0, cosval))
end# Triangle area via cross producttriangle_area2d(x1, y1, x2, y2) =0.5*abs(cross2d(x1, y1, x2, y2))
# ---------------- PROJECTION OPERATORS ----------------# Projection length of vector 1 onto vector 2functionproj_len2d(x1, y1, x2, y2)
denom =pythag_pos(x2, y2)
denom ==0.0?NaN:dot2d(x1, y1, x2, y2) / denom
end# Scalar projection coefficient of vector 1 along vector 2functionproj_scalar2d(x1, y1, x2, y2)
denom =pythag_pos(x2, y2)^2
denom ==0.0?NaN:dot2d(x1, y1, x2, y2) / denom
end# Perpendicular length from vector 1 to vector 2's directionfunctionrej_len2d(x1, y1, x2, y2)
s =proj_scalar2d(x1, y1, x2, y2)
isnan(s) &&returnNaN
rx = x1 - s*x2
ry = y1 - s*y2
pythag_pos(rx, ry)
end
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The new OperatorEnum feature is great: MilesCranmer/SymbolicRegression.jl#472
I've made some geometric inspired operators to take advantage of these below that have proven very powerful!
@MilesCranmer if only using a maximum of binary operators, is it faster to just keep the traditional structure (unary and binary operators)?
e.g. use
Beta Was this translation helpful? Give feedback.
All reactions