def get_sample(ordering, evidence={}):
    '''
    Given a valid ordering, sample the network.
    '''
    sample = []
    sample_dict = dict()
    for var, func in ordering:
        r = random.random()
        total = 0
        for val in var.domain:
            test_var = VariableNode(var.name)
            test_var.value = val
            # Now we need to build the
            # argument list out of any
            # variables already in the sample
            # and this new test value in
            # the order required by the function.
            args = []
            for arg in get_args(func):
                if arg == var.name:
                    #args.append(test_var)
                    args.append(val)
                else:
                    args.append(sample_dict[arg].value)

            total += func(*args)
            if r > total:
                # We only want to use this sample
                # if it corresponds to the evidence value...
                if var.name in evidence:
                    if test_var.value == evidence[var.name]:
                        sample.append(test_var)
                        sample_dict[var.name] = test_var
                else:
                    sample.append(test_var)
                    sample_dict[var.name] = test_var
                break
        if not var.name in sample_dict:
            print 'Iterated through all values for %s and %s but no go...' \
                % (var.name, func.__name__)
            # This seems to mean that we have never seen this combination
            # of variables before, we can either discard it as irrelevant or
            # use some type of +1 smoothing???
            # What if we just randomly select some value for var????
            # lets try that as it seems the easiest....
            raise InvalidSampleException
    return sample
dataset/ETHPy150Open eBay/bayesian-belief-networks/bayesian/factor_graph.py/get_sample/swapped operands of `>`