Quantum Fog  0.9.3
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
potentials.Potential.Potential Class Reference
Inheritance diagram for potentials.Potential.Potential:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, is_quantum, ord_nodes, pot_arr=None, bias=1)
 
def set_pot_arr_to (self, val)
 
def set_pot_arr_to_one (self)
 
def mask_self (self)
 
def get_new_marginal (self, fin_node_list)
 
def get_axes (self, node_list)
 
def get_slicex_ax (self, indices, axes)
 
def get_slicex_nd (self, indices, node_list)
 
def set_to_transpose (self, node_list)
 
def conj (self)
 
def __getitem__ (self, slicex)
 
def __setitem__ (self, slicex, value)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __add__ (self, right)
 
def __iadd__ (self, right)
 
def __sub__ (self, right)
 
def __isub__ (self, right)
 
def __mul__ (self, right)
 
def __imul__ (self, right)
 
def __truediv__ (self, right)
 
def __itruediv__ (self, right)
 
def __deepcopy__ (self, memo)
 
def __str__ (self)
 

Static Public Member Functions

def mag (pot)
 
def distance (pot1, pot2)
 

Public Attributes

 is_quantum
 
 ord_nodes
 
 nodes
 
 num_nodes
 
 nd_sizes
 
 pot_arr
 

Private Member Functions

def __binary_op (self, right, magic, imagic)
 
def __inplace_binary_op (self, right, imagic)
 

Static Private Member Functions

def __safe_truediv (xx, yy)
 
def __safe_itruediv (xx, yy)
 

Detailed Description

Potentials are basically just functions of several nodes = random
variables. A pot contains both a list of ordered nodes ('ord_nodes') and
a numpy array ('pot_arr'). When we permute the ord_nodes of the pot,
we also apply the corresponding numpy transposition to its pot_arr.

A DiscreteUniPot is a DiscreteCondPot is a Potential.

For is_quantum=False (resp., True), pot_arr is a numpy array of dtype
float64 (resp., complex128)

potential[index] yields pot_arr[index]

The Potential class is where most of the magical numpy functionality of
QuantumFog resides.

IMP. when labeling sets of nodes, we will call them just 'nodes' or
'subnodes' if they are a set and order doesn't matter. We will call them
'ord_nodes' or 'node_list' if they are in a list and order does matter.
This is especially important in the Potential class were we will use
both a 'nodes' and 'ord_nodes'.


Attributes
----------
is_quantum : bool
nd_sizes : list[int]
nodes : set[BayesNode]
num_nodes : int
ord_nodes : list[BayesNode]
pot_arr : numpy.ndarray

Constructor & Destructor Documentation

def potentials.Potential.Potential.__init__ (   self,
  is_quantum,
  ord_nodes,
  pot_arr = None,
  bias = 1 
)
Constructor

Parameters
----------
is_quantum : bool
ord_nodes : list[BayesNode]
pot_arr : numpy.ndarray
    potential's array
bias : complex

Returns
-------

Member Function Documentation

def potentials.Potential.Potential.__add__ (   self,
  right 
)
Pointwise addition (+) of elements in self and right. self and right
can be defined over different, perhaps overlapping node sets.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__binary_op (   self,
  right,
  magic,
  imagic 
)
private
This private method will be used to override binary operators
__add__, __sub__, __mult__ and __truediv__ for pots. A re-alignment
of the pot axes is required before applying the binary operator to
two numpy pot_arr's.

Parameters
----------
right : Potential
magic : wrapper_descriptor
    This is going to be either
    np.ndarray.[__add__, __sub__, __mul__],
    Potential.__safe_truediv
imagic : wrapper_descriptor
    This is going to be either
    np.ndarray.[__iadd__, __isub__, __imul__],
    Potential.__safe_itruediv]

Returns
-------
Potential
def potentials.Potential.Potential.__deepcopy__ (   self,
  memo 
)
We want deepcopy to produce a copy of pot_arr but not of the nodes
in self.nodes so need to override the usual deepcopy.

Parameters
----------
memo :

Returns
-------
Potential
def potentials.Potential.Potential.__eq__ (   self,
  other 
)
Overrides ==. This defines what it means for two pots to be equal.
The 2 pots don't have to have the same pot_arr. As long as one can
be converted to the other using set_to_transpose(), they are
considered equal.

Parameters
----------
other : Potential

Returns
-------
bool
def potentials.Potential.Potential.__getitem__ (   self,
  slicex 
)
Overrides the [] getter. This allows us to use a slicex as
an index of a Potential object.

Parameters
----------
slicex : tuple

Returns
-------
float | complex
def potentials.Potential.Potential.__iadd__ (   self,
  right 
)
Pointwise in place addition (+=) of elements in self and right. self
node set must contain right node set.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__imul__ (   self,
  right 
)
Pointwise in place multiplication (*=) of elements in self and
right. self node set must contain right node set.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__inplace_binary_op (   self,
  right,
  imagic 
)
private
This private method will be used to override the in place binary
operators __iadd__, __isub__, __imult__ and __itruediv__ for pots. A
re-alignment of the pot axes is required before applying the binary
operator to two numpy pot_arr's.

