Package-level declarations

Types

Link copied to clipboard

A class to save data to an expanding array.

Link copied to clipboard

A class to save pairs of observations to an array of double arrays, each with size 2.

Link copied to clipboard
fun interface GetTimeIfc

An interface to define a method to get simulated time as a double

Link copied to clipboard
fun interface GetValueIfc
Link copied to clipboard
open class Identity(name: String? = null) : IdentityIfc, NameIfc
Link copied to clipboard
interface IdentityIfc : NameIfc

An interface to define the identity of an object in terms of a name, a number, and an optional label.

Link copied to clipboard
class Interval(xLower: Double = Double.NEGATIVE_INFINITY, xUpper: Double = Double.POSITIVE_INFINITY)

Can be used to represent confidence intervals. Intervals between two real numbers where the lower limit must be less than or equal to the upper limit. The interval is inclusive of both end points.

Link copied to clipboard
object KSLArrays

This class has some array manipulation methods that I have found useful over the years.

Link copied to clipboard
open class Name(val name: String = "defaultName") : NameIfc
Link copied to clipboard
interface NameIfc

An interface for defining the name of an object

Link copied to clipboard
fun interface NewInstanceIfc<out T>

Permits implementers to indicate that they can create a new instance. The created instance should be a duplicate of the object instance in all relevant fields to achieve the same functionality.

Link copied to clipboard

This class encapsulates a list that is ordered Unfortunately, if the element is changed after being added to the list such that the comparison changes, then the ordering of the list will not be maintained. Ideally, only immutable objects are placed in the list.

Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard

Adds the two arrays element by element. Arrays must have same length and must not be null.

Link copied to clipboard

Takes an array of length, n, and computes k batch means where each batch mean is the average of batchSize (b) elements such that b = Math.FloorDiv(n, k). If the number of batches, k, does not divide evenly into n, then n - (k*b) observations are not processed at the end of the array.

Link copied to clipboard

Returns a BoxPlotSummary that summarizes the array of values

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Converts the 2-D array to a 1-D array by processing the source src array row-wise and concatenating the rows. For example if the data is organized as follows:

Link copied to clipboard

Copies all but element index of array fromA into array toB If fromA has 1 element, toB will be empty

Link copied to clipboard
Link copied to clipboard

Computes the difference, (di = xi+k - xi) for i = 0 until x.size - k This is the discrete difference operator. For example, if k = 1, then d0 = x1 - x0, d1 = x2 - x1, ..., dx.size - 2 = xx.size -1 - xx.size -2 and returns the new array of differences.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Copies the 2-D array by expanding to the maximum number of columns of the supplied (ragged) array so that the returned array is rectangular, where all row arrays have the same number of elements (columns).

Link copied to clipboard
fun Array<DoubleArray>.fill(theValue: GetValueIfc = ConstantRV.ZERO)

Fills the array with the provided value

fun DoubleArray.fill(theValue: GetValueIfc = ConstantRV.ZERO)

Fills the array with the value

Link copied to clipboard

The destination array is mutated by this method

Link copied to clipboard
fun Array<String>.findIndex(element: String): Int
fun IntArray.findIndex(element: Int): Int
fun LongArray.findIndex(element: Long): Int

If the array is empty, -1 is returned.

Link copied to clipboard

If the array is empty, -1 is returned.

Link copied to clipboard
Link copied to clipboard
fun DoubleArray.histogram(breakPoints: DoubleArray = Histogram.recommendBreakPoints(this)): Histogram

Returns a histogram that summarizes the array of values

Link copied to clipboard

Returns the index associated with the maximum element in the array For ties, this returns the first found.

Link copied to clipboard

Returns the index associated with the minimum element in the array For ties, this returns the first found.

Link copied to clipboard
fun IntArray.insertAt(value: Int, index: Int): IntArray

Inserts the value at the index, returning a new array

Link copied to clipboard

Examines each element, a_i starting at 0, and determines if all the elements are different (distinct) a_0 != a_1 != a_2, etc.

Link copied to clipboard

Examines each element, a_i starting at 0, and determines if all the elements are equal a_0 = a_1 = a_2, etc.

Link copied to clipboard

Examines each element, a_i starting at 0, and determines if all the elements are decreasing a_0 gte a_1 gte a_2, etc.

Link copied to clipboard

Examines each element, a_i starting at 0, and determines if all the elements are increasing a_0 lte a_1 lte a_2, etc.

Link copied to clipboard

A 2-D array is rectangular if all rows have the same number of elements (columns).

Link copied to clipboard

Examines each element, a_i starting at 0, and determines if all the elements are strictly decreasing a_0 gt a_1 gt a_2, etc.

Link copied to clipboard

Examines each element, a_i starting at 0, and determines if all the elements are strictly increasing a_0 lt a_1 lt a_2, etc.

Link copied to clipboard

Returns a new array of size (x.size -k) that is lagged by k elements yi = xi+k for i=0,1,...

