def set_distributions(self):
        """
        Set distributions in the network.

        Examples
        --------
        >>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
        >>> writer =XBNWriter()
        >>> writer.set_distributions()
        """
        distributions = etree.SubElement(self.bnmodel, 'DISTRIBUTIONS')

        cpds = self.model.get_cpds()
        cpds.sort(key=lambda x: x.variable)
        for cpd in cpds:
            cpd_values = cpd.values.ravel()
            var = cpd.variable
            dist = etree.SubElement(distributions, 'DIST', attrib={'TYPE': self.model.node[var]['TYPE']})
            etree.SubElement(dist, 'PRIVATE', attrib={'NAME': var})
            dpis = etree.SubElement(dist, 'DPIS')
            evidence = cpd.variables[:0:-1]
            if evidence:
                condset = etree.SubElement(dist, 'CONDSET')
                for condelem in sorted(evidence):
                    etree.SubElement(condset, 'CONDELEM', attrib={'NAME': condelem})
                # TODO: Get Index value.
                for val in range(0, len(cpd_values), 2):
                    etree.SubElement(dpis, "DPI", attrib={'INDEXES': ' '}).text = \
                        " " + str(cpd_values[val]) + " " + str(cpd_values[val+1]) + " "
            else:
                etree.SubElement(dpis, "DPI").text = ' ' + ' '.join(map(str, cpd_values))
def set_distributions ( self ) : distributions = etree . SubElement ( self . bnmodel , 'DISTRIBUTIONS' ) cpds = self . model . get_cpds ( ) cpds . sort ( key = lambda x : x . variable ) for cpd in cpds : cpd_values = cpd . values . ravel ( ) var = cpd . variable dist = etree . SubElement ( distributions , 'DIST' , attrib = { 'TYPE' : self . model . node [ var ] [ 'TYPE' ] } ) etree . SubElement ( dist , 'PRIVATE' , attrib = { 'NAME' : var } ) dpis = etree . SubElement ( dist , 'DPIS' ) evidence = cpd . variables [ : 0 : - 1 ] if evidence : condset = etree . SubElement ( dist , 'CONDSET' ) for condelem in sorted ( evidence ) : etree . SubElement ( condset , 'CONDELEM' , attrib = { 'NAME' : condelem } ) for val in range ( 0 , len ( cpd_values ) , 2 ) : etree . SubElement ( dpis , "DPI" , attrib = { 'INDEXES' : ' ' } ) . text = " " + str ( cpd_values [ val ] ) + " " + str ( cpd_values [ val + 1 ] ) + " " else : etree . SubElement ( dpis , "DPI" ) . text = ' ' + ' ' . join ( map ( str , cpd_values ) )
Set distributions in the network.

        Examples
        --------
        >>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
        >>> writer =XBNWriter()
        >>> writer.set_distributions()