Skip to content

Numpy operations on sparsed derivatives #124

@VondrakMar

Description

@VondrakMar

May I have a question about math operation on the sparse output of the descriptor, please?
I would like to do numpy operations on the sparse output. E.g., I want to do np.moveaxis, and einstein summation (attached code is creating derivatives of normalized soap).

As far as I know, this is not possible with the sparse output, and I would have to create dense array with .todense()? Or is there a way how to do a math operations?

At the end I am creating a neighbors list and want to do a matrix multiplication w.r.t. my pair list, so I would really like to keep a sparse representation until this moment, since my memory is exploding with a dense one.

Thank you for your answer
Best,
Martin

der, desc = soap.derivatives(molecule,attach=True) 
norms = np.linalg.norm(desc,axis=-1)
norm_desc = desc/norms[:,None]
norms2 = norms**2
deriv_final = np.moveaxis(der,[0,1],[2,0])
# normal_soap_vector = np.array(normal_soap_vector)
hold = (np.einsum('ij,arkj->arik',desc,deriv_final,optimize="greedy"))
vd = np.einsum('akii->aki',hold,optimize="greedy")
r1 = np.einsum('akl,lj,l->aklj',vd,desc,1/norms,optimize="greedy")
f1 = np.einsum('aklj,l->aklj',deriv_final,norms,optimize="greedy")
normDer = np.einsum('aklj,l->aklj',f1-r1,1/norms2,optimize="greedy")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions