コード例 #1
0
        /// <summary>
        ///   Attempts to create a distribution's property. If the property doesn't
        ///   qualify as a valid property to be shown in the automatic distribution
        ///   description, the method fails and returns false.
        /// </summary>
        /// 
        /// <param name="info">The property's reflection information.</param>
        /// <param name="owner">The distribution that should own this property.</param>
        /// <param name="property">The created distribution property.</param>
        /// 
        /// <returns>True if the property could be created; false otherwise.</returns>
        /// 
        public static bool TryParse(PropertyInfo info, DistributionViewModel owner, out PropertyViewModel property)
        {
            property = null;

            if (info.GetMethod.ReturnType != typeof(double))
                return false;

            property = new PropertyViewModel(info, owner);

            return true;
        }
コード例 #2
0
        /// <summary>
        ///   Attempts to create a distribution's property. If the property doesn't
        ///   qualify as a valid property to be shown in the automatic distribution
        ///   description, the method fails and returns false.
        /// </summary>
        ///
        /// <param name="info">The property's reflection information.</param>
        /// <param name="owner">The distribution that should own this property.</param>
        /// <param name="property">The created distribution property.</param>
        ///
        /// <returns>True if the property could be created; false otherwise.</returns>
        ///
        public static bool TryParse(PropertyInfo info, DistributionViewModel owner, out PropertyViewModel property)
        {
            property = null;

            if (info.GetMethod.ReturnType != typeof(double))
            {
                return(false);
            }

            property = new PropertyViewModel(info, owner);

            return(true);
        }
コード例 #3
0
        private void OnDistributionChanged(DistributionViewModel value)
        {
            if (!value.IsInitialized)
                throw new Exception();

            if (distribution != null)
                distribution.Updated -= distribution_DistributionUpdated;

            distribution = value;
            Probability = 0.5;
            updateInterval();
            updateChart();

            distribution.Updated += distribution_DistributionUpdated;
        }
コード例 #4
0
        /// <summary>
        ///   Attempts to create a distribution's constructor. If the constructor
        ///   parameter's aren't valid, this method fails and returns false.
        /// </summary>
        ///
        /// <param name="info">The constructor's reflection information.</param>
        /// <param name="distribution">The distribution that owns this constructor.</param>
        /// <param name="constructor">The created distribution constructor.</param>
        ///
        /// <returns>True if the constructor could be created; false otherwise.</returns>
        ///
        public static bool TryParse(ConstructorInfo info, DistributionViewModel distribution, out ConstructorViewModel constructor)
        {
            constructor = new ConstructorViewModel(info, distribution);

            foreach (var param in info.GetParameters())
            {
                ParameterViewModel viewModel;
                if (!ParameterViewModel.TryParse(param, constructor, out viewModel))
                {
                    return(false);
                }

                constructor.Parameters.Add(viewModel);
            }

            return(true);
        }
コード例 #5
0
        private void OnDistributionChanged(DistributionViewModel value)
        {
            if (!value.IsInitialized)
            {
                throw new Exception();
            }

            if (distribution != null)
            {
                distribution.Updated -= distribution_DistributionUpdated;
            }

            distribution = value;
            Probability  = 0.5;
            updateInterval();
            updateChart();

            distribution.Updated += distribution_DistributionUpdated;
        }
コード例 #6
0
        /// <summary>
        /// Attempts to create a new DistributionViewModel from a given type.
        /// </summary>
        public static bool TryParse(MainViewModel owner, Type type, Dictionary <string, DocumentationViewModel> doc, out DistributionViewModel distribution)
        {
            distribution = new DistributionViewModel(owner);

            if (!typeof(IUnivariateDistribution).IsAssignableFrom(type) || !doc.ContainsKey(type.Name))
            {
                return(false);
            }


            string name = DistributionManager.GetDistributionName(type);


            // Extract all properties with return value of double
            //
            var properties = new List <PropertyViewModel>();

            foreach (PropertyInfo prop in type.GetProperties())
            {
                PropertyViewModel property;
                if (PropertyViewModel.TryParse(prop, distribution, out property))
                {
                    properties.Add(property);
                }
            }

            // Extract buildable constructors. A constructor is
            // considered buildable if we can extract valid ranges
            // and default values from all of its parameters
            //
            var list = new List <ConstructorViewModel>();

            foreach (var ctor in type.GetConstructors())
            {
                ConstructorViewModel constructor;
                if (ConstructorViewModel.TryParse(ctor, distribution, out constructor))
                {
                    list.Add(constructor);
                }
            }

            if (list.Count == 0)
            {
                return(false);
            }

            // For the time being, just consider the buildable
            // constructor with the largest number of parameters.
            //
            var main = list.OrderByDescending(x => x.Parameters.Count).First();



            // Extract some documentation
            var documentation = doc[type.Name];

            documentation.Name = name;

            distribution.Constructor   = main;
            distribution.Properties    = new ObservableCollection <PropertyViewModel>(properties);
            distribution.Parameters    = main.Parameters;
            distribution.Type          = type;
            distribution.Name          = name;
            distribution.Documentation = documentation;


            foreach (var parameter in distribution.Constructor.Parameters)
            {
                parameter.ValueChanged += distribution.distribution_OnParameterChanged;
            }

            distribution.Options = DistributionManager.GetFittingOptions(distribution.Type);

            return(true);
        }
