コード例 #1
0
ファイル: Tree_optSim.py プロジェクト: supertree-toolkit/stk
def optLogLike(self,
               verbose=1,
               newtAndBrentPowell=1,
               allBrentPowell=0,
               simplex=0):
    """Calculate the likelihood of the tree, with optimization.

    There are 3 optimization methods-- choose one.  I've made
    'newtAndBrentPowell' the default, as it is fast and seems to be
    working.  The 'allBrentPowell' optimizer used to be the default,
    as it seems to be the most robust, although it is slow.  It would
    be good for checking important calculations.  The simplex
    optimizer is the slowest, and will sometimes find better optima
    for difficult data, but often fails to optimize (with no
    warning)."""

    if verbose:
        theStartTime = time.clock()
    self._commonCStuff()

    # We want only one opt method.
    if newtAndBrentPowell:
        newtAndBrentPowell = 1
    if allBrentPowell:
        allBrentPowell = 1
    if simplex:
        simplex = 1
    if (newtAndBrentPowell + allBrentPowell + simplex) != 1:
        gm = ['Tree.optLogLike()']
        gm.append("Choose 1 opt method.")
        raise Glitch, gm

    # Do the opt.
    if allBrentPowell:
        pf.p4_allBrentPowellOptimize(self.cTree)
    elif simplex:
        from Tree import Tree
        pf.p4_simplexOptimize(self.cTree, self, Tree.simplexDump)
    else:
        pf.p4_newtSetup(self.cTree)
        pf.p4_newtAndBrentPowellOpt(self.cTree)

    self.logLike = pf.p4_treeLogLike(self.cTree,
                                     0)  # second arg is getSiteLikes

    # get the brLens
    brLens = pf.p4_getBrLens(self.cTree)
    for n in self.iterNodesNoRoot():
        n.br.len = brLens[n.nodeNum]

    # get the other free prams
    prams = pf.p4_getFreePrams(self.cTree)
    self.model.restoreFreePrams(prams)

    if verbose:
        print "optLogLike = %f" % self.logLike
        theEndTime = time.clock()
        print "cpu time %s seconds." % (theEndTime - theStartTime)
コード例 #2
0
ファイル: Tree_optSim.py プロジェクト: Anaphory/p4-phylogeny
def optLogLike(self, verbose=1, newtAndBrentPowell=1, allBrentPowell=0, simplex=0):
    """Calculate the likelihood of the tree, with optimization.

    There are 3 optimization methods-- choose one.  I've made
    'newtAndBrentPowell' the default, as it is fast and seems to be
    working.  The 'allBrentPowell' optimizer used to be the default,
    as it seems to be the most robust, although it is slow.  It would
    be good for checking important calculations.  The simplex
    optimizer is the slowest, and will sometimes find better optima
    for difficult data, but often fails to optimize (with no
    warning)."""


    if verbose:
        theStartTime = time.clock()
    self._commonCStuff()

    # We want only one opt method.
    if newtAndBrentPowell:
        newtAndBrentPowell = 1
    if allBrentPowell:
        allBrentPowell = 1
    if simplex:
        simplex = 1
    if (newtAndBrentPowell + allBrentPowell + simplex) != 1:
        gm = ['Tree.optLogLike()']
        gm.append("Choose 1 opt method.")
        raise Glitch(gm)
    
    # Do the opt.
    if allBrentPowell:
        pf.p4_allBrentPowellOptimize(self.cTree)
    elif simplex:
        from .Tree import Tree
        pf.p4_simplexOptimize(self.cTree, self, Tree.simplexDump)
    else:
        pf.p4_newtSetup(self.cTree)
        pf.p4_newtAndBrentPowellOpt(self.cTree)

    self.logLike = pf.p4_treeLogLike(self.cTree, 0) # second arg is getSiteLikes

    # get the brLens
    brLens = pf.p4_getBrLens(self.cTree)
    for n in self.iterNodesNoRoot():
        n.br.len = brLens[n.nodeNum]

    # get the other free prams
    prams = pf.p4_getFreePrams(self.cTree)
    self.model.restoreFreePrams(prams)

    if verbose:
        print("optLogLike = %f" % self.logLike)
        theEndTime = time.clock()
        print("cpu time %s seconds." % (theEndTime - theStartTime))
コード例 #3
0
    def optLogLike(self, verbose=1, newtAndBrentPowell=1, allBrentPowell=0):
        """Calculate the likelihood of the tree, with optimization.

        There are two optimization methods-- choose one.  I've made
        'newtAndBrentPowell' the default, as it is fast and seems to be
        working.  The 'allBrentPowell' optimizer used to be the default,
        as it seems to be the most robust, although it is slow.  It would
        be good for checking important calculations.  
        """

        if verbose:
            theStartTime = time.clock()
        self._commonCStuff()

        # We want only one opt method.
        if newtAndBrentPowell:
            newtAndBrentPowell = 1
        if allBrentPowell:
            allBrentPowell = 1
        if (newtAndBrentPowell + allBrentPowell) != 1:
            gm = ['Tree.optLogLike()']
            gm.append("Choose 1 opt method.")
            raise P4Error(gm)

        # Do the opt.
        if allBrentPowell:
            pf.p4_allBrentPowellOptimize(self.cTree)
        else:
            pf.p4_newtSetup(self.cTree)
            pf.p4_newtAndBrentPowellOpt(self.cTree)

        # second arg is getSiteLikes
        self.logLike = pf.p4_treeLogLike(self.cTree, 0)

        # get the brLens
        brLens = pf.p4_getBrLens(self.cTree)
        for n in self.iterNodesNoRoot():
            n.br.len = brLens[n.nodeNum]

        # get the other free prams
        prams = pf.p4_getFreePrams(self.cTree)
        self.model.restoreFreePrams(prams)

        if verbose:
            print "optLogLike = %f" % self.logLike
            theEndTime = time.clock()
            print "cpu time %s seconds." % (theEndTime - theStartTime)
コード例 #4
0
ファイル: Tree_optSim.py プロジェクト: supertree-toolkit/stk
def optTest(self):
    self._commonCStuff()
    theStartTime = time.clock()
    doXfer = 0
    for i in range(1):
        if doXfer:
            self.model.setCStuff()
            self.setCStuff()
        pf.p4_setPrams(self.cTree, -1)
        self.logLike = pf.p4_treeLogLike(self.cTree, 0)

        if doXfer:
            # get the brLens
            brLens = pf.p4_getBrLens(self.cTree)
            for i in range(len(self.nodes)):
                n = self.nodes[i]
                if n != self.root:
                    n.br.len = brLens[i]

            # get the other free prams
            prams = pf.p4_getFreePrams(self.cTree)
            self.model.restoreFreePrams(prams)

    print "time %s seconds." % (time.clock() - theStartTime)
コード例 #5
0
ファイル: Tree_optSim.py プロジェクト: Anaphory/p4-phylogeny
def optTest(self):
    self._commonCStuff()
    theStartTime = time.clock()
    doXfer = 0
    for i in range(1):
        if doXfer:
            self.model.setCStuff()
            self.setCStuff()
        pf.p4_setPrams(self.cTree, -1)
        self.logLike = pf.p4_treeLogLike(self.cTree, 0)

        if doXfer:
            # get the brLens
            brLens = pf.p4_getBrLens(self.cTree)
            for i in range(len(self.nodes)):
                n = self.nodes[i]
                if n != self.root:
                    n.br.len = brLens[i]

            # get the other free prams
            prams = pf.p4_getFreePrams(self.cTree)
            self.model.restoreFreePrams(prams)

    print("time %s seconds." % (time.clock() - theStartTime))