<s> """<STR_LIT>""" <EOL> import numpy <EOL> import nose . tools <EOL> import borg <EOL> def test_sampled_pmfs_log_pmf ( ) : <EOL> """<STR_LIT>""" <EOL> cdfs = numpy . log ( [ <EOL> [ [ <NUM_LIT:0.1> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT:0.1> ] ] , <EOL> [ [ <NUM_LIT:0.1> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT:0.1> ] ] , <EOL> ] ) <EOL> counts = numpy . array ( <EOL> [ <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] ] , <EOL> [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:2> , <NUM_LIT:0> ] ] , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:2> , <NUM_LIT:0> ] ] , <EOL> ] , <EOL> numpy . intc , <EOL> ) <EOL> logs = borg . models . sampled_pmfs_log_pmf ( cdfs , counts ) <EOL> nose . tools . assert_almost_equal ( numpy . exp ( logs [ <NUM_LIT:0> , <NUM_LIT:0> ] ) , <NUM_LIT:0.1> ) <EOL> nose . tools . assert_almost_equal ( numpy . exp ( logs [ <NUM_LIT:0> , <NUM_LIT:1> ] ) , <NUM_LIT> ** <NUM_LIT:2> ) <EOL> nose . tools . assert_almost_equal ( numpy . exp ( logs [ <NUM_LIT:0> , <NUM_LIT:2> ] ) , <NUM_LIT:0.1> * <NUM_LIT> ** <NUM_LIT:2> ) <EOL> def test_kernel_model_sample ( ) : <EOL> """<STR_LIT>""" <EOL> successes = numpy . array ( [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] ] , numpy . intc ) <EOL> failures = numpy . array ( [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] , numpy . intc ) <EOL> durations = numpy . array ( [ <EOL> [ [ numpy . nan ] , [ <NUM_LIT> ] ] , <EOL> [ [ <NUM_LIT> ] , [ numpy . nan ] ] , <EOL> [ [ numpy . nan ] , [ numpy . nan ] ] , <EOL> ] ) <EOL> kernel = borg . models . DeltaKernel ( ) <EOL> alpha = <NUM_LIT:1.0> + <NUM_LIT> <EOL> model = borg . models . KernelModel ( successes , failures , durations , <NUM_LIT> , alpha , kernel ) <EOL> samples = model . sample ( <NUM_LIT:16> , <NUM_LIT:4> ) <EOL> nose . tools . assert_true ( numpy . all ( numpy . logaddexp . reduce ( samples , axis = - <NUM_LIT:1> ) < <NUM_LIT> ) ) <EOL> nose . tools . assert_true ( numpy . any ( numpy . abs ( samples [ ... , <NUM_LIT:0> ] - numpy . log ( ( alpha ) / ( <NUM_LIT:5> * alpha - <NUM_LIT:4> ) ) ) < <NUM_LIT> ) ) <EOL> nose . tools . assert_true ( numpy . any ( numpy . abs ( samples [ ... , - <NUM_LIT:1> ] - numpy . log ( <NUM_LIT:1.0> / <NUM_LIT:5> ) ) < <NUM_LIT> ) ) <EOL> nose . tools . assert_true ( numpy . any ( numpy . abs ( samples [ ... , - <NUM_LIT:1> ] - numpy . log ( ( alpha ) / ( <NUM_LIT:5> * alpha - <NUM_LIT:4> ) ) ) < <NUM_LIT> ) ) <EOL> nose . tools . assert_true ( numpy . any ( numpy . abs ( samples [ ... , - <NUM_LIT:1> ] - numpy . log ( ( alpha - <NUM_LIT:1> ) / ( <NUM_LIT:5> * alpha - <NUM_LIT:4> ) ) ) < <NUM_LIT> ) ) <EOL> def test_multinomial_model_fit ( ) : <EOL> """<STR_LIT>""" <EOL> runs = [ <EOL> ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:1.0> , True ) , <EOL> ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , True ) , <EOL> ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , False ) , <EOL> ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , True ) , <EOL> ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , True ) , <EOL> ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , False ) , <EOL> ] <EOL> training = borg . RunData ( ) <EOL> for run in runs : <EOL> training . add_run ( "<STR_LIT:foo>" , borg . storage . RunRecord ( * run ) ) <EOL> training . add_run ( "<STR_LIT:bar>" , borg . storage . RunRecord ( * run ) ) <EOL> alpha = <NUM_LIT:1.0> + <NUM_LIT> <EOL> model = borg . models . MultinomialModel . fit ( [ "<STR_LIT>" , "<STR_LIT>" ] , training , <NUM_LIT:4> , alpha ) <EOL> components = numpy . exp ( model . log_components ) <EOL> nose . tools . assert_true ( numpy . all ( numpy . abs ( components [ <NUM_LIT:0> ] - components [ <NUM_LIT:1> ] ) == <NUM_LIT:0.0> ) ) <EOL> nose . tools . assert_true ( numpy . all ( numpy . abs ( numpy . sum ( components , axis = - <NUM_LIT:1> ) - <NUM_LIT:1.0> ) < <NUM_LIT> ) ) <EOL> nose . tools . assert_true ( numpy . all ( components [ : , <NUM_LIT:0> , <NUM_LIT:0> ] == components [ : , <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> nose . tools . assert_true ( numpy . all ( components [ : , <NUM_LIT:0> , <NUM_LIT:1> ] > components [ : , <NUM_LIT:0> , <NUM_LIT:2> ] ) ) <EOL> nose . tools . assert_true ( numpy . all ( components [ : , <NUM_LIT:1> , <NUM_LIT:0> ] == components [ : , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> nose . tools . assert_true ( numpy . all ( components [ : , <NUM_LIT:1> , <NUM_LIT:1> ] < components [ : , <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_multinomial_model_condition ( ) : <EOL> model = borg . models . MultinomialModel ( <NUM_LIT> , numpy . log ( [ [ [ <NUM_LIT> , <NUM_LIT:0.1> ] ] , [ [ <NUM_LIT> , <NUM_LIT> ] ] ] ) , numpy . log ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] ) ) <EOL> posterior0 = model . condition ( [ ( <NUM_LIT:0> , <NUM_LIT:0> ) ] ) <EOL> posterior1 = model . condition ( [ ( <NUM_LIT:0> , <NUM_LIT:1> ) ] ) <EOL> nose . tools . assert_almost_equal ( posterior0 . log_weights [ <NUM_LIT:0> ] , numpy . log ( <NUM_LIT> * <NUM_LIT:0.5> / ( <NUM_LIT> * <NUM_LIT:0.5> + <NUM_LIT> * <NUM_LIT:0.5> ) ) ) <EOL> nose . tools . assert_almost_equal ( posterior0 . log_weights [ <NUM_LIT:1> ] , numpy . log ( <NUM_LIT> * <NUM_LIT:0.5> / ( <NUM_LIT> * <NUM_LIT:0.5> + <NUM_LIT> * <NUM_LIT:0.5> ) ) ) <EOL> nose . tools . assert_almost_equal ( posterior1 . log_weights [ <NUM_LIT:0> ] , numpy . log ( <NUM_LIT:0.1> * <NUM_LIT:0.5> / ( <NUM_LIT:0.1> * <NUM_LIT:0.5> + <NUM_LIT> * <NUM_LIT:0.5> ) ) ) <EOL> nose . tools . assert_almost_equal ( posterior1 . log_weights [ <NUM_LIT:1> ] , numpy . log ( <NUM_LIT> * <NUM_LIT:0.5> / ( <NUM_LIT:0.1> * <NUM_LIT:0.5> + <NUM_LIT> * <NUM_LIT:0.5> ) ) ) </s>
