Core classes¶
- class pydimple.Graph(*args, **kwargs)¶
Bases:
objectComputational graph. Consists of a set of Operators, Constants, and Distributions.
- Parameters:
num_folds (int) – Number of folds to use in cross-fitting. Defaults to 5.
simplify (bool) – A boolean indicating whether to use sympy to try to symbolically evaluate when a random variable is known to be zero based on the conditioning set. Defaults to True.
- class pydimple.Distribution(data, name=None, dtype=<class 'float'>)¶
Bases:
NodeA data-generating distribution node in the computational graph. This holds estimates of any needed features of the distribution (conditional means, densities, etc.).
- Parameters:
data (pd.DataFrame) – A DataFrame consisting of iid draws from the distribution.
name (str, optional) – Name of the distribution. Defaults to “Dist/”+count.
dtype (type, optional) – The type that the node holds, float, int, etc. Defaults to float.
- class pydimple.Constant(value, name=None)¶
Bases:
NodeRepresents a constant value in the computational graph.
- Parameters:
value (Any) – The value to assign to the constant. This value is immutable once set.
name (str, optional) – An optional name for the constant. If not provided, a unique name is generated.
- Returns:
A new instance of Constant with the specified value and name.
- Return type:
- Raises:
ValueError – When attempting to modify the value of the constant after it is set.
- class pydimple.Operator(*args, name='Operator')¶
Bases:
NodeAn operator node in the computational graph.
- Parameters:
args (Node) – The input nodes to the operator.
name (str, optional) – The name of the operator. Defaults to “Operator”.
- class pydimple.PointwiseFunction(func, unknown_vars=True, var_names=None, zero_if=None)¶
Bases:
objectRepresents a function that applies a mathematical operation pointwise.
- Parameters:
func (callable) – A function.
unknown_vars (bool) – A boolean indicating whether the variables the function relies on are known. If this is true, then the var_names argument is ignored.
var_names (set or list) – A set or list of strings indicating the names of the variables the function relies on. Only used if unknown_vars is False. If a list is passed, it is converted to a set.
zero_if (str or sympy.Expr, optional) – Condition under which the function is a priori known to evaluate to zero.
- Example:
>>> f = PointwiseFunction(lambda x: x ** 2, unknown_vars=False, var_names=["x"])
- class pydimple.L2(func, P, unknown_vars=True, var_names=None, zero_if=None)¶
Bases:
PointwiseFunctionRepresents an L2 function, which is a subclass of PointwiseFunction with an associated Distribution object to represent the L2 space.
- Parameters:
func (callable or PointwiseFunction) – A function or PointwiseFunction.
P (Distribution) – A Distribution object representing the L2 space.
unknown_vars (bool, optional) – A boolean indicating whether the variables the function relies on are known. If this is true, then the var_names argument is ignored. If func is a PointwiseFunction or L2, their unknown_vars values are used instead.
var_names (set or list, optional) – A set or list of strings indicating the names of the variables the function relies on. Only used if unknown_vars is False. If a list is passed, it is converted to a set. If func is a PointwiseFunction or L2, their var_names values are used instead.
zero_if (str or sympy.Expr, optional) – Condition under which the function is a priori known to evaluate to zero.
If func is already of type L2, the resulting L2 object will inherit its func and P attributes. The value of P can be updated by providing a new value in the P argument of the constructor, overriding the previous value.
- Example:
>>> f = L2(lambda x: x ** 2, P=P) # P is an existing Distribution object >>> g = L2(f, P=Q) # g inherits the func and var_names from f, but updates the value of P to an existing Distribution object Q