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


C# SparseVector类代码示例

本文整理汇总了C#中SparseVector的典型用法代码示例。如果您正苦于以下问题:C# SparseVector类的具体用法?C# SparseVector怎么用?C# SparseVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CanConvertArrayToSparseVector

 public void CanConvertArrayToSparseVector()
 {
     var array = new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1) };
     var vector = new SparseVector(array);
     Assert.IsInstanceOf(typeof(SparseVector), vector);
     CollectionAssert.AreEqual(array, array);
 }
开发者ID:the-vk,项目名称:mathnet-numerics,代码行数:7,代码来源:SparseVectorTest.cs

示例2: GetProof

        public ExampleSet GetProof(SparseVector x)
        {
            ExampleSet res = new ExampleSet();

            List<ExampleDistancePair> list = new List<ExampleDistancePair>();

            foreach (Example e in m_t_set.Examples)
            {
                list.Add(new ExampleDistancePair(e, SparseVector.Distance(x, e.X)));
            }

            list.Sort();

            int[] votes = new int[m_catnum];
            for (int i = 0; i < votes.Length; i++)
            {
                votes[i] = 0;
            }

            for (int i = 0; i < this.m_k; i++)
            {
                ExampleDistancePair pair = list[i];
                res.AddExample(pair.Example);
            }

            return res;
        }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:27,代码来源:KNN.cs

示例3: Compute

        public double Compute(SparseVector x, SparseVector z)
        {
            double temp;

            temp = ((SparseVector)(x - z)).Magnitude;
            return Math.Exp(-sigma * (temp * temp));
        }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:7,代码来源:Kernel.cs

示例4: CanConvertSparseVectorToArray

 public void CanConvertSparseVectorToArray()
 {
     var vector = new SparseVector(Data);
     var array = vector.ToArray();
     Assert.IsInstanceOf(typeof(double[]), array);
     CollectionAssert.AreEqual(vector, array);
 }
开发者ID:the-vk,项目名称:mathnet-numerics,代码行数:7,代码来源:SparseVectorTest.cs

示例5: AverageLogFactor

        //-- VMP -------------------------------------------------------------------------------------------

		/// <summary>
		/// Evidence message for VMP
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
		/// <param name="probsTrue">Incoming message from 'probsTrue'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
		/// <param name="MeanLog">Buffer 'MeanLog'.</param>
		/// <param name="MeanLogOneMinus">Buffer 'MeanLogOneMinus'.</param>
		/// <returns>Average of the factor's log-value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>sum_(sample,probsTrue) p(sample,probsTrue) log(factor(sample,probsTrue))</c>.
		/// Adding up these values across all factors and variables gives the log-evidence estimate for VMP.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
		/// <exception cref="ImproperMessageException"><paramref name="probsTrue"/> is not a proper distribution</exception>
		public static double AverageLogFactor([Proper] SparseBernoulliListBase sample,
			[Proper] SparseBetaList probsTrue, SparseVector MeanLog, SparseVector MeanLogOneMinus)
        {
			//var MeanLogOneMinus = probsTrue.GetMeanLogOneMinus();
            var p = sample.GetProbTrueVector();
			var res = p * MeanLog + (1 - p) * MeanLogOneMinus;
            return res.Sum();
        }
开发者ID:xornand,项目名称:Infer.Net,代码行数:24,代码来源:SparseBernoulliFromBeta.cs

示例6: AddInPlace

 /// <summary>
 /// Adds each element of vec to corresponding element of addTo vector
 /// addTo vector is being changed in place
 /// </summary>
 public static void AddInPlace(SparseVector<double> addTo, SparseVector<double> vec)
 {
     foreach (var vecIdx in vec.InnerIdx)
     {
         var num = addTo.TryGet(vecIdx, 0.0);
         addTo[vecIdx] = num + vec[vecIdx];
     }
 }
开发者ID:viidea,项目名称:latino,代码行数:12,代码来源:VectorUtils.cs

示例7: Multiply

 public static SparseVector<double> Multiply(double scalar, SparseVector<double> vector)
 {
     var newVector = vector.DeepClone();
     for (int i = 0; i < newVector.InnerDat.Count; i++ )
     {
         newVector.SetDirect(i, newVector.InnerDat[i] * scalar);
     }
     return newVector;
 }
