StandardDeviation (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Automatically generated page update)
 
mNo edit summary
Line 1: Line 1:
{{Template:Arraylist:StandardDeviation subtitle}}
{{Template:Arraylist:StandardDeviation subtitle}}


This page is [[under construction]].
This method returns the standard deviation, the variation from the mean, of the values of the items in the collection. This is the square root of the collection's variance.
 
==Syntax==
==Syntax==
{{Template:Arraylist:StandardDeviation syntax}}
{{Template:Arraylist:StandardDeviation syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%standardDev</th><td>number</td></tr>
<tr><th>%standardDev</th>
<td>A <var>Float</var> variable to contain the numeric result.</td></tr>
 
<tr><th>al</th>
<tr><th>al</th>
<td>Arraylist object</td></tr>
<td>An <var>Arraylist</var> object.</td></tr>
 
<tr><th>method</th>
<tr><th>method</th>
<td><var>ItemFunction</var> object</td></tr>
<td>A function that operates on the type of the items in the <var>Arraylist</var>. It may be a [[Local and Common entities#Defining and invoking a local method|local method]] or [[Method variables|method variable]] or a class member (<var>Variable</var>, <var>Property</var>), and it must return an [[Intrinsic classes|intrinsic]] (probably <var>Float</var>) value.
<p>
The default <var class="term">method</var> value is the special identity function, <var>This</var>, which simply returns the item value.</p></td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>The optional <var class="term">method</var> parameter lets you further manipulate the <var>Arraylist</var> item values
before performing the <var>StandardDeviation</var> method's operation.
If your <var>Arraylist</var>'s items are not intrinsic values, you must specify a function that can map the item values to intrinsic values or the method will fail.
<p>
For example, for an <var>Arraylist</var> that is a list of coordinates, you could
return the average of their distance from the origin by first applying a local function as the <var>StandardDeviation</var> method's <var class="term">method</var> parameter: </p>
<p class="code">b
class point
    public
      constructor new(%x is float, %y is float)
      variable x is float
      variable y is float
    end public
    constructor new(%x is float, %y is float)
      %this:x = %x
      %this:y = %y
    end constructor
end class
local function (point):distance is float
  return (%this:x * %this:x + %this:y * %this:y):squareRoot
end function
%al is arrayList of object point
%al = new
%al:add(new(1,1))
%al:add(new(3,4))
%al:add(new(-5,12))
print %al:standardDeviation(distance)
end
</p>
The result is <code>4.84295951476148</code>. </ul>
==Examples==
==Examples==
<p class="code">b
%al is arrayList of float
%al = new
%al:add(5)
%al:add(3)
%al:add(8)
print %al:standardDeviation
end
</p>
The result is:
<p class="output">2.05480466765633
</p>
==See also==
==See also==
{{Template:Arraylist:StandardDeviation footer}}
{{Template:Arraylist:StandardDeviation footer}}

Revision as of 21:40, 10 July 2012

Compute the standard deviation of the items (Arraylist class)

[Introduced in Sirius Mods 7.8]


This method returns the standard deviation, the variation from the mean, of the values of the items in the collection. This is the square root of the collection's variance.

Syntax

%standardDev = al:StandardDeviation[( [itemFunction])]

Syntax terms

%standardDev A Float variable to contain the numeric result.
al An Arraylist object.
method A function that operates on the type of the items in the Arraylist. It may be a local method or method variable or a class member (Variable, Property), and it must return an intrinsic (probably Float) value.

The default method value is the special identity function, This, which simply returns the item value.

Usage notes

  • The optional method parameter lets you further manipulate the Arraylist item values before performing the StandardDeviation method's operation. If your Arraylist's items are not intrinsic values, you must specify a function that can map the item values to intrinsic values or the method will fail.

    For example, for an Arraylist that is a list of coordinates, you could return the average of their distance from the origin by first applying a local function as the StandardDeviation method's method parameter:

    b class point public constructor new(%x is float, %y is float) variable x is float variable y is float end public constructor new(%x is float, %y is float) %this:x = %x %this:y = %y end constructor end class local function (point):distance is float return (%this:x * %this:x + %this:y * %this:y):squareRoot end function %al is arrayList of object point %al = new %al:add(new(1,1)) %al:add(new(3,4)) %al:add(new(-5,12)) print %al:standardDeviation(distance) end

    The result is 4.84295951476148.

Examples

b %al is arrayList of float %al = new %al:add(5) %al:add(3) %al:add(8) print %al:standardDeviation end

The result is:

2.05480466765633

See also