public IMiniBatch Get(IExecutionContext executionContext, IReadOnlyList <int> rows)
        {
            var ret   = new MiniBatch(rows, this);
            int index = 0;

            foreach (var row in _data)
            {
                var type = MiniBatchSequenceType.Standard;
                if (index == 0)
                {
                    type = MiniBatchSequenceType.SequenceStart;
                }
                else if (index == _data.Count - 1)
                {
                    type = MiniBatchSequenceType.SequenceEnd;
                }
                var inputList = new[]
                {
                    new MatrixGraphData(executionContext.LinearAlgebraProvider.CreateVector(row).
                                        ReshapeAsRowMatrix())
                };
                ret.Add(type, inputList, null);
            }

            return(ret);
        }
        public IMiniBatch Get(IExecutionContext executionContext, IReadOnlyList <int> rows)
        {
            var data      = rows.Select(i => _data[i]).ToList();
            var inputData = new Dictionary <int, List <FloatVector> >();

            foreach (var item in data)
            {
                var input = item;
                for (int i = 0, len = input.RowCount; i < len; i++)
                {
                    if (!inputData.TryGetValue(i, out List <FloatVector> temp))
                    {
                        inputData.Add(i, temp = new List <FloatVector>());
                    }
                    temp.Add(input.Row[i]);
                }
            }

            var miniBatch = new MiniBatch(rows, this);

            foreach (var item in inputData.OrderBy(kv => kv.Key))
            {
                var input = _lap.CreateMatrixFromRows(item.Value);
                var type  = (item.Key == 0) ? MiniBatchSequenceType.SequenceStart :
                            item.Key == (inputData.Count - 1) ? MiniBatchSequenceType.SequenceEnd :
                            MiniBatchSequenceType.Standard;
                var inputList = new List <IGraphData> {
                    new MatrixGraphData(input)
                };
                miniBatch.Add(type, inputList, null);
            }

            return(miniBatch);
        }
Esempio n. 3
0
        public override IMiniBatch Get(IExecutionContext executionContext, IReadOnlyList <int> rows)
        {
            var data = _GetRows(rows)
                       .Select(r => ((FloatVector)r.Data[_dataColumnIndex[0]], (FloatMatrix)r.Data[_dataTargetIndex]))
                       .ToList()
            ;
            var outputData = new Dictionary <int, List <FloatVector> >();

            foreach (var item in data)
            {
                var input  = item.Item1;
                var output = item.Item2;
                for (int i = 0, len = output.RowCount; i < len; i++)
                {
                    if (!outputData.TryGetValue(i, out List <FloatVector> temp))
                    {
                        outputData.Add(i, temp = new List <FloatVector>());
                    }
                    temp.Add(output.Row[i]);
                }
            }

            var miniBatch = new MiniBatch(rows, this);
            var curr      = _lap.CreateMatrix(data.Count, InputSize, (x, y) => data[x].Item1.Data[y]);

            foreach (var item in outputData.OrderBy(kv => kv.Key))
            {
                var output = _lap.CreateMatrix(item.Value);
                var type   = (item.Key == 0)
                    ? MiniBatchSequenceType.SequenceStart
                    : item.Key == (outputData.Count - 1)
                        ? MiniBatchSequenceType.SequenceEnd
                        : MiniBatchSequenceType.Standard
                ;
                var inputList = new List <IGraphData> {
                    new MatrixGraphData(curr)
                };
                miniBatch.Add(type, inputList, new MatrixGraphData(output));
                curr = output;
            }
            return(miniBatch);
        }