// T, string, object, object // CurrentTypeInstance , CurrentPropertyName, CurrentPropertyValue, ConvertedValue public static DataShape ToShapedData <T>(this IEnumerable <T> dataToShape, string fields, bool ignoreCase = true, Func <T, string, object, object> converter = null) { var result = new Dictionary <string, object>(); if (dataToShape == null) { return(null); } var propertyInfoList = GetPropertyInfos <T>(fields, ignoreCase); var list = dataToShape.Select(line => { var data = new Dictionary <string, object>(); data.FillDictionary(line, propertyInfoList, converter); return(data); }).Where(d => d.Keys.Count > 0).ToList(); var dsh = new DataShape(); var values = new List <List <DataShapeField> >(); foreach (var item in list) { var records = item.Select(x => new DataShapeField() { Key = x.Key, Value = x.Value }).ToList(); values.Add(records); } dsh.Values.AddRange(values); return(dsh); }
public Layer( LayerType type, int order, DataShape dataSize, ActivationType activationType, float activationThreshold = 0.5f) { this.layerType = type; this.dataShape = dataSize; switch (activationType) { case ActivationType.RelU: this.activationFunc = new ActivationRelu(); break; case ActivationType.Sigma: this.activationFunc = new ActivationSigmoid(activationThreshold); break; case ActivationType.Step: this.activationFunc = new ActivationStep(activationThreshold); break; } this.layerOrder = order; this.neurons = new List <Neuron[, ]>(); this.layerName = this.layerType + "_" + order; //this.AddNeurons(); }
public LayerInput( DataShape size, ActivationType activationType = ActivationType.RelU) : base(LayerType.Input, 1, activationType) { this.layerName = "Input"; this.dataShape = size; this.AddNeurons(); }
public static DataShape ConvertToDataShape(Shape shape) { DataShape dataShape = new DataShape(); dataShape.gridPosition = ConvertToDataVector(shape.gridPosition); dataShape.blocks = ConvertToDataBlocks(shape.blocks); dataShape.stateRelativePostions = ConvertToDataVectors(shape.stateRelativePositions[shape.currentShapeIndex]); return(dataShape); }
public override DataShape GetOutputShape() { var shape = new DataShape(); shape.NumberOfDimensions = this.dataShape.NumberOfDimensions; shape.Width = preserveSizeAfterConv ? this.dataShape.Width : this.dataShape.Width - this.kernelSize / 2; shape.Height = preserveSizeAfterConv ? this.dataShape.Height : this.dataShape.Height - this.kernelSize / 2; return(shape); }
private void GeneratePositions() { var points = DataShape.GetHexPoints(); Positions = new Position[points.Length]; for (var index = 0; index < points.Length; index++) { var i = points[index]; Positions[index] = new Position(i); } OnCreateBoard(); }
public static ObservableCollection <PointF> Create(DataShape shape, int npts, float max = 100) { var pts = new PointF[npts]; Func <int, PointF> f = null; switch (shape) { case DataShape.Line: f = (i) => new PointF(i, i); break; case DataShape.Sin: f = (i) => new PointF(i, (float)Math.Sin(0.1 * i)); break; case DataShape.Random: f = (i) => new PointF(i, (int)(rnd.NextDouble() * max)); break; case DataShape.Ellipse: f = (i) => new PointF((float)Math.Sin((2 * Math.PI * i) / npts), (float)Math.Cos((2 * Math.PI * i) / npts)); break; case DataShape.Spiral: f = (i) => new PointF(i * (float)Math.Sin((4 * Math.PI * i) / npts), i * (float)Math.Cos((4 * Math.PI * i) / npts)); break; case DataShape.Grid: var l = (int)Math.Sqrt(npts); f = (i) => new PointF(i % l, (int)(i / l)); break; } for (var i = 0; i < npts; i++) { pts[i] = f(i); } return(new ObservableCollection <PointF>(pts)); }
public static Point[] Create(DataShape shape, int npts) { var pts = new Point[npts]; Func <int, Point> f = null; switch (shape) { case DataShape.Line: f = (i) => new Point(i, i); break; case DataShape.Sin: f = (i) => new Point(i, (float)Math.Sin(0.1 * i)); break; case DataShape.Random: f = (i) => new Point(i, (float)rnd.NextDouble() * 100); break; case DataShape.Ellipse: f = (i) => new Point((float)Math.Sin((2 * Math.PI * i) / npts), (float)Math.Cos((2 * Math.PI * i) / npts)); break; case DataShape.Spiral: f = (i) => new Point(i * (float)Math.Sin((4 * Math.PI * i) / npts), i * (float)Math.Cos((4 * Math.PI * i) / npts)); break; case DataShape.Grid: var l = (int)Math.Sqrt(npts); f = (i) => new Point(i % l, (int)(i / l)); break; } for (var i = 0; i < npts; i++) { pts[i] = f(i); } return(pts); }
public LayerConvolution( int order, int numberOfKernels, int kernelSize, bool preserveSizeAfterConvolution, DataShape layerSize, ActivationType activationType = ActivationType.RelU, float activationThreshold = 0.5f) : base(LayerType.Convolution2D, order, activationType) { this.dataShape = layerSize; this.preserveSizeAfterConv = preserveSizeAfterConvolution; this.numberOfKernels = numberOfKernels; this.kernelSize = kernelSize; this.AddNeurons(); this.kernels = new List <Kernel>(); this.Generatekernels(); }
public override bool Equals(object obj) { try { if (!(obj is DataShape)) { return(false); } DataShape d = (DataShape)obj; if (!gridPosition.Equals(d.gridPosition)) { return(false); } for (int i = 0; i < blocks.Count; i++) { if (!blocks[i].Equals(d.blocks[i])) { return(false); } } for (int i = 0; i < stateRelativePostions.Count; i++) { if (!stateRelativePostions[i].Equals(d.stateRelativePostions[i])) { return(false); } } return(true); } catch { return(false); } }
public void AddLayer( LayerType layerType, int layerOrder = -1, DataShape shape = null, /*Convolution parameters*/ int convolution_numberOfKernels = 64, int convolution_kernelSize = 3, bool convolution_preserveSizeAfterConvolution = true, /*Pooling parameters*/ PoolingType poolingType = PoolingType.Max, /*UnPooling Layer parameters*/ UnPoolingType unPoolingType = UnPoolingType.ExactLocation, /*Fully Connected parameters*/ int fullyConnected_numberOfNeurons = 512, ActivationType activationType = ActivationType.RelU, float activationThreshold = 0.5f) { /*Validate if Input layer exist. This layer is added manually - before adding any other layers. It's important to define the Size of the Data. Input layer should with order = 1*/ if (layerType == LayerType.Input) { /*Shape should be specified when calling 'AddLayer' function*/ this.layers.Add(new LayerInput(shape)); } else if (ValidateInputLayer()) { /*If layer order is not provided -get last layer and increase with 1*/ if (layerOrder == -1) { layerOrder = this.layers[this.layers.Count - 1].layerOrder + 1; } /*Get previous layer Datashape*/ var previousLayerShape = (from t in this.layers where t.layerOrder == layerOrder - 1 select t.GetOutputShape()).FirstOrDefault(); /*Get number of inputs*/ var inputs = this.GetInputs(layerOrder); var numberOfItems_previousLayer = inputs.Count;//GetnumberOfInputs(layerOrder); /*Get previous layer dataShape*/ /*Add layer -connect neurons with synapses from previous layer to the current one*/ for (int i = 0; i < numberOfItems_previousLayer; i++) { Layer currentLayer = null; switch (layerType) { case LayerType.Convolution2D: currentLayer = new LayerConvolution( layerOrder, convolution_numberOfKernels, convolution_kernelSize, convolution_preserveSizeAfterConvolution, previousLayerShape, activationType, activationThreshold); break; case LayerType.Pooling: /*Construct new Pooling layer*/ break; } this.ConnectLayerToPrevious(inputs[i], currentLayer); this.layers.Add(currentLayer); } } }
public static Shape ConvertToOnlineShape(DataShape dataShape) { OnlineShape onlineShape = new OnlineShape(ConvertToVector(dataShape.gridPosition), ConvertToBlocks(dataShape.blocks), ConvertToVectors(dataShape.stateRelativePostions)); return(onlineShape); }