当前位置: 首页>>代码示例>>C#>>正文


C# Vector.Distinct方法代码示例

本文整理汇总了C#中numl.Math.LinearAlgebra.Vector.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Distinct方法的具体用法?C# Vector.Distinct怎么用?C# Vector.Distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numl.Math.LinearAlgebra.Vector的用法示例。


在下文中一共展示了Vector.Distinct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Conditional

        /// <summary>
        /// Calculates conditional impurity of y | x
        /// R(Y|X) is the average of H(Y|X = x) over all possible values
        /// X may take. 
        /// </summary>
        /// <param name="y">Target impurity</param>
        /// <param name="x">Conditioned impurity</param>
        /// <param name="width">Split of values over x to condition upon</param>
        /// <returns>Conditional impurity measure</returns>
        public double Conditional(Vector y, Vector x)
        {
            if (x == null && y == null)
                throw new InvalidOperationException("x and y do not exist!");

            double p = 0,               // probability of slice
                   h = 0,               // impurity of y | x_i : ith slice
                   result = 0,          // aggregated sum
                   count = x.Count();   // total items in list

            var values = x.Distinct().OrderBy(z => z);  // distinct values to split on

            Segments = values.Select(z => Range.Make(z, z)).ToArray();
            Discrete = true;

            // for each distinct value
            // calculate conditional impurity
            // and aggregate results
            foreach (var i in values)
            {
                // get slice
                var s = x.Indices(d => d == i);
                // slice probability
                p = (double)s.Count() / (double)count;
                // impurity of (y | x_i)
                h = Calculate(y.Slice(s));
                // sum up
                result += p * h;
            }

            return result;
        }
开发者ID:budbjames,项目名称:numl,代码行数:41,代码来源:Impurity.cs

示例2: Default

        /// <summary>Defaults.</summary>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activation">The activation.</param>
        /// <returns>A Network.</returns>
        public static Network Default(Descriptor d, Matrix x, Vector y, IFunction activation)
        {
            var nn = new Network();

            // set output to number of choices of available
            // 1 if only two choices
            var distinct = y.Distinct().Count();
            var output = distinct > 2 ? distinct : 1;

            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            var hidden = (int)Math.Ceiling((decimal)(x.Cols + output) * 2m / 3m);

            // creating input nodes
            nn.In = new Node[x.Cols + 1];
            nn.In[0] = new Node { Label = "B0", Activation = ident };
            for (var i = 1; i < x.Cols + 1; i++)
            {
                nn.In[i] = new Node { Label = d.ColumnAt(i - 1), Activation = ident };
            }

            // creating hidden nodes
            var h = new Node[hidden + 1];
            h[0] = new Node { Label = "B1", Activation = ident };
            for (var i = 1; i < hidden + 1; i++)
            {
                h[i] = new Node { Label = string.Format("H{0}", i), Activation = activation };
            }

            // creating output nodes
            nn.Out = new Node[output];
            for (var i = 0; i < output; i++)
            {
                nn.Out[i] = new Node { Label = GetLabel(i, d), Activation = activation };
            }

            // link input to hidden. Note: there are
            // no inputs to the hidden bias node
            for (var i = 1; i < h.Length; i++)
            {
                for (var j = 0; j < nn.In.Length; j++)
                {
                    Edge.Create(nn.In[j], h[i]);
                }
            }

            // link from hidden to output (full)
            for (var i = 0; i < nn.Out.Length; i++)
            {
                for (var j = 0; j < h.Length; j++)
                {
                    Edge.Create(h[j], nn.Out[i]);
                }
            }

            return nn;
        }
开发者ID:ChewyMoon,项目名称:Cupcake,代码行数:65,代码来源:Network.cs

示例3: Calculate

        /// <summary>Calculates Classification Error of x.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="x">The list in question.</param>
        /// <returns>Impurity measure.</returns>
        public override double Calculate(Vector x)
        {
            if (x == null)
            {
                throw new InvalidOperationException("x does not exist!");
            }

            double length = x.Count();

            var e = from i in x.Distinct() let q = (from j in x where j == i select j).Count() select q / length;

            return 1 - e.Max();
        }
开发者ID:ChewyMoon,项目名称:Cupcake,代码行数:17,代码来源:Error.cs

示例4: Calculate

        /// <summary>Calculates the Shannon Entropy of x.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="x">The list in question.</param>
        /// <returns>Impurity measure.</returns>
        public override double Calculate(Vector x)
        {
            if (x == null)
            {
                throw new InvalidOperationException("x does not exist!");
            }

            double length = x.Count();

            var px = from i in x.Distinct() let q = (from j in x where j == i select j).Count() select q / length;

            var e = (from p in px select -1 * p * Math.Log(p, 2)).Sum();

            return e;
        }
开发者ID:ChewyMoon,项目名称:Cupcake,代码行数:19,代码来源:Entropy.cs

示例5: Calculate

        /// <summary>Calculates Gini Index of x.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="x">The list in question.</param>
        /// <returns>Impurity measure.</returns>
        public override double Calculate(Vector x)
        {
            if (x == null)
            {
                throw new InvalidOperationException("x does not exist!");
            }

            double length = x.Count();

            var px = from i in x.Distinct() let q = (from j in x where j == i select j).Count() select q / length;

            var g = 1 - px.Select(d => d * d).Sum();

            return g;
        }
开发者ID:ChewyMoon,项目名称:Cupcake,代码行数:19,代码来源:Gini.cs

示例6: Create

        /// <summary>Defaults.</summary>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activationFunction">The activation.</param>
        /// <param name="outputFunction">The ouput function for hidden nodes (Optional).</param>
        /// <param name="epsilon">epsilon</param>
        /// <returns>A Network.</returns>
        public static Network Create(this Network network, Descriptor d, Matrix x, Vector y, IFunction activationFunction, IFunction outputFunction = null, double epsilon = double.NaN)
        {
            // set output to number of choices of available
            // 1 if only two choices
            int distinct = y.Distinct().Count();
            int output = distinct > 2 ? distinct : 1;
            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            int hidden = (int)System.Math.Ceiling((double)(x.Cols + output) * 2.0 / 3.0);

            return network.Create(x.Cols, output, activationFunction, outputFunction,
                fnNodeInitializer: new Func<int, int, Neuron>((l, i) =>
                {
                    if (l == 0) return new Neuron(false) { Label = d.ColumnAt(i - 1), ActivationFunction = activationFunction, NodeId = i, LayerId = l };
                    else if (l == 2) return new Neuron(false) { Label = Network.GetLabel(i, d), ActivationFunction = activationFunction, NodeId = i, LayerId = l };
                    else return new Neuron(false) { ActivationFunction = activationFunction, NodeId = i, LayerId = l };
                }), hiddenLayers: hidden);
        }
开发者ID:sethjuarez,项目名称:numl,代码行数:28,代码来源:NetworkOps.cs


注:本文中的numl.Math.LinearAlgebra.Vector.Distinct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。