Home > Mateda2.0 > functions > generators > ReadFunctionsFromData.m

# ReadFunctionsFromData

## PURPOSE

[Tables] = ReadFunctionsFromData(filename,ListFactors,Card)

## SYNOPSIS

function[Tables] = ReadFunctionsFromData(filename,ListFactors,Card)

## DESCRIPTION

     [Tables] = ReadFunctionsFromData(filename,ListFactors,Card)
     ReadFunctionsFromData:    Read the  values  of a given function whose structure is defined in ListFactors
     INPUTS
     filename: name of the file with the function
               File format: First the factor node number (starting at NumberVar and
                  ending in NumbVar+NumberOfNodes). After each factor node number, the
                  values of the function for the factor.
     ListFactors: Each  row i stores the variables in the factor
     Card: Cardinalities of the variables
     OUTPUTS
     Tables{i}: Contains the values for each of the configurations of factor i

     Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- BN_Prediction EXAMPLE 2: Evaluation of the prediction capability of the models
- DefaultEDA_NKRandom EXAMPLE 9: Bayesian tree for a multiobjective function of the NK random
- EBNA_PLS_MPC_NKRandom EXAMPLE 16:

## SOURCE CODE

    0001 function[Tables] = ReadFunctionsFromData(filename,ListFactors,Card)
    0002 % [Tables] = ReadFunctionsFromData(filename,ListFactors,Card)
    0003 % ReadFunctionsFromData:    Read the  values  of a given function whose structure is defined in ListFactors
    0004 % INPUTS
    0005 % filename: name of the file with the function
    0006 %           File format: First the factor node number (starting at NumberVar and
    0007 %              ending in NumbVar+NumberOfNodes). After each factor node number, the
    0008 %              values of the function for the factor.
    0009 % ListFactors: Each  row i stores the variables in the factor
    0010 % Card: Cardinalities of the variables
    0011 % OUTPUTS
    0012 % Tables{i}: Contains the values for each of the configurations of factor i
    0013 %
    0014 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
    0015
    0016 fid = fopen(filename,'r');
    0017 AllEntries = fscanf(fid,'%f');
    0018 fclose(fid);
    0019
    0020 EntryIndex = 1;
    0021 nvars = size(Card,2);
    0022
    0023 for i=1:size(ListFactors,2)
    0024   currentFactorIndex = AllEntries(EntryIndex) - nvars + 1;
    0025   currentFactor = ListFactors{currentFactorIndex};
    0026   auxTableSize = 1;
    0027   for j=1:size(currentFactor,2)
    0028    auxTableSize = auxTableSize * Card(currentFactor(j));
    0029   end
    0030   Tables{currentFactorIndex,:} = AllEntries(EntryIndex+1:EntryIndex+auxTableSize);
    0031   EntryIndex = EntryIndex + auxTableSize + 1;
    0032 end
    0033