Skip to content

Module_MachineLearning

cyclone_dll edited this page Jun 13, 2026 · 15 revisions

Location: Home / Machine learning

Machine learning module

The Vorcyc.Mathematics.MachineLearning namespace includes many machine learning algorithms and utilities: numeric decision trees/random forests, K-nearest neighbors (KnnClassifier / KNN), multiple linear regression, polynomial regression, ridge regression, simple linear regression, support vector machines, Gaussian naive Bayes, DBSCAN clustering, expectation maximization, Gaussian mixture models, hierarchical clustering, K-means clustering, vector quantization, factor analysis, principal component analysis (PCA), t-SNE dimensionality reduction, and more. It also provides many distance metric classes. From 0.9, the module adds unified interfaces, pipelines, numeric-feature classifiers, ensemble learning, and evaluation utilities (see table below). Runnable examples: Examples/MachineLearning_example/.

Subsystem Namespace / types Description
Interfaces IClassifier<T>, IRegressor<T>, IPreprocessor<T> Unified contracts for classification, regression, preprocessing
Pipelines ClassificationPipeline<T>, RegressionPipeline<T> Preprocessor chain + model
Classification Classfication.*, KnnClassifier, NumericDecisionTree, NumericRandomForest Softmax, KNN, logistic regression, OvR, GNB, numeric trees/forests
Ensembles AdaBoostClassifier<T>, GradientBoostingClassifier<T> SAMME decision stumps, gradient boosting multiclass
Regression Regression.*, KnnRegressor Multivariate linear/ridge regression, KNN regression; MLR/MVR/KnnRegressor implement IBatchRegressor
Preprocessing Preprocessing.* StandardScaler, MinMaxScaler, LabelEncoder, OneHotEncoder
Evaluation EvaluationMetrics, ClassificationMetrics MSE/RMSE/accuracy, confusion matrix, P/R/F1
Utilities DataSplit, CrossValidation, GridSearch, ModelBatchExtensions, IBatchClassifier / IBatchRegressor Split, K-fold CV, grid search, batch prediction
Dimensionality reduction DimensionalityReduction.LDA Linear discriminant analysis
Serialization Serialization.ModelJsonPersistence Scaler / Softmax JSON persistence

Quick examples

Classification pipeline

var pipeline = new ClassificationPipeline<double>()
    .AddPreprocessor(new StandardScaler<double>())
    .SetClassifier(new SoftmaxRegression<double>(learningRate: 0.1, epochs: 2000));
pipeline.Fit(xTrain, yTrain);
int label = pipeline.Predict(sample);

Regression pipeline + K-fold cross-validation

IRegressor<double> model = new MultipleLinearRegression<double>();
var regPipe = new RegressionPipeline<double>()
    .AddPreprocessor(new StandardScaler<double>())
    .SetRegressor(model);
regPipe.Fit(x, y);
double[] yHat = regPipe.PredictBatch(x);

var cv = CrossValidation.ValidateRegressor(
    x, y, folds: 5, seed: 1,
    buildPredictor: (xTr, yTr) =>
    {
        var m = new MultivariateRidgeRegression<double>(0.01);
        m.Fit(xTr, yTr);
        return s => m.Predict(s);
    });

AdaBoost / gradient boosting

var ada = new AdaBoostClassifier<double>(nEstimators: 50);
ada.Fit(xTrain, yTrain);

var gbt = new GradientBoostingClassifier<double>(nEstimators: 50, learningRate: 0.1, maxDepth: 3);
gbt.Fit(xTrain, yTrain);

0.9 classifier walkthrough

The examples below use 2D numeric features and integer class labels (0, 1, 2), consistent with Examples/MachineLearning_example and TESTS/ML_module_test. All classifiers implement IClassifier<T> with Fit(x, y) / Predict(sample).

# Run full classification demo (default)
dotnet run --project Examples/MachineLearning_example

# Regression pipeline demo
dotnet run --project Examples/MachineLearning_example -- regression

Data split

using Vorcyc.Mathematics.MachineLearning;

// x: [samples, features], y: integer class labels
double[,] x = { /* ... */ };
int[] y = { /* ... */ };

var (xTrain, yTrain, xTest, yTest) = DataSplit.TrainTestSplit(x, y, testRatio: 0.25, seed: 7);

Numeric decision tree / random forest

var tree = new NumericDecisionTree<double>(maxDepth: 8);
tree.Fit(xTrain, yTrain);
int label = tree.Predict([2.1, 1.8]);

var forest = new NumericRandomForest<double>(
    numTrees: 80, maxFeatures: 2, maxDepth: 10, seed: 11);
forest.Fit(xTrain, yTrain);
label = forest.Predict([2.1, 1.8]);

Gaussian naive Bayes / KNN

using Vorcyc.Mathematics.MachineLearning.Classfication;

var gnb = new GaussianNaiveBayes<double>();
gnb.Fit(xTrain, yTrain);
label = gnb.Predict([2.1, 1.8]);

// Per-class posterior probabilities (class → probability)
var posteriors = gnb.PredictProbabilities([2.1, 1.8]);

var knn = new KnnClassifier<double>(k: 3);
knn.Fit(xTrain, yTrain);
label = knn.Predict([2.1, 1.8]);

var knnReg = new KnnRegressor<double>(k: 3);
knnReg.Fit(xTrainReg, yTrainReg);
double yHat = knnReg.Predict(sample);
double[] yBatch = knnReg.PredictBatch(xTestReg);

Softmax / logistic regression / one-vs-rest

