<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> __all__ = [ '<STR_LIT>' ] <EOL> import numpy as np <EOL> from scipy . stats import mode <EOL> from . modeler import PeriodicModelerMultiband <EOL> from . lomb_scargle import LombScargle <EOL> def mode_in_range ( a , axis = <NUM_LIT:0> , tol = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> a_trunc = a // tol <EOL> vals , counts = mode ( a_trunc , axis ) <EOL> mask = ( a_trunc == vals ) <EOL> return np . sum ( a * mask , axis ) / np . sum ( mask , axis ) <EOL> class NaiveMultiband ( PeriodicModelerMultiband ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , optimizer = None , BaseModel = LombScargle , <EOL> fit_period = False , optimizer_kwds = None , <EOL> * args , ** kwargs ) : <EOL> self . BaseModel = BaseModel <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> PeriodicModelerMultiband . __init__ ( self , optimizer , <EOL> fit_period = fit_period , <EOL> optimizer_kwds = optimizer_kwds ) <EOL> def _fit ( self , t , y , dy , filts ) : <EOL> t , y , dy , filts = np . broadcast_arrays ( t , y , dy , filts ) <EOL> unique_filts = np . unique ( filts ) <EOL> masks = [ ( filts == filt ) for filt in unique_filts ] <EOL> self . models_ = dict ( [ ( filt , <EOL> self . BaseModel ( self . optimizer , <EOL> * self . args , <EOL> ** self . kwargs ) . fit ( t [ mask ] , <EOL> y [ mask ] , <EOL> dy [ mask ] ) ) <EOL> for filt , mask in zip ( unique_filts , masks ) ] ) <EOL> def _predict ( self , t , filts , period ) : <EOL> result = np . zeros_like ( t ) <EOL> for filt , model in self . models_ . items ( ) : <EOL> mask = ( filts == filt ) <EOL> result [ mask ] = model . predict ( t [ mask ] , period = period ) <EOL> return result <EOL> def _score ( self , periods ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def scores ( self , periods ) : <EOL> """<STR_LIT>""" <EOL> return dict ( [ ( filt , model . score ( periods ) ) <EOL> for ( filt , model ) in self . models_ . items ( ) ] ) <EOL> def best_periods ( self ) : <EOL> """<STR_LIT>""" <EOL> for ( key , model ) in self . models_ . items ( ) : <EOL> model . optimizer = self . optimizer <EOL> return dict ( ( filt , model . best_period ) <EOL> for ( filt , model ) in self . models_ . items ( ) ) <EOL> @ property <EOL> def best_period ( self ) : <EOL> best_periods = np . asarray ( list ( self . best_periods ( ) . values ( ) ) ) <EOL> return mode_in_range ( best_periods , tol = <NUM_LIT> ) </s>
