<s> from models . distribution import * <EOL> from utils import activation as act_fcn <EOL> import unittest as unittest <EOL> import numpy as np <EOL> VISIBLE_UNITS = <NUM_LIT:10> <EOL> HIDDEN_UNITS = <NUM_LIT:5> <EOL> SHAPE = ( VISIBLE_UNITS , HIDDEN_UNITS ) <EOL> class DistributionTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_correct_weight_matrix_dimension ( self ) : <EOL> """<STR_LIT>""" <EOL> dist = Distribution ( VISIBLE_UNITS , HIDDEN_UNITS ) <EOL> self . assertEqual ( dist . weights . shape , <EOL> ( VISIBLE_UNITS , HIDDEN_UNITS ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + str ( dist . weights . shape ) ) <EOL> def test_correct_bias_hidden_dimension ( self ) : <EOL> dist = Distribution ( VISIBLE_UNITS , HIDDEN_UNITS ) <EOL> self . assertEqual ( dist . bias_hidden . shape , ( HIDDEN_UNITS , ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + str ( dist . bias_hidden . shape ) ) <EOL> def test_correct_dimension_bias_visible ( self ) : <EOL> dist = Distribution ( VISIBLE_UNITS , HIDDEN_UNITS ) <EOL> self . assertEqual ( dist . bias_visible . shape , ( VISIBLE_UNITS , ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + str ( dist . bias_visible . shape ) ) <EOL> def test_error_wrong_weight_matrix_dim ( self ) : <EOL> weights = np . zeros ( shape = ( <NUM_LIT:15> , <NUM_LIT> ) ) <EOL> self . assertRaises ( AssertionError , Distribution , VISIBLE_UNITS , HIDDEN_UNITS , weights ) <EOL> def test_error_wrong_hidden_bias_dim ( self ) : <EOL> bias_hidden = np . ones ( shape = ( <NUM_LIT:12> ) ) <EOL> self . assertRaises ( AssertionError , Distribution , VISIBLE_UNITS , HIDDEN_UNITS , weights = None , bias_hidden = bias_hidden ) <EOL> def test_assert_wrong_visible_bias_dim ( self ) : <EOL> bias_visible = np . ones ( shape = <NUM_LIT:15> ) <EOL> self . assertRaises ( AssertionError , Distribution , VISIBLE_UNITS , HIDDEN_UNITS , weights = None , bias_hidden = None , bias_visible = bias_visible ) <EOL> class BernoulliTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> weights = np . ones ( shape = SHAPE ) <EOL> bias_hidden = np . ones ( shape = HIDDEN_UNITS ) <EOL> bias_visible = np . ones ( shape = VISIBLE_UNITS ) <EOL> vis_inp = np . ones ( shape = VISIBLE_UNITS ) <EOL> hid_inp = np . ones ( shape = HIDDEN_UNITS ) <EOL> def test_correct_score ( self ) : <EOL> """<STR_LIT>""" <EOL> dist = Bernoulli ( VISIBLE_UNITS , HIDDEN_UNITS , weights = self . weights , bias_hidden = self . bias_hidden , bias_visible = self . bias_visible ) <EOL> target = np . sum ( self . weights ) + np . sum ( self . bias_hidden ) + np . sum ( self . bias_visible ) <EOL> actual = np . abs ( dist . score_energy ( self . vis_inp , self . hid_inp ) ) <EOL> self . assertEqual ( target , actual , "<STR_LIT>" + str ( target ) + "<STR_LIT>" + str ( actual ) ) <EOL> def test_correct_conditional_prob_v ( self ) : <EOL> """<STR_LIT>""" <EOL> weights = self . weights * ( <NUM_LIT:1> / float ( HIDDEN_UNITS ) ) <EOL> bias_visible = self . bias_visible * - <NUM_LIT:1> <EOL> dist = Bernoulli ( VISIBLE_UNITS , HIDDEN_UNITS , weights , self . bias_hidden , bias_visible ) <EOL> target = <NUM_LIT:0.5> * VISIBLE_UNITS <EOL> actual = dist . conditional_prob_v ( self . hid_inp ) <EOL> self . assertEqual ( target , np . sum ( actual ) , "<STR_LIT>" + str ( target ) + "<STR_LIT>" + str ( actual ) ) <EOL> def test_correct_conditional_prob_h ( self ) : <EOL> """<STR_LIT>""" <EOL> weights = self . weights * ( <NUM_LIT:1> / float ( VISIBLE_UNITS ) ) <EOL> bias_hidden = self . bias_hidden * - <NUM_LIT:1> <EOL> dist = Bernoulli ( VISIBLE_UNITS , HIDDEN_UNITS , weights , bias_hidden , self . bias_visible ) <EOL> target = <NUM_LIT:0.5> * HIDDEN_UNITS <EOL> actual = dist . conditional_prob_h ( self . vis_inp ) <EOL> self . assertEqual ( target , np . sum ( actual ) , "<STR_LIT>" + str ( target ) + "<STR_LIT>" + str ( actual ) ) <EOL> def test_correct_state_v ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_state_h ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_distribution_type ( self ) : <EOL> dist = Bernoulli ( VISIBLE_UNITS , HIDDEN_UNITS ) <EOL> self . assertEqual ( Distribution . Type . DISCRETE , dist . get_distribution_type ( ) ) <EOL> class DynamicBernoulliTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_correct_score ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_conditional_prob_v ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_conditional_prob_h ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_state_v ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_state_h ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_correct_distribution_type ( self ) : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