开发者ID:viidea,项目名称:latino,代码行数:9,代码来源:VectorUtils.cs

示例8: CanCallUnaryNegationOperatorOnSparseVector

 public void CanCallUnaryNegationOperatorOnSparseVector()
 {
     var vector = new SparseVector(_data);
     var other = -vector;
     for (var i = 0; i < _data.Length; i++)
     {
         Assert.AreEqual(-_data[i], other[i]);
     }
 }
开发者ID:vivektewari,项目名称:mathnet-numerics,代码行数:9,代码来源:SparseVectorTest.cs

示例9: AddRowTestAddsRowWithGivenVector

        public void AddRowTestAddsRowWithGivenVector()
        {
            SparseVector v = new SparseVector(TestMatrix.Columns);
            v[2] = 5.1f;
            TestMatrix.AddRow(v);

            float expected = 5.1f;

            Assert.AreEqual(expected, TestMatrix[3, 2]);
        }
开发者ID:feupeu,项目名称:NyhedsfilterP2,代码行数:10,代码来源:SparseMatrixTest.cs

示例10: CreateVector

        /// <summary>
        /// Creates a new instance of the Vector class.
        /// </summary>
        /// <param name="data">The array to create this vector from.</param>
        /// <returns>The new <c>Vector</c>.</returns>
        protected override Vector<double> CreateVector(IList<double> data)
        {
            var vector = new SparseVector(data.Count);
            for (var index = 0; index < data.Count; index++)
            {
                vector[index] = data[index];
            }

            return vector;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:15,代码来源:SparseVectorTest.cs

示例11: ConstructorThrowsArgumentNullExceptionIfNullArgumentPassed

        public void ConstructorThrowsArgumentNullExceptionIfNullArgumentPassed()
        {
            // arrange

            // act
            var sv = new SparseVector<double>(null);
            
            // assert
            Assert.Fail("SparseVector ctor must throw ArgumentNullException if null argument passed.");
        }
开发者ID:yonglehou,项目名称:MachineLearning.NET,代码行数:10,代码来源:SparseVectorTests.cs

示例12: DivideInPlace

        /// <summary>
        /// Divides each element of dividee with corresponding element of divisor in place
        /// Dividee is being changed
        /// </summary>
        public static void DivideInPlace(SparseVector<double> dividee, SparseVector<double> divisor)
        {
            foreach (var divIdx in divisor.InnerIdx)
            {
                var num = dividee.TryGet(divIdx, 0.0);
                if (num < Double.Epsilon)
                    continue;

                dividee[divIdx] = num/divisor[divIdx];
            }
        }
开发者ID:viidea,项目名称:latino,代码行数:15,代码来源:VectorUtils.cs

示例13: CanCreateSparseVectorFromArray

        public void CanCreateSparseVectorFromArray()
        {
            var data = new double[Data.Length];
            Array.Copy(Data, data, Data.Length);
            var vector = new SparseVector(data);

            for (var i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], vector[i]);
            }
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:11,代码来源:SparseVectorTest.cs

示例14: Binary_SVM_SMO

        public Binary_SVM_SMO(int n)
        {
            this.m_NonBound = new List<int>();
            this.m_rand = new Random();
            this.m_weight = new SparseVector(n);

            // foamliu, 2008/12/29, default values
            this.m_c = Constants.SVM_C;
            this.m_eta = Constants.SVM_Eta;
            this.m_tolerance = Constants.SVM_Tolerance;
            this.m_epsilon = Constants.SVM_Epsilon;
        }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:12,代码来源:SVM-SMO.cs

示例15: AddColumnTestAddsColumnWithGivenValue

        public void AddColumnTestAddsColumnWithGivenValue()
        {
            SparseVector expected = new SparseVector(TestMatrix.Rows);
            expected[0] = 5.0f;
            expected[1] = 5.0f;
            expected[2] = 5.0f;

            TestMatrix.AddColumn(5.0f);

            Assert.IsTrue(expected.ApproximatelyEqual(
                TestMatrix.ColumnVector(TestMatrix.Columns - 1)));
        }
开发者ID:feupeu,项目名称:NyhedsfilterP2,代码行数:12,代码来源:SparseMatrixTest.cs


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