Files
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

117 lines
3.4 KiB
C#

// AForge Genetic Library
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © Andrew Kirillov, 2006-2009
// [email protected]
//
namespace Accord.Genetic
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Accord.Compat;
/// <summary>
/// Represents tree node of genetic programming tree.
/// </summary>
///
/// <remarks><para>In genetic programming a chromosome is represented by a tree, which
/// is represented by <see cref="GPTreeChromosome"/> class. The <see cref="GPTreeNode"/>
/// class represents single node of such genetic programming tree.</para>
///
/// <para>Each node may or may not have children. This means that particular node of a genetic
/// programming tree may represent its sub tree or even entire tree.</para>
/// </remarks>
///
[Serializable]
public class GPTreeNode : ICloneable
{
/// <summary>
/// Gene represented by the chromosome.
/// </summary>
public IGPGene Gene;
/// <summary>
/// List of node's children.
/// </summary>
public List<GPTreeNode> Children;
/// <summary>
/// Initializes a new instance of the <see cref="GPTreeNode"/> class.
/// </summary>
///
internal GPTreeNode( ) { }
/// <summary>
/// Initializes a new instance of the <see cref="GPTreeNode"/> class.
/// </summary>
///
public GPTreeNode( IGPGene gene )
{
Gene = gene;
}
/// <summary>
/// Get string representation of the node.
/// </summary>
///
/// <returns>Returns string representation of the node.</returns>
///
/// <remarks><para>String representation of the node lists all node's children and
/// then the node itself. Such node's string representations equals to
/// its reverse polish notation.</para>
///
/// <para>For example, if nodes value is '+' and its children are '3' and '5', then
/// nodes string representation is "3 5 +".</para>
/// </remarks>
///
public override string ToString( )
{
StringBuilder sb = new StringBuilder( );
if ( Children != null )
{
// walk through all nodes
foreach ( GPTreeNode node in Children )
{
sb.Append( node.ToString( ) );
}
}
// add gene value
sb.Append( Gene.ToString( ) );
sb.Append( " " );
return sb.ToString( );
}
/// <summary>
/// Clone the tree node.
/// </summary>
///
/// <returns>Returns exact clone of the node.</returns>
///
public object Clone( )
{
GPTreeNode clone = new GPTreeNode( );
// clone gene
clone.Gene = this.Gene.Clone( );
// clone its children
if ( this.Children != null )
{
clone.Children = new List<GPTreeNode>( );
// clone each child gene
foreach ( GPTreeNode node in Children )
{
clone.Children.Add( (GPTreeNode) node.Clone( ) );
}
}
return clone;
}
}
}