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.
179 lines
5.6 KiB
C#
179 lines
5.6 KiB
C#
// Accord Machine Learning 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
|
|
//
|
|
|
|
namespace Accord.MachineLearning
|
|
{
|
|
using Accord.MachineLearning.Performance;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using Accord.Compat;
|
|
|
|
/// <summary>
|
|
/// Contains the name and value of a parameter that should be used during fitting.
|
|
/// </summary>
|
|
///
|
|
/// <seealso cref="GridSearch"/>
|
|
///
|
|
[Serializable]
|
|
public struct GridSearchParameter
|
|
{
|
|
private string name;
|
|
private double value;
|
|
|
|
/// <summary>
|
|
/// Gets the name of the parameter
|
|
/// </summary>
|
|
///
|
|
public string Name { get { return name; } }
|
|
|
|
/// <summary>
|
|
/// Gets the value of the parameter.
|
|
/// </summary>
|
|
///
|
|
public double Value { get { return value; } }
|
|
|
|
/// <summary>
|
|
/// Constructs a new parameter.
|
|
/// </summary>
|
|
///
|
|
/// <param name="name">The name for the parameter.</param>
|
|
/// <param name="value">The value for the parameter.</param>
|
|
///
|
|
public GridSearchParameter(string name, double value)
|
|
{
|
|
this.name = name;
|
|
this.value = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether the specified object is equal
|
|
/// to the current GridSearchParameter object.
|
|
/// </summary>
|
|
///
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj is GridSearchParameter)
|
|
{
|
|
GridSearchParameter g = (GridSearchParameter)obj;
|
|
if (g.name != name || g.value != value)
|
|
return false;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the hash code for this GridSearchParameter
|
|
/// </summary>
|
|
///
|
|
public override int GetHashCode()
|
|
{
|
|
return name.GetHashCode() ^ value.GetHashCode();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compares two GridSearchParameters for equality.
|
|
/// </summary>
|
|
///
|
|
public static bool operator ==(GridSearchParameter parameter1, GridSearchParameter parameter2)
|
|
{
|
|
return (parameter1.name == parameter2.name && parameter1.value == parameter2.value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compares two GridSearchParameters for inequality.
|
|
/// </summary>
|
|
///
|
|
public static bool operator !=(GridSearchParameter parameter1, GridSearchParameter parameter2)
|
|
{
|
|
return (parameter1.name != parameter2.name || parameter1.value != parameter2.value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a <see cref="System.String" /> that represents this instance.
|
|
/// </summary>
|
|
///
|
|
/// <returns>
|
|
/// A <see cref="System.String" /> that represents this instance.
|
|
/// </returns>
|
|
///
|
|
public override string ToString()
|
|
{
|
|
return String.Format("{0}: {1}", name, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Performs an implicit conversion from <see cref="GridSearchParameter"/> to <see cref="System.Double"/>.
|
|
/// </summary>
|
|
///
|
|
/// <param name="param">The parameter to be converted.</param>
|
|
///
|
|
/// <returns>The value of the parameter's <see cref="GridSearchParameter.Value"/>.</returns>
|
|
///
|
|
public static implicit operator double(GridSearchParameter param)
|
|
{
|
|
return param.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Grid search parameter collection.
|
|
/// </summary>
|
|
///
|
|
/// <seealso cref="GridSearch"/>
|
|
///
|
|
[Serializable]
|
|
public class GridSearchParameterCollection : KeyedCollection<string, GridSearchParameter>
|
|
{
|
|
/// <summary>
|
|
/// Constructs a new collection of GridsearchParameter objects.
|
|
/// </summary>
|
|
///
|
|
public GridSearchParameterCollection(params GridSearchParameter[] parameters)
|
|
{
|
|
foreach (GridSearchParameter param in parameters)
|
|
this.Add(param);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructs a new collection of GridsearchParameter objects.
|
|
/// </summary>
|
|
///
|
|
public GridSearchParameterCollection(IEnumerable<GridSearchParameter> parameters)
|
|
{
|
|
foreach (GridSearchParameter param in parameters)
|
|
this.Add(param);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the identifying value for an item on this collection.
|
|
/// </summary>
|
|
///
|
|
protected override string GetKeyForItem(GridSearchParameter item)
|
|
{
|
|
return item.Name;
|
|
}
|
|
}
|
|
|
|
}
|