var softmax = new SoftmaxRegression<double>(learningRate: 0.1, epochs: 2500);
softmax.Fit(xTrain, yTrain);
label = softmax.Predict([2.1, 1.8]);

// Binary classification (labels must be 0 or 1)
var logit = new LogisticRegression<double>(learningRate: 0.05, epochs: 2000);
logit.Fit(xTrainBinary, yTrainBinary);

// Multiclass: trains one binary classifier per class
var ovr = new OneVsRestClassifier<double>(learningRate: 0.1, epochs: 2500);
ovr.Fit(xTrain, yTrain);
label = ovr.Predict([2.1, 1.8]);

Evaluation metrics

// Batch prediction (IBatchClassifier models use optimized paths: trees/forests, GNB, KNN, Softmax, logistic, OvR, pipelines, etc.)
int[] predictions = forest.PredictBatch(xTest);
// Or: var predictions = ModelBatchExtensions.PredictBatch(anyClassifier, xTest);

double accuracy = EvaluationMetrics.Accuracy(yTest, predictions);

var cm = ClassificationMetrics.ConfusionMatrix(yTest, predictions);
double macroF1 = ClassificationMetrics.MacroF1(cm);
double microF1 = ClassificationMetrics.MicroF1(cm);
double precision0 = ClassificationMetrics.Precision(cm, classLabel: 0);

Softmax / Logistic mini-batch training

var softmax = new SoftmaxRegression<double>(
    learningRate: 0.1, epochs: 2000, batchSize: 32, seed: 42);
softmax.Fit(xTrain, yTrain);

var logit = new LogisticRegression<double>(
    learningRate: 0.05, epochs: 2000, batchSize: 32, seed: 42);
logit.Fit(xTrainBinary, yTrainBinary);

K-fold cross-validation

var cv = CrossValidation.Validate(
    x, y,
    folds: 5,
    seed: 21,
    buildPredictor: (xTr, yTr) =>
    {
        var model = new GaussianNaiveBayes<double>();
        model.Fit(xTr, yTr);
        return sample => model.Predict(sample);
    });

Console.WriteLine($"Accuracy: {cv.MeanAccuracy:P1} ± {cv.StdAccuracy:P1}");
Console.WriteLine($"Macro-F1: {cv.MeanMacroF1:F3} ± {cv.StdMacroF1:F3}");

Grid search (hyperparameters)

var candidates = new[]
{
    new { Epochs = 1000, Lr = 0.05 },
    new { Epochs = 2000, Lr = 0.10 }
};

var result = GridSearch.SearchClassifier(
    x, y,
    candidates,
    opt => new SoftmaxRegression<double>(learningRate: opt.Lr, epochs: opt.Epochs),
    folds: 3,
    seed: 5);

// Retrain on full data with best hyperparameters
var bestOpts = result.BestOptions;
var bestModel = new SoftmaxRegression<double>(learningRate: bestOpts.Lr, epochs: bestOpts.Epochs);
bestModel.Fit(x, y);
label = bestModel.Predict([2.1, 1.8]);

JSON persistence (scaler + Softmax)

using Vorcyc.Mathematics.MachineLearning.Preprocessing;
using Vorcyc.Mathematics.MachineLearning.Serialization;

var scaler = new StandardScaler<double>();
scaler.Fit(xTrain);
ModelJsonPersistence.SaveStandardScaler(scaler, "scaler.json");

var xScaled = scaler.Transform(xTrain);
var model = new SoftmaxRegression<double>(learningRate: 0.1, epochs: 2000);
model.Fit(xScaled, yTrain);
ModelJsonPersistence.SaveSoftmaxRegression(model, "softmax.json");

// Inference after load
var loadedScaler = ModelJsonPersistence.LoadStandardScaler("scaler.json");
var loadedModel = ModelJsonPersistence.LoadSoftmaxRegression("softmax.json");
label = loadedModel.Predict(loadedScaler.Transform([2.1, 1.8]));

Linear discriminant analysis (LDA)

using Vorcyc.Mathematics.MachineLearning.DimensionalityReduction;

var lda = new LinearDiscriminantAnalysis<double>(components: 1);
lda.Fit(x, y);
label = lda.Predict([2.1, 1.8]);
var projected = lda.Transform([2.1, 1.8]); // reduced features

All types below are in the namespace Vorcyc.Mathematics.MachineLearning

📒 Contents


Vorcyc.Mathematics.MachineLearning.KNN<T> class

KNN<T> is for incremental K-nearest-neighbor regression (Add / Regress / RegressBatch); for matrix training use KnnRegressor<T> (IRegressor + IBatchRegressor). For classification use KnnClassifier<T>.

Properties

1. Task

  • public MachineLearningTask Task { get; }
    • Fixed to MachineLearningTask.Regression。

Constructors

1. KNN

  • public KNN()
    • Initializes KNN class instance。

Methods

1. Add

  • public void Add(Point<T> point, T target) / Add(ReadOnlySpan<T> features, T target)
    • Adds a regression sample.

2. Regress

  • public T Regress(Point<T> point, int k) / Regress(ReadOnlySpan<T> features, int k, bool distanceWeighted = false)
    • KNN regression on a feature vector; optional distance weighting.

Code example

using Vorcyc.Mathematics.MachineLearning;
using Vorcyc.Mathematics.Numerics;

var knn = new KNN<double>();
knn.Add(new Point<double>(1.0, 0.0), 2.0);
knn.Add(new Point<double>(2.0, 0.0), 4.0);
knn.Add(new Point<double>(3.0, 0.0), 6.0);
double y = knn.Regress(new Point<double>(2.5, 0.0), k: 2);

// Classification
var clf = new KnnClassifier<double>(k: 3);
clf.Fit(xTrain, yTrain);
int label = clf.Predict(sample);

Vorcyc.Mathematics.MachineLearning.MultipleLinearRegression<T> class

MultipleLinearRegression<T> fits multivariate linear regression. The normal equations use Cholesky (LinearEquationSolver.CholeskySolve) when positive definite, otherwise LU.

Properties

1. Coefficients

  • public T[]? Coefficients { get; }
    • Gets regression coefficients.

2. Intercept

  • public T? Intercept { get; }
    • Gets regression intercept.

3. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports regression.

Methods

1. Learn

  • public void Learn(T[,] x, T[] y)
    • Learns coefficients and intercept.
    • Parameters:
      • x: Independent variable matrix.
      • y: Dependent variable vector.

2. Predict

  • public T? Predict(T[] x)
    • Predicts the dependent variable from inputs and coefficients.
    • Parameters:
      • x: Independent variables.
    • Returns: Predicted dependent value.

Code example

The following example uses MultipleLinearRegression<T> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning;

public class MultipleLinearRegressionExample
{
    public static void Main()
    {
        // Independent variable matrix
        double[,] x = new double[,] { { 1, 2 }, { 2, 3 }, { 3, 4 }, { 4, 5 }, { 5, 6 } };
        // Dependent variable vector
        double[] y = new double[] { 2, 3, 5, 7, 11 };

        // Create multiple linear regression instance
        var regression = new MultipleLinearRegression<double>();
        regression.Learn(x, y);

        // Print intercept and coefficients
        Console.WriteLine("Intercept: " + regression.Intercept);
        Console.WriteLine("Coefficients:");
        for (int i = 0; i < regression.Coefficients.Length; i++)
        {
            Console.WriteLine("Coefficient " + (i + 1) + ": " + regression.Coefficients[i]);
        }

        // Predict for new input
        double[] newInput = new double[] { 6, 7 };
        double prediction = regression.Predict(newInput).Value;
        Console.WriteLine("Predicted value for input " + string.Join(", ", newInput) + ": " + prediction);
    }
}

Vorcyc.Mathematics.MachineLearning.SimpleLinearRegression<T> class

SimpleLinearRegression<T> performs simple (univariate) linear regression.

Properties

1. Slope

  • public T? Slope { get; }
    • Gets linear regression slope.

2. Intercept

  • public T? Intercept { get; }
    • Gets linear regression intercept.

3. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports regression.

Methods

1. Learn

  • public (T slope, T intercept) Learn(Point<T>[] data)

    • Computes slope and intercept.
    • Parameters:
      • data: Array of data points.
    • Returns: Tuple of slope and intercept.
  • public (T slope, T intercept) Learn(Span<T> x, Span<T> y)

    • Computes slope and intercept.
    • Parameters:
      • x: Independent variable array.
      • y: Dependent variable array.
    • Returns: Tuple of slope and intercept.

2. GetX

  • public T GetX(T y)
    • Computes x from y, slope, and intercept.
    • Parameters:
      • y: Dependent variable value.
    • Returns: Computed x.

3. GetY

  • public T GetY(T x)
    • Computes y from x, slope, and intercept.
    • Parameters:
      • x: Independent variable value.
    • Returns: Computed y.

Code example

The following example uses SimpleLinearRegression<T> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning;
using static System.Runtime.InteropServices.JavaScript.JSType;
public class SimpleLinearRegressionExample
{
    public static void Main()
    {
        // Data points
        var data = new Point<double>[] { new Point<double>(1.0, 2.0), new Point<double>(2.0, 3.0), new Point<double>(3.0, 5.0), new Point<double>(4.0, 4.0), new Point<double>(5.0, 6.0) };
        // Create simple linear regression instance
        var regression = new SimpleLinearRegression<double>();
        var (slope, intercept) = regression.Learn(data);

        // Print slope and intercept
        Console.WriteLine($"Slope: {slope}, Intercept: {intercept}");

        // Predict y for new x
        var x = 6.0;
        var y = regression.GetY(x);
        Console.WriteLine($"For x = {x}, predicted y = {y}");
    }
}

Vorcyc.Mathematics.MachineLearning.SupportVectorMachine<TSelf> class

SupportVectorMachine<TSelf> is a simple linear SVM with selectable kernels.

Properties

1. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports classification and regression.

Constructors

1. SupportVectorMachine

  • public SupportVectorMachine(int featureCount, TSelf? learningRate = null, int epochs = 1000, SupportVectorMachineKernelType kernelType = SupportVectorMachineKernelType.Linear)
    • Initializes SupportVectorMachine class instance。
    • Parameters:
      • featureCount: Number of input features.
      • learningRate: Learning rate; default 0.01 when null.
      • epochs: Training epochs.
      • kernelType: Kernel type; default linear.

Methods

1. Train

  • public void Train(TSelf[][] inputs, int[] outputs)
    • Trains SVM on provided data.
    • Parameters:
      • inputs: Training inputs (feature arrays).
      • outputs: Output labels.

2. Predict

  • public int Predict(Span<TSelf> input)
    • Predicts class label for input.
    • Parameters:
      • input: Feature array.
    • Returns: Predicted label (1 or -1).

3. PredictRaw

  • private TSelf PredictRaw(TSelf[] input)
    • Raw prediction score.
    • Parameters:
      • input: Feature array.
    • Returns: Raw prediction score.

4. GetKernelFunction

  • private Func<TSelf[], TSelf[], TSelf> GetKernelFunction(SupportVectorMachineKernelType kernelType)
    • Gets the kernel function for the specified type.
    • Parameters:
      • kernelType: Kernel type。
    • Returns: Kernel delegate.

5. LinearKernel

  • private static TSelf LinearKernel(TSelf[] x, TSelf[] y)
    • Linear kernel function.
    • Parameters:
      • x: First input vector。
      • y: Second input vector。
    • Returns: Kernel result.

6. PolynomialKernel

  • private static TSelf PolynomialKernel(TSelf[] x, TSelf[] y)
    • Polynomial kernel function.
    • Parameters:
      • x: First input vector。
      • y: Second input vector。
    • Returns: Kernel result.

7. GaussianKernel

  • private static TSelf GaussianKernel(TSelf[] x, TSelf[] y)
    • Gaussian (RBF) kernel function.
    • Parameters:
      • x: First input vector。
      • y: Second input vector。
    • Returns: Kernel result.

8. SigmoidKernel

  • private static TSelf SigmoidKernel(TSelf[] x, TSelf[] y)
    • Sigmoid kernel function.
    • Parameters:
      • x: First input vector。
      • y: Second input vector。
    • Returns: Kernel result.

Code example

The following example uses SupportVectorMachine<TSelf> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning;
public class SupportVectorMachineExample
{
    public static void Main()
    {
        // Training data
        double[][] inputs = new double[][] { new double[] { 1.0, 2.0 }, new double[] { 2.0, 3.0 }, new double[] { 3.0, 3.0 }, new double[] { 6.0, 5.0 }, new double[] { 7.0, 8.0 } };
        int[] outputs = new int[] { 1, 1, -1, -1, 1 };
        // Create SVM instance
        var svm = new SupportVectorMachine<double>(2);

        // Train SVM
        svm.Train(inputs, outputs);

        // Predict label for new input
        double[] newInput = new double[] { 4.0, 4.0 };
        int prediction = svm.Predict(newInput);
        Console.WriteLine($"Prediction for input {string.Join(", ", newInput)}: {prediction}");
    }
}

Vorcyc.Mathematics.MachineLearning.Clustering.DBSCAN<T> class

DBSCAN<T> performs DBSCAN clustering on 2D points.

Properties

1. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports clustering.

Constructors

1. DBSCAN

  • public DBSCAN(Point<T>[] points, T eps, int minPts)
    • Initializes DBSCAN with points, radius, and minimum points.
    • Parameters:
      • points: Points to cluster.
      • eps: Neighborhood radius.
      • minPts: Minimum points to form a cluster.

Methods

1. Cluster

  • public List<List<Point<T>>> Cluster()
    • Runs DBSCAN clustering.
    • Returns: List of clusters (each a list of points).

2. ExpandCluster

  • private void ExpandCluster(Point<T> point, List<Point<T>> neighbors, List<Point<T>> cluster)
    • Expands a cluster.
    • Parameters:
      • point: Current point.
      • neighbors: Neighbors of the current point.
      • cluster: Current cluster.

3. GetNeighbors

  • private List<Point<T>> GetNeighbors(Point<T> point)
    • Gets neighbors of a point.
    • Parameters:
      • point: Current point.
    • Returns: List of neighbors.

Code example

The following example uses DBSCAN<T> with comments:

using System;
using System.Collections.Generic;
using Vorcyc.Mathematics.MachineLearning.Clustering;
public class DBSCANExample
{
    public static void Main()
    { 
        
        // Points
        var points = new Point<double>[] { new Point<double>(1.0, 2.0), new Point<double>(2.0, 2.0), new Point<double>(2.0, 3.0), new Point<double>(8.0, 7.0), new Point<double>(8.0, 8.0), new Point<double>(25.0, 80.0) };
        // Create DBSCAN instance
        var dbscan = new DBSCAN<double>(points, 3.0, 2);

        // Run clustering
        var clusters = dbscan.Cluster();

        // Print clusters
        for (int i = 0; i < clusters.Count; i++)
        {
            Console.WriteLine($"Cluster {i + 1}:");
            foreach (var point in clusters[i])
            {
                Console.WriteLine($"({point.X}, {point.Y})");
            }
        }
    }
}

Vorcyc.Mathematics.MachineLearning.Clustering.ExpectationMaximization<T> class

ExpectationMaximization<T> implements the expectation-maximization (EM) algorithm.

Properties

1. Means

  • public IReadOnlyList<Vector<T>> Means { get; }
    • Gets cluster centers (means).

2. Covariances

  • public IReadOnlyList<Matrix<T>> Covariances { get; }
    • Gets covariance matrices.

3. Weights

  • public IReadOnlyList<T> Weights { get; }
    • Gets weights.

4. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports clustering.

Constructors

1. ExpectationMaximization

  • public ExpectationMaximization(int numClusters)
    • Initializes ExpectationMaximization class instance。
    • Parameters:
      • numClusters: Number of clusters.

Methods

1. Fit

  • public void Fit(List<Vector<T>> data)
    • Fits data with EM.
    • Parameters:
      • data: Data as a list of vectors.

Code example

The following example uses ExpectationMaximization<T> with comments:

using System;
using System.Collections.Generic;
using Vorcyc.Mathematics.MachineLearning.Clustering;
public class ExpectationMaximizationExample
{
    public static void Main()
    { 
        // Data points
        var data = new List<Vector<double>>
        { 
            new Vector<double>(new double[] { 1.0, 2.0 }), 
            new Vector<double>(new double[] { 2.0, 2.0 }), 
            new Vector<double>(new double[] { 2.0, 3.0 }),
            new Vector<double>(new double[] { 8.0, 7.0 }), 
            new Vector<double>(new double[] { 8.0, 8.0 }),
            new Vector<double>(new double[] { 25.0, 80.0 }) 
        };
        // Create EM instance
        var em = new ExpectationMaximization<double>(2);

        // Fit data
        em.Fit(data);

        // Print cluster centers
        Console.WriteLine("Cluster Centers (Means):");
        foreach (var mean in em.Means)
        {
            Console.WriteLine($"({string.Join(", ", mean.Elements)})");
        }

        // Print covariance matrices
        Console.WriteLine("Covariance Matrices:");
        foreach (var covariance in em.Covariances)
        {
            for (int i = 0; i < covariance.Rows; i++)
            {
                for (int j = 0; j < covariance.Columns; j++)
                {
                    Console.Write($"{covariance[i, j]} ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        // Print weights
        Console.WriteLine("Weights:");
        foreach (var weight in em.Weights)
        {
            Console.WriteLine(weight);
        }
    }
}

Vorcyc.Mathematics.MachineLearning.Clustering.GMM<T> class

GMM<T> implements a Gaussian mixture model.

Properties

1. Means

  • public IReadOnlyList<Vector<T>> Means { get; }
    • Gets cluster centers (means).

2. Covariances

  • public IReadOnlyList<Matrix<T>> Covariances { get; }
    • Gets covariance matrices.

3. Weights

  • public IReadOnlyList<T> Weights { get; }
    • Gets weights.

4. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports clustering.

Constructors

1. GMM

  • public GMM(int numComponents, int maxIterations = 100, double tolerance = 1e-6)
    • Initializes GMM class instance。
    • Parameters:
      • numComponents: Number of Gaussian components.
      • maxIterations: Maximum iterations.
      • tolerance: Log-likelihood convergence tolerance.

Methods

1. Fit

  • public void Fit(List<Vector<T>> data)
    • Fits data with GMM.
    • Parameters:
      • data: Data as a list of vectors.

Code example

The following example uses GMM<T> with comments:

using System;
using System.Collections.Generic;
using Vorcyc.Mathematics.MachineLearning.Clustering;
public class GMMExample
{
    public static void Main()
    {
        // Data points
        var data = new List<Vector<double>>
        {
            new Vector<double>(new double[] { 1.0, 2.0 }),
            new Vector<double>(new double[] { 2.0, 2.0 }),
            new Vector<double>(new double[] { 2.0, 3.0 }),
            new Vector<double>(new double[] { 8.0, 7.0 }),
            new Vector<double>(new double[] { 8.0, 8.0 }),
            new Vector<double>(new double[] { 25.0, 80.0 })
        };
        // Create GMM instance
        var gmm = new GMM<double>(2);

        // Fit data
        gmm.Fit(data);

        // Print cluster centers
        Console.WriteLine("Cluster Centers (Means):");
        foreach (var mean in gmm.Means)
        {
            Console.WriteLine($"({string.Join(", ", mean.Elements)})");
        }

        // Print covariance matrices
        Console.WriteLine("Covariance Matrices:");
        foreach (var covariance in gmm.Covariances)
        {
            for (int i = 0; i < covariance.Rows; i++)
            {
                for (int j = 0; j < covariance.Columns; j++)
                {
                    Console.Write($"{covariance[i, j]} ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        // Print weights
        Console.WriteLine("Weights:");
        foreach (var weight in gmm.Weights)
        {
            Console.WriteLine(weight);
        }
    }
}

Vorcyc.Mathematics.MachineLearning.Clustering.HierarchicalClustering<T> class

HierarchicalClustering<T> performs hierarchical clustering on 2D points.

Properties

1. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports clustering.

Constructors

1. HierarchicalClustering

  • public HierarchicalClustering(Point<T>[] points)
    • Initializes HierarchicalClustering with points.
    • Parameters:
      • points: Points to cluster.

Methods

1. Cluster

  • public List<List<Point<T>>> Cluster(int k)
    • Hierarchical clustering until k clusters remain.
    • Parameters:
      • k: Desired number of clusters.
    • Returns: List of clusters (each a list of points).

2. FindClosestClusters

  • private (int cluster1, int cluster2, T minDistance) FindClosestClusters()
    • Finds the two closest clusters.
    • Returns: Indices of closest clusters and distance.

3. AverageLinkage

  • private T AverageLinkage(List<Point<T>> cluster1, List<Point<T>> cluster2)
    • Average linkage distance between two clusters.
    • Parameters:
      • cluster1: First cluster.
      • cluster2: Second cluster.
    • Returns: Average linkage distance between two clusters.

4. Distance

  • private T Distance(Point<T> a, Point<T> b)
    • Computes Euclidean distance between two points.
    • Parameters:
      • a: First point.
      • b: Second point.
    • Returns: Euclidean distance between two points.

Code example

The following example uses HierarchicalClustering<T> with comments:

using System;
using System.Collections.Generic;
using Vorcyc.Mathematics.MachineLearning.Clustering;
public class HierarchicalClusteringExample
{
    public static void Main()
    {
        // Points
        var points = new Point<double>[]
        {
            new Point<double>(1.0, 2.0),
            new Point<double>(2.0, 2.0),
            new Point<double>(2.0, 3.0),
            new Point<double>(8.0, 7.0),
            new Point<double>(8.0, 8.0),
            new Point<double>(25.0, 80.0)
        };
        // Create hierarchical clustering instance
        var hierarchicalClustering = new HierarchicalClustering<double>(points);

        // Run clustering
        var clusters = hierarchicalClustering.Cluster(2);

        // Print clusters
        for (int i = 0; i < clusters.Count; i++)
        {
            Console.WriteLine($"Cluster {i + 1}:");
            foreach (var point in clusters[i])
            {
                Console.WriteLine($"({point.X}, {point.Y})");
            }
        }
    }
}

Vorcyc.Mathematics.MachineLearning.Clustering.KMeansClusterer<T> class

KMeansClusterer<T> implements K-means clustering.

Properties

1. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports clustering.

Constructors

1. KMeansClusterer

  • public KMeansClusterer(T[][] data, int numClusters, int maxIterations, T tolerance)
    • Initializes KMeansClusterer with data, cluster count, max iterations, and tolerance.
    • Parameters:
      • data: Data to cluster.
      • numClusters: Number of clusters.
      • maxIterations: Maximum iterations.
      • tolerance: Convergence tolerance.

Methods

1. Cluster

  • public int[] Cluster()
    • Runs K-means clustering.
    • Returns: Cluster assignment per point.

2. InitClustering

  • private int[] InitClustering(int numData, int numClusters)
    • Initializes cluster assignments.
    • Parameters:
      • numData: Number of data points.
      • numClusters: Number of clusters.
    • Returns: Initial cluster assignments.

3. Allocate

  • private T[][] Allocate(int numRows, int numCols)
    • Allocates a 2D array.
    • Parameters:
      • numRows: Row count.
      • numCols: Column count.
    • Returns: Allocated 2D array.

4. UpdateCentroids

  • private bool UpdateCentroids()
    • Updates centroids.
    • Returns: Whether centroids changed.

5. UpdateClustering

  • private bool UpdateClustering()
    • Updates cluster assignments.
    • Returns: Whether assignments changed.

6. Distance

  • private T Distance(T[] vector1, T[] vector2)
    • Computes Euclidean distance between two vectors.
    • Parameters:
      • vector1: First vector.
      • vector2: Second vector.
    • Returns: Euclidean distance between two vectors.

7. MinIndex

  • private int MinIndex(T[] distances)
    • Index of minimum value in an array.
    • Parameters:
      • distances: Distance array.
    • Returns: Index of minimum.

Code example

The following example uses KMeansClusterer<T> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning.Clustering;
public class KMeansClustererExample
{
    public static void Main()
    {
        // Data points
        var data = new double[][]
        {
            new double[] { 1.0, 2.0 },
            new double[] { 2.0, 2.0 },
            new double[] { 2.0, 3.0 },
            new double[] { 8.0, 7.0 },
            new double[] { 8.0, 8.0 },
            new double[] { 25.0, 80.0 }
        };
        // Create KMeansClusterer instance
        var kMeans = new KMeansClusterer<double>(data, 2, 100, 1e-6);

        // Run clustering
        var clustering = kMeans.Cluster();

        // Print clusters
        for (int i = 0; i < clustering.Length; i++)
        {
            Console.WriteLine($"Data point {i + 1} is in cluster {clustering[i] + 1}");
        }
    }
}

Vorcyc.Mathematics.MachineLearning.Clustering.VectorQuantization<T> class

VectorQuantization<T> implements vector quantization.

Properties

1. Codebook

  • public IReadOnlyList<Vorcyc.Mathematics.LinearAlgebra.Vector<T>> Codebook { get; }
    • Gets codebook.

2. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports clustering.

Constructors

1. VectorQuantization

  • public VectorQuantization(int codebookSize, int dimensions)
    • Initializes VectorQuantization class instance。
    • Parameters:
      • codebookSize: Codebook size.
      • dimensions: Vector dimensions.

Methods

1. Train

  • public List<T> Train(IEnumerable<Vorcyc.Mathematics.LinearAlgebra.Vector<T>> data, int maxIterations = 100)
    • Trains vector quantization model.
    • Parameters:
      • data: Training vectors.
      • maxIterations: Maximum iterations.
    • Returns: Per-iteration errors.

2. Predict

  • public Vorcyc.Mathematics.LinearAlgebra.Vector<T> Predict(Vorcyc.Mathematics.LinearAlgebra.Vector<T> vector)
    • Finds nearest code vector to input.
    • Parameters:
      • vector: Input vector.
    • Returns: Nearest code vector.

3. SaveCodebook

  • public void SaveCodebook(string filePath)
    • Saves codebook to file.
    • Parameters:
      • filePath: File path.

4. LoadCodebook

  • public void LoadCodebook(string filePath)
    • Loads codebook from file.
    • Parameters:
      • filePath: File path.

Code example

The following example uses VectorQuantization<T> with comments:

using System;
using System.Collections.Generic;
using Vorcyc.Mathematics.MachineLearning.Clustering;
using Vorcyc.Mathematics.LinearAlgebra;
using System.Numerics;
public class VectorQuantizationExample
{
    public static void Main()
    {
        // Data points
        var data = new List<Vector<double>> 
        { 
            new Vector<double>(new double[] { 1.0, 2.0 }), 
            new Vector<double>(new double[] { 2.0, 2.0 }),
            new Vector<double>(new double[] { 2.0, 3.0 }),
            new Vector<double>(new double[] { 8.0, 7.0 }),
            new Vector<double>(new double[] { 8.0, 8.0 }), 
            new Vector<double>(new double[] { 25.0, 80.0 }) 
        };
        // Create vector quantization instance
        var vq = new VectorQuantization<double>(2, 2);

        // Train model
        var errors = vq.Train(data);

        // Print training errors
        Console.WriteLine("Training Errors:");
        foreach (var error in errors)
        {
            Console.WriteLine(error);
        }

        // Predict for new vector
        var newVector = new Vector<double>(new double[] { 3.0, 3.0 });
        var nearestCodeVector = vq.Predict(newVector);
        Console.WriteLine($"Nearest code vector to ({string.Join(", ", newVector.Elements)}): ({string.Join(", ", nearestCodeVector.Elements)})");

        // Save codebook
        vq.SaveCodebook("codebook.json");

        // Load codebook
        vq.LoadCodebook("codebook.json");
    }
}

Vorcyc.Mathematics.MachineLearning.DimensionalityReduction.FactorAnalysis<T> class

FactorAnalysis<T> performs factor analysis.

Properties

1. Loadings

  • public Matrix<T> Loadings { get; private set; }
    • Gets factor loadings matrix.

2. Communalities

  • public T[] Communalities { get; private set; }
    • Gets communalities array.

3. SpecificVariances

  • public T[] SpecificVariances { get; private set; }
    • Gets specific variances array.

4. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports dimensionality reduction.

Constructors

1. FactorAnalysis

  • public FactorAnalysis()
    • Initializes FactorAnalysis class instance。

Methods

1. Analyze

  • public void Analyze(Matrix<T> data, int numFactors)
    • Runs factor analysis.
    • Parameters:
      • data: Data matrix (rows = samples, columns = variables).
      • numFactors: Number of factors.

Code example

The following example uses FactorAnalysis<T> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning.DimensionalityReduction;
using Vorcyc.Mathematics.LinearAlgebra;
public class FactorAnalysisExample
{
    public static void Main()
    {
        // Data matrix
        var data = new Matrix<double>(
            new double[,] 
            {
                { 1.0, 2.0, 3.0 }, 
                { 2.0, 3.0, 4.0 }, 
                { 3.0, 4.0, 5.0 }, 
                { 4.0, 5.0, 6.0 }, 
                { 5.0, 6.0, 7.0 } 
            });
        // Create factor analysis instance
        var factorAnalysis = new FactorAnalysis<double>();

        // Run factor analysis
        factorAnalysis.Analyze(data, 2);

        // Print factor loadings
        Console.WriteLine("Factor Loadings:");
        for (int i = 0; i < factorAnalysis.Loadings.Rows; i++)
        {
            for (int j = 0; j < factorAnalysis.Loadings.Columns; j++)
            {
                Console.Write($"{factorAnalysis.Loadings[i, j]} ");
            }
            Console.WriteLine();
        }

        // Print communalities
        Console.WriteLine("Communalities:");
        foreach (var communality in factorAnalysis.Communalities)
        {
            Console.WriteLine(communality);
        }

        // Print specific variances
        Console.WriteLine("Specific Variances:");
        foreach (var specificVariance in factorAnalysis.SpecificVariances)
        {
            Console.WriteLine(specificVariance);
        }
    }
}

Vorcyc.Mathematics.MachineLearning.DimensionalityReduction.PCA<TSelf> class

PCA<TSelf> performs principal component analysis for dimensionality reduction and feature extraction.

Properties

1. Task

  • public MachineLearningTask Task { get; }
    • Task type; supports dimensionality reduction.

Constructors

1. PCA

  • public PCA(TSelf[,] data)
    • Initializes PCA class instance。
    • Parameters:
      • data: Input data (rows = samples, columns = features).

Methods

1. Transform

  • public TSelf[,] Transform()
    • Transforms data to principal components.
    • Returns: Transformed principal components.

2. GetExplainedVarianceRatio

  • public TSelf[] GetExplainedVarianceRatio()
    • Gets explained variance ratios.
    • Returns: Explained variance ratio array.

Code example

The following example uses PCA<TSelf> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning.DimensionalityReduction;
public class PCAExample
{
    public static void Main()
    {
        // Data matrix
        var data = new double[,]
        {
          { 1.0, 2.0, 3.0 },
          { 2.0, 3.0, 4.0 },
          { 3.0, 4.0, 5.0 },
          { 4.0, 5.0, 6.0 },
          { 5.0, 6.0, 7.0 }
        };
        // Create PCA instance
        var pca = new PCA<double>(data);

        // Transform data
        var transformedData = pca.Transform();

        // Print transformed data
        Console.WriteLine("Transformed Data:");
        for (int i = 0; i < transformedData.GetLength(0); i++)
        {
            for (int j = 0; j < transformedData.GetLength(1); j++)
            {
                Console.Write($"{transformedData[i, j]} ");
            }
            Console.WriteLine();
        }

        // Print explained variance ratios
        var explainedVarianceRatio = pca.GetExplainedVarianceRatio();
        Console.WriteLine("Explained Variance Ratio:");
        foreach (var ratio in explainedVarianceRatio)
        {
            Console.WriteLine(ratio);
        }
    }
}

Vorcyc.Mathematics.MachineLearning.DimensionalityReduction.TSNE<T> class

TSNE<T> implements t-SNE for dimensionality reduction and visualization.

Properties

No public properties.

Constructors

1. TSNE

  • public TSNE(int perplexity = 30, int maxIter = 1000, T learningRate = default)
    • Initializes TSNE class instance。
    • Parameters:
      • perplexity: Perplexity.
      • maxIter: Maximum iterations.
      • learningRate: Learning rate.

Methods

1. FitTransform

  • public Matrix<T> FitTransform(Matrix<T> data)
    • Runs t-SNE and returns reduced matrix.
    • Parameters:
      • data: High-dimensional input matrix.
    • Returns: Reduced matrix.

Code example

The following example uses TSNE<T> with comments:

using System;
using Vorcyc.Mathematics.MachineLearning.DimensionalityReduction;
using Vorcyc.Mathematics.LinearAlgebra;
public class TSNEExample
{
    public static void Main()
    {
        // Data matrix
        var data = new Matrix<double>(
            new double[,]
            { 
                { 1.0, 2.0, 3.0 }, 
                { 2.0, 3.0, 4.0 }, 
                { 3.0, 4.0, 5.0 }, 
                { 4.0, 5.0, 6.0 }, 
                { 5.0, 6.0, 7.0 } 
            });
        // Create t-SNE instance
        var tsne = new TSNE<double>();

        // Run t-SNE
        var transformedData = tsne.FitTransform(data);

        // Print reduced data
        Console.WriteLine("Transformed Data:");
        for (int i = 0; i < transformedData.Rows; i++)
        {
            for (int j = 0; j < transformedData.Columns; j++)
            {
                Console.Write($"{transformedData[i, j]} ");
            }
            Console.WriteLine();
        }
    }
}

Distance metric classes

Vorcyc.Mathematics.MachineLearning.Distances.Angular<TSelf> class

Description

Angular distance; the proper metric version of cosine distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static TSelf Similarity(TSelf[] x, TSelf[] y)

    • Gets the similarity between two points.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.ArgMax<TSelf> class

Description

ArgMax distance (L0 distance).

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.BrayCurtis<TSelf> class

Description

Bray–Curtis distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Canberra<TSelf> class

Description

Canberra distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Chebyshev<TSelf> class

Description

Chebyshev distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Cosine<TSelf> class

Description

Cosine distance. For a proper metric, see Angular distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static TSelf Similarity(TSelf[] x, TSelf[] y)

    • Gets the similarity between two points.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Dice<TSelf> class

Description

Dice dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Euclidean<TSelf> class

Description

Euclidean distance metric.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static TSelf Similarity(TSelf[] x, TSelf[] y)

    • Gets the similarity between two points.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Hamming<TSelf> class

Description

Hamming distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Hellinger<TSelf> class

Description

Hellinger distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Jaccard<TSelf> class

Description

Jaccard (index) distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static TSelf Similarity(TSelf[] x, TSelf[] y)

    • Gets the similarity between two points.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Kulczynski<TSelf> class

Description

Kulczynski dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Levenshtein class

Description

Levenshtein distance.

Methods

  • public double Distance(string x, string y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Manhattan<TSelf> class

Description

Manhattan (taxicab or L1) distance.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Matching<TSelf> class

Description

Matching dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Minkowski<TNumber> class

Description

Minkowski distance generalizes Euclidean and Manhattan distance in a normed vector space.

Properties

  • public static TNumber Order { get; set; }
    • Gets or sets Minkowski order p.

Methods

  • public static TNumber Distance(TNumber[] x, TNumber[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.PearsonCorrelation<TSelf> class

Description

Pearson correlation similarity.

Methods

  • public static TSelf Similarity(TSelf[] x, TSelf[] y)
    • Computes the similarity between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.RogersTanimoto<TSelf> class

Description

Rogers–Tanimoto dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.RusselRao<TSelf> class

Description

Russel–Rao dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.SokalMichener<TSelf> class

Description

Sokal–Michener dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.SokalSneath<TSelf> class

Description

Sokal–Sneath dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)
    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.WeightedEuclidean<TSelf> class

Description

Weighted squared Euclidean distance and similarity. Not a metric (violates triangle inequality).

Properties

  • public static TSelf[] Weights { get; set; }
    • Gets or sets per-dimension weights (default all ones).

Methods

  • public static void SetDimensions(int dimensions)

    • Sets Weights to all ones for the given dimension count.
    • Parameters:
      • dimensions: Number of dimensions (columns).
  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static TSelf Similarity(TSelf[] x, TSelf[] y)

    • Gets the similarity between two points.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.WeightedSquareEuclidean<TSelf> class

Description

Weighted squared Euclidean distance and similarity. Not a metric (violates triangle inequality).

Properties

  • public TSelf[] Weights { get; set; }
    • Gets or sets per-dimension weights (default all ones).

Methods

  • public static void SetDimensions(int dimensions)

    • Sets Weights to all ones for the given dimension count.
    • Parameters:
      • dimensions: Number of dimensions (columns).
  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static TSelf Similarity(TSelf[] x, TSelf[] y)

    • Gets the similarity between two points.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Similarity between x and y.

Vorcyc.Mathematics.MachineLearning.Distances.Yule<TSelf> class

Description

Yule dissimilarity.

Methods

  • public static TSelf Distance(TSelf[] x, TSelf[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: Distance between x and y.
  • public static double Distance(int[] x, int[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: double distance between x and y.
  • public static float Distance(float[] x, float[] y)

    • Computes the distance between points x and y.
    • Parameters:
      • x: First point。
      • y: Second point。
    • Returns: float distance between x and y.

Language / 语言: English · 简体中文


Home


首页

Clone this wiki locally