Random Number Generation
Canvas widget for plotting (x,y) points.
1.0 by manta ray
Constructor parameters
Name | Type | Description | Required? |
---|---|---|---|
_x |
Real |
x position of the canvas | Yes |
_y |
Real |
y position of the canvas | Yes |
_w |
Real |
width of the canvas | Yes |
_h |
Real |
height of the canvas | Yes |
Methods
add_series(_series_idx)
adds a Series
instance to the canvas for plotting.
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_series_idx |
Series |
the series instance to add | Yes |
Series
self (for method chaining)
autofit()
automatically determines the canvas x and y axes according to the data series. Note that this is automatically called at creation.
canvas_to_x(_canvas_x)
transforms a canvas x position to a window x position
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_canvas_x |
Real |
the canvas x position | Yes |
Real
the window x position corresponding to the provided canvas x position
canvas_to_y(_canvas_y)
transforms a canvas y position to a window y position
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_canvas_y |
Real |
the canvas y position | Yes |
Real
the window y position corresponding to the provided canvas y position
clear_series()
removes all Series from the canvas Private method - won't be documented by GMLDocMaker because no method tag is specifiedrenders the canvas to the screen
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_redraw |
Bool |
determines whether the canvas is redrawn. | No |
delete_series(_series_name)
removes a Series from the canvas
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_series_name |
String |
the series name | Yes |
destroy()
destroys the canvas
get_series(_series_name)
gets a Series id from the series name
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_series_name |
String |
the series name | Yes |
Series
the series reference
mouseover()
gets the canvas x and y positions of the mouse
Struct
A struct of type {x, y}
with the position of the canvas that is being mouseovered.This will return
{x: -1, y: -1}
if the canvas is not being mouseovered.
plot([_update=false])
plots the canvas to the screen
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_update |
String |
determines whether the canvas is redrawn on each call. Set to true if you need real-time updating (default), at the cost of performance, or disable it by setting this parameter to false. | No |
x_to_canvas(_x)
transforms an x position to a canvas position
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_x |
Real |
the window x position | Yes |
Real
the canvas x position corresponding to the provided x position
y_to_canvas(_y)
transforms an y position to a canvas position
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_y |
Real |
the window y position | Yes |
Real
the canvas y position corresponding to the provided y position
Struct return value
Canvas
self
Series struct that represents a collection of (x,y) points
Constructor parameters
Name | Type | Description | Required? |
---|---|---|---|
_x_array |
Array |
an array of x-coordinates. Must be of the same size than _y_array . |
Yes |
_y_array |
Array |
an array of y-coordinates. Must be of the same size than _x_array . |
Yes |
_name |
String |
the series name. | No |
_type |
Enum |
the type of plot required for this series. By default, SERIES.SCATTER_PLOT | No |
Methods
add_point(_x, _y)
Adds an (x,y) coordinate to this Series
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_x |
Real |
the x-coordinate of the point to add | Yes |
_y |
Real |
the y-coordinate of the point to add | Yes |
save(_file)
Saves the Series data to a CSV file
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_file |
String |
the full file path | Yes |
set_data(_x_array, _y_array)
Sets the x and y arrays
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_x_array |
Array |
the array of x-coordinates. Must be of the same size than _y_array . |
Yes |
_y_array |
Array |
an array of y-coordinates. Must be of the same size than _x_array . |
Yes |
set_histogram_bins(_n)
Sets the number of histogram bins to n
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_n |
Real |
the number of bins | Yes |
Struct return value
Series
self
Generates a Binomial random variable.
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_k |
Real |
The number of successes. Must be integer. | Yes |
_n |
Real |
The number of trials. Must be integer. | Yes |
_p |
Real |
The probability of success of a single trial. | Yes |
Real
The Binomial random variable.
Generates a Normal random variable with given mu and sigma, using the Box-Muller transformation.
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_mu |
Real |
Mean of the distribution, by default 0. | No |
_sigma |
Real |
Standard deviation of the distribution, by default 1. | No |
Generates an exponential random variable with a given beta parameter, using the inverted CDF technique.
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_beta |
Real |
The beta parameter. Must be greater than 0. See Wikipedia for reference. | Yes |
Real
A random number from the exponential distribution.
Evaluates the Normal distribution function at _x, with mean _mu and standard deviation _sigma.
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_x |
Real |
The value of x. | Yes |
_mu |
Real |
Mean of the distribution. | Yes |
_sigma |
Real |
Standard deviation of the distribution. | Yes |
Real
The value of the distribution function at x.
Generates a Poisson random variable with given lambda parameter.
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_lambda |
Real |
The lambda parameter, the rate of arrival. Must be greater than 0. See Wikipedia for reference. | Yes |
_return_array |
Bool |
Optional boolean parameter. If true, returns the array of arrival times instead. If false, returns the Poisson variate. | No |
Any
Poisson variate (Integer) or an array of arrival times (Arrayselects an index from the array with the specified probabilities
Parameters
Name | Type | Description | Required? |
---|---|---|---|
_array |
Array |
the array that holds the values to select from. if not provided, it will create a consecutive integer array, starting with 1, up to the size of the _probabilities array.if the _probabilities array is also not provided, it will simply return a 0 or 1 random variable (Bernoulli) |
No |
_probabilities |
Array |
the array that holds the corresponding probabilities. Should add up to 1 - if not, the function will normalize them. if not provided, it will create a uniform probability array matching the size of the _probabilities array.if the _array array is also not provided, it will simply return a 0 or 1 random variable (Bernoulli) |
No |
_return_index |
Bool |
if true it will return the selected index; if false (default) it will return the corresponding value from _array . |
No |
Any
the randomly selected item or index