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


C# IKernel.Function方法代码示例

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


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

示例1: KernelFunctionCache

        /// <summary>
        ///   Constructs a new <see cref="KernelFunctionCache"/>.
        /// </summary>
        /// 
        /// <param name="kernel">The kernel function.</param>
        /// <param name="inputs">The inputs values.</param>
        /// <param name="cacheSize">
        ///   The size for the cache, measured in number of 
        ///   elements from the <paramref name="inputs"/> set.
        ///   Default is to use all elements.</param>
        /// 
        public KernelFunctionCache(IKernel kernel, double[][] inputs, int cacheSize)
        {
            if (cacheSize < 0)
                throw new ArgumentOutOfRangeException("cacheSize",
                    "The cache size must be non-negative.");

            this.kernel = kernel;
            this.inputs = inputs;

            this.size = cacheSize;
            if (cacheSize > inputs.Length)
                this.size = inputs.Length;


            if (cacheSize > inputs.Length)
            {
                // Create whole cache.
                matrix = new double[inputs.Length][];
                for (int i = 0; i < inputs.Length; i++)
                {
                    double[] row = matrix[i] = new double[inputs.Length - 1];
                    for (int j = 0; j < row.Length - 1; j++)
                        matrix[i][j] = kernel.Function(inputs[i], inputs[j]);
                }
            }

            else if (cacheSize > 0)
            {
                this.capacity = (size * (size - 1)) / 2;
                int collectionCapacity = (int)(1.1f * capacity);

                // Create lookup tables
                this.lruIndices = new LinkedList<int>();
                this.lruIndicesLookupTable =
                    new Dictionary<int, LinkedListNode<int>>(collectionCapacity);

                // Create cache for off-diagonal elements
                this.data = new Dictionary<int, double>(collectionCapacity);
            }

            // Create cache for diagonal elements
            this.diagonal = new double[inputs.Length];
            for (int i = 0; i < inputs.Length; i++)
                this.diagonal[i] = kernel.Function(inputs[i], inputs[i]);
        }
开发者ID:BiYiTuan,项目名称:framework,代码行数:56,代码来源:KernelFunctionCache.cs

示例2: EstimateComplexity

        /// <summary>
        ///   Estimates the <see cref="Complexity">complexity parameter C</see>
        ///   for a given kernel and a given data set.
        /// </summary>
        /// 
        /// <param name="kernel">The kernel function.</param>
        /// <param name="inputs">The input samples.</param>
        /// 
        /// <returns>A suitable value for C.</returns>
        /// 
        public static double EstimateComplexity(IKernel kernel, double[][] inputs)
        {
            // Compute initial value for C as the number of examples
            // divided by the trace of the input sample kernel matrix.

            double sum = 0.0;
            for (int i = 0; i < inputs.Length; i++)
                sum += kernel.Function(inputs[i], inputs[i]);
            return inputs.Length / sum;
        }
开发者ID:xyicheng,项目名称:Accord,代码行数:20,代码来源:SequentialMinimalOptimization.cs

示例3: EstimateComplexity

        /// <summary>
        ///   Estimates the <see cref="Complexity">complexity parameter C</see>
        ///   for a given kernel and a given data set.
        /// </summary>
        /// 
        /// <param name="kernel">The kernel function.</param>
        /// <param name="inputs">The input samples.</param>
        /// 
        /// <returns>A suitable value for C.</returns>
        /// 
        public static double EstimateComplexity(IKernel kernel, double[][] inputs)
        {
            // Compute initial value for C as the number of examples
            // divided by the trace of the input sample kernel matrix.

            double sum = 0.0;
            for (int i = 0; i < inputs.Length; i++)
            {
                sum += kernel.Function(inputs[i], inputs[i]);

                if (Double.IsNaN(sum))
                    throw new OverflowException();
            }
            return inputs.Length / sum;
        }
开发者ID:natepan,项目名称:framework,代码行数:25,代码来源:SequentialMinimalOptimization.cs

示例4: KernelFunctionCache

        /// <summary>
        ///   Constructs a new <see cref="KernelFunctionCache"/>.
        /// </summary>
        /// 
        /// <param name="kernel">The kernel function.</param>
        /// <param name="inputs">The inputs values.</param>
        /// <param name="cacheSize">The size for the cache.</param>
        /// 
        public KernelFunctionCache(IKernel kernel, double[][] inputs, int cacheSize)
        {
            this.kernel = kernel;
            this.inputs = inputs;
            this.size = inputs.Length;

            if (cacheSize < 0)
            {
                Enabled = false;
                return;
            }
            else
            {
                Enabled = true;
            }

            if (cacheSize == 0)
                cacheSize = inputs.Length;


                this.cacheSize = cacheSize;
                this.capacity = (size * size) / 2 + 1;

                // Create lookup tables
                this.lruIndices = new LinkedList<int>();
                this.lruIndicesLookupTable = new Dictionary<int, LinkedListNode<int>>(capacity);

                // Create cache for off-diagonal elements
                this.data = new Dictionary<int, double>(capacity);

                // Create cache for diagonal elements
                this.diagonal = new double[inputs.Length];
                for (int i = 0; i < inputs.Length; i++)
                    this.diagonal[i] = kernel.Function(inputs[i], inputs[i]);
        }
开发者ID:xyicheng,项目名称:Accord,代码行数:43,代码来源:KernelFunctionCache.cs


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