Exemplo n.º 1
0
        /// <summary>
        /// Searches for a parameter by name and returns its value as a <i>double</i> if found, or a default <i>double</i> value if not.
        /// </summary>
        /// <param name="strName">Specifies the name to look for.</param>
        /// <param name="dfDefault">Specifies the default value to return if not found.</param>
        /// <returns>The <i>double</i> value of the named parameter is returned if found, otherwise the default <i>double</i> value is returned.</returns>
        public double Find(string strName, double dfDefault)
        {
            string strVal = Find(strName, null);

            if (strVal == null)
            {
                return(dfDefault);
            }

            return(BaseParameter.ParseDouble(strVal));
        }
Exemplo n.º 2
0
        /// <summary>
        /// The ParseConfigurationString method parses a deep draw configuration string into the actual settings.
        /// </summary>
        /// <param name="strConfig">Specifies the configuration string to parse.</param>
        /// <param name="nWd">Returns the input width.</param>
        /// <param name="nHt">Returns the input height.</param>
        /// <param name="dfOutputDetailPct">Returns the percentage of detail to apply to the final image.</param>
        /// <param name="strSrcBlobName">Returns the source blob name.</param>
        /// <param name="dfRandomImageScale">Returns the random image scale to use, a number in the range [0,50] used to create varying degrees of gray in the random input image.
        /// A value of 0 removes the variation and uses a consistent image.  The default value is 16.</param>
        /// <returns>Returns the collection of Octaves to run.</returns>
        public static OctavesCollection ParseConfigurationString(string strConfig, out int nWd, out int nHt, out double dfOutputDetailPct, out string strSrcBlobName, out double dfRandomImageScale)
        {
            RawProto proto = RawProto.Parse(strConfig);
            string   strVal;

            nHt = -1;
            if ((strVal = proto.FindValue("input_height")) != null)
            {
                nHt = int.Parse(strVal);
            }

            nWd = -1;
            if ((strVal = proto.FindValue("input_width")) != null)
            {
                nWd = int.Parse(strVal);
            }

            dfOutputDetailPct = 0.25;
            if ((strVal = proto.FindValue("output_detail_pct")) != null)
            {
                dfOutputDetailPct = BaseParameter.ParseDouble(strVal);
            }

            strSrcBlobName = "data";
            if ((strVal = proto.FindValue("src_blob_name")) != null)
            {
                strSrcBlobName = strVal;
            }

            dfRandomImageScale = 16;
            if ((strVal = proto.FindValue("random_image_scale")) != null)
            {
                dfRandomImageScale = BaseParameter.ParseDouble(strVal);
            }

            OctavesCollection  col   = new OctavesCollection();
            RawProtoCollection rpcol = proto.FindChildren("octave");

            foreach (RawProto protoChild in rpcol)
            {
                col.Add(Octaves.FromProto(protoChild));
            }

            return(col);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load all memory items from file.
        /// </summary>
        /// <param name="strFile">Specifies the file containing the memory items.</param>
        public void Load(string strFile)
        {
            m_nNextIdx = 0;
            m_nCount   = 0;

            List <MemoryItem> rg = new List <MemoryItem>();

            using (StreamReader sr = new StreamReader(strFile))
            {
                string strLine = sr.ReadLine();

                while (strLine != null)
                {
                    string[] rgstr = strLine.Split(',');
                    int      nIdx  = 0;

                    List <double> rgdfData = new List <double>();
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    SimpleDatum sdCurrent = new SimpleDatum(true, 4, 1, 1, -1, DateTime.MinValue, rgdfData, 0, false, -1);

                    int    nAction     = int.Parse(rgstr[nIdx]); nIdx++;
                    double dfReward    = BaseParameter.ParseDouble(rgstr[nIdx]); nIdx++;
                    bool   bTerminated = (int.Parse(rgstr[nIdx]) == 1) ? true : false; nIdx++;

                    rgdfData = new List <double>();
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    rgdfData.Add(BaseParameter.ParseDouble(rgstr[nIdx])); nIdx++;
                    SimpleDatum sdNext = new SimpleDatum(true, 4, 1, 1, -1, DateTime.MinValue, rgdfData, 0, false, -1);

                    rg.Add(new MemoryItem(null, sdCurrent, nAction, null, sdNext, dfReward, bTerminated, 0, 0));
                    strLine = sr.ReadLine();
                }
            }

            foreach (MemoryItem m in rg)
            {
                Add(m);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The FromProto function parses a RawProto into a new Octaves.
        /// </summary>
        /// <param name="rp">Specifies the RawProto to parse.</param>
        /// <returns>The new Octaves is returned.</returns>
        public static Octaves FromProto(RawProto rp)
        {
            string strVal;

            string strLayer = "";

            if ((strVal = rp.FindValue("layer")) != null)
            {
                strLayer = strVal;
            }

            int nIterations = 10;

            if ((strVal = rp.FindValue("iterations")) != null)
            {
                nIterations = int.Parse(strVal);
            }

            double dfSigmaStart = 0;

            if ((strVal = rp.FindValue("sigma_start")) != null)
            {
                dfSigmaStart = BaseParameter.ParseDouble(strVal);
            }

            double dfSigmaEnd = 0;

            if ((strVal = rp.FindValue("sigma_end")) != null)
            {
                dfSigmaEnd = BaseParameter.ParseDouble(strVal);
            }

            double dfStepStart = 1.5;

            if ((strVal = rp.FindValue("step_start")) != null)
            {
                dfStepStart = BaseParameter.ParseDouble(strVal);
            }

            double dfStepEnd = 1.5;

            if ((strVal = rp.FindValue("step_end")) != null)
            {
                dfStepEnd = BaseParameter.ParseDouble(strVal);
            }

            bool bSave = false;

            if ((strVal = rp.FindValue("save")) != null)
            {
                bSave = bool.Parse(strVal);
            }

            double dfPctOfDetail = .25;

            if ((strVal = rp.FindValue("pct_of_prev_detail")) != null)
            {
                dfPctOfDetail = BaseParameter.ParseDouble(strVal);
            }

            return(new Octaves(strLayer, nIterations, dfSigmaStart, dfSigmaEnd, dfStepStart, dfStepEnd, bSave, dfPctOfDetail));
        }