text stringlengths 81 112k |
|---|
Normalizes the values of factor so that they sum to 1.
Parameters
----------
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor
Returns
-------
DiscreteFactor or None: if inplace=True (default) retur... |
Reduces the factor to the context of given variable values.
Parameters
----------
values: list, array-like
A list of tuples of the form (variable_name, variable_state).
inplace: boolean
If inplace=True it will modify the factor itself, else would return
... |
DiscreteFactor sum with `phi1`.
Parameters
----------
phi1: `DiscreteFactor` instance.
DiscreteFactor to be added.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor.
Returns
-------
... |
DiscreteFactor division by `phi1`.
Parameters
----------
phi1 : `DiscreteFactor` instance
The denominator for division.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor.
Returns
------... |
Returns a copy of the factor.
Returns
-------
DiscreteFactor: copy of the factor
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> phi = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 3], np.arange(18))
... |
Generate the string from `__str__` method.
Parameters
----------
phi_or_p: 'phi' | 'p'
'phi': When used for Factors.
'p': When used for CPDs.
print_state_names: boolean
If True, the user defined state names are displayed.
def _str(self,... |
Checks whether given parameter is a 1d array like object, and returns a numpy array object
def _check_1d_array_object(parameter, name_param):
"""
Checks whether given parameter is a 1d array like object, and returns a numpy array object
"""
if isinstance(parameter, (np.ndarray, list, tuple, np.matrix))... |
Raises an error when the length of given two arguments is not equal
def _check_length_equal(param_1, param_2, name_param_1, name_param_2):
"""
Raises an error when the length of given two arguments is not equal
"""
if len(param_1) != len(param_2):
raise ValueError("Length of {} must be same as ... |
Returns list of variables of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_variables()
['light-on', 'bowel-problem', 'dog-out', 'hear-bark', 'family-out']
def get_variables(self):
"""
Returns list of variables o... |
Returns the edges of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_edges()
[['family-out', 'light-on'],
['family-out', 'dog-out'],
['bowel-problem', 'dog-out'],
['dog-out', 'hear-bark']]
def get_edges... |
Returns the states of variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_states()
{'bowel-problem': ['true', 'false'],
'dog-out': ['true', 'false'],
'family-out': ['true', 'false'],
'he... |
Returns the parents of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_parents()
{'bowel-problem': [],
'dog-out': ['family-out', 'bowel-problem'],
'family-out': [],
'hear-bark': ... |
Returns the CPD of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_values()
{'bowel-problem': array([[ 0.01],
[ 0.99]]),
'dog-out': array([[ 0.99, 0.01, 0.97, 0... |
Returns the property of the variable
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_property()
{'bowel-problem': ['position = (190, 69)'],
'dog-out': ['position = (155, 165)'],
'family-out': ['position = (112, 69)'],
... |
Add variables to XMLBIF
Return
------
dict: dict of type {variable: variable tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_variables()
{'bowel-problem': <Element VARIABLE at 0x7fe28607dd88>,
'family-out': <Element VARIA... |
Add outcome to variables of XMLBIF
Return
------
dict: dict of type {variable: outcome tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_states()
{'dog-out': [<Element OUTCOME at 0x7ffbabfcdec8>, <Element OUTCOME at 0x7ffbabfcdf08>]... |
Transform the input state_name into a valid state in XMLBIF.
XMLBIF states must start with a letter an only contain letters,
numbers and underscores.
def _make_valid_state_name(self, state_name):
"""Transform the input state_name into a valid state in XMLBIF.
XMLBIF states must start wi... |
Add property to variables in XMLBIF
Return
------
dict: dict of type {variable: property tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_property()
{'light-on': <Element PROPERTY at 0x7f7a2ffac1c8>,
'family-out': <Element ... |
Add Definition to XMLBIF
Return
------
dict: dict of type {variable: definition tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_definition()
{'hear-bark': <Element DEFINITION at 0x7f1d48977408>,
'family-out': <Element DEFI... |
Add Table to XMLBIF.
Return
---------------
dict: dict of type {variable: table tag}
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.get_values()
{'dog-out': <Element TABLE at 0x7f240726f3c8>,
'light-on': <Element TABLE at 0x7f24072... |
Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.write_xmlbif(test_file)
def write_xmlbif(self, filename):
"""
Write the xml data into the file.
... |
Returns the marginal distribution over variables.
Parameters
----------
variables: string, list, tuple, set, dict
Variable or list of variables over which marginal distribution needs
to be calculated
inplace: Boolean (default True)
If Fals... |
Check if the Joint Probability Distribution satisfies the given independence condition.
Parameters
----------
event1: list
random variable whose independence is to be checked.
event2: list
random variable from which event1 is independent.
values: 2D array... |
Returns the independent variables in the joint probability distribution.
Returns marginally independent variables if condition=None.
Returns conditionally independent variables if condition!=None
Parameter
---------
condition: array_like
Random Variable on which ... |
Returns Conditional Probability Distribution after setting values to 1.
Parameters
----------
values: list or array_like
A list of tuples of the form (variable_name, variable_state).
The values on which to condition the Joint Probability Distribution.
inplace: Bo... |
Returns a Bayesian Model which is minimal IMap of the Joint Probability Distribution
considering the order of the variables.
Parameters
----------
order: array-like
The order of the random variables.
Examples
--------
>>> import numpy as np
>... |
Checks whether the given BayesianModel is Imap of JointProbabilityDistribution
Parameters
-----------
model : An instance of BayesianModel Class, for which you want to
check the Imap
Returns
--------
boolean : True if given bayesian model is Imap for Joint P... |
Returns the acceptance probability for given new position(position) and momentum
def _acceptance_prob(self, position, position_bar, momentum, momentum_bar):
"""
Returns the acceptance probability for given new position(position) and momentum
"""
# Parameters to help in evaluating Joint... |
Temporary method to fix issue in numpy 0.12 #852
def _get_condition(self, acceptance_prob, a):
"""
Temporary method to fix issue in numpy 0.12 #852
"""
if a == 1:
return (acceptance_prob ** a) > (1/(2**a))
else:
return (1/(acceptance_prob ** a)) > (2**(-a... |
Method for choosing initial value of stepsize
References
-----------
Matthew D. Hoffman, Andrew Gelman, The No-U-Turn Sampler: Adaptively
Setting Path Lengths in Hamiltonian Monte Carlo. Journal of
Machine Learning Research 15 (2014) 1351-1381
Algorithm 4 : Heuristic for... |
Runs a single sampling iteration to return a sample
def _sample(self, position, trajectory_length, stepsize, lsteps=None):
"""
Runs a single sampling iteration to return a sample
"""
# Resampling momentum
momentum = np.reshape(np.random.normal(0, 1, len(position)), position.shap... |
Method to return samples using Hamiltonian Monte Carlo
Parameters
----------
initial_pos: A 1d array like object
Vector representing values of parameter position, the starting
state in markov chain.
num_samples: int
Number of samples to be generated
... |
Method returns a generator type object whose each iteration yields a sample
using Hamiltonian Monte Carlo
Parameters
----------
initial_pos: A 1d array like object
Vector representing values of parameter position, the starting
state in markov chain.
num_... |
Run tha adaptation for stepsize for better proposals of position
def _adapt_params(self, stepsize, stepsize_bar, h_bar, mu, index_i, alpha, n_alpha=1):
"""
Run tha adaptation for stepsize for better proposals of position
"""
gamma = 0.05 # free parameter that controls the amount of shr... |
Method returns a generator type object whose each iteration yields a sample
using Hamiltonian Monte Carlo
Parameters
----------
initial_pos: A 1d array like object
Vector representing values of parameter position, the starting
state in markov chain.
num_... |
A list of states example -
[('x1', 'easy'), ('x2', 'hard')]
Returns
-------
True, if arg is a list of states else False.
def is_list_of_states(self, arg):
"""
A list of states example -
[('x1', 'easy'), ('x2', 'hard')]
Returns
-------
Tr... |
A list of list of states example -
[[('x1', 'easy'), ('x2', 'hard')], [('x1', 'hard'), ('x2', 'medium')]]
Returns
-------
True, if arg is a list of list of states else False.
def is_list_of_list_of_states(self, arg):
"""
A list of list of states example -
[[('x1... |
Add an edge between u and v.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can be any hashable Python object.
weight: int, float (default=None)
The weight of the edge... |
Check if the given nodes form a clique.
Parameters
----------
nodes: list, array-like
List of nodes to check if they are a part of any clique.
Examples
--------
>>> from pgmpy.base import UndirectedGraph
>>> G = UndirectedGraph(ebunch=[('A', 'B'), ('... |
Set the start state of the Markov Chain. If the start_state is given as a array-like iterable, its contents
are reordered in the internal representation.
Parameters:
-----------
start_state: dict or array-like iterable object
Dict (or list) of tuples representing the startin... |
Checks if a list representing the state of the variables is valid.
def _check_state(self, state):
"""
Checks if a list representing the state of the variables is valid.
"""
if not hasattr(state, '__iter__') or isinstance(state, six.string_types):
raise ValueError('Start stat... |
Add a variable to the model.
Parameters:
-----------
variable: any hashable python object
card: int
Representing the cardinality of the variable to be added.
Examples:
---------
>>> from pgmpy.models import MarkovChain as MC
>>> model = MC()... |
Add several variables to the model at once.
Parameters:
-----------
variables: array-like iterable object
List of variables to be added.
cards: array-like iterable object
List of cardinalities of the variables to be added.
Examples:
---------
... |
Adds a transition model for a particular variable.
Parameters:
-----------
variable: any hashable python object
must be an existing variable of the model.
transition_model: dict or 2d array
dict representing valid transition probabilities defined for every possib... |
Sample from the Markov Chain.
Parameters:
-----------
start_state: dict or array-like iterable
Representing the starting states of the variables. If None is passed, a random start_state is chosen.
size: int
Number of samples to be generated.
Return Type:... |
Given an instantiation (partial or complete) of the variables of the model,
compute the probability of observing it over multiple windows in a given sample.
If 'sample' is not passed as an argument, generate the statistic by sampling from the
Markov Chain, starting with a random initial state.
... |
Generator version of self.sample
Return Type:
------------
List of State namedtuples, representing the assignment to all variables of the model.
Examples:
---------
>>> from pgmpy.models.MarkovChain import MarkovChain
>>> from pgmpy.factors.discrete import State... |
Checks if the given markov chain is stationary and checks the steady state
probablity values for the state are consistent.
Parameters:
-----------
tolerance: float
represents the diff between actual steady state value and the computed value
sample: [State(i,j)]
... |
Generates a random state of the Markov Chain.
Return Type:
------------
List of namedtuples, representing a random assignment to all variables of the model.
Examples:
---------
>>> from pgmpy.models import MarkovChain as MC
>>> model = MC(['intel', 'diff'], [2, ... |
Returns a copy of Markov Chain Model.
Return Type:
------------
MarkovChain : Copy of MarkovChain.
Examples:
---------
>>> from pgmpy.models import MarkovChain
>>> from pgmpy.factors.discrete import State
>>> model = MarkovChain()
>>> model.add_v... |
Returns `True` if `assertion` is contained in this `Independencies`-object,
otherwise `False`.
Parameters
----------
assertion: IndependenceAssertion()-object
Examples
--------
>>> from pgmpy.independencies import Independencies, IndependenceAssertion
>>... |
Adds assertions to independencies.
Parameters
----------
assertions: Lists or Tuples
Each assertion is a list or tuple of variable, independent_of and given.
Examples
--------
>>> from pgmpy.independencies import Independencies
>>> independencies... |
Returns a new `Independencies()`-object that additionally contains those `IndependenceAssertions`
that are implied by the the current independencies (using with the `semi-graphoid axioms
<https://en.wikipedia.org/w/index.php?title=Conditional_independence&oldid=708760689#Rules_of_conditional_independenc... |
Returns `True` if the `entailed_independencies` are implied by this `Independencies`-object, otherwise `False`.
Entailment is checked using the semi-graphoid axioms.
Might be very slow if more than six variables are involved.
Parameters
----------
entailed_independencies: Indep... |
Add an edge between u and v.
The nodes u and v will be automatically added if they are
not already in the graph
Parameters
----------
u,v : nodes
Nodes can be any hashable python object.
Examples
--------
>>> from pgmpy.models import Naive... |
Returns a list of all ancestors of all the observed nodes.
Parameters
----------
obs_nodes_list: string, list-type
name of all the observed nodes
def _get_ancestors_of(self, obs_nodes_list):
"""
Returns a list of all ancestors of all the observed nodes.
Par... |
Returns all the nodes reachable from start via an active trail.
Parameters
----------
start: Graph node
observed : List of nodes (optional)
If given the active trail would be computed assuming these nodes to be observed.
Examples
--------
>>> from p... |
Returns an instance of Independencies containing the local independencies
of each of the variables.
Parameters
----------
variables: str or array like
variables whose local independencies are to found.
Examples
--------
>>> from pgmpy.models import ... |
Computes the CPD for each node from a given data in the form of a pandas dataframe.
If a variable from the data is not present in the model, it adds that node into the model.
Parameters
----------
data : pandas DataFrame object
A DataFrame object with column names same as th... |
Computes a score to measure how well the given `BayesianModel` fits to the data set.
(This method relies on the `local_score`-method that is implemented in each subclass.)
Parameters
----------
model: `BayesianModel` instance
The Bayesian network that is to be scored. Nodes ... |
Computes a score that measures how much a \
given variable is \"influenced\" by a given list of potential parents.
def local_score(self, variable, parents):
"Computes a score that measures how much a \
given variable is \"influenced\" by a given list of potential parents."
var_states =... |
Generate a cartesian product of input arrays.
Parameters
----------
arrays : list of array-like
1-D arrays to form the cartesian product of.
out : ndarray
Array to place the cartesian product in.
Returns
-------
out : ndarray
2-D array of shape (M, len(arrays)) cont... |
Generate a sample of given size, given a probability mass function.
Parameters
----------
values: numpy.array: Array of all possible values that the random variable
can take.
weights: numpy.array or list of numpy.array: Array(s) representing the PMF of the random variable.
size: int: Si... |
Generates all subsets of list `l` (as tuples).
Example
-------
>>> from pgmpy.utils.mathext import powerset
>>> list(powerset([1,2,3]))
[(), (1,), (2,), (3,), (1,2), (1,3), (2,3), (1,2,3)]
def powerset(l):
"""
Generates all subsets of list `l` (as tuples).
Example
-------
>>> ... |
Remove draft pages from space using datetime.now
:param confluence:
:param space_key:
:param count:
:param date_now:
:return: int counter
def clean_draft_pages_from_space(confluence, space_key, count, date_now):
"""
Remove draft pages from space using datetime.now
:param confluence:
... |
Remove all draft pages for all spaces older than DRAFT_DAYS
:param days: int
:param confluence:
:return:
def clean_all_draft_pages_from_all_spaces(confluence, days=30):
"""
Remove all draft pages for all spaces older than DRAFT_DAYS
:param days: int
:param confluence:
:return:
"""
... |
Provide content by type (page, blog, comment)
:param page_id: A string containing the id of the type content container.
:param type:
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: how many items should be returned after the... |
Returns the list of labels on a piece of Content.
:param space: Space key
:param title: Title of the page
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by... |
Get page by ID
:param page_id: Content ID
:param expand: OPTIONAL: expand e.g. history
:return:
def get_page_by_id(self, page_id, expand=None):
"""
Get page by ID
:param page_id: Content ID
:param expand: OPTIONAL: expand e.g. history
:return:
"""... |
Returns the list of labels on a piece of Content.
:param page_id: A string containing the id of the labels content container.
:param prefix: OPTIONAL: The prefixes to filter the labels with {@see Label.Prefix}.
Default: None.
:param start: OPTIONAL: The start poin... |
Provide content by id with status = draft
:param page_id:
:param status:
:return:
def get_draft_page_by_id(self, page_id, status='draft'):
"""
Provide content by id with status = draft
:param page_id:
:param status:
:return:
"""
url = 'res... |
Get all page by label
:param label:
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
fixed system limits. Default: 50
:return:
def g... |
Get all pages from space
:param space:
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
fixed system limits. Default: 50
:param... |
Get list of pages from trash
:param space:
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
fixed system limits. Default: 500
:... |
Get list of draft pages from space
Use case is cleanup old drafts from Confluence
:param space:
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
... |
Search list of draft pages by space key
Use case is cleanup old drafts from Confluence
:param space: Space Key
:param status: Can be changed
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of ... |
This method removes a page, if it has recursive flag, method removes including child pages
:param page_id:
:param status: OPTIONAL: type of page
:param recursive: OPTIONAL: if True - will recursively delete all children pages too
:return:
def remove_page(self, page_id, status=None, recu... |
Create page from scratch
:param space:
:param title:
:param body:
:param parent_id:
:param type:
:return:
def create_page(self, space, title, body, parent_id=None, type='page'):
"""
Create page from scratch
:param space:
:param title:
... |
Get all spaces with provided limit
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
fixed system limits. Default: 500
def get_all_spaces(self,... |
Add comment into page
:param page_id
:param text
def add_comment(self, page_id, text):
"""
Add comment into page
:param page_id
:param text
"""
data = {'type': 'comment',
'container': {'id': page_id, 'type': 'page', 'status': 'current'},
... |
Attach (upload) a file to a page, if it exists it will update the
automatically version the new file and keep the old one.
:param title: The page name
:type title: ``str``
:param space: The space name
:type space: ``str``
:param page_id: The page id to which we would li... |
Set a label on the page
:param page_id: content_id format
:param label: label to add
:return:
def set_page_label(self, page_id, label):
"""
Set a label on the page
:param page_id: content_id format
:param label: label to add
:return:
"""
u... |
Remove content history. It works as experimental method
:param page_id:
:param version_number: version number
:return:
def remove_content_history(self, page_id, version_number):
"""
Remove content history. It works as experimental method
:param page_id:
:param ve... |
Remove content history. It works in CLOUD
:param page_id:
:param version_id:
:return:
def remove_content_history_in_cloud(self, page_id, version_id):
"""
Remove content history. It works in CLOUD
:param page_id:
:param version_id:
:return:
"""
... |
Check has unknown attachment error on page
:param page_id:
:return:
def has_unknown_attachment_error(self, page_id):
"""
Check has unknown attachment error on page
:param page_id:
:return:
"""
unknown_attachment_identifier = 'plugins/servlet/confluence/pl... |
Compare content and check is already updated or not
:param page_id: Content ID for retrieve storage value
:param body: Body for compare it
:return: True if the same
def is_page_content_is_already_updated(self, page_id, body):
"""
Compare content and check is already updated or n... |
Update page if already exist
:param parent_id:
:param page_id:
:param title:
:param body:
:param type:
:param minor_edit: Indicates whether to notify watchers about changes.
If False then notifications will be sent.
:return:
def update_page(self, pare... |
Update page or create a page if it is not exists
:param parent_id:
:param title:
:param body:
:return:
def update_or_create(self, parent_id, title, body):
"""
Update page or create a page if it is not exists
:param parent_id:
:param title:
:param ... |
Set the page (content) property e.g. add hash parameters
:param page_id: content_id format
:param data: data should be as json data
:return:
def set_page_property(self, page_id, data):
"""
Set the page (content) property e.g. add hash parameters
:param page_id: content_i... |
Delete the page (content) property e.g. delete key of hash
:param page_id: content_id format
:param page_property: key of property
:return:
def delete_page_property(self, page_id, page_property):
"""
Delete the page (content) property e.g. delete key of hash
:param page_... |
Get the page (content) property e.g. get key of hash
:param page_id: content_id format
:param page_property_key: key of property
:return:
def get_page_property(self, page_id, page_property_key):
"""
Get the page (content) property e.g. get key of hash
:param page_id: con... |
Get the page (content) properties
:param page_id: content_id format
:return: get properties
def get_page_properties(self, page_id):
"""
Get the page (content) properties
:param page_id: content_id format
:return: get properties
"""
url = 'rest/api/content... |
Provide the ancestors from the page (content) id
:param page_id: content_id format
:return: get properties
def get_page_ancestors(self, page_id):
"""
Provide the ancestors from the page (content) id
:param page_id: content_id format
:return: get properties
"""
... |
Clean caches from cache management
e.g.
com.gliffy.cache.gon
org.hibernate.cache.internal.StandardQueryCache_v5
def clean_package_cache(self, cache_name='com.gliffy.cache.gon'):
""" Clean caches from cache management
e.g.
com.gliffy.cache.gon
... |
Get all groups from Confluence User management
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of groups to return, this may be restricted by
fixed system limits. Default: 1000
... |
Get a paginated collection of users in the given group
:param group_name
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
:param limit: OPTIONAL: The limit of the number of users to return, this may be restricted by
fixed system ... |
Get information about a space through space key
:param space_key: The unique space key name
:param expand: OPTIONAL: additional info from description, homepage
:return: Returns the space along with its ID
def get_space(self, space_key, expand='description.plain,homepage'):
"""
G... |
Get information about a user through username
:param username: The user name
:param expand: OPTIONAL expand for get status of user.
Possible param is "status". Results are "Active, Deactivated"
:return: Returns the user details
def get_user_details_by_username(self, username, ex... |
Get information about a user through user key
:param userkey: The user key
:param expand: OPTIONAL expand for get status of user.
Possible param is "status". Results are "Active, Deactivated"
:return: Returns the user details
def get_user_details_by_userkey(self, userkey, expand... |
Get results from cql search result with all related fields
Search for entities in Confluence using the Confluence Query Language (CQL)
:param cql:
:param start: OPTIONAL: The start point of the collection to return. Default: 0.
:param limit: OPTIONAL: The limit of the number of issues to... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.