Assign a parameter to multiple functions

7 views
Skip to first unread message

Keren Halabi

unread,
Apr 3, 2019, 7:45:30 AM4/3/19
to Bio++ Usage Help Forum
Hi dear team,

I wish to implement a class of a joint likelihood function that consist of two sub-likelihood functions.

 The class inherits from Function and AbstractParameterizble, and maintains the sub-likelihood functions as data members.

The function needs to have the parameters of its two sub-functions assigned to it as well, so that any alteration of these parameters would trigger the computation of two functions in practice:
- The sub-function that originally held the parameter (and more correctly, whose model originally held the parameter)
- The joint likelihood function instance (via its implementation of the function fireParameterChanged())

Please note that the computation of the joint likelihood relies on the computation of the sub-function, so the sub-function must be updated before the joint one, upon alteration of a shared parameter.

I saw there was an option to set a ParameterListener for a parameter, that respond to each event of alteration of the parameter. Can I can set for each parameter two listeners: the original sub-function and the joint function?

Many thanks!
Keren

Laurent Guéguen

unread,
Apr 4, 2019, 3:23:23 AM4/4/19
to Bio++ Usage Help Forum
Hi Keren,

yes in Parameter you can add several ParameterListeners:

    /**
     * @brief Add a new listener to this parameter.
     *
     * @param listener The listener to add.
     * @param attachListener Tell if the parameter will own this listener.
     * If so, deep copies will be made when cloning the parameter, and the listener will be destroyed upon
     * destruction of the parameter or upon removal. Alternatively, only superficial copies will be made,
     * and the listener will persist if the parameter is destroyed.
     */
    virtual void addParameterListener(ParameterListener* listener, bool attachListener = true)
 
Cheers,
Laurent


Keren Halabi

unread,
Apr 4, 2019, 7:15:31 AM4/4/19
to Bio++ Usage Help Forum
Thank you, Laurent!

I an not sure I understand what the role of these listeners is. I see that in models in Bio++, the parameters are created without listeners. So, not being a listener has no affect on whether the likelihood functions of the corresponding models would be computed or not upon alteration of the parameter. As per my understanding, the likelihood functions are updated upon each alteration of a parameter because their class functions (like matchParameterValues, for example), recognize the change and trigger computation of the likelihood (via fireParameterChanged).

As an alternative solution, I figured I could override all the functions in my class that use the parameters_ data member, and simply call the same functions for the character and sequence likelihood functions (that are data members of my function), from the overriding implementation. Do you happen to know if there is a better way to approach this?

Many thanks again,
Keren

Laurent Guéguen

unread,
Apr 8, 2019, 1:11:58 AM4/8/19
to Bio++ Usage Help Forum
Dear Keren,

yes indeed, ParameterListeners are only used to alias different parameters, for example all the kappas of branch specific models. And you understood the trigger mechanism match/fire.


About what you intend to do, the more usual way is to define your function which has its own parameters (copies of the subfunctions parameters). MatchParameterValues on these parameters
will call firePV of this function, which will call the matchPV of the subfunctions.

Also your problem is already done on the newlik branch. If I remember well, the limit of the newlik branch was the inclusion of mixture models? In a very short time (hopefully I count it in weeks)
it will be solved.

Cheers,
Laurent

Reply all
Reply to author
Forward
0 new messages