How to use the sdgym.utils.data.simulated.multivariate.MultivariateMaker function in sdgym

To help you get started, we’ve selected a few sdgym examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DAI-Lab / SDGym / sdgym / utils / data / simulated / multivariate.py View on Github external
model.add_edge(s2, s3)
        model.bake()
        self.model = model

        meta = []
        for i in range(self.model.node_count()):
            meta.append({
                "name": chr(ord('A') + i),
                "type": "categorical",
                "size": 3,
                "i2s": ['1', '2', '3']
        })
        self.meta = meta


class TreeMaker(MultivariateMaker):
    def __init__(self):
        A = DiscreteDistribution({'1': 1./3, '2': 1./3, '3': 1./3})
        B = ConditionalProbabilityTable(
            [['1','1',0.5],
            ['1','2',0.5],
            ['1','3',0],
            ['2','1',0],
            ['2','2',0.5],
            ['2','3',0.5],
            ['3','1',0.5],
            ['3','2',0],
            ['3','3',0.5],
            ],[A])
        C = ConditionalProbabilityTable(
            [['1','4',0.5],
            ['1','5',0.5],
github DAI-Lab / SDGym / sdgym / utils / data / simulated / multivariate.py View on Github external
meta = []
        for i in range(self.model.node_count()):
            meta.append({
                "name": None,
                "type": "categorical",
                "size": 2,
                "i2s": ['T', 'F']
        })
        meta[0]['name'] = 'Rain'
        meta[1]['name'] = 'Sprinkler'
        meta[2]['name'] = 'Wet'
        self.meta = meta


class GeneralMaker(MultivariateMaker):
    def __init__(self):
        Pollution = DiscreteDistribution({'F': 0.9, 'T': 0.1})
        Smoker = DiscreteDistribution({'T': 0.3, 'F': 0.7})
        print(Smoker)
        Cancer = ConditionalProbabilityTable(
            [['T','T','T',0.05],
            ['T','T','F',0.95],
            ['T','F','T',0.02],
            ['T','F','F',0.98],
            ['F','T','T',0.03],
            ['F','T','F',0.97],
            ['F','F','T',0.001],
            ['F','F','F',0.999],
            ],[Pollution,Smoker])
        print(Cancer)
        XRay = ConditionalProbabilityTable(
github DAI-Lab / SDGym / sdgym / utils / data / simulated / multivariate.py View on Github external
for i in range(self.model.node_count()-1):
            meta.append({
                "name": chr(ord('A') + i),
                "type": "categorical",
                "size": 3,
                "i2s": ['1', '2', '3']
        })
        meta.append({
                "name": "C",
                "type": "categorical",
                "size": 3,
                "i2s": ['4', '5', '6']
        })
        self.meta = meta

class FCMaker(MultivariateMaker):
    def __init__(self):
        Rain = DiscreteDistribution({'T': 0.2, 'F': 0.8})
        Sprinkler = ConditionalProbabilityTable(
            [['F','T',0.4],
            ['F','F',0.6],
            ['T','T',0.1],
            ['T','F',0.9],
            ],[Rain])
        Wet = ConditionalProbabilityTable(
            [['F','F','T',0.01],
            ['F','F','F',0.99],
            ['F','T','T',0.8],
            ['F','T','F',0.2],
            ['T','F','T',0.9],
            ['T','F','F',0.1],
            ['T','T','T',0.99],
github DAI-Lab / SDGym / sdgym / utils / data / simulated / multivariate.py View on Github external
try:
                            tmp = tmp.decode('utf8')
                        except:
                            pass
                        values[parents[i]] = tmp
                    data[_id, current] = distribution.sample(parent_values=values)

        data_t = np.zeros(data.shape)
        for col_id in range(data.shape[1]):
            data_t[:, col_id] = map_col(self.meta[col_id]['i2s'], data[:, col_id])
        return data_t




class ChainMaker(MultivariateMaker):

    def __init__(self):
        A = DiscreteDistribution({'1': 1./3, '2': 1./3, '3': 1./3})
        B = ConditionalProbabilityTable(
            [['1','1',0.5],
            ['1','2',0.5],
            ['1','3',0],
            ['2','1',0],
            ['2','2',0.5],
            ['2','3',0.5],
            ['3','1',0.5],
            ['3','2',0],
            ['3','3',0.5],
            ],[A])
        C = ConditionalProbabilityTable(
            [['1','1',0.5],
github DAI-Lab / SDGym / sdgym / utils / data / simulated / multivariate.py View on Github external
model.add_edge(s3, s5)
        model.bake()
        self.model = model

        meta = []
        name_mapper = ["Pollution", "Smoker", "Cancer", "XRay", "Dyspnoea"]
        for i in range(self.model.node_count()):
            meta.append({
                "name": name_mapper[i],
                "type": "categorical",
                "size": 2,
                "i2s": ['T', 'F']
        })
        self.meta = meta

class BIFMaker(MultivariateMaker):
    def __init__(self, filename):
        with open(filename) as f:
            bif = f.read()
        vars = re.findall(r"variable[^\{]+{[^\}]+}", bif)
        probs = re.findall(r"probability[^\{]+{[^\}]+}", bif)

        var_nodes = {}
        var_index_to_name = []
        edges = []

        self.meta = []
        todo = set()
        for v, p in zip(vars, probs):
            m = re.search(r"variable\s+([^\{\s]+)\s+", v)
            v_name = m.group(1)
            m = re.search(r"type\s+discrete\s+\[\s*(\d+)\s*\]\s*\{([^\}]+)\}", v)