Ejemplo n.º 1
0
        private void CreatePValues(MultilayerPerceptron mlp)
        {
            int uLayersCount = mlp.Layers.Count - 1;
            for (int lidx = 1; lidx < mlp.Layers.Count; lidx++)
            {
                var layer = mlp.Layers[lidx];
                var biases = mlp.Biases[lidx];

                var pWeightValues = new LinkedList<Marshaled<IDeviceArray[]>[]>();

                //// Biases:
                var pWeightValuesOfInput = new Marshaled<IDeviceArray[]>[biases.Size];

                for (int weightIndex = 0; weightIndex < biases.Size; weightIndex++)
                {
                    pWeightValuesOfInput[weightIndex] = mlp.AsMarshaled(new IDeviceArray[uLayersCount]);

                    for (int lidx2 = 0; lidx2 < uLayersCount; lidx2++)
                    {
                        pWeightValuesOfInput[weightIndex].Instance()[lidx2] = mlp.Adapter.DeviceArrayManagement.CreateArray(false, GetULayerSize(lidx2));
                    }
                }

                pWeightValues.AddLast(pWeightValuesOfInput);

                // Weighted conns:
                foreach (var inputConnectedLayer in layer.Layer.GetInputLayers())
                {
                    int inputIndex = mlp.GetLayerIndex(inputConnectedLayer);
                    var key = Tuple.Create(inputIndex, lidx);
                    var weigths = mlp.Weights[key];

                    pWeightValuesOfInput = new Marshaled<IDeviceArray[]>[weigths.Size];

                    for (int weightIndex = 0; weightIndex < weigths.Size; weightIndex++)
                    {
                        pWeightValuesOfInput[weightIndex] = mlp.AsMarshaled(new IDeviceArray[uLayersCount]);
                        for (int lidx2 = 0; lidx2 < uLayersCount; lidx2++)
                        {
                            pWeightValuesOfInput[weightIndex].Instance()[lidx2] = mlp.Adapter.DeviceArrayManagement.CreateArray(false, GetULayerSize(lidx2));
                        }
                    }

                    pWeightValues.AddLast(pWeightValuesOfInput);
                }

                this.pWeightValues.Add(pWeightValues.ToArray());
            }
        }
Ejemplo n.º 2
0
        internal RTLR(MultilayerPerceptron mlp)
        {
            Debug.Assert(mlp != null);

            this.mlp = mlp;
            this.netValueDerivates = mlp.AsMarshaled(mlp.NetValueDerivates.Values.ToArray());
            this.inputLayerInfos = mlp.AsMarshaled(
                (from lidx in Enumerable.Range(1, mlp.Layers.Count - 1)
                 let layer = mlp.Layers[lidx].Layer
                 select (from inputLayer in layer.GetInputLayers()
                         let iidx = mlp.GetLayerIndex(inputLayer)
                         select new RTLRLayerInfo
                         {
                             Index = iidx - 1,
                             Size = inputLayer.Size,
                             Weights = mlp.Weights[Tuple.Create(iidx, lidx)],
                             IsElementOfU = inputLayer != mlp.Layers[0].Layer
                         }).ToArray()).ToArray());

            CreatePValues();
        }