Parameters
----------
right : Potential
imagic : wrapper_descriptor
    This is going to be either
    np.ndarray.[__iadd__, __isub__, __imult__],
    Potential.__safe_itruediv

Returns
-------
Potential
def potentials.Potential.Potential.__isub__ (   self,
  right 
)
Pointwise in place subtraction (-=) of elements in self and right.
self node set must contain right node set.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__itruediv__ (   self,
  right 
)
Pointwise in place division (/=) of elements in self and
right. self node set must contain right node set.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__mul__ (   self,
  right 
)
Pointwise multiplication (*) of elements in self and right. self and
right can be defined over different, perhaps overlapping node sets.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__ne__ (   self,
  other 
)
Overrides !=

Parameters
----------
other : Potential

Returns
-------
bool
def potentials.Potential.Potential.__safe_itruediv (   xx,
  yy 
)
staticprivate
Used instead of __itruediv__ for pots. Needed when dividing
pointwise two pot_arr's yields either inf or nan.

Parameters
----------
xx : numpy.ndarray
yy : numpy.ndarray

Returns
-------
numpy.ndarray
def potentials.Potential.Potential.__safe_truediv (   xx,
  yy 
)
staticprivate
Used instead of __truediv__ for pots. Needed when dividing pointwise
two pot_arr's yields either inf or nan.

Parameters
----------
xx : numpy.ndarray
yy : numpy.ndarray

Returns
-------
numpy.ndarray
def potentials.Potential.Potential.__setitem__ (   self,
  slicex,
  value 
)
Overrides the [] setter. This allows us to use a slicex as
an index of a Potential object.


Parameters
----------
slicex : tuple
value : float | complex

Returns
-------
None
def potentials.Potential.Potential.__str__ (   self)
What string is outputted by print(pot) where pot is an object of
Potential

Returns
-------
str
def potentials.Potential.Potential.__sub__ (   self,
  right 
)
Pointwise subtraction (-) of elements in self and right. self and
right can be defined over different, perhaps overlapping node sets.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.__truediv__ (   self,
  right 
)
Pointwise division (/) of elements in self and right. self and
right can be defined over different, perhaps overlapping node sets.

Parameters
----------
right : Potential

Returns
-------
Potential
def potentials.Potential.Potential.conj (   self)
Returns new Potential whose pot_arr is the complex conjugate of
self.pot_arr

Returns
-------
Potential
def potentials.Potential.Potential.distance (   pot1,
  pot2 
)
static
Returns the mag of (pot1 - pot2).

Parameters
----------
pot1 : Potential
pot2 : Potential

Returns
-------
float
def potentials.Potential.Potential.get_axes (   self,
  node_list 
)
Generates a list of axes that correspond to node_list.

Parameters
----------
node_list : list[BayesNode]

Returns
-------
list[int]
def potentials.Potential.Potential.get_new_marginal (   self,
  fin_node_list 
)
Returns a new potential (marginal) obtained by summing self.pot_arr
over states of all nodes except those in fin_node_list. fin=final.
Note this does not modify pot_arr.

Parameters
----------
fin_node_list : list[BayesNode]

Returns
-------
Potential
def potentials.Potential.Potential.get_slicex_ax (   self,
  indices,
  axes 
)
slicex is a portmanteau that stands for slice index. This function
works hand in hand with __getitem__ and __setitem__ which override
getting and setting via [ ]. It takes in a list of indices and a
list of axes both of the same length and order. It generates a
slicex by padding the list 'indices' with extra slice(None) indices.

Parameters
----------
indices : list[int]
axes : list[int]

Returns
-------
tuple
def potentials.Potential.Potential.get_slicex_nd (   self,
  indices,
  node_list 
)
The _nd version of this function has node_list as argument, the _ax
version has axes instead, but they return the same thing.

Parameters
----------
indices : list[int]
node_list : list[BayesNode]

Returns
-------
tuple
def potentials.Potential.Potential.mag (   pot)
static
mag= magnitude. Returns the norm of self.pot_arr, where by norm we
mean the usual norm used in Quantum Mechanics, called either
Frobenius or 2-norm, \sqrt(\sum_index  abs(pot_arr[index])^2)

Parameters
----------
pot : Potential

Returns
-------
float
def potentials.Potential.Potential.mask_self (   self)
Multiply pot_arr entries times zero for those entries that are
forbidden by the active states constraint of the ord_nodes.

Returns
-------
None
def potentials.Potential.Potential.set_pot_arr_to (   self,
  val 
)
Sets all entries of pot_arr to val.

Parameters
----------
val : float | complex

Returns
-------
None
def potentials.Potential.Potential.set_pot_arr_to_one (   self)
Sets all entries of pot_arr to one.

Returns
-------
None
def potentials.Potential.Potential.set_to_transpose (   self,
  node_list 
)
node_list should be a permutation of self.ord_nodes. Like in numpy,
we will words "permutation" and "transpose" interchangeably. This
function replaces ord_nodes by node_list and applies corresponding
numpy transposition to pot_arr.


Parameters
----------
node_list : list[BayesNode]

Returns
-------
None

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