/  AI Tools

MLP

KNN

KNN2

HMM

SVM

Word2Vec

PCA

Wekinator

AI

ChucK for AI (ChAI) is a set of AI/ML tools for building interactive AI musical instruments and systems. (See also: Unit Analyzer API reference.)

MLP

inherits : Object

A multilayer perceptron (MLP)--a basic artificial neural network--that maps an input layer to an output layer across a number of fully-connected hidden layers. This implementation can be trained either 1) by using one of the comprehensive .train() functions OR 2) by iteratively calling .forward() and .backprop() for each input-output observation, and using .shuffle() for each epoch. Commonly used for regression or classification.

examples

constructors

MLP()

Default constructor for MLP.

member functions

void backprop(float[] output, float learningRate)

(Manually) backpropagate from the output layer, for a single input-output observation; compute the gradient of the loss function with respect to the weights in the network, one layer at a time.

void forward(float[] input)

(Manually) forward-propagate the input vector through the network.

void getActivations(int layer, float[] activations)

Get the activations of the given layer, after a manual .forward().

void getBiases(int layer, float[] biases)

Get the biases of the given layer.

void getGradients(int layer, float[] gradients)

Get the gradients of the given layer, after a manual .backprop().

void getWeights(int layer, float[][] weights)

Get the weights of the given layer.

void init(int[] nodesPerLayer)

Initialize the MLP with the given number of nodes per layer.

void init(int[] nodesPerLayer, int[] activationPerLayer)

Initialize the MLP with the given number of nodes per layer and the given activation function per layer, as specified in 'activationPerLayer' (options: AI.Linear, AI.Sigmoid, AI.ReLU, AI.Tanh, or AI.Softmax).

void init(int[] nodesPerLayer, int activationFunction)

Initialize the MLP with the given number of nodes per layer and the given activation function for all layers (options: AI.Linear, AI.Sigmoid, AI.ReLU, AI.Tanh, or AI.Softmax).

int load(string filename)

Load a MLP model from file.

int predict(float[] input, float[] output)

Predict the output layer from an input layer.

int save(string filename)

Save the MLP model to file.

void train(float[][] inputs, float[][] outputs)

Train the MLP with the given input and output observations with default learning rate=.01 and epochs=100. (Also see MLP.train(inputs,outputs,learningRate,epochs).)

void train(float[][] inputs, float[][] outputs, float learningRate, int epochs)

Train the MLP with the given input and output observations, the learning rate, and number of epochs.

static member functions

void shuffle(float[][] X, float[][] Y)

(Manually) shuffle the given input and output vectors.


KNN

inherits : Object

A basic k-NN utility that searches for k nearest neighbors from a set of observations / feature vectors. (Also see KNN2. The differrence between KNN and KNN2 is that KNN does not deal with labels whereas KNN2 is designed to work with labels.)

examples

constructors

KNN()

Default constructor for KNN.

member functions

void search(float[] query, int k, int[] indices)

Search for the 'k' nearest neighbors of 'query' and return their corresponding indices.

void search(float[] query, int k, int[] indices, float[][] observations)

Search for the 'k' nearest neighbors of 'query' and return their corresponding indices and observations.

int train(float[][] x)

Train the KNN model with the given observations 'x'

void weigh(float[] weights)

Set the weights for each dimension in the data.


KNN2

inherits : Object

A k-NN utility that predicts probabilities of class membership based on distances from a test input to its k nearest neighbors. (Also see KNN. The differrence between KNN and KNN2 is that KNN does not deal with labels whereas KNN2 is designed to work with labels.)

examples

constructors

KNN2()

Default constructor for KNN2.

member functions

int predict(float[] query, int k, float[] prob)

Predict the output probabilities 'prob' given unlabeled test input 'query' based on distances to 'k' nearest neighbors.

void search(float[] query, int k, int[] labels)

Search for the 'k' nearest neighbors of 'query' and return their labels.

void search(float[] query, int k, int[] labels, int[] indices)

Search for the 'k' nearest neighbors of 'query' and return their labels and indices.

void search(float[] query, int k, int[] labels, int[] indices, float[][] observations)

Search for the 'k' nearest neighbors of 'query' and return their labels, indices, and observations.

int train(float[][] x, int[] labels)

Train the KNN model with the given observations 'x' and corresponding labels.

void weigh(float[] weights)

Set the weights for each dimension in the data.


HMM

inherits : Object

A hidden markov model (HMM) utility that generates a sequence of observations based on the training data.

examples

constructors

HMM()

Default constructor for HMM.

member functions

int generate(int length, int[] output)

Generate a sequence of observations of the given length.

int load(float[] initiailDistribution, float[][] transitionMatrix, float[][] emissionMatrix)

Initialize the HMM model with the given initial state distribution, transition matrix, and emission matrix.

int train(int numStates, int numEmissions, int[] observations)

Train the HMM model with the given observations.


SVM

inherits : Object

A support vector machine (SVM) utility trains a model and predicts output based on new input.

examples

constructors

SVM()

Default constructor for SVM.

member functions

int predict(float[] x, float[] y)

Predict the output 'y' given the input 'x'.

int train(float[][] x, float[][] y)

Train the SVM model with the given samples 'x' and 'y'.


Word2Vec

inherits : Object

A word embeddings utility that maps words to vectors; can load a model and perform similarity retrieval.

examples

constructors

Word2Vec()

Default constructor for Word2Vec.

member functions

int contains(string word)

Query if 'word' is in the current model.

int dim()

Get number of dimensions for word embedding.

int getSimilar(string word, int k, string[] output)

Get the k most similar words to the given word; return false if 'word' is not in model.

int getSimilar(float[] vec, int k, string[] output)

Get the k most similar words to the given vector.

int getVector(string word, float[] output)

Get the vector of the given word; returns false if 'word' is not in model.

int load(string path)

Load pre-trained word embedding model from the given path.

int load(string path, int useKDTreeDim)

Load pre-trained word embedding model from the given path; will use KDTree for similarity searches if the data dimension is less than or equal to 'useKDTreeDim'. Set 'useKDTreeDim' to 0 to use linear (brute force) similarity search; set 'useKDTreeDim' to less than 0 to always use KDTree.

void minMax(float[] mins, float[] maxs)

Retrieve the minimums and maximums for each dimension.

int size()

Get number of words in dictionary.

int useKDTree()

Get whether a KDTree is used for similarity search.


PCA

inherits : Object

A principle component analysis (PCA) utility, commonly used for dimensionality reduction.

examples

constructors

PCA()

Default constructor for PCA.

static member functions

void reduce(float[][] input, int D, float[][] output)

Dimension-reduce 'input' (NxM) to 'output' (NxD) as the projection of the input data onto its first 'D' principle components.


Wekinator

inherits : Object

A Wekinator utility that maps input vectors to output vectors, commonly used for interactive machine learning combining human-computer interaction and ML. Based on Rebecca Fiebrink's Wekinator framework.

examples

constructors

Wekinator()

Default constructor for Wekinator.

member functions

void add()

Add current inputs and outputs to the observations.

void add(float[] inputs, float[] outputs)

Add given inputs and outputs to the observations.

void add(int output_index, float[] inputs, float[] outputs)

Add given inputs and outputs to the observations for the specified output.

void clear()

Clear everything except the global properties.

void clearAllObs()

Clear all observations.

void clearAllObs(int output_index)

Clear all observations for the specified output.

void clearObs(int lo, int hi)

Clear the observations by id range.

void clearObs(int output_index, int lo, int hi)

Clear the observations by id range for the specified output.

void deleteLastRound()

Delete the last round of observations.

void exportObs(string filename)

Export the observations to a file.

void exportObs(int output_index, string filename)

Export the observations for the specified output to a file.

int getAllRecordStatus()

Get the record status for all outputs.

int getAllRunStatus()

Get the run status for all outputs.

void getObs(float[][] obs)

Get the observations in the Wekinator.

void getObs(int output_index, float[][] obs)

Get the observations for the specified output in the Wekinator.

void getOutputProperty(int output_index, string property_name, int[] property_value)

Get the output property of the Wekinator. See the Wekinator documentation for more information.

float getOutputPropertyFloat(int output_index, int property_type, string property_name)

Get the output property of the Wekinator. See the Wekinator documentation for more information.

int getOutputPropertyInt(int output_index, string property_name)

Get the output property of the Wekinator. See the Wekinator documentation for more information.

int getOutputPropertyInt(int output_index, int property_type, string property_name)

Get the output property of the Wekinator. See the Wekinator documentation for more information.

int getOutputRecordStatus(int output_index)

Get the record status for the specified output.

int getOutputRunStatus(int output_index)

Get the run status for the specified output.

float getPropertyFloat(int property_type, string property_name)

Get the property of the Wekinator. See the Wekinator documentation for more information.

int getPropertyInt(int property_type, string property_name)

Get the property of the Wekinator. See the Wekinator documentation for more information.

int getRound()

Get the current recording round.

void importObs(string filename)

Import the observations from a file.

void input(float[] inputs)

Set the inputs of the Wekinator.

int inputDims(int n)

Set the number of input dimensions to Wekinator.

int inputDims()

Get the number of input dimensions to Wekinator.

void load(string filename)

Load the Wekinator from a file.

int modelType(int model_type)

Set the model type of the Wekinator. Options: AI.Regression: AI.MLP, AI.LR, AI.Classification: AI.KNN, AI.SVM, AI.DT.

int modelType()

Get the model type id of the Wekinator.

string modelTypeName()

Get the model type name of the Wekinator.

void nextRound()

Bump the recording round.

int numObs()

Get the number of observations in the Wekinator.

int numObs(int output_index)

Get the number of observations for the specified output in the Wekinator.

void output(float[] outputs)

Set the outputs of the Wekinator.

int outputDims(int n)

Set the number of output dimensions to Wekinator.

int outputDims()

Get the number of output dimensions to Wekinator.

void predict(float[] inputs, float[] outputs)

Predict outputs for the given inputs.

void randomizeOutputs()

Randomize the outputs of the Wekinator.

void save(string filename)

Save the Wekinator to a file.

void setAllRecordStatus(int status)

Set the record status for all outputs.

void setAllRunStatus(int status)

Set the run status for all outputs.

void setOutputProperty(int output_index, string property_name, int property_value)

Set the output property of the Wekinator. See the Wekinator documentation for more information.

void setOutputProperty(int output_index, int property_type, string property_name, int property_value)

Set the output property of the Wekinator. See the Wekinator documentation for more information.

void setOutputProperty(int output_index, int property_type, string property_name, float property_value)

Set the output property of the Wekinator. See the Wekinator documentation for more information.

void setOutputProperty(int output_index, string property_name, int[] property_value)

Set the output property of the Wekinator. See the Wekinator documentation for more information.

void setOutputRecordStatus(int output_index, int status)

Set the record status for the specified output.

void setOutputRunStatus(int output_index, int status)

Set the run status for the specified output.

void setProperty(int property_type, string property_name, int property_value)

Set the property of the Wekinator. See the Wekinator documentation for more information.

void setProperty(int property_type, string property_name, float property_value)

Set the property of the Wekinator. See the Wekinator documentation for more information.

int taskType(int task_type)

Set the task type of the Wekinator. Options: AI.Regression, AI.Classification.

int taskType()

Get the task type id of the Wekinator.

string taskTypeName()

Get the task type name of the Wekinator.

void train()

Train models for all outputs.


AI

inherits : Object

AI class library.

static member variables

int BOOST

Model type: Boosting.

int Classification

Task type: Classification.

int DT

Model type: Decision tree.

int KNN

Model type: K-nearest neighbor.

int Linear

Activation type: Linear.

int LR

Model type: Logistic regression.

int MLP

Model type: Multi-layer perceptron.

int NAIVEBAYES

Model type: Naive Bayes.

int PR

Model type: Polynomial regression.

int Regression

Task type: Regression.

int ReLU

Activation type: ReLU.

int Sigmoid

Activation type: Sigmoid.

int Softmax

Activation type: Softmax.

int SVM

Model type: Support vector machine.

int Tanh

Activation type: Tanh.