SOLR-12634: Add gaussfit to the Math Expressions user guide

This commit is contained in:
Joel Bernstein 2018-08-28 17:00:47 -04:00
parent 6430749d46
commit 1cfc735fff
1 changed files with 135 additions and 13 deletions

View File

@ -133,28 +133,22 @@ responds with:
----
== Prediction, Derivatives and Integrals
=== Prediction, Derivatives and Integrals
The `polyfit` function returns an array which contains the *y* value data points
of the fitted curve.
In order to predict values along the curve an interpolation function must be created
for the curve. Once an interpolation functin has been created the `predict`,
`derivative` and `integral` functions can be applied to the curve.
The `polyfit` function returns a function that can be used with the `predict`
function.
In the example below the x axis is included for clarity.
The `polyfit` function returns an array with the fitted curve.
A linear inpolation function is then created for the curve with the `lerp` function.
The `polyfit` function returns a function for the fitted curve.
The `predict` function is then used to predict a value along the curve, in this
case the prediction is made for the *x* value of .5.
case the prediction is made for the *x* value of 5.
[source,text]
----
let(x=array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
y=array(0, 1, 2, 3, 4, 5.7, 6, 7, 6, 5, 5, 3, 2, 1, 0),
curve=polyfit(x, y, 5),
interp=lerp(x, curve),
p=predict(interp, .5))
p=predict(curve, 5))
----
When this expression is sent to the /stream handler it
@ -166,7 +160,57 @@ responds with:
"result-set": {
"docs": [
{
"p": 0.4481424148606813
"p": 5.439695598519129
},
{
"EOF": true,
"RESPONSE_TIME": 0
}
]
}
}
----
The `derivative` and `integrate` functions can be used to compute the derivative
and integrals for the fitted
curve. The example below demonstrates how to compute a derivative
for the fitted curve.
[source,text]
----
let(x=array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
y=array(0, 1, 2, 3, 4, 5.7, 6, 7, 6, 5, 5, 3, 2, 1, 0),
curve=polyfit(x, y, 5),
d=derivative(curve))
----
When this expression is sent to the /stream handler it
responds with:
[source,json]
----
{
"result-set": {
"docs": [
{
"d": [
0.3198918573686361,
0.9261492094077225,
1.2374272373653175,
1.30051359631081,
1.1628032287629813,
0.8722983646900058,
0.47760852150945,
0.02795050408827482,
-0.42685159525716865,
-0.8363663967611356,
-1.1495552332084857,
-1.3147721499346892,
-1.2797639048258267,
-0.9916699683185771,
-0.3970225234002308
]
},
{
"EOF": true,
@ -178,5 +222,83 @@ responds with:
----
== Gaussian Curve Fitting
The `gaussfit` function fits a smooth curve through a gaussian peak.
This is shown in the example below.
[source,text]
----
let(x=array(0,1,2,3,4,5,6,7,8,9, 10),
y=array(4,55,1200,3028,12000,18422,13328,6426,1696,239,20),
f=gaussfit(x, y))
----
When this expression is sent to the /stream handler it
responds with:
[source,json]
----
{
"result-set": {
"docs": [
{
"f": [
2.81764431935644,
61.157417979413424,
684.2328985468831,
3945.9411154167447,
11729.758936952656,
17972.951897338007,
14195.201949425435,
5779.03836032222,
1212.7224502169634,
131.17742331530349,
7.3138931735866946
]
},
{
"EOF": true,
"RESPONSE_TIME": 0
}
]
}
}
----
Like the `polyfit` function, the `gaussfit` function returns a function that can
be used directly by the `predict`, `derivative` and `integrate` functions.
The example below demonstrates how to compute an integral for a
fitted gaussian curve.
[source,text]
----
let(x=array(0,1,2,3,4,5,6,7,8,9, 10),
y=array(4,55,1200,3028,12000,18422,13328,6426,1696,239,20),
f=gaussfit(x, y),
i=integrate(f, 0, 5))
----
When this expression is sent to the /stream handler it
responds with:
[source,json]
----
{
"result-set": {
"docs": [
{
"i": 25261.666789766092
},
{
"EOF": true,
"RESPONSE_TIME": 3
}
]
}
}
----