Files
jube-fork/Accord.Math/Vector/Vector.Interval.tt
richard-churchman cc0a2bee21 Extensive modifications to the serialisation of Neural Network models to support Newtonsoft Json.net rather than Binary Serializer.
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.
2023-12-24 10:22:22 +01:00

225 lines
6.2 KiB
Plaintext

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension="Generated.cs" #>
<#@ 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 Vector.Interval.tt so this file can be regenerated.
// ======================================================================
namespace Accord.Math
{
using System;
using Accord.Math;
public static partial class Vector
{
<#
Func<string, bool> isWhole = (s) =>
{
switch (s)
{
case "int":
case "short":
case "byte":
case "sbyte":
case "long":
case "ulong":
case "ushort":
return true;
case "float":
case "double":
case "decimal":
return false;
}
throw new Exception("Unexpected type.");
};
string remarks = @" ///
/// <remarks>
/// <para>
/// The Range methods should be equivalent to NumPy's np.linspace function. For
/// a similar method that accepts a step size instead of a number of steps, see
/// <see cref=""Vector.Range(int, int)""/>.</para>
/// </remarks>
///
/// <seealso cref=""Vector.Range(int, int)""/>
///";
string[] types = { "int", "float", "double", "short", "byte", "sbyte", "long", "decimal", "ulong", "ushort" };
foreach (string i in types)
{
string s = null;
if (isWhole(i))
s = "double";
if (i == "float")
s = "double";
if (i == "decimal")
s = "decimal";
if (i == "double")
s = "double";
#>
/// <summary>
/// Creates an interval vector (like NumPy's linspace function).
/// </summary>
<#=remarks#>
public static <#=i#>[] Interval(<#=i#> a, <#=i#> b)
{
<#
if (isWhole(i))
{
#>
if (a < b)
return Interval(a, b, steps: (int)(b - a) + 1);
return Interval(a, b, steps: (int)(a - b) + 1);
<#
}
else
{
#>
return Interval(a, b, steps: (int)Math.Ceiling(Math.Abs(a - b)));
<#
}
#>
}
/// <summary>
/// Obsolete. Please use Vector.Range(a, b, stepSize) instead.
/// </summary>
[Obsolete("Please use Vector.Range(a, b, stepSize) instead.")]
public static <#=i#>[] Interval(<#=i#> a, <#=i#> b, <#=s#> stepSize)
{
if (a == b)
return new [] { a };
<#=i#>[] r;
if (a > b)
{
int steps = (int)System.Math.Ceiling((a - b) / (<#=s#>)stepSize) + 1;
r = new <#=i#>[steps];
for (uint i = 0; i < r.Length; i++)
r[i] = (<#=i#>)(a - i * stepSize);
r[steps - 1] = (<#=i#>)(b);
}
else
{
int steps = (int)System.Math.Ceiling((b - a) / (<#=s#>)stepSize) + 1;
r = new <#=i#>[steps];
for (uint i = 0; i < r.Length; i++)
r[i] = (<#=i#>)(a + i * stepSize);
r[steps - 1] = (<#=i#>)(b);
}
return r;
}
/// <summary>
/// Creates an interval vector (like NumPy's linspace function).
/// </summary>
<#=remarks#>
public static <#=i#>[] Interval(<#=i#> a, <#=i#> b, int steps, bool includeLast = true)
{
if (steps < 0)
throw new ArgumentOutOfRangeException("steps", "The number of steps must be positive.");
if (steps == 0)
return new <#=i#>[] { };
if (steps == 1)
return new <#=i#>[] { a };
if (a == b)
return Vector.Create(size: steps, value: a);
<#=i#>[] r = new <#=i#>[steps];
<#=s#> length;
if (includeLast)
{
length = ((<#=i#>)(steps - 1));
}
else
{
length = ((<#=i#>)(steps));
}
if (a > b)
{
var stepSize = (<#=s#>)((a - b) / length);
for (uint i = 0; i < r.Length; i++)
r[i] = (<#=i#>)(a - i * stepSize);
}
else
{
var stepSize = (<#=s#>)((b - a) / length);
for (uint i = 0; i < r.Length; i++)
r[i] = (<#=i#>)(a + i * stepSize);
}
if (includeLast)
r[r.Length - 1] = b;
return r;
}
<#
}
string[] ranges = { "DoubleRange", "Range", "ByteRange", "IntRange" };
string[] rtypes = { "double", "float", "byte", "int" };
for (int i = 0; i < ranges.Length; i++)
{
var ri = ranges[i];
var ti = rtypes[i];
#>
/// <summary>
/// Creates an interval vector (like NumPy's linspace function).
/// </summary>
<#=remarks#>
public static <#=ti#>[] Interval(this <#=ri#> range, int steps)
{
return Interval(range.Min, range.Max, steps);
}
/// <summary>
/// Obsolete. Please use Vector.Range(range, stepSize) instead.
/// </summary>
[Obsolete("Please use Vector.Range(range, stepSize) instead.")]
public static <#=ti#>[] Interval(this <#=ri#> range, double stepSize)
{
return Interval(range.Min, range.Max, stepSize);
}
<#
}
#>
}
}