<s> import tensorflow as tf <EOL> from . . import config <EOL> from . . distribution import Distribution <EOL> @ Distribution <EOL> def Polynomial ( coefficients , name = None ) : <EOL> assert len ( coefficients ) >= <NUM_LIT:2> <EOL> for coeff in coefficients : <EOL> assert isinstance ( coeff , tf . Tensor ) <EOL> X = tf . placeholder ( config . dtype , name = name ) <EOL> pdf = [ ] <EOL> for i , coeff in enumerate ( coefficients ) : <EOL> pdf . append ( coeff * X ** tf . constant ( i , dtype = config . dtype ) ) <EOL> Distribution . logp = tf . log ( tf . add_n ( pdf ) ) <EOL> def integrate ( lower , upper ) : <EOL> result = [ ] <EOL> for i , coeff in enumerate ( coefficients , start = <NUM_LIT:1> ) : <EOL> order = tf . constant ( i , dtype = config . dtype ) <EOL> result . append ( coeff / order * ( upper ** order - lower ** order ) ) <EOL> return tf . add_n ( result ) <EOL> Distribution . integral = integrate <EOL> return X </s>
