Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
C#
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Properties
.gitignore
App.config
Oryql.csproj
Oryql.sln
Program.cs
README.md
iris.data

README.md

Oryql

KNN

Shoot From The Hip Usage

static void Main(string[] args)
{
    // Load the IRIS dataset with every 10th case as a validation case
    IRIS iris = new IRIS("iris.data", 10);

    // Choose your KNN flavour
    var knn = new KNNEuclideanNeighbourhood(iris.Train);
    //var knn = new KNNAbsoluteNeighbourhood(iris.Train);
    //var knn = new KNNDotNeighbourhood(iris.Train);
    //var knn = new KNNEuclideanKernalEuclideanNeighbourhood(iris.Train);
    //var knn = new KNNEuclideanKernalAbsoluteNeighbourhood(iris.Train);
    //var knn = new KNNEuclideanKernalDotNeighbourhood(iris.Train);
    //var knn = new KNNAbsoluteKernalEuclideanNeighbourhood(iris.Train);
    //var knn = new KNNAbsoluteKernalAbsoluteNeighbourhood(iris.Train);
    //var knn = new KNNAbsoluteKernalDotNeighbourhood(iris.Train);
    //var knn = new KNNDotKernalEuclideanNeighbourhood(iris.Train);
    //var knn = new KNNDotKernalAbsoluteNeighbourhood(iris.Train);
    //var knn = new KNNDotKernalDotNeighbourhood(iris.Train);
    //var knn = new KNNDotNeighbourhood(iris.Train);

    // Iterate through all validation cases
    iris.Validation.AsParallel().ForAll((v) => 
    { 
        // Log the actual classification and the estimated for K=10 (All KNNs conveniently share method signatures)
        Console.WriteLine("Actual:    " + Log(v.Classification) + "\nEstimated: " + Log(knn.Nearest(v, 10)) + "\n"); 
    });

    // Shit that was easy
    Console.WriteLine("Done!");
    Console.ReadLine();
}

Euclidean Distance

double Delta = 0;
for (int v = 0; v < From.Length; v++)
    Delta += Math.Pow(To[v] - From[v], 2);
return Math.Sqrt(Delta);

Absolute Distance

double Delta = 0;
for (int v = 0; v < From.Length; v++)
    Delta += Math.Abs(To[v] - From[v]);
return Delta;

Dot Distance

double Delta = 0;
for (int v = 0; v < From.Length; v++)
    Delta += To[v] * From[v];
return Delta;

Euclidean Kernel

double[] KernelVector = new double[TrainingVectors.Count];
for (int t = 0; t < TrainingVectors.Count; t++)
    KernelVector[t] = DistanceEuclidean(From, TrainingVectors[t]);
return KernelVector;

Absolute Kernel

double[] KernelVector = new double[TrainingVectors.Count];
for (int t = 0; t < TrainingVectors.Count; t++)
    KernelVector[t] = DistanceAbsolute(From, TrainingVectors[t]);
return KernelVector;

Dot Kernel

double[] KernelVector = new double[TrainingVectors.Count];
for (int t = 0; t < TrainingVectors.Count; t++)
    KernelVector[t] = DistanceDot(From, TrainingVectors[t]);
return KernelVector;
Something went wrong with that request. Please try again.