⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 export_model.m.svn-base

📁 Probabilistic graphical models in matlab.
💻 SVN-BASE
字号:
function [] = export_model(filename, model, method, method_arg1)fid = fopen(filename, 'w');unknown_method = true;if (strcmp (method, 'loopy' ) )    unknown_method = false;endif (strcmp (method, 'exact_bp' ) )    unknown_method = false;endif (strcmp (method, 'gibbs' ) )    unknown_method = false;endif (strcmp (method, 'tree_mcmc' ) )    unknown_method = false;endif (strcmp (method, 'tree_mcmc_no_rb' ) )    unknown_method = false;endif (strcmp (method, 'tree_partition' ) )    %model.variables_sizes = ones(3);    unknown_method = false;endif (unknown_method)    error('Error: unknown method type');    exit;endfprintf(fid,'<method> (' );fprintf(fid, method );fprintf(fid, ')' );if (strcmp (method, 'loopy' ) )    fprintf(fid, '( %d ) ', method_arg1);endif (strcmp (method, 'gibbs' ) )    fprintf(fid, '( %d ) ', method_arg1);endif (strcmp (method, 'tree_mcmc' ) )    fprintf(fid, '( %d ) ', method_arg1);endif (strcmp (method, 'tree_mcmc_no_rb' ) )    fprintf(fid, '( %d ) ', method_arg1);endfprintf(fid,'\n' );% Number of vertices for the graphfprintf(fid, '<number of vertices> ');if (strcmp (model.type, 'pairwise-discrete' ) )    fprintf(fid, '( %d ) ', model.number_vertices);endif (strcmp (model.type, 'factorgraph-discrete' ) )    fprintf(fid, '( %d ) ', model.number_vertices+model.number_potential_tables);endfprintf(fid,'\n');fprintf(fid,'<model type> (' );fprintf(fid, model.type );fprintf(fid,') \n' );% Now comes the RV sizesif (model.all_variables ~= 1)    fprintf(fid, '<random variable sizes> ');    for i = 1:model.number_vertices        fprintf(fid, '( %d %d ) ', i, model.variables_sizes(1, i));    end    fprintf(fid,'\n');else    if (strcmp (model.type, 'factorgraph-discrete' ) )        fprintf(fid, '<all random variable sizes> (');        fprintf (fid, ' %d %d)\n', model.number_vertices, model.all_variables_size);    else        fprintf(fid, '<all random variable sizes> (');        fprintf (fid, ' %d )\n', model.all_variables_size);    endend% Now comes the links...if (model.structure)    fprintf(fid, '%s', model.structure_code);else    counted_links = 0;    fprintf(fid, '<link> ');    if (strcmp (model.type, 'factorgraph-discrete' ) )        if (strcmp (model.structure_code, 'qmr' ) )            fprintf(fid, '(qmr) ');        else            fprintf(fid, '(normal) ');        end        for i = 1:model.number_potential_tables            fprintf(fid, '(');            for j = 1:size(model.link_tables{i},2)                fprintf(fid, ' %d ', model.link_tables{i} (j) );            end            fprintf(fid, ') ');        end    end    if (strcmp (model.type, 'pairwise-discrete' ) )        for i = 1:model.number_vertices            for j = 1:model.number_vertices                if model.link_matrix (i, j) == 1                    fprintf(fid, '( %d %d) ', i, j);                    counted_links = counted_links +1 ;                end            end        end    endendfprintf(fid,'\n');% Now comes the potential tablesif (model.all_potentials ~= 1)    fprintf(fid, '<potential tables> ');    if (strcmp (model.type, 'factorgraph-discrete' ) )        if (strcmp (model.structure_code, 'qmr' ) )            fprintf(fid, '(qmr) ');        else            fprintf(fid, '(normal) ');        end        for i = 1:model.number_potential_tables            fprintf(fid, '(');            s = prod (size (model.potential_tables{i} ) );            temp_pot_table = reshape (model.potential_tables{i}, [1 s] );            for j = 1:size(temp_pot_table, 2)                fprintf(fid, ' %d ', temp_pot_table (j) );            end            fprintf(fid, ') ');        end    end    if (strcmp (model.type, 'pairwise-discrete' ) )        if ( strcmp (method, 'tree_partition' ) )        elseif ( counted_links ~= size(model.edges(:,1) ) )            error('You did not specify the correct number of potential tables');        else            for i = 1: size(model.edges)                fprintf(fid, '( %d %d) ', model.edges(i, 1), model.edges(i, 2) );                fprintf(fid, '( ');                [m,n] = size(model.potential_tables{i});                for j = 1: m                    for k = 1: n                        fprintf(fid, ' %d ', model.potential_tables{i}(j,k) );                    end                end                fprintf(fid, ' ) ');            end        end    endelse    fprintf(fid, '<all potential tables> ');    %fprintf(fid, '(');    fprintf (fid, '%s', model.all_potentials_code);endfprintf(fid,'\n');% Observed variablesfprintf(fid,'<observations> ');for i = 1: size(model.observations,2)        if (model.observations{i} ~= 0)    fprintf(fid,'(%d %d) ', i, model.observations{i}-1);        endendfprintf(fid,'\n');% Using timer?if (model.timer)    fprintf(fid, '<timer>\n');end% Using monitor?if (model.monitor)    fprintf(fid, '<monitor>\n');    fprintf(fid, '<ground truth> (external) (');    fprintf(fid, '%s', model.ground_truth_file);    fprintf(fid, ')\n');        fprintf(fid, '<monitoring interval> (%d) \n', model.monitoring_interval);end% Number of runs?if (model.number_of_runs ~= 1)    fprintf(fid, '<number of runs> ( %d )\n', model.number_of_runs);end% Internal Potentials (priors)if (model.all_internal_potentials)    % Writing special all internal potential code    fprintf(fid, '%s\n', model.all_internal_potentials_code);else    if (model.internal_potentials_bool)        % Normal case        fprintf(fid, '<internal potentials> ');        for i=1:size(model.internal_potentials,2)            fprintf(fid, '( %d ) ( ', i);            for j=1:size(model.internal_potentials{i}, 2 )                fprintf(fid, '%g ', model.internal_potentials{i}(j));            end            fprintf(fid, ') ');        end    endend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -