I’m trying to do the same thing. So we are kind of business competitors :).
I will put up my work in github very soon.
I’m a beginner so take my advice with a grain of salt, but Let me make some points:
(1) What I have done is to write a script that reads a .bif file and writes a file containing the corresponding Edward model. For that, I use tools from my own B net application Quantum Fog. Maybe you should do something similar, but using your preferred application Bayes Server.
For example, for the network (all arrows pointing down)
Cloudy
/ \
Sprinkler Rain
\ /
WetGrass
my script reads the bif fiile and writes the following model:
import numpy as np
import tensorflow as tf
import edward as ed
import edward.models as edm
# node names in lexicographic (alphabetic) order
nd_names_lex_ord = ['Cloudy', 'Rain', 'Sprinkler', 'WetGrass']
# node names in topological (chronological) order
nd_names_topo_ord = ['Cloudy', 'Sprinkler', 'Rain', 'WetGrass']
with tf.name_scope('model'):
p_Cloudy = np.array([ 0.5, 0.5])
Cloudy = edm.Categorical(
probs=p_Cloudy, name='Cloudy')
arr_Sprinkler = np.array([[ 0.2, 0.8],
[ 0.7, 0.3]])
p_Sprinkler = tf.convert_to_tensor(arr_Sprinkler, dtype=tf.float32)[
Cloudy, :]
Sprinkler = edm.Categorical(
probs=p_Sprinkler, name='Sprinkler')
arr_Rain = np.array([[ 0.4, 0.6],
[ 0.5, 0.5]])
p_Rain = tf.convert_to_tensor(arr_Rain, dtype=tf.float32)[
Cloudy, :]
Rain = edm.Categorical(
probs=p_Rain, name='Rain')
arr_WetGrass = np.array([[[ 0.99, 0.01],
[ 0.01, 0.99]],
[[ 0.01, 0.99],
[ 0.01, 0.99]]])
p_WetGrass = tf.convert_to_tensor(arr_WetGrass, dtype=tf.float32)[
Sprinkler, Rain, :]
WetGrass = edm.Categorical(
probs=p_WetGrass, name='WetGrass')
with tf.name_scope('posterior'):
Cloudy_q = edm.Categorical(
probs=tf.nn.softmax(tf.get_variable('Cloudy_q/probs', shape=[2])),
name='Cloudy_q')
Sprinkler_q = edm.Categorical(
probs=tf.nn.softmax(tf.get_variable('Sprinkler_q/probs', shape=[2])),
name='Sprinkler_q')
Rain_q = edm.Categorical(
probs=tf.nn.softmax(tf.get_variable('Rain_q/probs', shape=[2])),
name='Rain_q')
WetGrass_q = edm.Categorical(
probs=tf.nn.softmax(tf.get_variable('WetGrass_q/probs', shape=[2])),
name='WetGrass_q')
I define a query (_q) variable for all the nodes but of course, I will only use the query variables for latent nodes. The script also has an option to define the root nodes as placeholders or as Categoricals. In this example, I defined them all as Categoricals
(2) I see from github that you are interested in QISKit in Chinese.
We seem to be on the same page there. I am very interested in using Edward for doing quantum computing. I’m not Chinese, but if you are, the CTO Dr. Tao Yin of my company (artiste-qb.net) is Chinese and lives in ShenZhen