Literal base class used to construct equation trees.
Literals are base pieces of the equation hierarchy. The ‘identify’
method identifies the Literal to a visitor by calling the identifying
method of the vistior.
Operators are combined with other Literals to create an equation.
Operators are non-leaf nodes on a Literal tree. These trees can be
evaluated by the Evaluator visitor, or otherwise inspected.
The Operator class contains all the information necessary to be
identified and evaluated by a Visitor. Thus, a single onOperator method
exists in the Visitor base class. Other Operators can be derived from
Operator (see AdditionOperator), but they all identify themselves with
the Visitor.onOperator method.
This convolves two signals such that centroid of the first array is
not altered by the convolution. Furthermore, the integrated
amplitude of the convolution is scaled to be that of the first
signal. This is mean to act as a convolution of a signal by a
probability distribution.
Note that this is only possible when the signals are computed over
the same range.
This forms part of the old polynomial API. Since version 1.4, the
new polynomial API defined in numpy.polynomial is preferred.
A summary of the differences can be found in the
transition guide.
If p is of length N, this function returns the value:
p[0]*x**(N-1)+p[1]*x**(N-2)+...+p[N-2]*x+p[N-1]
If x is a sequence, then p(x) is returned for each element of x.
If x is another polynomial then the composite polynomial p(x(t))
is returned.
Parameters:
p (array_like or poly1d object) – 1D array of polynomial coefficients (including coefficients equal
to zero) from highest degree to the constant term, or an
instance of poly1d.
x (array_like or poly1d object) – A number, an array of numbers, or an instance of poly1d, at
which to evaluate p.
Returns:
values – If x is a poly1d instance, the result is the composition of the two
polynomials, i.e., x is “substituted” in p and the simplified
result is returned. In addition, the type of x - array_like or
poly1d - governs the type of the output: x array_like => values
array_like, x a poly1d object => values is also.
Return type:
ndarray or poly1d
See also
poly1d
A polynomial class.
Notes
Horner’s scheme [1]_ is used to evaluate the polynomial. Even so,
for polynomials of high degree the values may be inaccurate due to
rounding errors. Use carefully.
If x is a subtype of ndarray the return value will be of the same type.
axis (None or int or tuple of ints, optional) – Axis or axes along which a sum is performed. The default,
axis=None, will sum all of the elements of the input array. If
axis is negative it counts from the last to the first axis. If
axis is a tuple of ints, a sum is performed on all of the axes
specified in the tuple instead of a single axis or all the axes as
before.
dtype (dtype, optional) – The type of the returned array and of the accumulator in which the
elements are summed. The dtype of a is used by default unless a
has an integer dtype of less precision than the default platform
integer. In that case, if a is signed then the platform integer
is used while if a is unsigned then an unsigned integer of the
same precision as the platform integer is used.
out (ndarray, optional) – Alternative output array in which to place the result. It must have
the same shape as the expected output, but the type of the output
values will be cast if necessary.
keepdims (bool, optional) –
If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the input array.
If the default value is passed, then keepdims will not be
passed through to the sum method of sub-classes of
ndarray, however any non-default value will be. If the
sub-class’ method does not implement keepdims any
exceptions will be raised.
initial (scalar, optional) – Starting value for the sum. See ~numpy.ufunc.reduce for details.
where (array_like of bool, optional) – Elements to include in the sum. See ~numpy.ufunc.reduce for details.
Returns:
sum_along_axis – An array with the same shape as a, with the specified
axis removed. If a is a 0-d array, or if axis is None, a scalar
is returned. If an output array is specified, a reference to
out is returned.
Return type:
ndarray
See also
ndarray.sum
Equivalent method.
add
numpy.add.reduce equivalent function.
cumsum
Cumulative sum of array elements.
trapezoid
Integration of array values using composite trapezoidal rule.
mean, average
Notes
Arithmetic is modular when using integer types, and no error is
raised on overflow.
The sum of an empty array is the neutral element 0:
>>> np.sum([])0.0
For floating point numbers the numerical precision of sum (and
np.add.reduce) is in general limited by directly adding each number
individually to the result causing rounding errors in every step.
However, often numpy will use a numerically better approach (partial
pairwise summation) leading to improved precision in many use-cases.
This improved precision is always provided when no axis is given.
When axis is given, it will depend on which axis is summed.
Technically, to provide the best speed possible, the improved precision
is only used when the summation is along the fast axis in memory.
Note that the exact precision may vary depending on other parameters.
In contrast to NumPy, Python’s math.fsum function uses a slower but
more precise approach to summation.
Especially when summing a large number of lower precision floating point
numbers, such as float32, numerical errors can become significant.
In such cases it can be advisable to use dtype=”float64” to use a higher
precision for the output.
Building blocks for defining a lazy evaluation network.
Literals are the building blocks of the evaluation network. An Argument
holds the name and value of an equation variable. Operators are used to
compose other Literals to produce a new value.
Literal networks can be evaluated or have other actions performed on
them by Visitors (in diffpy.srfit.equation.visitors). The Literal-
Visitor relationship is that described by the Visitor pattern (
Abstract class for a binary operator with two inputs and one result.
This base class defines the nin and nout attributes. The derived
concrete operator must define the remaining abstract attributes
of the Operator class.
This convolves two signals such that centroid of the first array is
not altered by the convolution. Furthermore, the integrated
amplitude of the convolution is scaled to be that of the first
signal. This is mean to act as a convolution of a signal by a
probability distribution.
Note that this is only possible when the signals are computed over
the same range.
This forms part of the old polynomial API. Since version 1.4, the
new polynomial API defined in numpy.polynomial is preferred.
A summary of the differences can be found in the
transition guide.
If p is of length N, this function returns the value:
p[0]*x**(N-1)+p[1]*x**(N-2)+...+p[N-2]*x+p[N-1]
If x is a sequence, then p(x) is returned for each element of x.
If x is another polynomial then the composite polynomial p(x(t))
is returned.
Parameters:
p (array_like or poly1d object) – 1D array of polynomial coefficients (including coefficients equal
to zero) from highest degree to the constant term, or an
instance of poly1d.
x (array_like or poly1d object) – A number, an array of numbers, or an instance of poly1d, at
which to evaluate p.
Returns:
values – If x is a poly1d instance, the result is the composition of the two
polynomials, i.e., x is “substituted” in p and the simplified
result is returned. In addition, the type of x - array_like or
poly1d - governs the type of the output: x array_like => values
array_like, x a poly1d object => values is also.
Return type:
ndarray or poly1d
See also
poly1d
A polynomial class.
Notes
Horner’s scheme [1]_ is used to evaluate the polynomial. Even so,
for polynomials of high degree the values may be inaccurate due to
rounding errors. Use carefully.
If x is a subtype of ndarray the return value will be of the same type.
axis (None or int or tuple of ints, optional) – Axis or axes along which a sum is performed. The default,
axis=None, will sum all of the elements of the input array. If
axis is negative it counts from the last to the first axis. If
axis is a tuple of ints, a sum is performed on all of the axes
specified in the tuple instead of a single axis or all the axes as
before.
dtype (dtype, optional) – The type of the returned array and of the accumulator in which the
elements are summed. The dtype of a is used by default unless a
has an integer dtype of less precision than the default platform
integer. In that case, if a is signed then the platform integer
is used while if a is unsigned then an unsigned integer of the
same precision as the platform integer is used.
out (ndarray, optional) – Alternative output array in which to place the result. It must have
the same shape as the expected output, but the type of the output
values will be cast if necessary.
keepdims (bool, optional) –
If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the input array.
If the default value is passed, then keepdims will not be
passed through to the sum method of sub-classes of
ndarray, however any non-default value will be. If the
sub-class’ method does not implement keepdims any
exceptions will be raised.
initial (scalar, optional) – Starting value for the sum. See ~numpy.ufunc.reduce for details.
where (array_like of bool, optional) – Elements to include in the sum. See ~numpy.ufunc.reduce for details.
Returns:
sum_along_axis – An array with the same shape as a, with the specified
axis removed. If a is a 0-d array, or if axis is None, a scalar
is returned. If an output array is specified, a reference to
out is returned.
Return type:
ndarray
See also
ndarray.sum
Equivalent method.
add
numpy.add.reduce equivalent function.
cumsum
Cumulative sum of array elements.
trapezoid
Integration of array values using composite trapezoidal rule.
mean, average
Notes
Arithmetic is modular when using integer types, and no error is
raised on overflow.
The sum of an empty array is the neutral element 0:
>>> np.sum([])0.0
For floating point numbers the numerical precision of sum (and
np.add.reduce) is in general limited by directly adding each number
individually to the result causing rounding errors in every step.
However, often numpy will use a numerically better approach (partial
pairwise summation) leading to improved precision in many use-cases.
This improved precision is always provided when no axis is given.
When axis is given, it will depend on which axis is summed.
Technically, to provide the best speed possible, the improved precision
is only used when the summation is along the fast axis in memory.
Note that the exact precision may vary depending on other parameters.
In contrast to NumPy, Python’s math.fsum function uses a slower but
more precise approach to summation.
Especially when summing a large number of lower precision floating point
numbers, such as float32, numerical errors can become significant.
In such cases it can be advisable to use dtype=”float64” to use a higher
precision for the output.