tf.math.polyval
Stay organized with collections
Save and categorize content based on your preferences.
Computes the elementwise value of a polynomial.
tf.math.polyval(
coeffs, x, name=None
)
If x
is a tensor and coeffs
is a list n + 1 tensors,
this function returns the value of the n-th order polynomial
p(x) = coeffs[n-1] + coeffs[n-2] * x + ... + coeffs[0] * x**(n-1)
evaluated using Horner's method, i.e.
p(x) = coeffs[n-1] + x * (coeffs[n-2] + ... + x * (coeffs[1] + x * coeffs[0]))
Usage Example:
coefficients = [1.0, 2.5, -4.2]
x = 5.0
y = tf.math.polyval(coefficients, x)
y
<tf.Tensor: shape=(), dtype=float32, numpy=33.3>
Usage Example:
tf.math.polyval([2, 1, 0], 3) # evaluates 2 * (3**2) + 1 * (3**1) + 0 * (3**0)
<tf.Tensor: shape=(), dtype=int32, numpy=21>
tf.math.polyval
can also be used in polynomial regression. Taking
advantage of this function can facilitate writing a polynomial equation
as compared to explicitly writing it out, especially for higher degree
polynomials.
x = tf.constant(3)
theta1 = tf.Variable(2)
theta2 = tf.Variable(1)
theta3 = tf.Variable(0)
tf.math.polyval([theta1, theta2, theta3], x)
<tf.Tensor: shape=(), dtype=int32, numpy=21>
Args |
coeffs
|
A list of Tensor representing the coefficients of the polynomial.
|
x
|
A Tensor representing the variable of the polynomial.
|
name
|
A name for the operation (optional).
|
Returns |
A tensor of the shape as the expression p(x) with usual broadcasting
rules for element-wise addition and multiplication applied.
|
Equivalent to numpy.polyval.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.polyval\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L5149-L5218) |\n\nComputes the elementwise value of a polynomial.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.math.polyval`](https://www.tensorflow.org/api_docs/python/tf/math/polyval)\n\n\u003cbr /\u003e\n\n tf.math.polyval(\n coeffs, x, name=None\n )\n\nIf `x` is a tensor and `coeffs` is a list n + 1 tensors,\nthis function returns the value of the n-th order polynomial\n\n`p(x) = coeffs[n-1] + coeffs[n-2] * x + ... + coeffs[0] * x**(n-1)`\n\nevaluated using Horner's method, i.e. \n\n p(x) = coeffs[n-1] + x * (coeffs[n-2] + ... + x * (coeffs[1] + x * coeffs[0]))\n\n#### Usage Example:\n\n coefficients = [1.0, 2.5, -4.2]\n x = 5.0\n y = tf.math.polyval(coefficients, x)\n y\n \u003ctf.Tensor: shape=(), dtype=float32, numpy=33.3\u003e\n\n#### Usage Example:\n\n tf.math.polyval([2, 1, 0], 3) # evaluates 2 * (3**2) + 1 * (3**1) + 0 * (3**0)\n \u003ctf.Tensor: shape=(), dtype=int32, numpy=21\u003e\n\n[`tf.math.polyval`](../../tf/math/polyval) can also be used in polynomial regression. Taking\nadvantage of this function can facilitate writing a polynomial equation\nas compared to explicitly writing it out, especially for higher degree\npolynomials. \n\n x = tf.constant(3)\n theta1 = tf.Variable(2)\n theta2 = tf.Variable(1)\n theta3 = tf.Variable(0)\n tf.math.polyval([theta1, theta2, theta3], x)\n \u003ctf.Tensor: shape=(), dtype=int32, numpy=21\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|---------------------------------------------------------------------|\n| `coeffs` | A list of `Tensor` representing the coefficients of the polynomial. |\n| `x` | A `Tensor` representing the variable of the polynomial. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `tensor` of the shape as the expression p(x) with usual broadcasting rules for element-wise addition and multiplication applied. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nnumpy compatibility\n-------------------\n\n\u003cbr /\u003e\n\nEquivalent to numpy.polyval.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]