Friday, 2 October 2020

k-means calculator for arbitrary sized vectors

This blog post implements a basic k-means clustering algorithm, which can be applied to arbitrary sized vectors. The clusters will be displayed graphically using a 3d plot once the calculation button is clicked (using a great library from Plotly, where you can zoom and turn the plot amongst other handy capabilities). This will be useful for visualising the spatial clustering of vectors of size 1 to 3 inclusive - the centroids are higlighted in black, while each cluster has its own colour.

The cluster centres (or centroids) are initialised using a variant of the k-means++ algorithm as proposed by David Arthur and Sergei Vassilvitski in 2007.

Please enter lines of comma separated numbers in the text areas below - after the last number in each line there must be no trailing comma. In addition, there must be no new line after the last sample.

Alternatively you can choose to load a CSV file, that must contain only comma separated numbers.

To perform the k-means clustering, please enter the number of clusters in the appropriate field, then press the button labelled "Perform k-means clustering" below - the results will populate the textareas below labelled "Label and data sample" and "Label and Centroid values". In addition a 3-d graph plot will appear.

Note that the k-means algorithm can converge to a local minimum, and also exhibit degeneracy, whereby one of the clusters has no members, although the kmeans++ initialisation should somewhat mitigate this. Should these scenarios occur, simply re-run the algorithm, by clicking on the button labelled "Perform k-means clustering".

An example three-dimensional dataset has been loaded, with three clusters of 200 samples, as guidance.



Input




Enter number of clusters (k value):-




Label and data sample:-
Label and Centroid values:-



Wednesday, 30 September 2020

Matrix Inverse

This blog post calculates the inverse of a square matrix with complex numbers.

For the (square) matrix entry, comma separated numbers need to be entered into the Input box, with no newline after the last line. A comma at the end of each line can be added optionally for comma separated numbers. Alternatively, you can load a CSV file into the Input box, by clicking on the Choose File button.

The precision of the results in decimal places can be specified in the text box headed "Precision (decimal places)". To perform the calculation, simply press the button labelled "Perform Matrix Inverse" further down this page. In addition, the matrix size and determinant will be printed.


Precision (decimal places)






Input


Results pending...


Inverse Matrix

Wednesday, 20 May 2020

Matrix Utilities: Binary Operators for Complex Matrices

Binary operations on two matrices are implemented in this blog post. The operations include the following (two types of operations for non-commutative operations, a single for commutative ones):

  • Addition : A + B
  • Subtraction : A - B
  • Subtraction : B - A
  • Multiplication : A * B
  • Multiplication : B * A
  • Hadamard product: A .* B
  • Kronecker product: A kron B
  • Kronecker product: B kron A

For the matrix entries in Input A and Input B, comma separated (the separation can also be a single whitespace) Complex numbers need to be entered into the Input boxes, with no newline after the last line. A comma at the end of each line can be added optionally for comma separated numbers. For guidance, the textareas for Input A and Input B have already been populated with example entries.

Note that it is possible to either just transpose the matrices in the textareas for Input A and Input B, or perform a Hermitian tranpose on the matrices in the textareas for Input A and Input B. This is achieved by clicking the relevant buttons. When a Hermitian transpose is performed, the full complex form of the number is displayed.

Alternatively, you can load a CSV file into each of the Input boxes, by clicking on the Choose File button. There is a select drop down menu which allows you to specify into which of the Input boxes (A or B) should the CSV file be loaded. The drop down menu needs to be set appropriately before clicking on the "Chose File" button. The CSV files that need to be loaded into the two boxes must have a different name, even if the contents are the same (due to a limitation of how the CSV loading is implemented).

The precision of the results in decimal places can be specified in the text box headed "Precision (decimal places)".

To perform the calculation, simply press the button labelled "Perform matrix operation" further down this page. Before clicking on this button, you need to specify which binary operation to perform with another select drop down menu. The result will be displayed in the yellow textarea.


Precision (decimal places)






Input A

Input B




A + B



Table of Probability Distributions

Below is a table listing commonly used probability distributions and their Cumulative Distribution Function (CDF). The table could come in ...