Link copied to clipboard
fun main()
Link copied to clipboard
fun <T> makeNameFromClass(clazz: Class<T>, id: Int, str: String? = null): String
Link copied to clipboard
fun <T> Array<T>.mapInPlace(transform: (T) -> T)
fun DoubleArray.mapInPlace(transform: (Double) -> Double)
fun IntArray.mapInPlace(transform: (Int) -> Int)

Applies the transformation to each element of the array in place

Link copied to clipboard
inline fun <T> matrixOfNulls(n: Int, m: Int): Array<Array<T?>>

Extension functions and other functions for working with arrays

Link copied to clipboard
Link copied to clipboard

Assumes that the array can be ragged. Returns the number of elements in the row array that has the most elements.

Link copied to clipboard
Link copied to clipboard

Returns a new array that has been scaled so that the values are between the minimum and maximum values of the supplied array

Link copied to clipboard

Assumes that the 2-D array can be ragged. Returns the number of columns necessary that would cause the array to not be ragged. In other words, the minimum number of columns to make the array an un-ragged array (matrix) where all row arrays have the same number of elements.

Link copied to clipboard
Link copied to clipboard

Multiplies the two arrays element by element. Arrays must have same length.

Link copied to clipboard

Returns a new array that has been scaled so that the values are the (x - avg)/sd values of the supplied array

Link copied to clipboard
Link copied to clipboard
fun Array<String>.parseToDoubles(parseFail: Double = Double.NaN): DoubleArray

Converts the array of strings to Doubles

fun List<String>.parseToDoubles(parseFail: Double = Double.NaN): DoubleArray

Converts the list of strings to Doubles

Link copied to clipboard

Computes the product of the elements in the array

Link copied to clipboard
Link copied to clipboard

Remove the element at the index, returning a new array

Link copied to clipboard

Returns a new array with duplicate data values removed from the original array, preserving the order of the observations.

Link copied to clipboard

Returns a new array in the same order as the original array but with the specified value removed. All instances of the value will be removed.

Link copied to clipboard

Returns a statistic that summarizes the array of values

Returns a statistic that summarizes the data in the collection.

Link copied to clipboard
fun Array<DoubleArray>.statisticsByRow(rowNames: List<String> = emptyList()): List<StatisticIfc>

Computes the statistics for the 2D array of doubles by rows. If the row name is not supplied then the row is called rowj where j is the number of the missing row name.

Link copied to clipboard
Link copied to clipboard

The array must not be null

Link copied to clipboard

The array must not be null

Link copied to clipboard
inline fun <T> to2DArray(lists: List<List<T>>): Array<Array<T>>
Link copied to clipboard

Convert the 2D array of double to a 2D array of Double with each element the corresponding value

Convert the array of int to an array of double with each element the corresponding value

Link copied to clipboard

Convert the 2D array of Int to a 2D array of Int with each element the corresponding value

Link copied to clipboard

Convert the 2D array of Long to a 2D array of Long with each element the corresponding value

Link copied to clipboard
fun Array<DoubleArray>.toMapOfColumns(colNames: List<String> = emptyList()): Map<String, DoubleArray>

Converts the 2D array of doubles to a map that holds the arrays by column. If the column name is not supplied then the column is called col1, col2, etc. The 2D array must be rectangular.

Link copied to clipboard
fun Array<DoubleArray>.toMapOfLists(colNames: List<String> = emptyList()): Map<String, List<Double>>

Converts the 2D array of doubles to a map that holds the arrays by column. If the column name is not supplied then the column is called col1, col2, etc. The 2D array must be rectangular.

Link copied to clipboard
fun Array<DoubleArray>.toMapOfRows(rowNames: List<String> = emptyList()): Map<String, DoubleArray>

Converts the 2D array of doubles to a map that holds the arrays by rows. If the row name is not supplied then the row is called row1, row2, etc. The 2D array must be rectangular.

Link copied to clipboard
fun Array<Double?>.toPrimitives(replaceNull: Double = 0.0): DoubleArray

Converts any null values to replaceNull. For Array use toDoubleArray()

fun Array<Int?>.toPrimitives(replaceNull: Int = 0): IntArray

Converts any null values to replaceNull. For Array use toDoubleArray()

fun Array<Long?>.toPrimitives(replaceNull: Long = 0): LongArray

Converts any null values to replaceNull. For Array use toDoubleArray()

fun List<Double?>.toPrimitives(replaceNull: Double = 0.0): DoubleArray

Converts any null values to replaceNull. For List use toDoubleArray()

fun List<Int?>.toPrimitives(replaceNull: Int = 0): IntArray

Converts any null values to replaceNull. For List use toDoubleArray()

fun List<Long?>.toPrimitives(replaceNull: Long = 0): LongArray

Converts any null values to replaceNull. For List use toDoubleArray()

Link copied to clipboard

Convert the array of double to an array of strings with each element the corresponding value

Link copied to clipboard

Transposes the n rows by m columns array returned transposey = arrayx

Link copied to clipboard

Copies the array by trimming to the minimum number of columns of the supplied (potentially ragged) array so that the returned array is rectangular, where all row arrays have the same number of elements (columns)