コード例 #7
0
 private PropertyViewModel(PropertyInfo prop, DistributionViewModel distribution)
 {
     this.Property = prop;
     this.Owner    = distribution;
     this.Name     = DistributionManager.Normalize(prop.Name);
 }
コード例 #8
0
 private ConstructorViewModel(ConstructorInfo info, DistributionViewModel owner)
 {
     this.Owner       = owner;
     this.Constructor = info;
     this.Parameters  = new ObservableCollection <ParameterViewModel>();
 }
コード例 #9
0
        /// <summary>
        ///   Attempts to create a distribution's constructor. If the constructor 
        ///   parameter's aren't valid, this method fails and returns false.
        /// </summary>
        /// 
        /// <param name="info">The constructor's reflection information.</param>
        /// <param name="distribution">The distribution that owns this constructor.</param>
        /// <param name="constructor">The created distribution constructor.</param>
        /// 
        /// <returns>True if the constructor could be created; false otherwise.</returns>
        /// 
        public static bool TryParse(ConstructorInfo info, DistributionViewModel distribution, out ConstructorViewModel constructor)
        {
            constructor = new ConstructorViewModel(info, distribution);

            foreach (var param in info.GetParameters())
            {
                ParameterViewModel viewModel;
                if (!ParameterViewModel.TryParse(param, constructor, out viewModel))
                    return false;

                constructor.Parameters.Add(viewModel);
            }

            return true;
        }
コード例 #10
0
 private ConstructorViewModel(ConstructorInfo info, DistributionViewModel owner)
 {
     this.Owner = owner;
     this.Constructor = info;
     this.Parameters = new ObservableCollection<ParameterViewModel>();
 }
コード例 #11
0
 private PropertyViewModel(PropertyInfo prop, DistributionViewModel distribution)
 {
     this.Property = prop;
     this.Owner = distribution;
     this.Name = DistributionManager.Normalize(prop.Name);
 }
コード例 #12
0
        /// <summary>
        /// Attempts to create a new DistributionViewModel from a given type.
        /// </summary>
        public static bool TryParse(MainViewModel owner, Type type, Dictionary<string, DocumentationViewModel> doc, out DistributionViewModel distribution)
        {
            distribution = new DistributionViewModel(owner);

            if (!typeof(IUnivariateDistribution).IsAssignableFrom(type) || !doc.ContainsKey(type.Name))
                return false;


            string name = DistributionManager.GetDistributionName(type);


            // Extract all properties with return value of double
            //
            var properties = new List<PropertyViewModel>();
            foreach (PropertyInfo prop in type.GetProperties())
            {
                PropertyViewModel property;
                if (PropertyViewModel.TryParse(prop, distribution, out property))
                    properties.Add(property);
            }

            // Extract buildable constructors. A constructor is 
            // considered buildable if we can extract valid ranges
            // and default values from all of its parameters
            //
            var list = new List<ConstructorViewModel>();
            foreach (var ctor in type.GetConstructors())
            {
                ConstructorViewModel constructor;
                if (ConstructorViewModel.TryParse(ctor, distribution, out constructor))
                    list.Add(constructor);
            }

            if (list.Count == 0)
                return false;

            // For the time being, just consider the buildable 
            // constructor with the largest number of parameters.
            //
            var main = list.OrderByDescending(x => x.Parameters.Count).First();



            // Extract some documentation
            var documentation = doc[type.Name];
            documentation.Name = name;

            distribution.Constructor = main;
            distribution.Properties = new ObservableCollection<PropertyViewModel>(properties);
            distribution.Parameters = main.Parameters;
            distribution.Type = type;
            distribution.Name = name;
            distribution.Documentation = documentation;


            foreach (var parameter in distribution.Constructor.Parameters)
                parameter.ValueChanged += distribution.distribution_OnParameterChanged;

            distribution.Options = DistributionManager.GetFittingOptions(distribution.Type);

            return true;
        }