|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
using ANN.Perceptron.ArchiveSerialization;
using ANN.Perceptron.Layers;
namespace ANN.Perceptron.Network
{
public class ConvolutionNetwork : IDisposable, IArchiveSerialization
{
//const
const ulong ULONG_MAX = 0xffffffff;
private CommonLayer[] layers;
private int layerCount;
Size inputDesignedPatternSize;
public List<Char> TagetOutputs { get; set; }
private bool isUnknownOutput;
private Char unknownOuput;
public bool IsUnknownOutput
{
get
{
return isUnknownOutput;
}
set
{
if (isUnknownOutput == value)
return;
isUnknownOutput = value;
}
}
public Char UnknownOuput
{
get
{
return unknownOuput;
}
set
{
if (unknownOuput == value)
return;
unknownOuput = value;
isUnknownOutput = true;
}
}
public CommonLayer[] Layers
{
get
{
return layers;
}
set
{
if (layers == value)
return;
layers = value;
}
}
public int LayerCount
{
get
{
return layerCount;
}
set
{
if (layerCount == value)
return;
layerCount = value;
}
}
public Size InputDesignedPatternSize
{
get
{
return inputDesignedPatternSize;
}
set
{
if (inputDesignedPatternSize == value)
return;
inputDesignedPatternSize = value;
}
}
public ConvolutionNetwork()
{
layers = null;
inputDesignedPatternSize = Size.Empty;
TagetOutputs = null;
isUnknownOutput = false;
unknownOuput = new Char();
}
~ConvolutionNetwork()
{
// In case the client forgets to call
// Dispose , destructor will be invoked for
Dispose(false);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
}
// Free unmanaged objects
}
public void Dispose()
{
Dispose(true);
// Ensure that the destructor is not called
layers = null;
}
public virtual void Serialize(Archive ar)
{
if (ar.IsStoring())
{
//store taget outputs
ar.Write(TagetOutputs.Count);
foreach (var op in TagetOutputs)
{
ar.Write(op);
}
//
ar.Write(layerCount);
ar.Write(inputDesignedPatternSize.Width);
ar.Write(inputDesignedPatternSize.Height);
ar.Write(isUnknownOutput);
if (isUnknownOutput == true)
{
ar.Write(unknownOuput);
}
//read layers' parameters
foreach (var layer in layers)
{
layer.Serialize(ar);
}
}
else
{
//read target outputs
int outputcount = 0;
ar.Read(out outputcount);
TagetOutputs = new List<char>(outputcount);
for (int ii = 0; ii < outputcount; ii++)
{
Char op = new Char();
ar.Read(out op);
TagetOutputs.Add(op);
}
//
//read layer count
int lc = 0;
ar.Read(out lc);
layerCount = lc;
int w, h;
//read input designed patern size
ar.Read(out w);
ar.Read(out h);
inputDesignedPatternSize.Width = w;
inputDesignedPatternSize.Height = h;
//read isunknownoutput
ar.Read(out isUnknownOutput);
if (isUnknownOutput)
{
ar.Read(out unknownOuput);
}
//
layers = new CommonLayer[LayerCount];
CommonLayer prelayer = null;
for (int ii = 0; ii < layerCount; ii++)
{
var layer = new CommonLayer();
layer.Serialize(ar);
layer.PrevLayer = prelayer;
layers[ii] = layer;
prelayer = layer;
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.