Difference between revisions of "LlListStatistics"
Jump to navigation
Jump to search
m |
Omei Qunhua (talk | contribs) (Add an example showing expected results for each statistical operation on a sample list) |
||
(10 intermediate revisions by 5 users not shown) | |||
Line 5: | Line 5: | ||
|func_footnote=If a list entry type is not a float or an integer it is silently ignored. | |func_footnote=If a list entry type is not a float or an integer it is silently ignored. | ||
|func_desc | |func_desc | ||
|return_text=that is the result of performing statistical aggregate function | |return_text=that is the result of performing statistical aggregate function {{LSLP|operation}} on {{LSLP|src}}. | ||
|spec | |spec | ||
|caveats | |caveats | ||
|constants={{{!}}{{Prettytable}} | |constants={{{!}} class="sortable" {{Prettytable|style=margin-top:0;}} | ||
{{!}}-{{Hl2}} | {{!}}-{{Hl2}} | ||
! | !Constant | ||
!Description | ! title="Value" {{!}} | ||
! class="unsortable" {{!}} Description | |||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_RANGE|integer|0|c=Calculates the range.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_MIN|integer|1|c=Calculates the smallest number.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_MAX|integer|2|c=Calculates the largest number.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_MEAN|integer|3|c=Calculates the mean (average).}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_MEDIAN|integer|4|c=Calculates the median number.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_STD_DEV|integer|5|c=Calculates the standard deviation.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_SUM|integer|6|c=Calculates the sum.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_SUM_SQUARES|integer|7|c=Calculates the sum of the squares.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_NUM_COUNT|integer|8|c=Determines the number of float and integer elements.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} Determines the number of [[float]] and [[integer]] elements. | ||
{{!}}- | {{!}}- | ||
{{!}}{{ | {{!}} {{LSL Const|LIST_STAT_GEOMETRIC_MEAN|integer|9|c=Calculates the geometric mean.}} | ||
{{!}} | {{!}} {{#var:value}} | ||
{{!}} | {{!}} {{#var:comment}} | ||
{{!}}} | {{!}}} | ||
|examples=< | |examples= | ||
// shows just how bad SL is behaving and demonstrates the use of llListStatistics() | <source lang="lsl2">// Show results for each operation for a sample list | ||
default | |||
{ | |||
state_entry() | |||
{ | |||
list LX = [-1, 3.33, 17, "object", -4.5, 0.8675 ]; | |||
llSay(0, "G.Mean= " + (string) llListStatistics(LIST_STAT_GEOMETRIC_MEAN, LX) ); // 0. 000000 | |||
llSay(0, "Max= " + (string) llListStatistics(LIST_STAT_MAX, LX) ); // 17.000000 | |||
llSay(0, "Min= " + (string) llListStatistics(LIST_STAT_MIN, LX) ); // -4.500000 | |||
llSay(0, "Mean= " + (string) llListStatistics(LIST_STAT_MEAN, LX) ); // 3.139500 | |||
llSay(0, "Median= " + (string) llListStatistics(LIST_STAT_MEDIAN, LX) ); // 0.867500 | |||
llSay(0, "Count= " + (string) llListStatistics(LIST_STAT_NUM_COUNT, LX) ); // 5.000000 | |||
llSay(0, "Range= " + (string) llListStatistics(LIST_STAT_RANGE, LX) ); // 21.500000 | |||
llSay(0, "Std.Dev= " + (string) llListStatistics(LIST_STAT_STD_DEV, LX) ); // 8.258468 | |||
llSay(0, "Sum= " + (string) llListStatistics(LIST_STAT_SUM, LX) ); // 15.697500 | |||
llSay(0, "Sum of squares= " + (string) llListStatistics(LIST_STAT_SUM_SQUARES, LX) ); // 322.091500 | |||
} | |||
} | |||
// Note that LSLEditor produces "NaN" (Not A Number) for the geometric mean above. Geometric mean applies only to numbers of the same sign. | |||
</source> | |||
<source lang="lsl2">// shows just how bad SL is behaving and demonstrates the use of llListStatistics() | |||
list dil_s; | list dil_s; | ||
list fps_s; | list fps_s; | ||
integer ticks = 0; | |||
default | default | ||
{ | { | ||
state_entry () | state_entry() | ||
{ | { | ||
llSetTimerEvent(1.0); | |||
llSetTimerEvent (1.0); | |||
} | } | ||
on_rez (integer parm) | on_rez (integer parm) | ||
{ | { | ||
llResetScript (); | llResetScript(); | ||
} | } | ||
timer() | timer() | ||
{ | { | ||
dil_s + | dil_s = llList2List(dil_s + llGetRegionTimeDilation(), -60, -1); | ||
fps_s + | fps_s = llList2List(fps_s + llGetRegionFPS(), -60, -1); | ||
if(3 <= ++ticks) | |||
{ | |||
llSetText( | |||
"Dilation: min="+(string) llListStatistics(LIST_STAT_MIN, dil_s) + ", mean=" + | |||
(string) llListStatistics(LIST_STAT_MEAN, dil_s) + ", max=" + | |||
(string) llListStatistics(LIST_STAT_MAX, dil_s) + ", std.dev=" + | |||
(string) llListStatistics(LIST_STAT_STD_DEV, dil_s) + "\n" + | |||
"FPS: min="+(string) llListStatistics(LIST_STAT_MIN, fps_s) + ", mean=" + | |||
(string) llListStatistics(LIST_STAT_MEAN, fps_s) + ", max=" + | |||
(string) llListStatistics(LIST_STAT_MAX, fps_s) + ", std.dev=" + | |||
(string) llListStatistics(LIST_STAT_STD_DEV, fps_s), | |||
<1.0, 1.0, 0.0>, //yellow | |||
1.0); | |||
} | } | ||
} | |||
changed(integer change) | |||
{ | |||
if(change & CHANGED_REGION) | |||
{ | |||
llResetScript(); | |||
} | } | ||
} | } | ||
} | }</source> | ||
</ | |||
|helpers | |helpers | ||
|also_functions={{LSL DefineRow||[[llGetListEntryType]]|}} | |also_functions= | ||
{{LSL DefineRow||[[llGetListEntryType]]|}} | |||
|also_events | |also_events | ||
|also_tests | |also_tests= | ||
{{LSL DefineRow||[[llListStatistics Test]]|}} | |||
|also_articles | |also_articles | ||
|notes | |notes=Given that this operation ignores any non-numbers in a list, it can be used to tell you, in a mixed list, how many of the elements in a list are numbers (when used with the [[LIST_STAT_NUM_COUNT]] parameter.) | ||
|permission | |permission | ||
|negative_index | |negative_index |
Latest revision as of 07:41, 13 January 2016
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: float llListStatistics( integer operation, list src );0.0 | Forced Delay |
10.0 | Energy |
Returns a float that is the result of performing statistical aggregate function operation on src.
• integer | operation | – | a LIST_STAT_* flag | |
• list | src |
If a list entry type is not a float or an integer it is silently ignored.
Constant | Description | |
---|---|---|
LIST_STAT_RANGE | 0 | Calculates the range. |
LIST_STAT_MIN | 1 | Calculates the smallest number. |
LIST_STAT_MAX | 2 | Calculates the largest number. |
LIST_STAT_MEAN | 3 | Calculates the mean (average). |
LIST_STAT_MEDIAN | 4 | Calculates the median number. |
LIST_STAT_STD_DEV | 5 | Calculates the standard deviation. |
LIST_STAT_SUM | 6 | Calculates the sum. |
LIST_STAT_SUM_SQUARES | 7 | Calculates the sum of the squares. |
LIST_STAT_NUM_COUNT | 8 | Determines the number of float and integer elements. |
LIST_STAT_GEOMETRIC_MEAN | 9 | Calculates the geometric mean. |
Examples
// Show results for each operation for a sample list
default
{
state_entry()
{
list LX = [-1, 3.33, 17, "object", -4.5, 0.8675 ];
llSay(0, "G.Mean= " + (string) llListStatistics(LIST_STAT_GEOMETRIC_MEAN, LX) ); // 0. 000000
llSay(0, "Max= " + (string) llListStatistics(LIST_STAT_MAX, LX) ); // 17.000000
llSay(0, "Min= " + (string) llListStatistics(LIST_STAT_MIN, LX) ); // -4.500000
llSay(0, "Mean= " + (string) llListStatistics(LIST_STAT_MEAN, LX) ); // 3.139500
llSay(0, "Median= " + (string) llListStatistics(LIST_STAT_MEDIAN, LX) ); // 0.867500
llSay(0, "Count= " + (string) llListStatistics(LIST_STAT_NUM_COUNT, LX) ); // 5.000000
llSay(0, "Range= " + (string) llListStatistics(LIST_STAT_RANGE, LX) ); // 21.500000
llSay(0, "Std.Dev= " + (string) llListStatistics(LIST_STAT_STD_DEV, LX) ); // 8.258468
llSay(0, "Sum= " + (string) llListStatistics(LIST_STAT_SUM, LX) ); // 15.697500
llSay(0, "Sum of squares= " + (string) llListStatistics(LIST_STAT_SUM_SQUARES, LX) ); // 322.091500
}
}
// Note that LSLEditor produces "NaN" (Not A Number) for the geometric mean above. Geometric mean applies only to numbers of the same sign.
// shows just how bad SL is behaving and demonstrates the use of llListStatistics()
list dil_s;
list fps_s;
integer ticks = 0;
default
{
state_entry()
{
llSetTimerEvent(1.0);
}
on_rez (integer parm)
{
llResetScript();
}
timer()
{
dil_s = llList2List(dil_s + llGetRegionTimeDilation(), -60, -1);
fps_s = llList2List(fps_s + llGetRegionFPS(), -60, -1);
if(3 <= ++ticks)
{
llSetText(
"Dilation: min="+(string) llListStatistics(LIST_STAT_MIN, dil_s) + ", mean=" +
(string) llListStatistics(LIST_STAT_MEAN, dil_s) + ", max=" +
(string) llListStatistics(LIST_STAT_MAX, dil_s) + ", std.dev=" +
(string) llListStatistics(LIST_STAT_STD_DEV, dil_s) + "\n" +
"FPS: min="+(string) llListStatistics(LIST_STAT_MIN, fps_s) + ", mean=" +
(string) llListStatistics(LIST_STAT_MEAN, fps_s) + ", max=" +
(string) llListStatistics(LIST_STAT_MAX, fps_s) + ", std.dev=" +
(string) llListStatistics(LIST_STAT_STD_DEV, fps_s),
<1.0, 1.0, 0.0>, //yellow
1.0);
}
}
changed(integer change)
{
if(change & CHANGED_REGION)
{
llResetScript();
}
}
}
Notes
Given that this operation ignores any non-numbers in a list, it can be used to tell you, in a mixed list, how many of the elements in a list are numbers (when used with the LIST_STAT_NUM_COUNT parameter.)
See Also
Functions
• | llGetListEntryType |