Reputation: 2440
let J = (-1.0 * y) .* MatrixMath.log <| Activation.sigmoid (X * theta)
let J = (-1.0 * y) .* MatrixMath.log (Activation.sigmoid (X * theta))
I have the follow two sets of code with the former giving a compile error saying "This funciton takes too many arguements", but the latter works fine.
I thought the pipe backwards operator's goal is essentially to change the order of evaluation which is what I'm trying to do.
How do I write my expression without using parenthesis?
EDIT:
MatrixMath.log just does this
type MatrixMath =
static member log X = X |> Matrix.map log
static member log X = X |> Vector.map log
Upvotes: 3
Views: 131
Reputation: 13577
Pipe operator has low precedence. What you try to evaluate is something like this:
let J = ((-1.0 * y) .* MatrixMath.log) <| (Activation.sigmoid (X * theta))
or a similar atrocity.
If you really need to put backwards pipe in there, try something like this:
let J = (-1.0 * y) .* (MatrixMath.log <| Activation.sigmoid <| X * theta)
or break it up in two lines:
let J =
let K = MatrixMath.log <| Activation.sigmoid (X * theta)
(-1.0 * y) .* K
Upvotes: 5
Reputation: 1602
In F# (<|)
operator has left associativity, so your expression is parsed like this:
let J = ((-1.0 * y) .* MatrixMath.log) <| Activation.sigmoid (X * theta)
If you feel opposed to parentheses, you could possibly rewrite the code like this:
(*not tested*)
let flip f a b = f b a
let J = MatrixMath.log <| Activation.sigmoid (X * theta) |> flip (.*) <| -1.0 * y
Upvotes: 3