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


C# Matrix.Resize方法代码示例

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


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

示例1: op_Resize_int_int_whenArgumentOutOfRangeException

        public void op_Resize_int_int_whenArgumentOutOfRangeException(int width,
                                                                      int height)
        {
            var matrix = new Matrix<string>(1, 1);

            Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Resize(width, height));
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:Matrix`1.Facts.cs

示例2: op_Resize_int_int

        public void op_Resize_int_int()
        {
            const string expected = "example";

            var matrix = new Matrix<string>(1, 1);

            Assert.Throws<ArgumentOutOfRangeException>(() => matrix[2, 2]);

            matrix.Resize(3, 3);

            matrix[2, 2] = expected;

            var actual = matrix[2, 2];

            Assert.Equal(expected, actual);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:16,代码来源:Matrix`1.Facts.cs

示例3: FitImplVolModel

        /// <summary>
        /// This method allows to fit the implied volatility using different models.
        /// </summary>
        /// <param name="Hdataset"></param>
        /// <returns></returns>
        IFunction FitImplVolModel(CallPriceMarketData Hdataset)
        {
            int model = 1;
            switch (model)
            {
                case 0:
                    PFunction2D.PFunction2D pf = new PFunction2D.PFunction2D(Hdataset.Maturity, Hdataset.Strike, Hdataset.Volatility);
                    pf.Interpolation = DVPLUtils.EInterpolationType.LEAST_SQUARES;
                    pf.Extrapolation = DVPLUtils.ExtrapolationType.USEMODEL;
                    pf.Parse(null);
                    return pf;
                case 1:

                    //define a model for fitting the implied volatility
                    Fairmat.Statistics.LinearModel impVol = new Fairmat.Statistics.LinearModel(
                                                            new Fairmat.Statistics.Predictor[] {
                                                            delegate(Vector xx) { return 1; },
                                                            delegate(Vector xx) { return xx[0]; },
                                                            delegate(Vector xx) { return xx[1]; },
                                                            delegate(Vector xx) { return System.Math.Pow(xx[0], 2); },
                                                            delegate(Vector xx) { return System.Math.Pow(xx[1], 2); },
                                                            delegate(Vector xx) { return xx[0] * xx[1]; }, });

                    // Unroll matrix and coordinate vectors in order to make it suitable
                    // for the Quadratic model implementation.

                    int n = Hdataset.Volatility.R * Hdataset.Volatility.C;
                    Matrix xy = new Matrix(n, 2);
                    Vector z = new Vector(n);
                    int count = 0;
                    for (int x = 0; x < Hdataset.Volatility.R; x++)
                    {
                        for (int y = 0; y < Hdataset.Volatility.C; y++)
                        {
                            if (Hdataset.Volatility[x, y] > 0.01)
                            {
                                xy[count, Range.All] = (new Vector() { Hdataset.Maturity[x],Hdataset.Strike[y] }).T;
                                z[count] = Hdataset.Volatility[x, y];
                                count++;
                            }
                        }
                    }
                    xy.Resize(count, xy.C);
                    z.Resize(count);
                    impVol.Estimate(xy, z);
                    return impVol;
            }

            return null;
        }
开发者ID:fairmat,项目名称:EquityModels,代码行数:55,代码来源:DupireEstimator.cs

示例4: op_Resize_Size_whenShrink

        public void op_Resize_Size_whenShrink(int x,
                                              int y)
        {
            var matrix = new Matrix<string>(3, 3);

            matrix[2, 2] = "example";

            matrix.Resize(new Size(2, 2));

            matrix.Resize(new Size(3, 3));

            Assert.Null(matrix[2, 2]);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:13,代码来源:Matrix`1.Facts.cs

示例5: ResizeTest

		public void ResizeTest()
		{
			IMatrix<int> matrix = new Matrix<int>(10, 10);

			int number = 0;
			for (int r = 0; r < matrix.Rows; r++)
			{
				for (int c = 0; c < matrix.Columns; c++)
				{
					matrix[r, c] = number++;
				}
			}

			int orgRows = matrix.Rows;
			int orgColumns = matrix.Columns;
			matrix.Resize(20, 20);
			Assert.AreEqual(20, matrix.Rows);
			Assert.AreEqual(20, matrix.Columns);

			number = 0;
			for (int r = 0; r < orgRows; r++)
			{
				for (int c = 0; c < orgColumns; c++)
				{
					Assert.AreEqual(number++, matrix[r, c]);
				}
			}

			matrix.Resize(5, 6);

			Assert.AreEqual(5, matrix.Rows);
			Assert.AreEqual(6, matrix.Columns);

			number = 0;
			for (int r = 0; r < orgRows; r++)
			{
				if (r < matrix.Rows)
				{
					for (int c = 0; c < orgColumns; c++)
					{
						if (c < matrix.Columns)
						{
							Assert.AreEqual(number++, matrix[r, c]);
						}
						else
						{
							number++;
						}
					}
				}
			}

			AssertHelpers.ThrowsException<MatrixException>(() => { matrix.Resize(-1, 50); });
			AssertHelpers.ThrowsException<MatrixException>(() => { matrix.Resize(50, -1); });
		}
开发者ID:holtsoftware,项目名称:Sannel.Helpers,代码行数:55,代码来源:MatrixTests.cs


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