Direct sampling

With direct sampling, our goal is to approximate the full joint probability through a sequence of samples drawn from each conditional distribution. If we assume that the graph is well-structured (without unnecessary edges) and we have N variables, the algorithm is made up of the following steps:

  1. Initialize the variable NSamples.
  2. Initialize a vector S with shape (N, NSamples).
  3. Initialize a frequency vector FSamples with shape (N, NSamples). In Python, it's better to employ a dictionary where the key is a combination (x1, x2, x3, ..., xN).
  4. For t=1 to NSamples:
    1. For i=1 to N:
      1. Sample from P(Xi|Predecessors(Xi))
      2. Store the sample in S[i, t]
    2. If FSamples contains the sampled tuple S[:, t]:
      1. FSamples[S[:, t]] += 1
    3. Else:
      1. FSamples[S[:, t]] = 1 (both these operations are immediate with Python dictionaries)
  5. Create a vector PSampled with shape (N, 1).
  6. Set PSampled[i, 0] = FSamples[i]/N.

From a mathematical viewpoint, we are first creating a frequency vector FSamples(x1, x2, x3, ..., xNNSamples) and then we approximate the full joint probability considering NSamples → ∞:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.51.145