mirror of
https://github.com/hanzoai/jube-fork.git
synced 2026-10-30 18:33:33 +00:00
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.
201 lines
7.2 KiB
Plaintext
201 lines
7.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.Random.tt so this file can be regenerated.
|
|
// ======================================================================
|
|
|
|
|
|
namespace Accord.Math
|
|
{
|
|
using System;
|
|
using Accord.Math;
|
|
|
|
public static partial class Vector
|
|
{
|
|
|
|
<#
|
|
foreach (string i in new[] { "int", "float", "double", "short", "byte", "sbyte", "long", "decimal", "ulong", "ushort" })
|
|
{
|
|
#>
|
|
|
|
/// <summary>
|
|
/// Returns a vector containing indices (0, 1, 2, ..., n - 1) in random
|
|
/// order. The vector grows up to to <paramref name="size"/>, but does not
|
|
/// include <c>size</c> among its values.
|
|
/// </summary>
|
|
///
|
|
/// <param name="size">The size of the sample vector to be generated.</param>
|
|
///
|
|
/// <example>
|
|
/// <code>
|
|
/// var a = Vector.Sample(3); // a possible output is { 2, 1, 0 };
|
|
/// var b = Vector.Sample(10); // a possible output is { 5, 4, 2, 0, 1, 3, 7, 9, 8, 6 };
|
|
///
|
|
/// foreach (var i in Vector.Sample(5))
|
|
/// {
|
|
/// // ...
|
|
/// }
|
|
/// </code>
|
|
/// </example>
|
|
///
|
|
public static <#=i#>[] Sample(<#=i#> size)
|
|
{
|
|
var random = Accord.Math.Random.Generator.Random;
|
|
|
|
var idx = Vector.Range(size);
|
|
var x = new double[idx.Length];
|
|
for (int i = 0; i < x.Length; i++)
|
|
x[i] = random.NextDouble();
|
|
|
|
Array.Sort(x, idx);
|
|
|
|
return idx;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a vector of the specified <paramref name="sampleSize"/> containing
|
|
/// non-repeating indices in the range [0, populationSize) in random order.
|
|
/// </summary>
|
|
///
|
|
/// <param name="sampleSize">The size of the sample vector to be generated.</param>
|
|
/// <param name="populationSize">The non-inclusive maximum number an index can have.</param>
|
|
///
|
|
/// <remarks>
|
|
/// In other words, this return a sample of size <c>k</c> from a population
|
|
/// of size <c>N</c>, where <c>k</c> is the parameter <paramref name="sampleSize"/>
|
|
/// and <c>N</c> is the parameter <paramref name="populationSize"/>.
|
|
/// </remarks>
|
|
///
|
|
/// <example>
|
|
/// <code>
|
|
/// var a = Vector.Sample(3, 10); // a possible output is { 1, 7, 4 };
|
|
/// var b = Vector.Sample(10, 10); // a possible output is { 5, 4, 2, 0, 1, 3, 7, 9, 8, 6 };
|
|
///
|
|
/// foreach (var i in Vector.Sample(5, 6))
|
|
/// {
|
|
/// // ...
|
|
/// }
|
|
/// </code>
|
|
/// </example>
|
|
///
|
|
public static <#=i#>[] Sample(int sampleSize, <#=i#> populationSize)
|
|
{
|
|
if ((<#=i#>)sampleSize > populationSize)
|
|
{
|
|
throw new ArgumentOutOfRangeException("size", String.Format(
|
|
"The sample size {0} must be less than the size of the population {1}.",
|
|
sampleSize, populationSize));
|
|
}
|
|
|
|
<#=i#>[] idx = Sample(populationSize);
|
|
return idx.First(sampleSize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a vector of the specified <paramref name="percentage"/> of the
|
|
/// <paramref name="populationSize"/> containing non-repeating indices in the
|
|
/// range [0, populationSize) in random order.
|
|
/// </summary>
|
|
///
|
|
/// <param name="percentage">The percentage of the population to sample.</param>
|
|
/// <param name="populationSize">The non-inclusive maximum number an index can have.</param>
|
|
///
|
|
/// <example>
|
|
/// <code>
|
|
/// var a = Vector.Sample(0.3, 10); // a possible output is { 1, 7, 4 };
|
|
/// var b = Vector.Sample(1.0, 10); // a possible output is { 5, 4, 2, 0, 1, 3, 7, 9, 8, 6 };
|
|
///
|
|
/// foreach (var i in Vector.Sample(0.2, 6))
|
|
/// {
|
|
/// // ...
|
|
/// }
|
|
/// </code>
|
|
/// </example>
|
|
///
|
|
public static <#=i#>[] Sample(double percentage, <#=i#> populationSize)
|
|
{
|
|
if (percentage < 0 || percentage > 1)
|
|
{
|
|
throw new ArgumentOutOfRangeException("percentage", String.Format(
|
|
"The sample percentage {0} must be between 0 and 1.", percentage));
|
|
}
|
|
|
|
int sampleSize = (int)System.Math.Floor(percentage * (double)populationSize);
|
|
|
|
<#=i#>[] idx = Sample(populationSize);
|
|
return idx.First(sampleSize);
|
|
}
|
|
<#
|
|
}
|
|
|
|
foreach (string i in new[] { "int", "short", "byte", "sbyte", "long", "ulong", "ushort" })
|
|
{
|
|
#>
|
|
/// <summary>
|
|
/// Creates a vector with uniformly distributed random data.
|
|
/// </summary>
|
|
///
|
|
public static <#=i#>[] Random(int size, <#=i#> min, <#=i#> max)
|
|
{
|
|
if (size < 0)
|
|
throw new ArgumentOutOfRangeException("size", size, "Size must be a positive integer.");
|
|
|
|
var random = Accord.Math.Random.Generator.Random;
|
|
|
|
var vector = new <#=i#>[size];
|
|
for (int i = 0; i < size; i++)
|
|
vector[i] = (<#=i#>)random.Next((int)min, (int)max);
|
|
return vector;
|
|
}
|
|
<#
|
|
}
|
|
|
|
foreach (string i in new[] { "float", "double", "decimal" })
|
|
{
|
|
#>
|
|
/// <summary>
|
|
/// Creates a vector with uniformly distributed random data.
|
|
/// </summary>
|
|
///
|
|
public static <#=i#>[] Random(int size, <#=i#> min, <#=i#> max)
|
|
{
|
|
if (size < 0)
|
|
throw new ArgumentOutOfRangeException("size", size, "Size must be a positive integer.");
|
|
|
|
var random = Accord.Math.Random.Generator.Random;
|
|
|
|
var vector = new <#=i#>[size];
|
|
for (int i = 0; i < size; i++)
|
|
vector[i] = (<#=i#>)random.NextDouble() * (max - min) + min;
|
|
return vector;
|
|
}
|
|
<#
|
|
}
|
|
#>
|
|
}
|
|
} |