Beispiel #1
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public URandomValueSettings(URandomValueSettings source)
 {
     Min      = source.Min;
     Max      = source.Max;
     DistrCfg = (IDistrSettings)((RCNetBaseSettings)source.DistrCfg).DeepClone();
     return;
 }
Beispiel #2
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public RandomValueSettings(RandomValueSettings source)
 {
     Min        = source.Min;
     Max        = source.Max;
     RandomSign = source.RandomSign;
     DistrType  = source.DistrType;
     DistrCfg   = source.DistrCfg?.DeepClone();
     return;
 }
Beispiel #3
0
        /// <summary>
        /// Creates an instance and initializes it from given xml element.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing RandomValueSettings settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public RandomValueSettings(XElement elem)
        {
            //Validation
            ElemValidator validator     = new ElemValidator();
            Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RandomValue.RandomValueSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement randomValueSettingsElem = validator.Validate(elem, "rootElem");

            //Parsing
            Min        = double.Parse(randomValueSettingsElem.Attribute("min").Value, CultureInfo.InvariantCulture);
            Max        = double.Parse(randomValueSettingsElem.Attribute("max").Value, CultureInfo.InvariantCulture);
            RandomSign = bool.Parse(randomValueSettingsElem.Attribute("randomSign").Value);
            XElement distrParamsElem = randomValueSettingsElem.Elements().FirstOrDefault();

            if (distrParamsElem == null)
            {
                DistrType = RandomExtensions.DistributionType.Uniform;
                DistrCfg  = new UniformDistrSettings();
            }
            else
            {
                switch (distrParamsElem.Name.LocalName)
                {
                case "uniformDistr":
                    DistrType = RandomExtensions.DistributionType.Uniform;
                    DistrCfg  = new UniformDistrSettings(distrParamsElem);
                    break;

                case "gaussianDistr":
                    DistrType = RandomExtensions.DistributionType.Gaussian;
                    DistrCfg  = new GaussianDistrSettings(distrParamsElem);
                    break;

                case "exponentialDistr":
                    DistrType = RandomExtensions.DistributionType.Exponential;
                    DistrCfg  = new ExponentialDistrSettings(distrParamsElem);
                    break;

                case "gammaDistr":
                    DistrType = RandomExtensions.DistributionType.Gamma;
                    DistrCfg  = new GammaDistrSettings(distrParamsElem);
                    break;

                default:
                    throw new Exception($"Unexpected element {distrParamsElem.Name.LocalName}");
                }
            }
            Check();
            return;
        }
Beispiel #4
0
 //Constructors
 /// <summary>
 /// Creates an initialized instance
 /// </summary>
 /// <param name="min">Min random value</param>
 /// <param name="max">Max random value</param>
 /// <param name="distrCfg">Specific parameters of the distribution</param>
 public URandomValueSettings(double min,
                             double max,
                             IDistrSettings distrCfg = null
                             )
 {
     Min      = min;
     Max      = max;
     DistrCfg = distrCfg;
     if (DistrCfg == null)
     {
         DistrCfg = new UniformDistrSettings();
     }
     Check();
     return;
 }
Beispiel #5
0
 //Constructors
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="min">The min value (inclusive).</param>
 /// <param name="max">The max value (exclusive).</param>
 /// <param name="randomSign">Specifies whether to randomize the value sign.</param>
 /// <param name="distrCfg">The configuration of the distribution.</param>
 public RandomValueSettings(double min,
                            double max,
                            bool randomSign         = DefaultRandomSign,
                            IDistrSettings distrCfg = null
                            )
 {
     Min        = min;
     Max        = max;
     RandomSign = randomSign;
     DistrCfg   = distrCfg;
     if (DistrCfg == null)
     {
         DistrCfg = new UniformDistrSettings();
     }
     Check();
     return;
 }
Beispiel #6
0
        /// <summary>
        /// Creates an instance and initializes it from given xml element.
        /// </summary>
        /// <param name="elem">Xml data containing RandomValueSettings settings.</param>
        public URandomValueSettings(XElement elem)
        {
            //Validation
            XElement settingsElem = Validate(elem, XsdTypeName);

            //Parsing
            Min = double.Parse(settingsElem.Attribute("min").Value, CultureInfo.InvariantCulture);
            Max = double.Parse(settingsElem.Attribute("max").Value, CultureInfo.InvariantCulture);
            XElement distrParamsElem = settingsElem.Elements().FirstOrDefault();

            if (distrParamsElem == null)
            {
                DistrCfg = new UniformDistrSettings();
            }
            else
            {
                DistrCfg = RandomCommon.CreateUDistrSettings(distrParamsElem);
            }
            Check();
            return;
        }
Beispiel #7
0
 //Constructors
 /// <summary>
 /// Creates an initialized instance
 /// </summary>
 /// <param name="min">Min random value</param>
 /// <param name="max">Max random value</param>
 /// <param name="randomSign">Specifies whether to randomize value sign</param>
 /// <param name="distrCfg">Specific parameters of the distribution</param>
 public RandomValueSettings(double min              = -1,
                            double max              = 1,
                            bool randomSign         = false,
                            IDistrSettings distrCfg = null
                            )
 {
     Min        = min;
     Max        = max;
     RandomSign = randomSign;
     DistrCfg   = distrCfg;
     if (DistrCfg == null)
     {
         DistrType = RandomExtensions.DistributionType.Uniform;
     }
     else
     {
         Type dcType = DistrCfg.GetType();
         if (dcType == typeof(GaussianDistrSettings))
         {
             DistrType = RandomExtensions.DistributionType.Gaussian;
         }
         else if (dcType == typeof(ExponentialDistrSettings))
         {
             DistrType = RandomExtensions.DistributionType.Exponential;
         }
         else if (dcType == typeof(GammaDistrSettings))
         {
             DistrType = RandomExtensions.DistributionType.Gamma;
         }
         else
         {
             throw new Exception($"Unexpected distribution configuration");
         }
     }
     Check();
     return;
 }