<s> """<STR_LIT>""" <EOL> from numpy import zeros , fill_diagonal , asarray <EOL> import numpy <EOL> from numpy . random import rand , randn , permutation <EOL> from kameleon_mcmc . distribution . Hopfield import Hopfield <EOL> from kameleon_mcmc . distribution . full_conditionals . HopfieldFullConditionals import HopfieldFullConditionals <EOL> from kameleon_mcmc . kernel . HypercubeKernel import HypercubeKernel <EOL> from kameleon_mcmc . mcmc . MCMCChain import MCMCChain <EOL> from kameleon_mcmc . mcmc . MCMCParams import MCMCParams <EOL> from kameleon_mcmc . mcmc . output . DiscretePlottingOutput import DiscretePlottingOutput <EOL> from kameleon_mcmc . mcmc . output . StatisticsOutput import StatisticsOutput <EOL> from kameleon_mcmc . mcmc . samplers . DiscreteKameleon import DiscreteKameleon <EOL> from kameleon_mcmc . mcmc . samplers . Gibbs import Gibbs <EOL> def sample_gibbs ( distribution , num_samples = <NUM_LIT:1000> ) : <EOL> mcmc_sampler = Gibbs ( distribution ) <EOL> current_state = [ rand ( ) < <NUM_LIT:0.5> for _ in range ( distribution . dimension ) ] <EOL> mcmc_params = MCMCParams ( start = asarray ( current_state , dtype = numpy . bool8 ) , num_iterations = num_samples ) <EOL> chain = MCMCChain ( mcmc_sampler , mcmc_params ) <EOL> chain . run ( ) <EOL> return chain . samples <EOL> def main ( ) : <EOL> d = <NUM_LIT:5> <EOL> b = randn ( d ) <EOL> V = randn ( d , d ) <EOL> W = V + V . T <EOL> fill_diagonal ( W , zeros ( d ) ) <EOL> hopfield = Hopfield ( W , b ) <EOL> current_state = [ rand ( ) < <NUM_LIT:0.5> for _ in range ( d ) ] <EOL> distribution = HopfieldFullConditionals ( full_target = hopfield , <EOL> current_state = current_state ) <EOL> print ( "<STR_LIT>" ) <EOL> Z = sample_gibbs ( distribution , num_samples = <NUM_LIT> ) [ <NUM_LIT> : ] . astype ( numpy . bool8 ) <EOL> inds = permutation ( len ( Z ) ) <EOL> Z = Z [ inds [ : <NUM_LIT> ] ] <EOL> print ( "<STR_LIT>" ) <EOL> threshold = <NUM_LIT> <EOL> spread = <NUM_LIT> <EOL> gamma = <NUM_LIT> <EOL> kernel = HypercubeKernel ( gamma ) <EOL> mcmc_sampler = DiscreteKameleon ( hopfield , kernel , Z , threshold , spread ) <EOL> start = zeros ( distribution . dimension , dtype = numpy . bool8 ) <EOL> mcmc_params = MCMCParams ( start = start , num_iterations = <NUM_LIT> ) <EOL> chain = MCMCChain ( mcmc_sampler , mcmc_params ) <EOL> chain . append_mcmc_output ( StatisticsOutput ( plot_times = True ) ) <EOL> chain . append_mcmc_output ( DiscretePlottingOutput ( plot_from = <NUM_LIT:0> , lag = <NUM_LIT> ) ) <EOL> chain . run ( ) <EOL> main ( ) </s>
