簡介:Tensorflow.js 是 Google 開發的一個開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.movingAverage() 函數用於確定變量的移動平均值。
注意:
- 在沒有 zeroDebias 的情況下,移動平均操作由:v += delta 指定。其中,delta = (1 - 衰減) * (x - v)。
- 在 zeroDebias(默認)存在的情況下,測量 delta 項以消除 v 的(假定的)zero-initialization 的影響。其中 delta /= (1 - decay^step)。
- 這個函數是完全無狀態的,不保留步數的路徑。此外,規定的步數要求調用者保存並作為步數傳入。
用法:
tf.movingAverage(v, x, decay, step?, zeroDebias?)
參數:
- v:規定的當前移動平均值。它可以是 tf.Tensor、TypedArray 或 Array 類型。
- x:規定的新輸入值,它應該具有相同的形狀以及像 v 這樣的數據類型。
- decay:規定的衰減因子。其值通常為 0.95 和 0.99。它可以是 number 類型,也可以是 tf.Scalar。
- step:規定的步數。它是可選的,類型為 number 或 tf.Scalar。
- zeroDebias:它檢查是否要執行 zeroDebias。默認值為 true。它是可選的並且是布爾類型。
返回值:它返回tf.Tensor。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining current moving average value
const v = tf.tensor1d([1, 3, 5, 1]);
// Defining new input value
const x = tf.tensor1d([1, 7, 2, 1]);
// Defining decay factor
const decay_factor = 0.75;
// Calling movingAverage() method
const res = tf.movingAverage(v, x, decay_factor, 2, true);
// Printing output
res.print();
輸出:
Tensor [1, 5.2857141, 3.2857144, 1]
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Calling movingAverage() method
tf.movingAverage(tf.tensor1d([1.1, 3.1, 5.5, 1.3]),
tf.tensor1d([1.2, 7.4, 2.6, 1.1]), 0.99, 5, false).print();
輸出:
Tensor [1.1010001, 3.1429999, 5.4710002, 1.298]
參考: https://js.tensorflow.org/api/latest/#movingAverage
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP Imagick floodFillPaintImage()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.movingAverage() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。