/// <summary> /// Define the steps for constructing new Matrix. /// </summary> /// <param name="builder">Take a MatrixBuilder class and make him construct the matrix.</param> public void Construct(MatrixBuilder builder) { builder.SetField(); builder.InitCells(); builder.SetBombs(); builder.SetNumberOfMines(); }
public void NoDimensionCalcSumTest() { var array = new[] { 1, 2 }; var iterator = new MatrixBuilder<int, int>(array.Repeat(), (int target, int[] locals, ref bool continuation) => { var localSum = locals.Sum(); if (localSum + target == 3) { continuation = false; return new[] { target }; } if (localSum + target > 3) { continuation = false; return new int[0]; } return array; }); var actual = iterator.Select(x => string.Join("+", x)).Distinct().ToArray(); Assert.AreEqual(3, actual.Length); CollectionAssert.AreEquivalent(new[] { "1+1+1", "1+2", "2+1" }, actual); }
/// <summary> /// 通过三个点的原始位置和校准位置对工件坐标系进行标定 /// </summary> /// <param name="pt1"></param> /// <param name="pt2"></param> /// <param name="pt3"></param> /// <param name="pt1_cor"></param> /// <param name="pt2_cor"></param> /// <param name="pt3_cor"></param> /// <returns></returns> Matrix4 TransformCorrect(Vector3 pt1, Vector3 pt2, Vector3 pt3, Vector3 pt1_cor, Vector3 pt2_cor, Vector3 pt3_cor) { Matrix4 mat_1 = MatrixByTriPoints(pt1, pt2, pt3); Matrix4 mat_2 = MatrixByTriPoints(pt1_cor, pt2_cor, pt3_cor); Matrix4 mat_1_rev = TransformReverse(mat_1); MatrixBuilder builder = new MatrixBuilder(); return(builder.Multiply(mat_1_rev, mat_2)); }
public static Matrix <double> Translation(this MatrixBuilder <double> builder, double x, double y) { Matrix <double> result = builder.DenseIdentity(3); result[0, 2] = x; result[1, 2] = y; return(result); }
public static Matrix <double> RotationRadiansAround(this MatrixBuilder <double> builder, double radians, double x, double y) { Matrix <double> result = builder.Translation(-x, -y); result *= builder.RotationRadians(radians); result *= builder.Translation(x, y); return(result); }
public static Matrix <double> Scale(this MatrixBuilder <double> builder, double scaleX, double scaleY) { Matrix <double> result = builder.DenseIdentity(3); result[0, 0] = scaleX; result[1, 1] = scaleY; return(result); }
public void InitialiseGeneral() { Means = new Dictionary <DateTime, double[]>(); CoVariances = new Dictionary <DateTime, double[, ]>(); //Measurements = new Dictionary<TimeSpan, Vector<double>>(); Mbuilder = Matrix <double> .Build; Vbuilder = Vector <double> .Build; rand = new Random(); }
public static Matrix <double> ScaleAround(this MatrixBuilder <double> builder, double scaleX, double scaleY, double offsetX, double offsetY) { Matrix <double> result = builder.Translation(-offsetX, -offsetY); result *= builder.Scale(scaleX, scaleY); result *= builder.Translation(offsetX, offsetY); return(result); }
public static Matrix <double> Skew(this MatrixBuilder <double> builder, double skewX, double skewY) { Matrix <double> result = builder.DenseIdentity(3); result[0, 1] = skewX; result[1, 0] = skewY; return(result); }
public void BuildMatrixWithRandomNumbers_1row1column_MatrixWith1Element() { var builder = new MatrixBuilder(); var expectedLengthOfMatrix = 1; var matrix = builder.BuildMatrixWithRandomNumbers(1, 1, 1, 1); var actualLengthOfMatrix = matrix.Length; Assert.AreEqual(expectedLengthOfMatrix, actualLengthOfMatrix); }
// Compute the optimal rotation and translation vectors // Accepts the Matrix4X4 registration matrix, center of mass of source and target point sets //outputs the rotationMatrix and the translation vector public static void GetTransformationVectors (float[,] registrationMatrix, Vector3 SourceCenterOfMass, Vector3 TargeCenterOfMass, out Vector3 TranslationVector, out Quaternion UnityQuat) { //initialise matrix builder MatrixBuilder <float> regMatrix = Matrix <float> .Build; //fill matrix builder with contents of our params registrationmatri to create a Matrix Matrix <float> reg = regMatrix.DenseOfArray(registrationMatrix); //EVD decompose to generate our eignevalues Evd <float> registrationevd = reg.Evd(); //Cholesky<float> registrationevd = reg.Cholesky(); Console.WriteLine("Symmetric" + registrationevd.IsSymmetric); //get inex of maximum eigenvalue for correspond eigenvector double maxValue = double.NegativeInfinity; //int maxEigenValue = registrationevd.EigenValues. int index = 0; for (int i = 0; i < registrationevd.EigenValues.Count; i++) { if (registrationevd.EigenValues[i].Real > maxValue) { maxValue = registrationevd.EigenValues[i].Real; index = i; } } //Get the eigenvalue index and copy the vector as our unit eigenvector. //Our unit EigenVector below MathNet.Numerics.LinearAlgebra.Vector <float> unitEigenVector = registrationevd.EigenVectors.Column(index); float q0 = unitEigenVector.At(0); float q1 = unitEigenVector.At(1); float q2 = unitEigenVector.At(2); float q3 = unitEigenVector.At(3); UnityQuat = new Quaternion(q1, q2, q3, q0); Matrix4x4 rotMatrix = Matrix4x4.CreateFromQuaternion(UnityQuat); Vector3 y = new Vector3(0, 0, 0); //get optimal translation vector // Vector3 y = Matrix4x4.Rotate(UnityQuat).MultiplyPoint(SourceCenterOfMass); Vector3 optimalTranslation = TargeCenterOfMass - y; TranslationVector = optimalTranslation; }
/// <summary> /// 正規化した座標のリストを作成 /// </summary> /// <param name="tail"></param> private void NormalizePoints(int listnum) { VectorBuilder <double> Vector = Vector <double> .Build; MatrixBuilder <double> Matrix = Matrix <double> .Build; for (int i = 0; i < listnum; i++) { //体が常に横を向くように正規化 //HipRightからHipLeftへのびるXZ平面ベクトルに対して垂直なXZ平面ベクトルを計算 double[] hip = new double[3] { -(kinectPoints[12][i][2] - kinectPoints[16][i][2]), 0, kinectPoints[12][i][0] - kinectPoints[16][i][0] }; var VecHip = Vector.DenseOfArray(hip); //求めたベクトルの絶対値を1に var e_x = VecHip.Divide((float)VecHip.L2Norm()); //e_y = (0,1,0) var e_y = Vector.DenseOfArray(new double[3] { 0, 1, 0 }); //e_z = e_x × e_y var e_z = Vector.DenseOfArray(new double[3] { -e_x.At(2), 0, e_x.At(0) }); //e_x,e_y,e_zを一つの行列に var mat = Matrix.DenseOfColumnVectors(new Vector <double>[] { e_x, e_y, e_z }).Inverse(); double[] norm = new double[3];//正規化した座標を格納する三次元座標 for (int j = 0; j < 21; j++) { var VecJ = Vector.DenseOfArray(new double[3] { kinectPoints[j][i][0] - kinectPoints[0][i][0], kinectPoints[j][i][1] - kinectPoints[0][i][1], kinectPoints[j][i][2] - kinectPoints[0][i][2] }); var E = mat * VecJ; for (int k = 0; k < 3; k++) { norm[k] = E.At(k); } kinectNormalizedPoints[j].Add((double[])norm.Clone()); } //頭の高さを1として正規化 double[] head = kinectNormalizedPoints[3][i]; double headVec = Math.Sqrt(head[0] * head[0] + head[1] * head[1] + head[2] * head[2]); for (int j = 0; j < 21; j++)//jointnum:3 = head { double[] points = kinectNormalizedPoints[j][i]; double Vec = Math.Sqrt(points[0] * points[0] + points[1] * points[1] + points[2] * points[2]); Vec /= headVec; //kinectNormalizedPoints[j][i][0] *= Vec; } } }
public void NoIteratorTest() { var iterator = new MatrixBuilder <int, int>(new[] { Enumerable.Range(0, 3) }, (int target, int[] locals, ref bool continuation) => { continuation = false; return(new[] { target }); }); var actual = iterator.SelectMany(x => x).ToArray(); CollectionAssert.AreEquivalent(new[] { 0, 1, 2 }, actual); }
public static Matrix <double> RotationRadians(this MatrixBuilder <double> builder, double radians) { Matrix <double> result = builder.DenseIdentity(3); result[0, 0] = Math.Cos(radians); result[0, 1] = -Math.Sin(radians); result[1, 0] = Math.Sin(radians); result[1, 1] = Math.Cos(radians); result[2, 2] = 1; return(result); }
public WordFinder(IEnumerable <string> wordstream) { int rows = wordstream.Count(), cols = rows; CharMatrix = MatrixBuilder .For(wordstream) .WithSize(rows, cols) .ToMatrix(); _matrixRows = rows; _matrixCols = cols; }
public SolutionStats GetFinalStats(MatrixBuilder matrixBuilder, List <MatrixRow> matrix, Solution solution) { var rowIndexes = (solution != null) ? solution.RowIndexes : Enumerable.Range(0, matrix.Count); var maxActualDirectionChanges = rowIndexes.Max(rowIndex => matrixBuilder.GetMatrixRowAtRowIndex(rowIndex).Path.NumDirectionChanges); return(new SolutionStats( matrix.Count, matrix.Any() ? matrix.First().DlxRowEnumerable.Count() : 0, MatrixBuildingDuration, MatrixSolvingDuration, maxActualDirectionChanges)); }
public static MatrixD Random(this MatrixBuilder <double> mb, int rows, int cols, double minVal, double maxVal) { var matrix = new double[rows, cols]; for (var i = 0; i < rows; i++) { for (var j = 0; j < cols; j++) { matrix[i, j] = GlobalRandom.NextDouble(minVal, maxVal); } } return(MatrixD.Build.DenseOfArray(matrix)); }
public Signal Apply(System.Func <double, double> func) { if (IsMatrix) { MatrixBuilder <double> m = Matrix <double> .Build; Matrix <double> matrix = matrixValue.Map(func); return(new Signal(matrix)); } else { return(new Signal(func(doubleValue))); } }
public static MatrixD repeat(this MatrixBuilder <double> mb, int rows, int cols, double value) { var matrix = new double[rows, cols]; for (var i = 0; i < rows; i++) { for (var j = 0; j < cols; j++) { matrix[i, j] = value; } } return(MatrixD.Build.DenseOfArray(matrix)); }
/// <summary> /// 三个不共线的点构成的坐标系 /// </summary> /// <param name="pt1">origin</param> /// <param name="pt2">x</param> /// <param name="pt3"></param> /// <returns></returns> Matrix4 MatrixByTriPoints(Vector3 pt1, Vector3 pt2, Vector3 pt3) { Vector3 x_dir = pt2 - pt1; x_dir.Normalize(); Vector3 dir_1 = pt3 - pt1; dir_1.Normalize(); Vector3 z_dir = x_dir.CrossProduct(dir_1); Vector3 y_dir = x_dir.CrossProduct(z_dir); MatrixBuilder builder = new MatrixBuilder(); return(builder.ToWorldMatrix(new Coordinate3(pt1, x_dir, y_dir, z_dir))); }
public static Signal BroadcastDivide(this Matrix <double> left, Signal right) { if (right.IsMatrix) { Matrix <double> rightMatrix = right.Unpack() as Matrix <double>; MatrixBuilder <double> m = Matrix <double> .Build; Matrix <double> result = left.PointwiseDivide(rightMatrix); return(new Signal(result)); } else { return(new Signal(left / ((double)right.Unpack()))); } }
public void FloatMatrixTestIdentityBuilder() { //Identity float[][] I_Data = new float[][] { new float[] { 1, 0, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 0, 1 } }; var I = MatrixBuilder <float> .Identity(3); for (int i = 0; i < I_Data.Length; i++) { for (int j = 0; j < I_Data[0].Length; j++) { Assert.AreEqual(I_Data[i][j], I.Get(i, j)); } } }
public static Matrix <double> Random(this MatrixBuilder <double> builder, int rows, int columns) { Random randomizer = new Random(); Matrix <double> weights = Matrix <double> .Build.Dense(rows, columns); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { weights[row, column] = randomizer.NextDouble() * 0.24 - 0.12; } } return(weights); }
/// <summary> /// Get the Report Definition been Dynamic or Static /// </summary> /// <returns></returns> private void ProcessReportSettings(out DataTable table, out Report report) { // // Dynamic // //if (Page.PreviousPage is ReportGeneratorPage) //{ InfoControl.Web.Reporting.DataClasses.ReportSettings settings = Session["ReportSettings"] as InfoControl.Web.Reporting.DataClasses.ReportSettings; // // Create Report Generator // ReportDefinitionBuilder generator = new ReportDefinitionBuilder(settings); // // Create Table // if (settings.MatrixRows.Count > 0) { MatrixBuilder matrixBuilder = new MatrixBuilder(settings); matrixBuilder.RowsStyle = rowsStyle; matrixBuilder.HeaderStyle = headerStyle; generator.ReportItems.Add(matrixBuilder.ToMatrix()); } else { TableBuilder tableBuilder = new TableBuilder(settings); tableBuilder.RowsStyle = rowsStyle; tableBuilder.HeaderStyle = headerStyle; generator.ReportItems.Add(tableBuilder.ToTable()); } // // Create the dataTable // table = new ReportsManager(this).ExecuteReport(settings); report = generator.Report; //} //else //{ // table = new DataTable(); // string fileName = Server.MapPath("../Static/") + Request["r"]; // report = System.IO.File.ReadAllText(fileName).DeserializeFromXml<Report>(); //} }
public void FloatMatrixTestAllBuilder() { //All values float[][] a_Data = new float[][] { new float[] { 1, 1, 1 }, new float[] { 1, 1, 1 } }; var A = new Matrix <float>(a_Data); var B = MatrixBuilder <double> .All(1, 2, 3); for (int i = 0; i < a_Data.Length; i++) { for (int j = 0; j < a_Data[0].Length; j++) { Assert.AreEqual(A.Get(i, j), B.Get(i, j)); } } }
public void NoDimension2Test() { Console.WriteLine(); char[] arr1 = new[] { 'a', 'b' }; char[] arr2 = new[] { '1', '2', '3' }; var iterator = new MatrixBuilder<char, char>(new[] { arr1, arr2 }, (char target, char[] locals, ref bool continuation) => { continuation = false; return arr2; }); var actual = iterator.Select(x => string.Join("", x)).ToArray(); Assert.AreEqual(6, actual.Length); }
private async void initializeButton_Click(object sender, EventArgs e) { try { temperatureListView.Items.Clear(); var sD = dataInput.getSimulationData(); mesh = new MeshCreator() .createMesh( sD.SampleWidth, sD.SampleHeight, sD.XaxisNodesCount, sD.YaxisNodesCount); progressBar.Value = 0; progressBar.Visible = true; progressBar.Maximum = Convert.ToInt32(sD.Simulation_Time / sD.Simulation_Step_Time); visualiser.visualiseMesh(mesh); solutions?.Clear(); showSimulationButton.Enabled = false; initializeButton.Enabled = false; cancelSolverButton.Visible = true; //await Task.Run(() => // { Solver solver = new Solver(); solver.onStepTimeSolve += Solver_onStepTimeSolve; MatrixBuilder matrixBuilder = new MatrixBuilder(mesh, sD); var h = matrixBuilder.buildHglobalMatrix(); var p = matrixBuilder.buildPglobalVector(); var c = matrixBuilder.buildCglobalMatrix(); token = new CancellationTokenSource(); solutions = await solver.SolveUnstationaryAsync(h, c, p, sD, token.Token); //},token.Token); showSimulationButton.Enabled = true; initializeButton.Enabled = true; Cursor.Current = Cursors.Arrow; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected override List <Signal> Calculate(List <Signal> values) { Signal firstSignal = values[0]; Matrix <double> firstMatrix; MatrixBuilder <double> m = Matrix <double> .Build; switch (firstSignal.Unpack()) { case Matrix <double> matrix: firstMatrix = matrix; break; case double value: firstMatrix = m.Dense(1, 1, value); break; default: throw logger.Error(new LigralException("Signal with undefined type")); } foreach (Signal signal in values.Skip(1)) { try { switch (signal.Unpack()) { case Matrix <double> matrix: firstMatrix = firstMatrix.Append(matrix); break; case double value: firstMatrix = firstMatrix.Append(m.Dense(1, 1, value)); break; } } catch (System.ArgumentException e) { string message = e.Message; int indexOfParenthesis = message.IndexOf('('); if (indexOfParenthesis >= 0) { message = message.Substring(0, indexOfParenthesis); } throw logger.Error(new ModelException(this, message)); } } Results[0].Pack(firstMatrix); return(Results); }
public void AutoFinish() { int[][] array = new[] { new []{ 1, 2 }, new []{ 3, 4,5 }, }; var iterator = new MatrixBuilder<int, int>(array, (int target, int[] locals, ref bool continuation) => { return new int[] { target }; }); var actual = iterator.Select(x => string.Join("+", x)).Distinct().ToArray(); Assert.AreEqual(6, actual.Length); }
public void NoDimension2Test() { Console.WriteLine(); char[] arr1 = new[] { 'a', 'b' }; char[] arr2 = new[] { '1', '2', '3' }; var iterator = new MatrixBuilder <char, char>(new[] { arr1, arr2 }, (char target, char[] locals, ref bool continuation) => { continuation = false; return(arr2); }); var actual = iterator.Select(x => string.Join("", x)).ToArray(); Assert.AreEqual(6, actual.Length); }
public void UserInputValidatorTest() { //arrange var inputreader = new ConsoleInputReader(); var printer = new ConsolePrinter(); MatrixBuilder m = new MatrixBuilder(inputreader, printer); //act int min = 0, max = 100; Random random = new Random(); m.BuildMatrix((uint)random.Next(min, max), (uint)random.Next(min, max)); //assert Assert.IsTrue(m.MatrixTrail >= 0); }
public void GlobalMatrixOnFirstFiniteElementTest() { // Arrange int finiteElementIndex = 0; MatrixBuilder matrixBuilder = new MatrixBuilder( new CoordinateSystemConfig(a: 0, b: 0.4, c: 0, d: Math.PI / 25, n: 4, m: 1), new CylindricalShellConfig(e: 80.1e10, v: 0.3, h: 0.005, r: 0.1)); Matrix expectedGlobalMatrix; Matrix.Read(out expectedGlobalMatrix, @"..\..\Resources\GlobalMatrixOnFirstFiniteElement.txt"); // Act Matrix actualGlobalMatrix = matrixBuilder.BuildGlobalMatrixForFiniteElement(finiteElementIndex); // Assert Assert.AreEqual(expectedGlobalMatrix, actualGlobalMatrix); }
public Signal GetSignal(Func <T, double> getValue) { Signal signal = new Signal(); if (rowNo == 0 && colNo == 0) { signal.Pack(getValue(space[0])); } else { IEnumerable <double> row = space.ConvertAll(room => getValue(room)); MatrixBuilder <double> m = Matrix <double> .Build; Matrix <double> matrix = m.Dense(colNo, rowNo, row.ToArray()).Transpose(); signal.Pack(matrix); } return(signal); }
public void AutoFinish() { int[][] array = new[] { new [] { 1, 2 }, new [] { 3, 4, 5 }, }; var iterator = new MatrixBuilder <int, int>(array, (int target, int[] locals, ref bool continuation) => { return(new int[] { target }); }); var actual = iterator.Select(x => string.Join("+", x)).Distinct().ToArray(); Assert.AreEqual(6, actual.Length); }
public static double[,] MatrixFromFunc(MatrixBuilder f, int nrow, int ncol) { double[,] ret = new double[nrow, ncol]; for (int irow = 0; irow < nrow; irow++) { for (int icol = 0; icol < ncol; icol++) { ret[irow, icol] = f(irow, icol); } } return ret; }
public void NoIteratorTest() { var iterator = new MatrixBuilder<int, int>(new[] { Enumerable.Range(0, 3) }, (int target, int[] locals, ref bool continuation) => { continuation = false; return new[] { target }; }); var actual = iterator.SelectMany(x => x).ToArray(); CollectionAssert.AreEquivalent(new[] { 0, 1, 2 }, actual); }