Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adapting this formula to Python Polars, stuck on Euluers Number and Exponent

I have the following formula

enter image description here

Citation: https://www.chess-journal.com/evaluatingSharpness1.html

In terms of my data frame:

w = "win"
d = "draw"
l = "loss"

and e is our buddy Euler's number.

What would be a tidy way of representing that final component? And should I use math.e for the e?

This is what I have so far

df = df.with_columns(
    ((pl.min_horizontal(pl.col("win"), pl.col("loss")) / 50) * (333 / pl.col("draw"))).alias("sharpness")
)
like image 364
hackpoetic Avatar asked Nov 17 '25 17:11

hackpoetic


1 Answers

As in your case you need to exponent of the constant e, you can use pure polars expression - Expr.exp():

def sharpness(w, l, d):
    a = pl.min_horizontal(w, l) / 50
    b = 333 / d
    c = -(w + l) / 1000
    return a * b / (1 + c.exp())

df.with_columns(
    sharpness(pl.col("win"), pl.col("loss"), pl.col("draw")).alias("sharpness")
)

Just a note, there's a way to apply exponent to the column - Expr.pow()

like image 139
Roman Pekar Avatar answered Nov 20 '25 08:11

Roman Pekar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!