function compile_sof(bnet)
% COMPILE_SOF Compile C versions of likelihood weighting specific to bnet for use by the sof algorithm.
% compile_sof(bnet) generates the files mylw1.h, mylw2.h, C_lw1.mex and C_lw2.mex in the directory BNT/bnet
% All subsequent calls to sof will use the parameters of this particular model.
% We assume bnet.observed_nodes has been specified.

assert(bnet.is_dbn);
fprintf('compiling sof...\n');
tic
global BNTroot
cd([BNTroot 'bnet']);

ss = bnet.slice_size;
!rm mylw2.h
fid = fopen([BNTroot 'bnet/mylw2.h'], 'w');
generate_mylw_C(bnet, fid, 2*ss, [bnet.observed_slice(:)' bnet.observed_slice(:)'+ss]);
fclose(fid);
!mex C_lw2.c

% We make a separate version that only samples from the first slice
!rm mylw1.h
fid = fopen([BNTroot 'bnet/mylw1.h'], 'w');
generate_mylw_C(bnet, fid, ss, bnet.observed_slice);
fclose(fid);
!mex C_lw1.c

toc

