NetParamsLner (Net Parameters Learner) learns the parameters ( i.e.,
the pots) of a bnet (either a cbnet or qbnet) given the bnet's structure.
The input data from which the parameters are learned consists of one
dataframe states_df in the classical case, and two dataframes states_df
and degs_df in the quantum case. Both dataframes have the same column
labels, one column for each node of the bnet whose pots are being learned.
Each row of degs_df gives an angle Ang in degrees (a float) for the
column node C for that sample. If z = A( C | parents(C) ) is the
amplitude for node C, then z = |z| exp(i Ang*pi/180).
In order to use degs_df, its degree entries (floats) are first binned.
Each bin is then mapped to the mean value of the angles that went into
that bin. No a priori info is used in this class so its approach is
purely frequentist.
In the quantum case, states_df must be measured by an incoherent
measurement of all the nodes, whereas degs_df must be measured
by a coherent measurement of node bunches, one bunch for each node and
its parents.
IMPORTANT: We will use the word 'vtx' = vertex to denote a node name and
the word 'node' to denote a Node object.
Attributes
----------
is_quantum : bool
True for quantum bnets amd False for classical bnets
bnet : BayesNet
a BayesNet in which we store what is learned
states_df : pandas.DataFrame
a Pandas DataFrame with training data. column = node and row =
sample. Each row/sample gives the state of the col/node.
use_int_sts : bool
If False, the states_df has state names as entries. If True,
states_df has int entries. The int entries are the index in the
states_names list of the node for that column.
degs_df : pandas.DataFrame
Only used in the quantum case. None in classical case. A Pandas
DataFrame with training data. column=node and row=sample. Each
row/sample gives an angle Ang in degrees for the column/node.
do_qtls : bool
If True (False, resp.), will use quantiles (equal size bins,
resp) to bin ALL columns of degs_df.
nd_to_num_deg_bins: dict[DirectedNode, int]
node to number of degree bins. Use this to specify how many bins you
want to use for each node when binning degs_df.
def learning.NetParamsLner.NetParamsLner.convert_pot_df_to_pot |
( |
|
is_quantum, |
|
|
|
pot_df, |
|
|
|
ord_nodes, |
|
|
|
s_d_pair, |
|
|
|
use_int_sts = None , |
|
|
|
normalize = True |
|
) |
| |
|
static |
Returns a DiscreteCondPot pot with ordered nodes ord_nodes.
Parameters
----------
is_quantum : bool
pot_df : pandas.DataFrame
a dataframe returned by learn_pot_df(). pot_df must have one
column for each node in ord_nodes plus additioanl final column
with pot values
ord_nodes : list[BayesNode]
ordered nodes of Potential pot that is returned. Nodes must be
ordered so that pot_df[:-1].columns = [nd.name for nd in
ord_nodes]
s_d_pair : tuple[int|str, float]
a pair consisting of a state and a degs. The state is taken
directly from states_df, so it might be a digit or an actual
state name, depending on whether use_int_sts was True or False
when states_df was generated. The state is a state of the focus
node (the last column of states_cols corresponds to the focus
node). The degs is an angle in degrees. For an s_d_pair equal to
(x0,ang), whenever pot(C=x| pa(C)=y) = 0 for all x, we will set
pot(C=x|pa(C)=y) = exp( 1j*ang*pi/180)*delta(x, x0) in the
quantum case and pot( C=x| pa(C)=y) = delta(x, x0) in the
classical case.
use_int_sts : bool
True if states in states_df are integers, False if they are the
actual state names. If the parameter use_int_sts is set to None,
this function will attempt to find its bool value using the
function NetStrucLner:int_sts_detector()
normalize : bool
True if want pot to be normalized as a cond probability
or cond amplitude, P(x|y) or A(x|y), where x is ord_nodes[-1]
Returns
-------
DiscreteCondPot
def learning.NetParamsLner.NetParamsLner.learn_pot_df |
( |
|
is_quantum, |
|
|
|
states_cols, |
|
|
|
degs_col = None , |
|
|
|
num_deg_bins = 2 , |
|
|
|
do_qtls = True |
|
) |
| |
|
static |
Returns a dataframe called pot_df containing one more column (the
last one) than states_cols. That column contains either complex
probability amplitudes A for the quantum case or probabilities |A|^2
for the classical case. The non-last columns of pot_df are a list of
distinct states of the nodes whose names are given by the column
labels of pot_df.
Besides returning a pot_df, this function also returns two
s_d_pair's, max_s_d_pair and min_s_d_pair. An s_d_pair is a tuple of
a state entry from states_df and a degs. The state is a state of the
focus node (the last column of states_cols corresponds to the focus
node). The degs is an angle in degrees. max_s_d_pair (resp.,
min_s_d_pair) is a pair with maximum (resp., minimum) likelihood.
Parameters
----------
is_quantum : bool
True for quantum bnets amd False for classical bnets. In the
classical case, degs_col will be ignored.
states_cols : pandas.DataFrame
usually a dataframe containing a subset of the columns of
self.states_df
degs_col : pandas.DataFrame
usually a dataframe or series containing a single column of
self.degs_df
num_deg_bins : int
how many bins will be used to bin degs_col.
do_qtls : bool
If True, will use quantile bins when binning degs_col. If False,
will use equal length bins.
Returns
-------
pandas.DataFrame, tuple[int|str, float], tuple[int|str, float]