串流評估器參考
串流評估器與串流來源或串流裝飾器不同。串流來源和串流裝飾器都回傳元組串流。串流評估器更像是傳統函式,會評估其參數並回傳結果。該結果可以是單一值、陣列、對應或其他結構。
串流評估器可以巢狀,讓一個評估器的輸出成為另一個評估器的輸入。
串流評估器可以在不同的內容中呼叫。例如,可以單獨呼叫串流評估器,也可以在串流運算式的內容中呼叫。
add
add
函式將採用 2 個或更多數值並將它們相加。如果任何值不是數值,add
函式將無法執行。如果找到 null 值,則將回傳 null 作為結果。
add 語法
以下運算式顯示您可以使用 add
評估器的各種方式。這些參數的數量和順序並不重要,且不限於至少需要兩個參數。回傳數值。
add(1,2,3,4) // 1 + 2 + 3 + 4 == 10
add(1,fieldA) // 1 + value of fieldA
add(fieldA,1.4) // value of fieldA + 1.4
add(fieldA,fieldB,fieldC) // value of fieldA + value of fieldB + value of fieldC
add(fieldA,div(fieldA,fieldB)) // value of fieldA + (value of fieldA / value of fieldB)
add(fieldA,if(gt(fieldA,fieldB),fieldA,fieldB)) // if fieldA > fieldB then fieldA + fieldA, else fieldA + fieldB
analyze
analyze
函式會使用可用的分析器分析文字,並回傳分析器發射的標記清單。可以單獨呼叫 analyze
函式,也可以在 select
和 cartesianProduct
串流運算式中呼叫。
analyze 語法
以下運算式顯示您可以使用 analyze
評估器的各種方式。
-
分析原始文字:
analyze("hello world", analyzerField)
-
分析
select
運算式中的文字欄位。這將使用分析器的輸出標註元組:select(expr, analyze(textField, analyzerField) as outField)
-
使用
cartesianProduct
表達式分析文字欄位。這會將分析器發出的每個 token 以個別的 tuple 形式串流輸出:cartesianProduct(expr, analyze(textField, analyzer) as outField)
anova
anova
函數會計算兩個或多個數值陣列的變異數分析。
betaDistribution
betaDistribution
函數會根據其參數回傳一個beta 機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、kolmogorovSmirnov
和 cumulativeProbability
函數搭配使用。
binomialCoefficient
binomialCoefficient
函數會回傳二項式係數,即從 n 個元素的集合中選取 k 個元素子集的數量。
binomialDistribution
binomialDistribution
函數會根據其參數回傳一個二項式機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、probability
和 cumulativeProbability
函數搭配使用。
constantDistribution
constantDistribution
函數會根據其參數回傳一個常數機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
和 cumulativeProbability
函數搭配使用。
當取樣時,常數分佈總是回傳其常數值。
corr
corr
函數會回傳兩個數值陣列的相關性,或矩陣的相關性矩陣。
corr
函數支援 Pearson's、Kendall's 和 Spearman's 相關性。
corr 語法
corr(numericArray1, numericArray2) // Compute the Pearsons correlation for two numeric arrays
corr(numericArray1, numericArray2, type=kendalls) // Compute the Kendalls correlation for two numeric arrays
corr(matrix) // Compute the Pearsons correlation matrix for a matrix
corr(matrix, type=spearmans) // Compute the Spearmans correlation matrix for a matrix
cosineSimilarity
cosineSimilarity
函數會回傳兩個數值陣列的餘弦相似度。
diff
diff
函數執行時間序列差分。
時間序列差分通常用於在進一步分析之前,使時間序列達到平穩狀態。
distance
distance
函數計算兩個數值陣列之間的距離,或是一個矩陣的距離矩陣。
distance 語法
distance(numericArray1, numericArray2) // Computes the euclidean distance for two numeric arrays.
distance(numericArray1, numericArray2, type=manhattan) // Computes the manhattan distance for two numeric arrays.
distance(matrix) // Computes the euclidean distance matrix for a matrix.
distance(matrix, type=canberra) // Computes the canberra distance matrix for a matrix.
dotProduct
dotProduct
函數會回傳兩個數值陣列的點積。
empiricalDistribution
empiricalDistribution
函數會回傳經驗分佈函數,這是一個基於實際數據集的連續機率分佈函數。這個函數是機率分佈框架的一部分,旨在與 sample
、kolmogorovSmirnov
和 cumulativeProbability
函數搭配使用。
這個函數旨在處理連續數據。若要從離散數據集建構分佈,請使用 enumeratedDistribution
。
enumeratedDistribution
enumeratedDistribution
函數會回傳基於實際數據集或預先定義的數據和機率集合的離散機率分佈函數。這個函數是機率分佈框架的一部分,旨在與 sample
、probability
和 cumulativeProbability
函數搭配使用。
enumeratedDistribution
可以透過兩種不同的情境呼叫
-
單一離散值陣列。這就像離散數據的經驗分佈。
-
單一離散值陣列和代表離散值機率的雙精度值陣列。
這個函數旨在處理離散數據。若要從連續數據集建構分佈,請使用 empiricalDistribution
。
enumeratedDistribution 語法
enumeratedDistribution(integerArray) // This creates an enumerated distribution from the observations in the numeric array.
enumeratedDistribution(array(1,2,3,4), array(.25,.25,.25,.25)) // This creates an enumerated distribution with four discrete values (1,2,3,4) each with a probability of .25.
eq
eq
函數會根據 Java 的標準 equals(…)
函數,回傳所有參數是否相等。這個函數接受任何類型的參數,但是如果所有參數的類型不同,則會執行失敗。也就是說,全部都是布林值,全部都是字串,或是全部都是數值。如果任何參數為 null,且至少有一個參數不是 null,則會回傳 false。回傳一個布林值。
expMovingAge
expMovingAverage
函數會計算數值陣列的指數移動平均。
factorial
factorial
函數會回傳其參數的階乘。
gammaDistribution
gammaDistribution
函數會根據其參數回傳伽瑪機率分佈。這個函數是機率分佈框架的一部分,旨在與 sample
、kolmogorovSmirnov
和 cumulativeProbability
函數搭配使用。
geometricDistribution
geometricDistribution
函數會根據其參數返回一個幾何機率分佈。此函數是機率分佈框架的一部分,旨在與sample、probability 和 cumulativeProbability 函數一起使用。
gt
gt
函數會返回第一個參數是否大於第二個參數。此函數接受數值或字串參數,但如果所有參數不是相同類型,則會無法執行。也就是說,全部都是字串或全部都是數值。如果任何參數為 null,則會引發錯誤。返回布林值。
gteq
gteq
函數會返回第一個參數是否大於或等於第二個參數。此函數接受數值和字串參數,但如果所有參數不是相同類型,則會無法執行。也就是說,全部都是字串或全部都是數值。如果任何參數為 null,則會引發錯誤。返回布林值。
if
if
函數的作用類似標準的條件 if/then 陳述式。如果第一個參數為 true,則會返回第二個參數,否則會返回第三個參數。此函數接受布林值作為第一個參數,而任何值作為第二個和第三個參數。如果第一個參數不是布林值或為 null,則會發生錯誤。
loess
leoss
函數是一個平滑曲線擬合器,它使用局部迴歸演算法。與觸及每個控制點的 spline 函數不同,loess
函數會將平滑曲線穿過控制點,而不需要觸及控制點。loess
結果可以由 derivative 函數用來從不平滑的資料產生平滑導數。
loess 命名參數
-
bandwidth
:(選用)繪製局部迴歸線時要使用的資料點百分比,預設為 .25。減少頻寬會增加 loess 可以擬合的曲線數。 -
robustIterations
:(選用)用來平滑離群值的迭代次數,預設為 2。
loess 語法
loess(yValues) // This creates the xValues automatically and fits a smooth curve through the data points.
loess(xValues, yValues) // This will fit a smooth curve through the data points.
loess(xValues, yValues, bandwidth=.15) // This will fit a smooth curve through the data points using 15 percent of the data points for each local regression line.
logNormalDistribution
logNormalDistribution
函數會根據其參數返回一個對數常態機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、kolmogorovSmirnov
和 cumulativeProbability
函數一起使用。
kolmogorovSmirnov
kolmogorovSmirnov
函數會執行Kolmogorov Smirnov 檢定,在參考連續機率分佈與樣本集之間執行。
lt
lt
函數會返回第一個參數是否小於第二個參數。此函數接受數值或字串參數,但如果所有參數不是相同類型,則會無法執行。也就是說,全部都是字串或全部都是數值。如果任何參數為 null,則會引發錯誤。返回布林值。
lteq
lteq
函數會返回第一個參數是否小於或等於第二個參數。此函數接受數值和字串參數,但如果所有參數的類型不相同,則會執行失敗。也就是說,所有參數都必須是字串或所有參數都必須是數值。如果任何參數為 null,則會引發錯誤。返回布林值。
markovChain
markovChain
函數可用於執行馬可夫鏈模擬。 markovChain
函數將轉移矩陣作為其參數,並返回一個可以使用 sample 函數取樣的數學模型。從馬可夫鏈取得的每個樣本都表示系統的當前狀態。
markovChain 語法
sample(markovChain(transitionMatrix), 5) // This creates a Markov Chain given a specific transition matrix.
The sample function takes 5 samples from the Markov Chain, representing the next five states of the system.
markovChain 返回值
馬可夫鏈模型:馬可夫鏈模型可以與 sample 函數一起使用。
matrix
matrix 函數會返回一個矩陣,該矩陣可以由支援矩陣運算的函數操作。
minMaxScale
minMaxScale
函數會在最小值和最大值範圍內縮放數值陣列。預設情況下,minMaxScale
會在 0 和 1 之間縮放。minMaxScale
函數可以對數值陣列和矩陣進行操作。
在矩陣上操作時,minMaxScale
函數會對矩陣的每一列進行操作。
minMaxScale 語法
minMaxScale(numericArray) // scale a numeric array between 0 and 1
minMaxScale(numericArray, 0, 100) // scale a numeric array between 1 and 100
minMaxScale(matrix) // Scale each row in a matrix between 0 and 1
minMaxScale(matrix, 0, 100) // Scale each row in a matrix between 0 and 100
mod
mod
函數會返回第一個參數除以第二個參數的餘數(模數)。
mod 語法
以下表達式顯示使用 mod
評估器的各種方式。
mod(100,3) // returns the remainder of 100 / 3 .
mod(100,fieldA) // returns the remainder of 100 divided by the value of fieldA.
mod(fieldA,1.4) // returns the remainder of fieldA divided by 1.4.
if(gt(fieldA,fieldB),mod(fieldA,fieldB),mod(fieldB,fieldA)) // if fieldA > fieldB then return the remainder of fieldA/fieldB, else return the remainder of fieldB/fieldA.
monteCarlo
movingAvg
movingAvg
函數會計算數字陣列的移動平均值。
mult
mult
函數會將兩個或多個數值相乘。如果任何值不是數值,則 mult
函數將執行失敗。如果找到 null 值,則會將 null 作為結果返回。
mult 語法
以下表達式顯示使用 mult
評估器的各種方式。這些參數的數量和順序並不重要,並且沒有限制,但至少需要兩個參數。返回數值。
mult(1,2,3,4) // 1 * 2 * 3 * 4
mult(1,fieldA) // 1 * value of fieldA
mult(fieldA,1.4) // value of fieldA * 1.4
mult(fieldA,fieldB,fieldC) // value of fieldA * value of fieldB * value of fieldC
mult(fieldA,div(fieldA,fieldB)) // value of fieldA * (value of fieldA / value of fieldB)
mult(fieldA,if(gt(fieldA,fieldB),fieldA,fieldB)) // if fieldA > fieldB then fieldA * fieldA, else fieldA * fieldB
normalDistribution
normalDistribution
函數會根據其參數返回常態機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、kolmogorovSmirnov
和 cumulativeProbability
函數一起使用。
olsRegress
olsRegress
函數會執行普通最小平方法、多元線性迴歸。
olsRegress
函數會返回一個包含迴歸模型以及估計迴歸參數、R 平方和迴歸診斷的單一元組。
olsRegress
的輸出可以與 predict 函數一起使用,以根據迴歸模型預測值。
olsRegress 參數
-
matrix
:迴歸變數觀測矩陣。矩陣中的每一列代表單個多元迴歸變數觀測。請注意,在指定包含截距項的模型時,不需要新增初始單位列(1 的列),此列將會自動新增。 -
numeric array
:與迴歸變數觀測矩陣中的每一列匹配的結果陣列。
poissonDistribution
poissonDistribution
函數會根據其參數返回泊松機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、probability
和 cumulativeProbability
函數一起使用。
polyFit
polyFit
函數會執行多項式曲線擬合。
polyFit 語法
polyFit(yValues) // This creates the xValues automatically and fits a curve through the data points using the default 3 degree polynomial.
polyFit(yValues, 5) // This creates the xValues automatically and fits a curve through the data points using a 5 degree polynomial.
polyFit(xValues, yValues, 5) // This will fit a curve through the data points using a 5 degree polynomial.
pow
pow
函數會返回第一個參數的值,該值會提高到第二個參數的冪次方。
pow 語法
以下表達式展示了您可以使用 pow
評估器的各種方式。
pow(2,3) // returns 2 raised to the 3rd power.
pow(4,fieldA) // returns 4 raised by the value of fieldA.
pow(fieldA,1.4) // returns the value of fieldA raised by 1.4.
if(gt(fieldA,fieldB),pow(fieldA,fieldB),pow(fieldB,fieldA)) // if fieldA > fieldB then raise fieldA by fieldB, else raise fieldB by fieldA.
predict
predict
函式基於迴歸模型或函式預測應變數的值。
predict
函式可以基於以下函式的輸出預測值:spline、loess、regress、olsRegress。
predict 語法
predict(regressModel, number) // predict using the output of the <<regress>> function and single numeric predictor. This will return a single numeric prediction.
predict(regressModel, numericArray) // predict using the output of the <<regress>> function and a numeric array of predictors. This will return a numeric array of predictions.
predict(splineFunc, number) // predict using the output of the <<spline>> function and single numeric predictor. This will return a single numeric prediction.
predict(splineFunc, numericArray) // predict using the output of the <<spline>> function and a numeric array of predictors. This will return a numeric array of predictions.
predict(olsRegressModel, numericArray) // predict using the output of the <<olsRegress>> function and a numeric array containing one multi-variate predictor. This will return a single numeric prediction.
predict(olsRegressModel, matrix) // predict using the output of the <<olsRegress>> function and a matrix containing rows of multi-variate predictor arrays. This will return a numeric array of predictions.
probability
probability
函式會傳回機率分佈中隨機變數的機率。
probability
函式僅能計算離散機率分佈的特定隨機變數的機率。
支援的連續分佈函式為:normalDistribution、logNormalDistribution、betaDistribution、gammaDistribution、empiricalDistribution、triangularDistribution、weibullDistribution、uniformDistribution、constantDistribution
支援的離散分佈為:poissonDistribution、binomialDistribution、enumeratedDistribution、zipFDistribution、geometricDistribution、uniformIntegerDistribution
probability 語法
probability(poissonDistribution(10), 7) // Returns the probability of a random sample of 7 in a poisson distribution with a mean of 10.
probability(normalDistribution(10, 2), 7.5, 8.5) // Returns the probability between the range of 7.5 to 8.5 for a normal distribution with a mean of 10 and standard deviation of 2.
regress
regress
函式會對兩個數值陣列執行簡單迴歸。
此表達式的結果也由 predict
函式使用。
sample
sample
函式可用於從機率分佈或馬可夫鏈中提取隨機樣本。
sample 語法
sample(poissonDistribution(5)) // Returns a single random sample from a poissonDistribution with mean of 5.
sample(poissonDistribution(5), 1000) // Returns 1000 random samples from poissonDistribution with a mean of 5.
sample(markovChain(transitionMatrix), 1000) // Returns 1000 random samples from a Markov Chain.
scalarAdd
scalarDivide
scalarMultiply
scalarMultiply
函式會將數值陣列或矩陣中的每個元素乘以純量值。 使用數值陣列時,scalarMultiply
會傳回具有新值的新陣列。 使用矩陣時,scalarMultiply
會傳回具有新值的新矩陣。
scalarSubtract
scalarSubtract
函式會從數值陣列或矩陣中的每個值減去純量值。 使用數值陣列時,scalarSubtract
會傳回具有新值的新陣列。 使用矩陣時,scalarSubtract
會傳回具有新值的新矩陣。
spline
spline
函數會對給定的一組 x,y 座標執行三次樣條插值 (https://en.wikiversity.org/wiki/Cubic_Spline_Interpolation)。spline 函數的回傳值是一個插值函數,可用於預測沿曲線的值並產生曲線的導數。
sub
sub
函數會取 2 個或更多數值,並從左到右相減。如果任何值不是數值,sub
函數將無法執行。如果找到 null 值,則會將 null
作為結果傳回。
sub 語法
以下運算式顯示您可以使用 sub
評估器的各種方式。這些參數的數量並不重要,且不受限制,但至少需要兩個參數。回傳數值。
sub(1,2,3,4) // 1 - 2 - 3 - 4
sub(1,fieldA) // 1 - value of fieldA
sub(fieldA,1.4) // value of fieldA - 1.4
sub(fieldA,fieldB,fieldC) // value of fieldA - value of fieldB - value of fieldC
sub(fieldA,div(fieldA,fieldB)) // value of fieldA - (value of fieldA / value of fieldB)
if(gt(fieldA,fieldB),sub(fieldA,fieldB),sub(fieldB,fieldA)) // if fieldA > fieldB then fieldA - fieldB, else fieldB - field
transpose
transpose
函數會轉置矩陣。
triangularDistribution
triangularDistribution
函數會根據其參數回傳一個三角機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、probability
和 cumulativeProbability
函數搭配使用。
uniformDistribution
uniformDistribution
函數會根據其參數回傳一個連續均勻機率分佈。請參閱 uniformIntegerDistribution
以使用離散均勻分佈。此函數是機率分佈框架的一部分,旨在與 sample
和 cumulativeProbability
函數搭配使用。
uniformIntegerDistribution
uniformIntegerDistribution
函數會根據其參數回傳一個離散均勻機率分佈。請參閱 uniformDistribution
以使用連續均勻分佈。此函數是機率分佈框架的一部分,旨在與 sample
、probability
和 cumulativeProbability
函數搭配使用。
unitize
unitize
函數會將數值陣列縮放到 1 的量級,通常稱為單位向量。unitize 函數可以對數值陣列和矩陣進行操作。
在矩陣上操作時,unitize 函數會將矩陣的每一列單位化。
weibullDistribution
weibullDistribution
函數會根據其參數回傳一個 Weibull 機率分佈。此函數是機率分佈框架的一部分,旨在與 sample
、kolmogorovSmirnov
和 cumulativeProbability
函數搭配使用。
zipFDistribution
zipFDistribution
函數會根據其參數回傳一個 ZipF 分佈。此函數是機率分佈框架的一部分,旨在與 sample
、probability
和 cumulativeProbability
函數搭配使用。