public PoolingLayer(LayerConnection inputConnection, Filter mask, int stride, PoolingMethod method) { model = new MatrixModel(inputConnection.length, stride); this.mask = mask; nodes = new DepthList <PoolingNode>(inputConnection.depth); int filterOutputsCount = model.filterOutputsCount(mask); int filterLineCount = model.filterLineCount(mask); for (int d = 0; d < inputConnection.depth; d++) { for (int i = 0; i < filterOutputsCount; i++) { List <Unit> inputUnits = new List <Unit>(); for (int x = 0; x < mask.count; x++) { int inner = x % mask.size + x / mask.size * model.size; int outer = i % filterLineCount + i / filterLineCount * model.size; inputUnits.Add(inputConnection[inner + outer, d]); } nodes.Add(new PoolingNode(inputUnits, method)); } } input = new PoolingLayerConnection(nodes); }
public MatrixModel NormalMultiply(MatrixModel a, MatrixModel b) { if (a.Columns != b.Rows) { throw new ArgumentException("Number of rows of the matrix a doesnt equal to number of columns of the matrix b."); } MatrixModel result = new MatrixModel(a.Rows, b.Columns); for (int row = 0; row < a.Rows; row++) { for (int col = 0; col < b.Columns; col++) { double tmp = 0; for (int i = 0; i < a.Columns; i++) // or i < b.Rows, it's equal { tmp += a[row, i] * b[i, col]; } result[row, col] = tmp; } } return(result); }
private static MatrixModel ReadModel(IDataRecord reader) { var id = reader.GetInt32(0); var data = reader.GetInt16(1); var errorLogModel = new MatrixModel(id, (byte)data); return(errorLogModel); }
private void RotateMatrix() { _matrix = MatrixModel.RotateMatrix(_matrix); for (int i = 0; i < Settings.MatrixSize; i++) { for (int j = 0; j < Settings.MatrixSize; j++) { Numbers[_matrix[j, i]].Index = new Vector2(i, j); } } }
private void ResetMatrix() { Numbers.Clear(); _matrix = MatrixModel.GetInitialMatrix(); for (int i = 0; i < Settings.MatrixSize; i++) { for (int j = 0; j < Settings.MatrixSize; j++) { Numbers.Add(new NumberViewModel(j + (i * Settings.MatrixSize) + 1, new Vector2(j, i))); } } }
public MatrixModel SubMatrix(int rowFrom, int rowTo, int colFrom, int colTo) { MatrixModel result = new MatrixModel(rowTo - rowFrom, colTo - colFrom); for (int row = rowFrom, i = 0; row < rowTo; row++, i++) { for (int col = colFrom, j = 0; col < colTo; col++, j++) { result[i, j] = MatrixValues[row, col]; } } return(result); }
public IActionResult Post([FromBody] MatrixModel model) { Guard.AgainstNull(model, nameof(model)); _bus.Send(new RegisterMatrixCommand { Name = model.Name, RowArgumentId = model.RowArgumentId, ColumnArgumentId = model.ColumnArgumentId, DataTypeName = model.DataTypeName }); return(Ok()); }
public MatrixModel Generate(int m, int n, int minValue = -9, int maxValue = 9) { MatrixModel matrix = new MatrixModel(m, n); for (int row = 0; row < matrix.Rows; row++) { for (int col = 0; col < matrix.Columns; col++) { matrix[row, col] = random.Next(minValue, maxValue + 1); } } return(matrix); }
public ConvolutionalLayer(LayerConnection inputConnection, Filter filter, int filtersAmount, int stride, ActivationFunction activationFunction) { kernels = new List <List <Filter> >(); model = new MatrixModel(inputConnection.length, stride); for (int f = 0; f < filtersAmount; f++) { kernels.Add(new List <Filter>()); for (int d = 0; d < inputConnection.depth; d++) { kernels[f].Add((Filter)filter.Clone()); } } neurons = new DepthList <ConvolutionalNeuron>(filtersAmount * inputConnection.depth); for (int f = 0; f < filtersAmount; f++) { for (int d = 0; d < inputConnection.depth; d++) { for (int o = 0; o < model.filterOutputsCount(filter); o++) { List <int> indexes = new List <int>(); for (int x = 0; x < filter.count; x++) { int inner = x % filter.size + x / filter.size * model.size; int outer = o % model.filterLineCount(filter) + o / model.filterLineCount(filter) * model.size; indexes.Add(inner + outer); } List <Unit> inputUnits = new List <Unit>(inputConnection.length); for (int i = inputConnection.depth * inputConnection.length; i < (inputConnection.depth + 1) * inputConnection.length; i++) { inputUnits.Add(inputConnection[i]); } neurons.Add(new ConvolutionalNeuron(inputUnits, kernels[f][d], indexes, activationFunction)); } } } input = new ConvolutionalLayerConnection(neurons); }
public MatrixModel Populate(int m, int n, string[] values) { var a = Array.ConvertAll(values, int.Parse); MatrixModel matrix = new MatrixModel(m, n); var index = 0; for (int row = 0; row < matrix.Rows; row++) { for (int col = 0; col < matrix.Columns; col++) { matrix[row, col] = a[index]; index++; } } return(matrix); }
private static MatrixModel CombineSubMatrices(MatrixModel a11, MatrixModel a12, MatrixModel a21, MatrixModel a22) { MatrixModel result = new MatrixModel(a11.Rows * 2); int shift = a11.Rows; for (int row = 0; row < a11.Rows; row++) { for (int col = 0; col < a11.Columns; col++) { result[row, col] = a11[row, col]; result[row, col + shift] = a12[row, col]; result[row + shift, col] = a21[row, col]; result[row + shift, col + shift] = a22[row, col]; } } return(result); }
public MatrixModel StrassenMultiply(MatrixModel a, MatrixModel b) { // If the matrices A, B are not of type 2n x 2n Fallback to using NormalMultiply var sizes = new int[] { a.Rows, a.Columns, b.Rows, b.Columns }; if (sizes.Distinct().Count() != 1 || (a.Rows & (a.Rows - 1)) != 0) { this.NormalMultiply(a, b); } int N = b.Rows; if (N <= 48) { return(NormalMultiply(a, b)); } int halfN = N / 2; var a11 = a.SubMatrix(0, halfN, 0, halfN); var a12 = a.SubMatrix(0, halfN, halfN, N); var a21 = a.SubMatrix(halfN, N, 0, halfN); var a22 = a.SubMatrix(halfN, N, halfN, N); var b11 = b.SubMatrix(0, halfN, 0, halfN); var b12 = b.SubMatrix(0, halfN, halfN, N); var b21 = b.SubMatrix(halfN, N, 0, halfN); var b22 = b.SubMatrix(halfN, N, halfN, N); MatrixModel[] m = new MatrixModel[] { StrassenMultiply(this.Add(a11, a22), this.Add(b11, b22)), StrassenMultiply(this.Add(a21, a22), b11), StrassenMultiply(a11, this.Subtract(b12, b22)), StrassenMultiply(a22, this.Subtract(b21, b11)), StrassenMultiply(this.Add(a11, a12), b22), StrassenMultiply(this.Subtract(a21, a11), this.Add(b11, b12)), StrassenMultiply(this.Subtract(a12, a22), this.Add(b21, b22)) }; var c11 = this.Add(this.Subtract(this.Add(m[0], m[3]), m[4]), m[6]); var c12 = this.Add(m[2], m[4]); var c21 = this.Add(m[1], m[3]); var c22 = this.Add(this.Add(this.Subtract(m[0], m[1]), m[2]), m[5]); return(CombineSubMatrices(c11, c12, c21, c22)); }
public MatrixModel Subtract(MatrixModel a, MatrixModel b) { if (a.Rows != b.Rows || a.Columns != b.Columns) { throw new ArgumentException("Not identical matrices."); } MatrixModel result = new MatrixModel(a.Rows, a.Columns); for (int row = 0; row < a.Rows; row++) { for (int col = 0; col < a.Columns; col++) { result[row, col] = a[row, col] - b[row, col]; } } return(result); }
public ActionResult SetMatrixDetails(int Xdimention, int Ydimention, int?FormatNumber) /*this Function will receive the 3 arguments (int Xdimention, int Ydimention, int? FormatNumber) fromm the view GetMatrixDetails.cshtml * to be set at the SetMatrixDetails.cshtml ( * Note:'int?' means that the FormatNumber is null able: FormatNumber can be--> int? FormatNumber=null is ok; !! if is not used--> int FormatNumber=null not ok*/ { MatrixModel matrixObj = new MatrixModel();//MatrixModel object that will be passed to the SetMatrixDetails.cshtml view in order to display the values on it! if (FormatNumber == null)//if the formatNumber is Null (not selected) will set the value to 0 { matrixObj.FormatNumber = 0; } matrixObj.Xdimention = Xdimention; //Passing the value to the MatrixModel object "matrixObj" matrixObj.Ydimention = Ydimention; //Passing the value to the MatrixModel object "matrixObj" matrixObj.FormatNumber = Convert.ToInt32(FormatNumber); //Implicity convertion is not possible ! int? to int! ,cast( Convert.ToInt32) is used instead return(View(matrixObj)); //Passing the MatrixModel object to the SetMatrixDetails.cshtml view }
private List <Columns> Shedule(MatrixModel matrix) { List <Columns> shedule = new List <Columns>(); int n = matrix.Matrix[0].Row.Count; int m = matrix.Matrix.Count; int minElement = matrix.Matrix[0].Row.Min(); int minIndex = matrix.Matrix[0].Row.IndexOf(minElement); List <int> firstStep = new List <int>(); for (int i = 0; i < n; i++) { if (i != minIndex) { firstStep.Add(0); } else { firstStep.Add(minElement); } } }
public IActionResult RotateMatrix([FromBody] MatrixModel matrix) { return(Json(_matrixService.Degree90Matrix(matrix.Matrix))); }
protected override void OnModelCreating(ModelBuilder builder) { builder.Entity <SampleModel>().HasKey(s => s.Id); builder.Entity <SampleModel>().HasMany(s => s.SampleTestParameters).WithOne(t => t.Sample).HasForeignKey(t => t.SampleId).OnDelete(DeleteBehavior.Cascade); builder.Entity <SampleModel>().HasOne(s => s.ReceivedBy).WithMany(u => u.Samples).HasForeignKey(s => s.ReceivedByUserId); builder.Entity <QuotationModel>().HasKey(q => q.PurchaseOrderRequestId); builder.Entity <PurchaseOrderRequestModel>().HasKey(p => p.Id); builder.Entity <PurchaseOrderRequestModel>().HasOne <QuotationModel>(p => p.Quotation).WithOne(q => q.PurchaseOrderRequest).OnDelete(DeleteBehavior.Cascade); builder.Entity <PurchaseOrderRequestModel>().HasMany <SampleModel>(p => p.Samples).WithOne(s => s.PurchaseOrderRequest).HasForeignKey(s => s.PurchaseOrderRequestId).OnDelete(DeleteBehavior.Cascade); builder.Entity <IdentityUserRole <int> >().HasKey(r => new { r.UserId, r.RoleId }); builder.Entity <TestParameterMatrixModel>().HasKey(t => t.Id); builder.Entity <TestParameterMatrixModel>().HasAlternateKey(t => new { t.MatrixId, t.TestParameterId }); builder.Entity <TestParameterMethodModel>().HasKey(t => t.Id); builder.Entity <TestParameterMethodModel>().HasAlternateKey(t => new { t.MethodId, t.TestParameterId }); builder.Entity <SampleTestParameterModel>().HasKey(s => s.Id); // builder.Entity<SampleTestParameterModel>().HasAlternateKey( s => new { s.SampleId, s.TestParameterId, s.MethodId } ); // builder.Entity<SampleTestParameterModel>().HasAlternateKey( s => new { s.SampleId, s.TestParameterMethodId } ); builder.Entity <SampleTestParameterModel>().HasMany(s => s.SampleTestParameterResults).WithOne(r => r.SampleTestParameter).OnDelete(DeleteBehavior.Cascade); builder.Entity <SampleTestParameterResultModel>().HasKey(r => r.Id); builder.Entity <SampleTestParameterResultModel>().HasAlternateKey(r => new { r.SampleTestParameterId, r.Revision }); LimsUser user = new LimsUser() { Id = 1, UserName = "******", NormalizedUserName = "******", Email = "*****@*****.**", NormalizedEmail = "*****@*****.**".ToUpper(), EmailConfirmed = true, SecurityStamp = "lol" }; PasswordHasher <LimsUser> hasher = new PasswordHasher <LimsUser>(); user.PasswordHash = hasher.HashPassword(user, "maa"); builder.Entity <LimsUser>().HasData(user); var userIdClaim = new IdentityUserClaim <int> { UserId = 1, Id = 1, ClaimType = "Claim1", ClaimValue = "1" }; var userNameClaim = new IdentityUserClaim <int> { UserId = 1, Id = 2, ClaimType = "Claim2", ClaimValue = "moa995" }; var userRoleClaim = new IdentityUserClaim <int> { UserId = 1, Id = 3, ClaimType = "Claim3", ClaimValue = "admin" }; builder.Entity <IdentityUserClaim <int> >().HasData(userIdClaim, userNameClaim, userRoleClaim); var customer = new CustomerModel { Id = 1, Name = "KNPC", PhoneNumber = "+965-999999", Address = "Salmyia" }; var contact = new ContactModel { Id = 1, Name = "Mohammad Abdullah", PhoneNumber = "+965-99828764", CustomerId = 1 }; var contact2 = new ContactModel { Id = 2, Name = "Ibrahim Al-Hajeri", PhoneNumber = "+965-0017235", CustomerId = 1 }; var customer1 = new CustomerModel { Id = 2, Name = "Architecture", PhoneNumber = "+965-999999", Address = "Salmyia" }; var contact11 = new ContactModel { Id = 3, Name = "Hiba Abdulqader", PhoneNumber = "+965-99828764", CustomerId = 2 }; var contact12 = new ContactModel { Id = 4, Name = "Khalil", PhoneNumber = "+965-63273627", CustomerId = 2 }; var contact13 = new ContactModel { Id = 5, Name = "Mohammad", PhoneNumber = "+965-8273928", CustomerId = 2 }; var customer2 = new CustomerModel { Id = 3, Name = "Kindergarten", PhoneNumber = "+965-999999", Address = "Salmyia" }; var contact21 = new ContactModel { Id = 6, Name = "Yousef Abdullah", PhoneNumber = "+965-1234567", CustomerId = 3 }; var contact22 = new ContactModel { Id = 7, Name = "Celen", PhoneNumber = "+965-7654321", CustomerId = 3 }; builder.Entity <CustomerModel>().HasData(customer, customer1, customer2); builder.Entity <ContactModel>().HasData(contact, contact2, contact11, contact12, contact13, contact21, contact22); var matrixSolid = new MatrixModel { Id = 1, Name = "Solid", Code = MatrixModel.Codes.Solid }; var matrixLiquid = new MatrixModel { Id = 2, Name = "Liquid", Code = MatrixModel.Codes.Liquid }; var matrixGas = new MatrixModel { Id = 3, Name = "Gas", Code = MatrixModel.Codes.Gas }; builder.Entity <MatrixModel>().HasData(matrixSolid, matrixLiquid, matrixGas); var method = new MethodModel { Id = 1, Name = "Method1", Description = "a generic test method", UnitOfMeasurement = "cm^2", Code = "MTD" }; var sulphurMethod1 = new MethodModel { Id = 2, Name = "Sulphur Method", Description = "a test method for sulphur", UnitOfMeasurement = "p.cm^2", Code = "SLPRTST" }; var carbonMethod2 = new MethodModel { Id = 3, Name = "Carbon Method", Description = "a test method for carbon", UnitOfMeasurement = "cm^2", Code = "CBNTST" }; builder.Entity <MethodModel>().HasData(method, sulphurMethod1, carbonMethod2); var sulphurTest = new TestParameterModel { Id = 1, Name = "Sulphur Test", Code = "SLPTST", Description = "Test for Sulphur 'S'" }; var carbonTest = new TestParameterModel { Id = 2, Name = "Carbon Test", Code = "CBNTST", Description = "Test for carbon 'C'" }; var waterTest = new TestParameterModel { Id = 3, Name = "Water Test", Code = "WTRTST", Description = "Test for water 'H2O'" }; var clorideTest = new TestParameterModel { Id = 4, Name = "Cloride Test", Code = "CLTST", Description = "Test for Cloride 'CL2'" }; //builder.Entity<TestParameterModel>().HasData(sulphurTest, carbonTest, waterTest, clorideTest); var genericTestMethodforSulphur = new TestParameterMethodModel { Id = 1, MethodId = 1, TestParameterId = 1, Price = 50.250d }; var genericTestMethodforCarbon = new TestParameterMethodModel { Id = 2, MethodId = 1, TestParameterId = 2, Price = 23.200d }; var sulpherTestMethod = new TestParameterMethodModel { Id = 3, MethodId = 2, TestParameterId = 1, Price = 30.400d }; var carbonTestMethod = new TestParameterMethodModel { Id = 4, MethodId = 3, TestParameterId = 2, Price = 10.850d }; //builder.Entity<TestParameterMethodModel>().HasData(genericTestMethodforCarbon, genericTestMethodforSulphur, sulpherTestMethod, carbonTestMethod); var carbonSolidMatrixTest = new TestParameterMatrixModel { Id = 1, TestParameterId = 1, MatrixId = 1 }; var sulphurSolidMatrixTest = new TestParameterMatrixModel { Id = 2, TestParameterId = 2, MatrixId = 1 }; var waterLiquidMatrixTest = new TestParameterMatrixModel { Id = 3, TestParameterId = 3, MatrixId = 2 }; var clorideGasMatrixTest = new TestParameterMatrixModel { Id = 4, TestParameterId = 4, MatrixId = 3 }; //builder.Entity<TestParameterMatrixModel>().HasData(carbonSolidMatrixTest, sulphurSolidMatrixTest, waterLiquidMatrixTest, clorideGasMatrixTest); var por = new PurchaseOrderRequestModel { //Id = 1, ContactId = 1, Code = PurchaseOrderRequestService.GeneratePORCode(1, 1), ReceivedDate = DateTime.Now }; // builder.Entity<PurchaseOrderRequestModel>().HasData(por); var sulphurSample = new SampleModel { //Id = 1, Locked = false, Location = "Ahmadi", Remarks = "No Remarks", ReceivedByUserId = 1, SamplingPoint = "Salmyia", SamplingBy = "Mohammad", MatrixId = matrixSolid.Id, PurchaseOrderRequestId = 1, ReceivedDate = DateTime.Now, SamplingDate = DateTime.Now.AddDays(-3), Code = SampleService.GenerateSampleCode(matrixSolid.Name, 1, 1) }; var carbonSample = new SampleModel { //Id = 2, Locked = false, Location = "Sabhan", Remarks = "Carbon Sample", ReceivedByUserId = 1, SamplingPoint = "Salmyia", SamplingBy = "Yousef", MatrixId = matrixSolid.Id, PurchaseOrderRequestId = 1, ReceivedDate = DateTime.Now, SamplingDate = DateTime.Now.AddDays(-6), Code = SampleService.GenerateSampleCode(matrixSolid.Name, 1, 1) }; // builder.Entity<SampleModel>().HasData(sulphurSample, carbonSample); var sulphurSampleTestParameter = new SampleTestParameterModel { //Id = 1, MethodId = 2, TestParameterId = 1, TestParameterMethodId = 3, SampleId = 1, ModifiedPrice = 8 }; var sulphurGenericSampleTestParameter = new SampleTestParameterModel { //Id = 2, MethodId = 1, TestParameterId = 1, TestParameterMethodId = 1, SampleId = 1, ModifiedPrice = 8 }; var carbonSampleTestParameter = new SampleTestParameterModel { //Id = 3, MethodId = 3, TestParameterId = 2, TestParameterMethodId = 4, SampleId = 2, ModifiedPrice = 8 }; var carbonGenericSampleTestParameter = new SampleTestParameterModel { //Id = 4, MethodId = 1, TestParameterId = 2, TestParameterMethodId = 2, SampleId = 2, ModifiedPrice = 8 }; // builder.Entity<SampleTestParameterModel>().HasData(sulphurSampleTestParameter, sulphurGenericSampleTestParameter, carbonSampleTestParameter, carbonGenericSampleTestParameter); }