markovmodel / PyEMMA

🚂 Python API for Emma's Markov Model Algorithms 🚂
http://pyemma.org
GNU Lesser General Public License v3.0
308 stars 118 forks source link

Question to tica: How to add weights? #1060

Closed AlexanderJussupow closed 7 years ago

AlexanderJussupow commented 7 years ago

Hello,

I try to use tica with a metadynamics trajectory. Each frame of the trajectory has a different weight which are already precomputed. My problem is, that I do not understand how to use the weights option for pyemma.coordinates.tica ("An object that allows to compute re-weighting factors. It must possess a method"). Is it somehow possible to create a weight object, which just gives out the precomputed weights?

Best

Alex

marscher commented 7 years ago

On 03/21/2017 12:32 PM, AlexanderJussupow wrote:

Hello,

I try to use tica with a metadynamics trajectory. Each frame of the trajectory has a different weight which are already precomputed. My problem is, that I do not understand how to use the weights option for pyemma.coordinates.tica ("An object that allows to compute re-weighting factors. It must possess a method"). Is it somehow possible to create a weight object, which just gives out the precomputed weights?

Best

Alex

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/markovmodel/PyEMMA/issues/1060, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKZL9Fo3NmZCGBfP3Bw25WbxiwPgLzjks5rn7VbgaJpZM4Mjq0F.

I guess this has to be class like this:

class GetWeights(object): def init(self, my_weights): self.frame_counter = 0 self.my_weights = my_weights

def weights(ndarray):
    result = self.my_weights[self.frame_counter:len(ndarray)]
    self.frame_counter += len(ndarray)
    return result
marscher commented 7 years ago

This of course assumes that the ordering of my_weights is the same as the one you feed in the trajectories into tica.

marscher commented 7 years ago

Sorry, I've looked into the code and you have to derive the GetWeights class from this one: from pyemma.coordaintes.estimation.koopman import _Weights class GetWeights(_Weights): ...

I think we should change that into a plain signature check [hasattr(weights, "weights") and type(getattr(weights, "weights")) == types.MethodType to make this pythonic, eg. duck typed.

franknoe commented 7 years ago

I think this was implemented by @fabian-paul or @fnueske . Guys, what's the intended usecase?

fnueske commented 7 years ago

This was primarily written for Koopman re-weighting. Here, the class only holds the re-weighting vector u, and transform an incoming trajectory X by multiplication by u. This assumes that X contains the same features / basis functions that were used to obtain u. It can be used in more general situations, though. All that matters is that the user supplies a class that possesses a method "weights(X)" to assign re-weighting factors to a given trajectory X. It is, of course, the responsibility of the user to make sure that re-weighting factors are assigned correctly. Does that make sense?

fabian-paul commented 7 years ago

I think there is no particular use case. The goal was just to have a flexible interface for the computation of the weights that can accommodate unanticipated future use cases. That's why we introduced this class.

franknoe commented 7 years ago

Yes it makes sense. But I agree with @marscher , you shouldn't have to derive from a base class if the base class doesn't provide code that you want to reuse, so just check for hasattr.

marscher commented 7 years ago

fixed by #1061