GithubHelp home page GithubHelp logo

Comments (5)

ashermancinelli avatar ashermancinelli commented on July 19, 2024

numpy.linalg.norm would work well, though Nathan mentioned he wanted to avoid using the square root for as long as possible.

from apbs.

intendo avatar intendo commented on July 19, 2024

@sobolevnrm, what would you recommend for replacing return np.sum((self.position._data - other) ** 2) to calculate the euclidean distance in https://github.com/Electrostatics/apbs/blob/master/apbs/chemistry/atom.py?

You had mentioned using https://numpy.org/doc/stable/reference/generated/numpy.dot.html but the Googles seems to recommend numpy.linalg.norm like the answer on https://stackoverflow.com/questions/1401712/how-can-the-euclidean-distance-be-calculated-with-numpy.

Can you give us some guidance?

from apbs.

sobolevnrm avatar sobolevnrm commented on July 19, 2024

I recommended the dot function because it avoids square roots. In general, when we can compare squared distances to squared distances, we will save a lot of computational effort. That's why I wanted to avoid the norm for now.

from apbs.

intendo avatar intendo commented on July 19, 2024

@sobolevnrm is this what you were thinking (with optionally not performing the square root)?

import numpy as np 
  
# intializing points in numpy arrays 
point1 = np.array((1, 2, 3)) 
point2 = np.array((1, 1, 1)) 
  
# subtracting vector 
temp = point1 - point2 
  
# doing dot product for finding sum of the squares 
sum_sq = np.dot(temp.T, temp) 
print(sum_sq)
  
# Doing squareroot and printing Euclidean distance 
print(np.sqrt(sum_sq)) 

from apbs.

sobolevnrm avatar sobolevnrm commented on July 19, 2024

Yes, more or less. I was actually thinking of mapping atom coordinates to (N, 3)-size arrays, where N is the number of atoms, so we could quickly apply operations like dot, etc. to those arrays .

from apbs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.