Git Product home page Git Product logo

Comments (9)

jmcq89 avatar jmcq89 commented on June 14, 2024

@jakevdp how should the init() geometry function handle the **kwargs for the adjacency, affinity & laplacian methods? e.g

def init(self,
adjacency_method='auto', adjacency_ags = None,
affinity_method='auto', adjacency_ags = None,
laplacian_method='auto', adjacency_ags = None):

or

def init(self,
adjacency_method='auto', affinity_method='auto', laplacian_method='auto',
**kwargs):

Edit: we shouldn't pass a nbhd radius or affinity radius directly either since they will depend on the adjacency and affinity (for example if it's number of neighbors instead of radius).

from megaman.

jmcq89 avatar jmcq89 commented on June 14, 2024

In a similar vein with respect to the following situation:

  • Initialize geometry object, pass data matrix
  • call get_adjacency_matrix(distance_method, **kwargs)
  • do something else
  • call get_adjacency_matrix(distance_method, **kwargs) again

Since kwargs can be of an arbitrary length I don't think it makes sense to store these and then check and see if they are the same so that if someone calls get_adjacency_matrix() twice then it calculates twice -- even if they have the same arguments. We should therefore encourage users to use the attribute geom.adjacency_matrix to get the existing matrix and only call get_adjacency_matrix() only when they want to re-calculate it.

Same with affinity & Laplacian. This simplifies things I think.

from megaman.

jakevdp avatar jakevdp commented on June 14, 2024

My thought would be:

def init(self, adjacency_method='auto', adjacency_kwds=None, 
         affinity_method='auto', adjacency_kwds=None, 
         laplacian_method='auto', adjacency_kwds=None):

Regarding the computation of the matrix... how about we change get_adjacency_matrix to compute_adjacency_matrix, so that it's more explicit? Then we could use an adjacency_matrix attribute (or perhaps a property) to access the already-computed value.

from megaman.

jmcq89 avatar jmcq89 commented on June 14, 2024

I agree. One more quick questions. If I outline it like this:

def __init__(self, adjacency_method = 'auto', adjacency_kwds=None,  
                    affinity_method = 'auto', affinity_kwds=None,  
                    laplacian_method = 'auto', laplacian_kwds=None):   
        [...]    
    def compute_adjacency_matrix(self, copy = False, **kwargs):    
        [...]     
        self.adjacency_matrix = compute_adjacency_matrix(self.X, self.adjacency_method,
                                                         self.adjacency_kwds, **kwargs)    

will the self.compute_adjacency_matrix work as intended passing both the adjacency_kwds passed at initialization AND the **kwargs passed to self.compute_adjacency_matrix() itself?

from megaman.

jakevdp avatar jakevdp commented on June 14, 2024

No, I think you have a danger of getting a repeated argument there. I'd do something like this:

kwds = self.adjacency_kwds.copy()
kwds.update(kwargs)

then pass **kwds to the function.

(in Python 3.5 you could do kwds = {**self.adjacency_kwds, **kwargs} but we need backward compatibility for the time being 😄)

from megaman.

jmcq89 avatar jmcq89 commented on June 14, 2024

I figured as much. Thanks again Jake! Things are going well and look much cleaner. I should be able to push the pull request tonight.

from megaman.

jakevdp avatar jakevdp commented on June 14, 2024

Awesome! I'm working on the other parts of the refactor, and I think I'll have it done tonight as well. Tomorrow we can work on merging our two sets of changes.

from megaman.

jmcq89 avatar jmcq89 commented on June 14, 2024

@jakevdp just an FYI the following functions inside test_geometry:

test_laplacian_unknown_normalization
test_laplacian_create_A_sparse
test_equal_original

are testing affinity/laplacian methods.

from megaman.

jmcq89 avatar jmcq89 commented on June 14, 2024

re-factor done.

from megaman.

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.