• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Matrices.Matrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: RowsAndCols

        public void RowsAndCols()
        {
            var matrix = new Matrix(6, 3);
            Assert.AreEqual(matrix.Rows, 6);
            Assert.AreEqual(matrix.Cols, 3);

            matrix[1, 2] = 1.5;
            Assert.AreEqual(matrix[1, 2], 1.5);
        }
开发者ID:OperatorOverload,项目名称:encog-cs,代码行数:9,代码来源:TestMatrix.cs


示例2: DotProduct

        public void DotProduct()
        {
            double[][] matrixData1 = {new[] {1.0, 2.0, 3.0, 4.0}};
            double[][] matrixData2 = {
                                         new[] {5.0},
                                         new[] {6.0},
                                         new[] {7.0},
                                         new[] {8.0}
                                     };

            var matrix1 = new Matrix(matrixData1);
            var matrix2 = new Matrix(matrixData2);

            double dotProduct = MatrixMath.DotProduct(matrix1, matrix2);

            Assert.AreEqual(dotProduct, 70.0);

            // test dot product errors
            double[][] nonVectorData = {
                                           new[] {1.0, 2.0},
                                           new[] {3.0, 4.0}
                                       };
            double[][] differentLengthData = {
                                                 new[] {1.0}
                                             };
            var nonVector = new Matrix(nonVectorData);
            var differentLength = new Matrix(differentLengthData);

            try
            {
                MatrixMath.DotProduct(matrix1, nonVector);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }

            try
            {
                MatrixMath.DotProduct(nonVector, matrix2);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }

            try
            {
                MatrixMath.DotProduct(matrix1, differentLength);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }
开发者ID:OperatorOverload,项目名称:encog-cs,代码行数:55,代码来源:TestMatrixMath.cs


示例3: Copy

 public void Copy()
 {
     double[][] data = {
                           new[] {1.0, 2.0},
                           new[] {3.0, 4.0}
                       };
     var source = new Matrix(data);
     var target = new Matrix(2, 2);
     MatrixMath.Copy(source, target);
     Assert.IsTrue(source.Equals(target));
 }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:11,代码来源:TestMatrixMath.cs


示例4: RowAndColRangeUnder

        public void RowAndColRangeUnder()
        {
            var matrix = new Matrix(6, 3);

            // make sure set registers error on under-bound row
            try
            {
                matrix[-1, 0] = 1;
                Assert.IsTrue(false); // should have thrown an exception
            }
            catch (MatrixError)
            {
            }

            // make sure set registers error on under-bound col
            try
            {
                matrix[0, -1] = 1;
                Assert.IsTrue(false); // should have thrown an exception
            }
            catch (MatrixError)
            {
            }

            // make sure get registers error on under-bound row
            try
            {
                double d = matrix[-1, 0];
                matrix[0, 0] = d;
                Assert.IsTrue(false); // should have thrown an exception
            }
            catch (MatrixError)
            {
            }

            // make sure set registers error on under-bound col
            try
            {
                double d = matrix[0, -1];
                matrix[0, 0] = d;
                Assert.IsTrue(false); // should have thrown an exception
            }
            catch (MatrixError)
            {
            }
        }
开发者ID:OperatorOverload,项目名称:encog-cs,代码行数:46,代码来源:TestMatrix.cs


示例5: Boolean

        public void Boolean()
        {
            bool[][] matrixDataBoolean = {
                                             new[] {true, false},
                                             new[] {false, true}
                                         };

            double[][] matrixDataDouble = {
                                              new[] {1.0, -1.0},
                                              new[] {-1.0, 1.0},
                                          };

            var matrixBoolean = new Matrix(matrixDataBoolean);
            var matrixDouble = new Matrix(matrixDataDouble);

            Assert.IsTrue(matrixBoolean.Equals(matrixDouble));
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:17,代码来源:TestMatrix.cs


示例6: Inverse

        public void Inverse()
        {
            double[][] matrixData1 = {
                                         new[] {1.0, 2.0, 3.0, 4.0}
                                     };
            double[][] matrixData2 = {
                                         new[] {1.0},
                                         new[] {2.0},
                                         new[] {3.0},
                                         new[] {4.0}
                                     };

            var matrix1 = new Matrix(matrixData1);
            var checkMatrix = new Matrix(matrixData2);

            Matrix matrix2 = MatrixMath.Transpose(matrix1);

            Assert.IsTrue(matrix2.Equals(checkMatrix));
        }
开发者ID:OperatorOverload,项目名称:encog-cs,代码行数:19,代码来源:TestMatrixMath.cs


示例7: Bipolar2Double

        public void Bipolar2Double()
        {
            // test a 1x4
            bool[] boolData1 = { true, false, true, false };
            double[] checkData1 = { 1, -1, 1, -1 };
            Matrix matrix1 = Matrix.CreateRowMatrix(BiPolarUtil.Bipolar2double(boolData1));
            Matrix checkMatrix1 = Matrix.CreateRowMatrix(checkData1);
            Assert.IsTrue(matrix1.Equals(checkMatrix1));

            // test a 2x2
            bool[][] boolData2 = {
                new[]{ true, false },
                new[]{ false, true } };
            double[][] checkData2 = {
                new[] { 1.0, -1.0 },
                new[] { -1.0, 1.0 } };
            var matrix2 = new Matrix(BiPolarUtil.Bipolar2double(boolData2));
            var checkMatrix2 = new Matrix(checkData2);
            Assert.IsTrue(matrix2.Equals(checkMatrix2));
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:20,代码来源:TestBiPolarUtil.cs


示例8: DeleteRow

        public void DeleteRow()
        {
            double[][] origData = {
                                      new[] {1.0, 2.0},
                                      new[] {3.0, 4.0}
                                  };
            double[][] checkData = {new[] {3.0, 4.0}};
            var orig = new Matrix(origData);
            Matrix matrix = MatrixMath.DeleteRow(orig, 0);
            var check = new Matrix(checkData);
            Assert.IsTrue(check.Equals(matrix));

            try
            {
                MatrixMath.DeleteRow(orig, 10);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:21,代码来源:TestMatrixMath.cs


示例9: VerifySame

 public void VerifySame()
 {
     double[][] dataBase = {
                               new[] {1.0, 2.0},
                               new[] {3.0, 4.0}
                           };
     double[][] dataTooManyRows = {
                                      new[] {1.0, 2.0},
                                      new[] {3.0, 4.0},
                                      new[] {5.0, 6.0}
                                  };
     double[][] dataTooManyCols = {
                                      new[] {1.0, 2.0, 3.0},
                                      new[] {4.0, 5.0, 6.0}
                                  };
     var baseMatrix = new Matrix(dataBase);
     var tooManyRows = new Matrix(dataTooManyRows);
     var tooManyCols = new Matrix(dataTooManyCols);
     MatrixMath.Add(baseMatrix, baseMatrix);
     try
     {
         MatrixMath.Add(baseMatrix, tooManyRows);
         Assert.IsFalse(true);
     }
     catch (MatrixError)
     {
     }
     try
     {
         MatrixMath.Add(baseMatrix, tooManyCols);
         Assert.IsFalse(true);
     }
     catch (MatrixError)
     {
     }
 }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:36,代码来源:TestMatrixMath.cs


示例10: MultiplyScalar

 public void MultiplyScalar()
 {
     double[][] data = {
                           new[] {2.0, 4.0},
                           new[] {6.0, 8.0}
                       };
     var matrix = new Matrix(data);
     Matrix result = MatrixMath.Multiply(matrix, 2.0);
     Assert.AreEqual(4.0, result[0, 0]);
 }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:10,代码来源:TestMatrixMath.cs


示例11: Multiply

        public void Multiply()
        {
            double[][] matrixData1 = {
                                         new[] {1.0, 4.0},
                                         new[] {2.0, 5.0},
                                         new[] {3.0, 6.0}
                                     };
            double[][] matrixData2 = {
                                         new[] {7.0, 8.0, 9.0},
                                         new[] {10.0, 11.0, 12.0}
                                     };

            double[][] matrixData3 = {
                                         new[] {47.0, 52.0, 57.0},
                                         new[] {64.0, 71.0, 78.0},
                                         new[] {81.0, 90.0, 99.0}
                                     };

            var matrix1 = new Matrix(matrixData1);
            var matrix2 = new Matrix(matrixData2);

            var matrix3 = new Matrix(matrixData3);

            Matrix result = MatrixMath.Multiply(matrix1, matrix2);

            Assert.IsTrue(result.Equals(matrix3));
        }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:27,代码来源:TestMatrixMath.cs


示例12: Identity

        public void Identity()
        {
            try
            {
                MatrixMath.Identity(0);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }

            double[][] checkData = {
                                       new[] {1.0, 0.0},
                                       new[] {0.0, 1.0}
                                   };
            var check = new Matrix(checkData);
            Matrix matrix = MatrixMath.Identity(2);
            Assert.IsTrue(check.Equals(matrix));
        }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:19,代码来源:TestMatrixMath.cs


示例13: GetCol

        public void GetCol()
        {
            double[][] matrixData1 = {
                                         new[] {1.0, 2.0},
                                         new[] {3.0, 4.0}
                                     };
            double[][] matrixData2 = {
                                         new[] {2.0},
                                         new[] {4.0}
                                     };

            var matrix1 = new Matrix(matrixData1);
            var matrix2 = new Matrix(matrixData2);

            Matrix matrixCol = matrix1.GetCol(1);
            Assert.IsTrue(matrixCol.Equals(matrix2));

            try
            {
                matrix1.GetCol(3);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
                Assert.IsTrue(true);
            }
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:27,代码来源:TestMatrix.cs


示例14: MatrixMultiply

        public void MatrixMultiply()
        {
            double[][] a = {
                               new[] {1.0, 0.0, 2.0},
                               new[] {-1.0, 3.0, 1.0}
                           };

            double[][] b = {
                               new[] {3.0, 1.0},
                               new[] {2.0, 1.0},
                               new[] {1.0, 0.0}
                           };

            double[][] c = {
                               new[] {5.0, 1.0},
                               new[] {4.0, 2.0}
                           };

            var matrixA = new Matrix(a);
            var matrixB = new Matrix(b);
            var matrixC = new Matrix(c);

            var result = (Matrix) matrixA.Clone();
            result.ToString();
            result = MatrixMath.Multiply(matrixA, matrixB);

            Assert.IsTrue(result.Equals(matrixC));

            double[][] a2 = {
                                new[] {1.0, 2.0, 3.0, 4.0},
                                new[] {5.0, 6.0, 7.0, 8.0}
                            };

            double[][] b2 = {
                                new[] {1.0, 2.0, 3.0},
                                new[] {4.0, 5.0, 6.0},
                                new[] {7.0, 8.0, 9.0},
                                new[] {10.0, 11.0, 12.0}
                            };

            double[][] c2 = {
                                new[] {70.0, 80.0, 90.0},
                                new[] {158.0, 184.0, 210.0}
                            };

            matrixA = new Matrix(a2);
            matrixB = new Matrix(b2);
            matrixC = new Matrix(c2);

            result = MatrixMath.Multiply(matrixA, matrixB);
            Assert.IsTrue(result.Equals(matrixC));

            matrixB.Clone();

            try
            {
                MatrixMath.Multiply(matrixB, matrixA);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:63,代码来源:TestMatrix.cs


示例15: Divide

 public void Divide()
 {
     double[][] data = {
                           new[] {2.0, 4.0},
                           new[] {6.0, 8.0}
                       };
     var matrix = new Matrix(data);
     Matrix result = MatrixMath.Divide(matrix, 2.0);
     Assert.AreEqual(1.0, result[0, 0]);
 }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:10,代码来源:TestMatrixMath.cs


示例16: Sum

 public void Sum()
 {
     double[][] doubleData = {
                                 new[] {1.0, 2.0},
                                 new[] {3.0, 4.0}
                             };
     var matrix = new Matrix(doubleData);
     Assert.AreEqual((int) matrix.Sum(), 1 + 2 + 3 + 4);
 }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:9,代码来源:TestMatrix.cs


示例17: MatrixConstruct

 public void MatrixConstruct()
 {
     double[][] m = {
                        new[] {1.0, 2.0, 3.0, 4.0},
                        new[] {5.0, 6.0, 7.0, 8.0},
                        new[] {9.0, 10.0, 11.0, 12.0},
                        new[] {13.0, 14.0, 15.0, 16.0}
                    };
     var matrix = new Matrix(m);
     Assert.AreEqual(matrix.Rows, 4);
     Assert.AreEqual(matrix.Cols, 4);
 }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:12,代码来源:TestMatrix.cs


示例18: MatrixEquals

        public void MatrixEquals()
        {
            double[][] m1 = {
                                new[] {1.0, 2.0},
                                new[] {3.0, 4.0}
                            };

            double[][] m2 = {
                                new[] {0.0, 2.0},
                                new[] {3.0, 4.0}
                            };

            var matrix1 = new Matrix(m1);
            var matrix2 = new Matrix(m1);

            Assert.IsTrue(matrix1.Equals(matrix2));

            matrix2 = new Matrix(m2);

            Assert.IsFalse(matrix1.Equals(matrix2));
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:21,代码来源:TestMatrix.cs


示例19: Randomize

 public void Randomize()
 {
     const double min = 1.0;
     const double max = 10.0;
     var matrix = new Matrix(10, 10);
     matrix.Ramdomize(min, max);
     var array = matrix.ToPackedArray();
     foreach (double t in array)
     {
         if (t < min || t > max)
             Assert.IsFalse(true);
     }
 }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:13,代码来源:TestMatrix.cs


示例20: PackedArray2

 public void PackedArray2()
 {
     double[] data = {1.0, 2.0, 3.0, 4.0};
     var matrix = new Matrix(1, 4);
     matrix.FromPackedArray(data, 0);
     Assert.AreEqual(1.0, matrix[0, 0]);
     Assert.AreEqual(2.0, matrix[0, 1]);
     Assert.AreEqual(3.0, matrix[0, 2]);
 }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:9,代码来源:TestMatrix.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Networks.BasicNetwork类代码示例发布时间:2022-05-24
下一篇:
C# LIBSVM.svm_problem类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap