ConversionsHelper

Helpers & Utilities · AiDotNet.Helpers

Provides utility methods for converting between different data structures used in machine learning models.

For Beginners

This helper class contains methods to convert between different mathematical objects used in AI (Tensor, Matrix, Vector). Think of it like a universal adapter that lets different parts of your AI system work together even when they expect different data formats.

How It Works

For example, if one algorithm outputs a Matrix but another needs a Tensor, these methods help you convert between them without writing complex conversion code yourself.

Methods

Method Summary
Func<Matrix<T>, Vector<T>> ConvertFitFunction(Func<TInput, TOutput> fitFunction) Converts a fit function that works with generic types to one that works with Matrix and Vector.
Matrix<T> ConvertToMatrix(TInput input) Converts an input of generic type to a Matrix.
Matrix<T> TensorToMatrix(Tensor<T> tensor, int rows, int columns) Converts a tensor to a matrix with the specified dimensions.
T ConvertToScalar(TOutput output) Converts an output value to a scalar value of type T.
TInput ConvertVectorToInput(Vector<T> vector, TInput referenceInput) Converts a Vector to the generic TInput type (Vector, Matrix, or Tensor) using a reference input for shape information.
TInput ConvertVectorToInputWithoutReference(Vector<T> vector) Converts a Vector to the generic TInput type (Vector, Tensor, Matrix, T[], or scalar T) without requiring a reference input.
Tensor<T> ConvertToTensor(object input) Converts a Matrix or Vector to a Tensor.
Tensor<T> MatrixToTensor(Matrix<T> matrix, int[] shape) Converts a matrix to a tensor with the specified shape.
Tensor<T> VectorToTensor(Vector<T> vector, int[] shape) Converts a vector to a tensor with the specified shape.
Vector<T> ConvertObjectToVector(object obj) Converts a generic object to a Vector.
Vector<T> ConvertToVector(TOutput output) Converts an output of generic type to a Vector.
int GetSampleCount(TData data) Gets the sample count from supported input/output data types.