def lnlike(self, p, use_cache=True):
if use_cache and self._cache_key is not None and np.all(p==self._cache_key):<EOL><INDENT>return self._cache_val<EOL><DEDENT>self._cache_key = p<EOL>pardict = self.p2pardict(p)<EOL>lnl = <NUM_LIT:0><EOL>for n in self:<EOL><INDENT>if n is not self:<EOL><INDENT>lnl += n.lnlike(pardict, use_cache=use_cache)<EOL><DEDENT>if not np.isfinite(lnl):<EOL><INDENT>self._cache_val = -np.inf<EOL>return -np.inf<EOL><DEDENT><DEDENT>for l in self.spectroscopy:<EOL><INDENT>for prop,(val,err) in self.spectroscopy[l].items():<EOL><INDENT>mod = self.get_leaf(l).evaluate(pardict[l], prop)<EOL>lnl += -<NUM_LIT:0.5>*(val - mod)**<NUM_LIT:2>/err**<NUM_LIT:2><EOL><DEDENT>if not np.isfinite(lnl):<EOL><INDENT>self._cache_val = -np.inf<EOL>return -np.inf<EOL><DEDENT><DEDENT>for l in self.limits:<EOL><INDENT>for prop,(vmin,vmax) in self.limits[l].items():<EOL><INDENT>mod = self.get_leaf(l).evaluate(pardict[l], prop)<EOL>if mod < vmin or mod > vmax or not np.isfinite(mod):<EOL><INDENT>self._cache_val = -np.inf<EOL>return -np.inf<EOL><DEDENT><DEDENT><DEDENT>for s,(val,err) in self.parallax.items():<EOL><INDENT>dist = pardict['<STR_LIT>'.format(s)][<NUM_LIT:3>]<EOL>mod = <NUM_LIT:1.>/dist * <NUM_LIT><EOL>lnl += -<NUM_LIT:0.5>*(val-mod)**<NUM_LIT:2>/err**<NUM_LIT:2><EOL><DEDENT>if not np.isfinite(lnl):<EOL><INDENT>self._cache_val = -np.inf<EOL>return -np.inf<EOL><DEDENT>self._cache_val = lnl<EOL>return lnl<EOL>
takes parameter vector, constructs pardict, returns sum of lnlikes of non-leaf nodes