Quantum Fog  0.9.3
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
learning.NetParamsLner.NetParamsLner Class Reference

Public Member Functions

def __init__ (self, is_quantum, bnet, states_df, degs_df=None, nd_to_num_deg_bins=None, do_qtls=True)
 
def learn_pot (self, ord_nodes)
 
def learn_all_bnet_pots (self)
 

Static Public Member Functions

def learn_pot_df (is_quantum, states_cols, degs_col=None, num_deg_bins=2, do_qtls=True)
 
def convert_pot_df_to_pot (is_quantum, pot_df, ord_nodes, s_d_pair, use_int_sts=None, normalize=True)
 
def compare_true_and_emp_pots (bnet, bnet_emp)
 

Public Attributes

 is_quantum
 
 bnet
 
 states_df
 
 use_int_sts
 
 degs_df
 
 nd_to_num_deg_bins
 
 do_qtls
 

Detailed Description

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.

Constructor & Destructor Documentation

def learning.NetParamsLner.NetParamsLner.__init__ (   self,
  is_quantum,
  bnet,
  states_df,
  degs_df = None,
  nd_to_num_deg_bins = None,
  do_qtls = True 
)
Constructor

This constructor assumes that the parameter bnet is a BayesNet
which already contains the correct net structure and the desired
state names for each node.

If bnet does not contain the desired state names for each node,
you will have to do some pre-processing of bnet before you pass it
in to this constructor. The two static methods
NetStrucLner:learn_nd_state_names() and
NetStrucLner:import_nd_state_names() can be used for this purpose.

Parameters
----------
is_quantum : bool
bnet : BayesNet
states_df : pandas.DataFrame
degs_df : pandas.DataFrame
nd_to_num_deg_bins : dict[DirectedNode, int]
do_qtls : bool

Returns
-------

Member Function Documentation

def learning.NetParamsLner.NetParamsLner.compare_true_and_emp_pots (   bnet,
  bnet_emp 
)
static
Prints a comparison of the potentials of true and empirical bnets

Parameters
----------
bnet : BayesNet
    true BayesNet
bnet_emp : BayesNet
    empirical BayesNet

Returns
-------
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_all_bnet_pots (   self)
Learns all the pots of a bnet given its structure and given
empirical data in the form of dataframes states_df and degs_df.

Returns
-------
BayesNet
def learning.NetParamsLner.NetParamsLner.learn_pot (   self,
  ord_nodes 
)
Learns from the data in states_df and degs_df a single Potential
called pot. The nodes in pot are ordered according to the list of
ordered nodes ord_nodes. pot is a DiscreteCondPot and it is
normalized assuming as usual that the last node in ord_nodes,
ord_nodes[-1], is the focus node. In the quantum case, the degs_col
used is given by the column of the focus node in self.degs_df.

Parameters
----------
ord_nodes : list[BayesNode]
    list of ordered nodes used in the potential that is returned

Returns
-------
Potential
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]

The documentation for this class was generated from the following file: