Example #1
0
        /// <summary>
        /// Convert the data to suitable type trainer supports
        /// </summary>
        /// <param name="args"> data being converted</param>
        /// <returns></returns>
        private UnorderedMapVariableMinibatchData prepareForTrainerEx(UnorderedMapStreamInformationMinibatchData args, bool cloneData)
        {
            // var d = new Dictionary<Variable, MinibatchData>();
            var d = new UnorderedMapVariableMinibatchData();

            for (int i = 0; i < args.Count; i++)
            {
                var k = args.ElementAt(i);

                var var = InputVariables.Union(OutputVariables).Where(x => x.Name.Equals(k.Key.m_name)).FirstOrDefault();
                if (var == null)
                {
                    throw new Exception("Variable doesn't exist!");
                }

                //clone data first
                var           key    = k.Key;
                MinibatchData mbData = null;
                if (cloneData)
                {
                    mbData = new MinibatchData(k.Value.data.DeepClone(), k.Value.numberOfSequences, k.Value.numberOfSamples, k.Value.sweepEnd);
                }
                else
                {
                    mbData = k.Value;
                }
                d.Add(var, mbData);
            }

            return(d);
        }
Example #2
0
        void AssignDataFromMinibatch(IDictionary <Variable, Value> minibatch,
                                     UnorderedMapVariableMinibatchData inputMap,
                                     int batchSize)
        {
            foreach (var kvp in minibatch)
            {
                var variable = kvp.Key;
                var value    = kvp.Value;

                inputMap.Add(variable, new MinibatchData(value, (uint)batchSize));
            }
        }
Example #3
0
        /// <summary>
        /// Convert minibatch data
        /// </summary>
        /// <param name="args"> data being converted</param>
        /// <returns></returns>
        public static UnorderedMapVariableMinibatchData ToMinibatchData(UnorderedMapStreamInformationMinibatchData args, List <Variable> vars, MinibatchType type)
        {
            var arguments = new UnorderedMapVariableMinibatchData();

            foreach (var mbd in args)
            {
                var v = vars.Where(x => x.Name == mbd.Key.m_name).FirstOrDefault();
                if (v == null)
                {
                    throw new Exception("Stream is invalid!");
                }
                if (type == MinibatchType.Custom)
                {
                    var mbd1 = new MinibatchData(mbd.Value.data.DeepClone(), mbd.Value.numberOfSamples, mbd.Value.sweepEnd);
                    arguments.Add(v, mbd1);
                }

                else
                {
                    arguments.Add(v, mbd.Value);
                }
            }
            return(arguments);
        }