Skip to content

Unable to differentiate sum of broadcast #498

@ForceBru

Description

@ForceBru
let
    @variables q[1:5]
    
    Symbolics.gradient(
        sum(q .* log.(q)), collect(q)
    )
end

This outputs a vector of zeros: [0, 0, 0, 0, 0], but the correct gradient consists of elements like 1 + log(q[k]):

import sympy as sp

q = sp.symbols("q1:5", real=True)
the_sum = sum(
    q_ * sp.log(q_) for q_ in q
)
sp.Matrix([
    [the_sum.diff(q_) for q_ in q]
]).T

Output:

grad

┆Issue is synchronized with this Trello card by Unito

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions