Included open-source Accord.net library code natively to the solution given the deprecated state of that project. Accord.net will be supported inside Jube for own needs (such as upgrading to .Net 7+). Accord.net libraries modified to compile to .Net 6. Modified Accord.net libraries to better support Newtonsoft Json.net serialisation. Included annotations in the Accord.net libraries to house important dependency statistics. Serialised json can be used independently of Jube to recall a Neural Network. Removal of Binary Serializer totally as a precursor to the projects support of .Net 7+. Extensive bug fixing in crucial functions of Neural Network training and recall. While this part of the system remains in Alpha, it is substantially more fit for purpose.
358 lines
10 KiB
Plaintext
358 lines
10 KiB
Plaintext
<#@ template debug="false" hostspecific="true" language="C#" #>
|
|
<#@ output extension="Generated.cs" #>
|
|
<#@ assembly name="EnvDTE" #>
|
|
<#@ assembly name="System.Core" #>
|
|
<#@ assembly name="Microsoft.VisualStudio.Shell.11.0" #>
|
|
<#@ assembly name="Microsoft.VisualStudio.Shell.Interop" #>
|
|
<#@ import namespace="EnvDTE" #>
|
|
<#@ import namespace="System.Linq" #>
|
|
<#@ import namespace="System.Text" #>
|
|
<#@ import namespace="System.Collections.Generic" #>
|
|
<#@ import namespace="Microsoft.VisualStudio.Shell" #>
|
|
<#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
|
|
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
|
|
<#@ include file="T4Toolbox.tt" #>
|
|
// Accord Math Library
|
|
// The Accord.NET Framework
|
|
// http://accord-framework.net
|
|
//
|
|
// Copyright © César Souza, 2009-2017
|
|
// cesarsouza at gmail.com
|
|
//
|
|
// This library is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
// License as published by the Free Software Foundation; either
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this library; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
//
|
|
|
|
// ======================================================================
|
|
// This code has been generated by a tool; do not edit manually. Instead,
|
|
// edit the T4 template Distance.tt so this file can be regenerated.
|
|
// ======================================================================
|
|
|
|
namespace Accord.Math
|
|
{
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using Accord;
|
|
using Accord.Math.Distances;
|
|
using Accord.Math.Decompositions;
|
|
|
|
/// <summary>
|
|
/// Static class Distance. Defines a set of methods defining distance measures.
|
|
/// </summary>
|
|
///
|
|
public static partial class Norm
|
|
{
|
|
<#
|
|
string[] types =
|
|
{
|
|
"float", "double",
|
|
// "decimal",
|
|
};
|
|
|
|
foreach (string a in types)
|
|
{
|
|
|
|
#>
|
|
/// <summary>
|
|
/// Gets the square root of the sum of squares for all elements in a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> Frobenius(this <#=a#>[,] a)
|
|
{
|
|
return Euclidean(a);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the square root of the sum of squares for all elements in a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> Frobenius(this <#=a#>[][] a)
|
|
{
|
|
return Euclidean(a);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> SquareEuclidean(this <#=a#>[,] a)
|
|
{
|
|
<#=a#> sum = 0;
|
|
foreach (var v in a)
|
|
sum += v * v;
|
|
return sum;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> SquareEuclidean(this <#=a#>[][] a)
|
|
{
|
|
<#=a#> sum = 0;
|
|
|
|
for (int j = 0; j < a.Length; j++)
|
|
{
|
|
for (int i = 0; i < a[j].Length; i++)
|
|
{
|
|
var v = a[j][i];
|
|
sum += v * v;
|
|
}
|
|
}
|
|
|
|
return sum;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm for a vector.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> SquareEuclidean(this <#=a#>[] a)
|
|
{
|
|
<#=a#> sum = 0;
|
|
|
|
for (int j = 0; j < a.Length; j++)
|
|
{
|
|
var v = a[j];
|
|
sum += v * v;
|
|
}
|
|
|
|
return sum;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm for a vector.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> SquareEuclidean(this Sparse<<#=a#>> a)
|
|
{
|
|
<#=a#> sum = 0;
|
|
|
|
for (int j = 0; j < a.Length; j++)
|
|
{
|
|
var v = a.Values[j];
|
|
sum += v * v;
|
|
}
|
|
|
|
return sum;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm vector for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#>[] SquareEuclidean(this <#=a#>[,] a, int dimension)
|
|
{
|
|
int rows = a.Rows();
|
|
int cols = a.Columns();
|
|
|
|
<#=a#>[] norm;
|
|
|
|
if (dimension == 0)
|
|
{
|
|
norm = new <#=a#>[cols];
|
|
for (int j = 0; j < norm.Length; j++)
|
|
{
|
|
<#=a#> sum = 0;
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
var v = a[i, j];
|
|
sum += v * v;
|
|
}
|
|
norm[j] = sum;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
norm = new <#=a#>[rows];
|
|
for (int i = 0; i < norm.Length; i++)
|
|
{
|
|
<#=a#> sum = 0;
|
|
for (int j = 0; j < cols; j++)
|
|
{
|
|
var v = a[i, j];
|
|
sum += v * v;
|
|
}
|
|
norm[i] = sum;
|
|
}
|
|
}
|
|
|
|
return norm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm vector for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#>[] SquareEuclidean(this <#=a#>[][] a, int dimension)
|
|
{
|
|
int rows = a.Rows();
|
|
int cols = a.Columns();
|
|
|
|
<#=a#>[] norm;
|
|
|
|
if (dimension == 0)
|
|
{
|
|
norm = new <#=a#>[cols];
|
|
for (int j = 0; j < norm.Length; j++)
|
|
{
|
|
<#=a#> sum = 0;
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
var v = a[i][j];
|
|
sum += v * v;
|
|
}
|
|
norm[j] = sum;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
norm = new <#=a#>[rows];
|
|
for (int i = 0; i < norm.Length; i++)
|
|
{
|
|
<#=a#> sum = 0;
|
|
for (int j = 0; j < a[i].Length; j++)
|
|
{
|
|
var v = a[i][j];
|
|
sum += v * v;
|
|
}
|
|
norm[i] = sum;
|
|
}
|
|
}
|
|
|
|
return norm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Squared Euclidean norm vector for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#>[] SquareEuclidean(this Sparse<<#=a#>>[] a, int dimension)
|
|
{
|
|
int rows = a.Rows();
|
|
int cols = a.Columns();
|
|
|
|
<#=a#>[] norm;
|
|
|
|
if (dimension == 0)
|
|
{
|
|
norm = new <#=a#>[cols];
|
|
for (int j = 0; j < norm.Length; j++)
|
|
{
|
|
<#=a#> sum = 0;
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
var v = a[i][j];
|
|
sum += v * v;
|
|
}
|
|
norm[j] = sum;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
norm = new <#=a#>[rows];
|
|
for (int i = 0; i < norm.Length; i++)
|
|
{
|
|
<#=a#> sum = 0;
|
|
for (int j = 0; j < a[i].Values.Length; j++)
|
|
{
|
|
var v = a[i].Values[j];
|
|
sum += v * v;
|
|
}
|
|
norm[i] = sum;
|
|
}
|
|
}
|
|
|
|
return norm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> Euclidean(this <#=a#>[,] a)
|
|
{
|
|
return (<#=a#>)Math.Sqrt(SquareEuclidean(a));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> Euclidean(this <#=a#>[][] a)
|
|
{
|
|
return (<#=a#>)Math.Sqrt(SquareEuclidean(a));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> Euclidean(this Sparse<<#=a#>> a)
|
|
{
|
|
return (<#=a#>)Math.Sqrt(SquareEuclidean(a));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a vector.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#> Euclidean(this <#=a#>[] a)
|
|
{
|
|
return (<#=a#>)Math.Sqrt(SquareEuclidean(a));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#>[] Euclidean(this <#=a#>[,] a, int dimension)
|
|
{
|
|
var norm = Norm.SquareEuclidean(a, dimension);
|
|
for (int i = 0; i < norm.Length; i++)
|
|
norm[i] = (<#=a#>)System.Math.Sqrt(norm[i]);
|
|
return norm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#>[] Euclidean(this <#=a#>[][] a, int dimension)
|
|
{
|
|
var norm = Norm.SquareEuclidean(a, dimension);
|
|
for (int i = 0; i < norm.Length; i++)
|
|
norm[i] = (<#=a#>)System.Math.Sqrt(norm[i]);
|
|
return norm;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Euclidean norm for a matrix.
|
|
/// </summary>
|
|
///
|
|
public static <#=a#>[] Euclidean(this Sparse<<#=a#>>[] a, int dimension)
|
|
{
|
|
var norm = Norm.SquareEuclidean(a, dimension);
|
|
for (int i = 0; i < norm.Length; i++)
|
|
norm[i] = (<#=a#>)System.Math.Sqrt(norm[i]);
|
|
return norm;
|
|
}
|
|
<#
|
|
}
|
|
#>
|
|
}
|
|
}
|