public RecordValue(IMatrix matr1, IMatrix matr2, IDrawer dr1, IDrawer dr2)
 {
     this.matr1 = matr1;
       this.matr2 = matr2;
       this.dr1 = dr1;
       this.dr2 = dr2;
 }
 public void Border(IMatrix m)
 {
     if (matrComp.col_num == matrComp.col_num - 1 && matrComp.row_num == matrComp.row_num - 1)
     {
       drawer.Border(this);
     }
 }
		public void RemoveMatrixRow(IMatrix matrix, IDBDataSource dBDataSource, int row)
		{
			dBDataSource.RemoveRecord(row - 1);

			// Loads the user interface with current data from the matrix objects data source.
			matrix.LoadFromDataSource();
		}
Example #4
0
        /// <summary>
        ///  Ensures a minimum number of self loops exist in the matrix by adding values to the diagonal.
        /// </summary>
        public static void EnsureMinSelfLoopCount(IMatrix<double> network, int n)
        {
            int ctr = 0;

            // find all non-zeros on diagonal
            for (int i = 0; i < network.NodeCount; i++)
            {
                if (network[i,i]!=0.0)
                    ctr++;
            }

            // if that many self loops exist, return
            if (ctr >= n)
                return;

            // else create the needed number of self loops
            int needed = n;
            if (n < ctr)
                needed = ctr - n;

            ctr = 0;  // re-use ctr variable
            do
            {
                for (int i = 0; i < network.NodeCount; i++)
                {
                    network[i, i] = network[i, i] + 1.0;
                    ctr++;
                    if (ctr >= needed)
                        break;
                }
            } while (needed >ctr);
        }
 /// <summary>
 /// Сумма элементов матрицы
 /// </summary>
 /// <param name="matrix">Матрица</param>
 /// <returns>Сумма элементов</returns>
 public static long Sum(IMatrix<int> matrix)
 {
     long sum = 0;
     foreach (IIndex index in MultiDimensionMatrixEnumerator.Indexes(matrix))
         sum += matrix[index];
     return sum;
 }
        //here we have _gradient as sum of gradients, should make step in this direction
        protected override bool LearnBatch(INet net, double currentLearningCycleError)
        {
            if (_prevStep != null)
            {
                var y = _gradient.Negate().Sum(_prevGradient); //yk
                //_gradientDiffNorm = y.Norm;
                //Console.WriteLine("Gradient diff norm: {0}", _gradientDiffNorm.GetMod().X);
                //Console.WriteLine();
                //if (IsNetLearned(currentLearningCycleError))
                //    return;
                //its time to calculate b(k + 1)
                _b = CalculateInvertedPseudoGaussian(_b, _prevStep, y);
            }

            var direction = CalculateMinimizeDirection(_b, _gradient); //pk - direction of next step
            var step = MakeStep(direction, net, currentLearningCycleError); //step = alpha*pk
            //var step = MakeStepGoldstein(direction, net, currentLearningCycleError, _gradient); //step = alpha*pk
            if (step == null)
            {

            }

            //Save step and grad
            _prevStep = step;
            _prevGradient = _gradient;
            //clear gradient vector
            _gradient = null;

            return true;
        }
    public void EhCrossPRESS(int[]group, IMatrix XX, IMatrix YY, IMatrix XU, IMatrix YU)
    {
      IVector meanX,scaleX,meanY,scaleY;
      if(_predictedY==null || _predictedY.Rows!=YU.Rows || _predictedY.Columns!=YU.Columns)
        _predictedY = new MatrixMath.BEMatrix(YU.Rows,YU.Columns);

      MultivariateRegression.PreprocessForAnalysis(_preprocessOptions,_spectralRegions, XX, YY, out meanX, out scaleX, out meanY, out scaleY);
      _analysis.AnalyzeFromPreprocessed(XX,YY,_numFactors);
      _numFactors = Math.Min(_numFactors,_analysis.NumberOfFactors);
   
      MultivariateRegression.PreprocessSpectraForPrediction(_preprocessOptions,XU,meanX,scaleX);


      // allocate the crossPRESS vector here, since now we know about the number of factors a bit more
      if(null==_crossPRESS)
        _crossPRESS = new double[_numFactors+1]; // one more since we want to have the value at factors=0 (i.e. the variance of the y-matrix)

      // for all factors do now a prediction of the remaining spectra
      _crossPRESS[0] += MatrixMath.SumOfSquares(YU);
      for(int nFactor=1;nFactor<=_numFactors;nFactor++)
      {
        _analysis.PredictYFromPreprocessed(XU,nFactor,_predictedY);
        MultivariateRegression.PostprocessY(_predictedY,meanY,scaleY);
        _crossPRESS[nFactor] += MatrixMath.SumOfSquaredDifferences(YU,_predictedY);
      }
    }
        public void CellValue(IMatrix m, int row, int col)
        {
            if (row == r || col == c) { }
                   else {

                drawer.CellValue(this, row, col);
            }
        }
		public void SetTransform (LinearGradientBrush widget, IMatrix transform)
		{
			var brush = ((BrushObject)widget.ControlObject);
			brush.Matrix = transform;
			var newmatrix = brush.InitialMatrix.Clone ();
			newmatrix.Multiply (transform.ToSD ());
			brush.Brush.Transform = newmatrix;
		}
		/// <summary>Write a matrix of floats to a StreamWriter object</summary>
		/// <param name="writer">a <see cref="StreamWriter"/></param>
		/// <param name="matrix">the matrix of floats to write out</param>
		static public void WriteMatrix(this TextWriter writer, IMatrix<float> matrix)
		{
			writer.WriteLine(matrix.NumberOfRows + " " + matrix.NumberOfColumns);
			for (int i = 0; i < matrix.NumberOfRows; i++)
				for (int j = 0; j < matrix.NumberOfColumns; j++)
					writer.WriteLine(i + " " + j + " " + matrix[i, j].ToString(CultureInfo.InvariantCulture));
			writer.WriteLine();
		}
Example #11
0
 public void Inititialize()
 {
     _container = new Mock<IContainer>();
     _container.Setup(x => x.GetInstance<IPrimeNumber>()).Returns(new PrimeNumber());
     _primeNumber = _container.Object.GetInstance<IPrimeNumber>();
     _container.Setup(x => x.GetInstance<IMatrix>()).Returns(new Matrix(_primeNumber));
     _matrix = _container.Object.GetInstance<IMatrix>();
 }
        /// <summary>
        /// Средняя нагрузка при заданных параметрах разбиения матрицы
        /// </summary>
        /// <param name="matrix">Матрица</param>
        /// <param name="partitioning">Параметры разбиения матрицы</param>
        /// <returns>Сумма элементов</returns>
        public static double W(IMatrix<int> matrix, PartitioningParameters partitioning)
        {
            int N = 1;
            for (int i = 0; i < partitioning.Dimensions; i++)
                N *= partitioning[i];

            return Sum(matrix) / (double)N;
        }
        /// <summary>
        /// Средняя нагрузка при заданных параметрах разбиения матрицы
        /// </summary>
        /// <param name="matrix">Матрица</param>
        /// <param name="partitioning">Параметры разбиения матрицы</param>
        /// <returns>Сумма элементов</returns>
        public static double W(IMatrix<int> matrix, params int[] partitioning)
        {
            int N = 1;
            for (int i = 0; i < partitioning.Length; i++)
                N *= partitioning[i];

            return Sum(matrix) / (double)N;
        }
 public SolutionVisualizerForm(SplittedMatrix splittedMatrix, IMatrix<int> matrix, ISolution solution, int min, int max, double criterion)
 {
     InitParameters(splittedMatrix, matrix, solution);
     SetSizeOfBitmap();
     SetMinMax(min, max);
     SetBoundOfValuesOfMatrix(min, max);
     SetCriterion(criterion);
     settingsEvent();
 }
Example #15
0
        public void ReadFromFile(out IMatrix A, out Vector b, out Vector x_init)
        {
            //          Не хватает проверки path
            using (System.IO.StreamReader file = new System.IO.StreamReader(path))
            {
                var st = file.ReadToEnd().Replace('.',',').Split(new char[] { '\n', ' ', '\t', '\r' },
                StringSplitOptions.RemoveEmptyEntries);
                int n, m;
                if (!int.TryParse(st[0], out n))
                    throw new Exception("Bad file format");
                n = int.Parse(st[0]);

                int[] ia = new int[n + 1];

                double[] d = new double[n];
                double[] rightPart = new double[n];
                double[] x0 = new double[n];
                long offset = 1;

                for (int i = 0; i < n + 1; i++, offset++)
                    ia[i] = int.Parse(st[offset]);
                m = ia[n] - 1;
                int[] ja = new int[m];
                double[] al = new double[m];
                double[] au = new double[m];
                for (int i = 0; i < m; i++, offset++)
                    ja[i] = int.Parse(st[offset]);
                if (ia[0] != 0)
                {
                    for (int i = 0; i < n + 1; i++)
                        ia[i]--;

                    for (int i = 0; i < m; i++)
                        ja[i]--;
                }

                for (int i = 0; i < m; i++,offset++)
                    al[i] = double.Parse(st[offset]);

                for (int i = 0; i < m; i++, offset++)
                    au[i] = double.Parse(st[offset]);

                for (int i = 0; i < n; i++,offset++)
                    d[i] = double.Parse(st[offset]);

                for (int i = 0; i <  n; i++,offset++)
                    rightPart[i] = double.Parse(st[offset]);

                for (int i = 0; i < n; i++, offset++)
                    x0[i] = double.Parse(st[offset]);

                A = new RowColumnSparseMatrix(n, ia, ja, al, au, d);
                b = new Vector(rightPart);
                x_init = new Vector(x0);
            }
        }
Example #16
0
 public override void CellValue(IMatrix m, int row, int col)
 {
     string s = m[row, col].ToString();
     Font font = new Font("Arial",12);
     SolidBrush brush = new SolidBrush(Color.CornflowerBlue);
     RectangleF rect = new RectangleF(x + h*col, y +h*row, h , h);
     StringFormat format = new StringFormat();
     format.Alignment = StringAlignment.Center;
     g.DrawString(s,font,brush,rect,format);
 }
Example #17
0
		public static bool Equals(IMatrix m, float xx, float yx, float xy, float yy, float x0, float y0)
		{
			var e = m.Elements;
			return
				FloatEquals(e[0], xx) &&
				FloatEquals(e[1], yx) &&
				FloatEquals(e[2], xy) &&
				FloatEquals(e[3], yy) &&
				FloatEquals(e[4], x0) &&
				FloatEquals(e[5], y0);
		}
Example #18
0
        public Matrix(IMatrix x)
        {
            m = x.ColumnDimension;
            n = x.RowDimension;
            el = new double[n, m];

            for (int row = 0; row < n; row++)
                for (int column = 0; column < m; column++)
                    el[row, column] = x[row, column];

        }
Example #19
0
		void Push (IMatrix matrix)
		{
			// If we're in a SaveTransform block,
			// increment the pop count.
			current = current ?? NewEntry ();
			current.Matrices.Add (matrix);

			current.PopCount++;
			
			// push the transform
			push (matrix);
		}
 public void Execute()
 {
     ManagComm.getInstance().addComm(this);
     g = form2.getGraph1();
     g1 = form2.getGraph2();
     d = new Sheme1(g, 10, 10);
     d1 = new Sheme1(g1, 10, 10);
     m1 = m1.GetComponent();
     m2 = m2.GetComponent();
     RecordValue c = new RecordValue(m1, m2, d, d1);
     c.record();
 }
Example #21
0
		void Prepend(IMatrix matrix)
		{
			if (Current != null)
			{
				pop();
				Current.Prepend(matrix);
			}
			else
			{
				Current = matrix.Clone();
			}
			push(Current);
		}
Example #22
0
		public void SaveTransform()
		{
			if (stack == null)
				stack = new Stack<IMatrix>();

			if (Current != null)
			{
				stack.Push(Current);
				Current = Current.Clone();
			}
			else
				stack.Push(null);
		}
 public void Execute()
 {
     ManagComm.getInstance().addComm(this);
     form2.getGraph1().Clear(Color.AntiqueWhite);
     form2.getGraph2().Clear(Color.AntiqueWhite);
     draw1 = new Sheme4(form2.getGraph1(), 10, 10);
     draw2 = new Sheme4(form2.getGraph2(), 10, 10);
     smatrix = new HideDecorator(smatrix, 1, 2);
     dmatrix = new HideDecorator(dmatrix, 1, 2);
     smatrix.setDrawer(draw1);
     dmatrix.setDrawer(draw2);
     smatrix.draw();
     dmatrix.draw();
 }
Example #24
0
 public void Execute()
 {
     ManagComm.getInstance().addComm(this);
     form2.getGraph1().Clear(Color.AntiqueWhite);
     form2.getGraph2().Clear(Color.AntiqueWhite);
     draw1 = new Sheme4(form2.getGraph1(), 10, 10);
     draw2 = new Sheme4(form2.getGraph2(), 10, 10);
     smatrix = smatrix.GetComponent();
     dmatrix = dmatrix.GetComponent();
     smatrix.setDrawer(draw1);
     dmatrix.setDrawer(draw2);
     smatrix.draw();
     dmatrix.draw();
 }
Example #25
0
        private static IMatrix CalculateInvertedPseudoGaussian(IMatrix b, IVector s, IVector y)
        {
            var syNumber = s.Mul(y);

            var syNumberSqr = syNumber.Mul(syNumber);
            var yByNumber = y.Mul(b.Mul(y));
            var ssMatrix = s.OuterMul(s);
            var second = ssMatrix.Mul(syNumber.Sum(yByNumber)).Div(syNumberSqr);

            var ysMatrix = y.OuterMul(s);
            var syMatrix = s.OuterMul(y);
            var third = b.Mul(ysMatrix).Sum(syMatrix.Mul(b)).Div(syNumber);

            return b.Sum(second).Sub(third);
        }
        private void InitParameters(IMatrix<int> matrix)
        {
            Name = "MatrixVisualizerForm";
            Text = "     Visualizer of matrix";
            this.matrix = matrix;
            coefficient = 255.0 / CoreUtilities.Utilities.Max(matrix);
            sizeOfMatrix = new Size(matrix.Size(1), matrix.Size(0));
            matrixBitmap = new Bitmap(sizeOfMatrix.Width, sizeOfMatrix.Height);
            modeOfDrawing = Mode.Matrix;

            settingsEvent = SetStep;
            settingsEvent += SetCriterionSettings;
            settingsEvent += SetZoom;
            settingsEvent += SetBitmap;
        }
Example #27
0
        private void button2_Click(object sender, EventArgs e)
        {
            CleanMatrix();
            Graphics g = Graphics.FromHwnd(panel1.Handle);
            Graphics g1 = Graphics.FromHwnd(panel2.Handle);

            d = new Sheme4(g, 10, 10);
            d1 = new Sheme4(g1, 10, 10);
            m1 = new HideDecorator(m1, 1, 2);
            m2 = new HideDecorator(m2, 1, 2);
            m1.setDrawer(d);
            m2.setDrawer(d1);
            m1.draw();
            m2.draw();
        }
Example #28
0
 public void Execute()
 {
     ManagComm.getInstance().addComm(this);
     m1 = new SimpleMatrix(3, 4);
     m2 = new DisperseMatrix(5, 3);
     IniciatorMatrix.fullMatrix(m1, 8, 45);
     IniciatorMatrix.fullMatrix(m2, 6, 45);
     g = form2.getGraph1();
     g1 = form2.getGraph2();
     d = new Sheme1(g, 10, 10);
     d1 = new Sheme1(g1, 10, 10);
     m1.setDrawer(d);
     m2.setDrawer(d1);
     m1.draw();
     m2.draw();
 }
        /// <summary>
        /// Prints the matrix with player info.
        /// </summary>
        /// <param name="matrix">Current matrix.</param>
        /// <param name="player">Current player.</param>
        /// <returns></returns>
        public override string GetPrintFrame(IMatrix matrix, IPlayer player)
        {
            var numberOfRows = matrix.Field.GetLength(0);
            var numberOfCols = matrix.Field.GetLength(1);
            var output = new StringBuilder();

            output.AppendLine("Score: " + player.Score);
            output.AppendLine();
            output.Append(this.AddRowIndexator(numberOfRows));
            output.Append(this.AddDashes(numberOfRows));

            for (int row = 0; row < numberOfRows; row++)
            {
                output.AppendFormat("{0, -2} | ", row);

                for (int col = 0; col < numberOfCols; col++)
                {
                    var currentCell = matrix.Field[row, col];

                    if (!currentCell.IsOpen)
                    {
                        output.AppendFormat("{0, -3}", UnrevealedCellCharacter);
                    }
                    else if (!currentCell.IsBomb)
                    {
                        if (currentCell.NumberOfMines != 0)
                        {
                            output.AppendFormat("{0, -3}", currentCell.NumberOfMines);
                        }
                        else
                        {
                            output.AppendFormat("{0, -3}", currentCell.NumberOfMines);
                        }
                    }
                    else
                    {
                        output.AppendFormat("{0, -3}", BombCharacter);
                    }
                }

                output.Append("|\n");
            }

            output.Append(this.AddDashes(numberOfRows));

            return output.ToString();
        }
Example #30
0
 private void button2_Click(object sender, EventArgs e)
 {
     m1 = new SimpleMatrix(2, 3);
     m2 = new DisperseMatrix(4, 2);
     IniciatorMatrix.fullMatrix(m1, 4, 7);
     IniciatorMatrix.fullMatrix(m2, 10, 5);
     Statistics j = new Statistics(m1);
     int y = j.max;
     Statistics l = new Statistics(m2);
     int x = l.max;
     textBox1.Text = y.ToString();
     textBox3.Text = x.ToString();
     int z = j.notnull;
     int v = l.notnull;
     textBox2.Text = z.ToString();
     textBox4.Text = v.ToString();
 }
Example #31
0
 public virtual IVector MultAdd(double alpha, IMatrix A, IVector x, IVector y, IVector z)
 {
     return(MultAdd(alpha, A, x, 1.0, y, z));
 }
Example #32
0
        public void Execute(IPCBIWindow parent)
        {
            if (parent == null)
            {
                return;
            }
            TextType tt = TextType.angle;

            ShowInputDialog(ref tt);

            // MessageBox.Show( tt.ToString());
            IMatrix m    = parent.GetMatrix();
            IStep   step = parent.GetCurrentStep();

            if (tt == TextType.angle)
            {
                foreach (string layerName in m.GetAllSignalLayerNames())
                {
                    IODBLayer layer = (IODBLayer)step.GetLayer(layerName);

                    foreach (IODBObject obj in layer.GetAllLayerObjects())
                    {
                        IObjectSpecifics os = obj.GetSpecifics();
                        if (os.GetType() == typeof(ILineSpecifics))
                        {
                            ILineSpecifics lineEdges = (ILineSpecifics)os;
                            double         angle     = PCBI.MathUtils.IMath.GetAngle(PCBI.MathUtils.PointD.FromPointF(lineEdges.Start), PCBI.MathUtils.PointD.FromPointF(lineEdges.End));
                            obj.FreeText = "? " + angle.ToString();
                        }
                        if (os.GetType() == typeof(IPadSpecifics))
                        {
                            IPadSpecifics PAD   = (IPadSpecifics)os;
                            double        angle = PAD.Rotation;
                            obj.FreeText = "? " + angle.ToString();
                        }
                    }
                }
            }
            if (tt == TextType.lenght)
            {
                foreach (string layerName in m.GetAllSignalLayerNames())
                {
                    IODBLayer layer = (IODBLayer)step.GetLayer(layerName);

                    foreach (IODBObject obj in layer.GetAllLayerObjects())
                    {
                        IObjectSpecifics os = obj.GetSpecifics();
                        if (os.GetType() == typeof(ILineSpecifics))
                        {
                            ILineSpecifics lineEdges = (ILineSpecifics)os;

                            double length = PCBI.MathUtils.IMath.DistancePointToPoint(PCBI.MathUtils.PointD.FromPointF(lineEdges.Start), PCBI.MathUtils.PointD.FromPointF(lineEdges.End)) / 100;
                            if (parent.GetUnit())
                            {
                                length *= 2.54f;
                            }
                            length       = Math.Round(length, 2);
                            obj.FreeText = "L: " + length.ToString();
                        }
                        if (os.GetType() == typeof(IPadSpecifics))
                        {
                            IPadSpecifics PAD    = (IPadSpecifics)os;
                            RectangleF    bounds = obj.GetBounds();
                            double        w      = bounds.Width / 100;
                            double        h      = bounds.Height / 100;

                            if (parent.GetUnit())
                            {
                                w *= 2.54f;
                                h *= 2.54f;
                            }
                            w            = Math.Round(w, 2);
                            h            = Math.Round(h, 2);
                            obj.FreeText = "w: " + w.ToString() + " h: " + h.ToString();
                        }
                    }
                }
            }
            if (tt == TextType.ViaCount)
            {
                foreach (INet NetList in step.GetNets())
                {
                    int drillCount = 0;
                    foreach (IODBObject obj in NetList.GetAllNetObjects(parent))
                    {
                        if (m.GetMatrixLayerType(obj.GetParentLayerName()) == MatrixLayerType.Drill)
                        {
                            drillCount++;
                        }
                    }
                    foreach (IODBObject obj in NetList.GetAllNetObjects(parent))
                    {
                        obj.FreeText = "DrillCount: " + drillCount.ToString();
                    }
                }
            }
            if (tt == TextType.NetOnLayer)
            {
                foreach (INet NetList in step.GetNets())
                {
                    string LNames = "";
                    foreach (string LayerNames in NetList.GetAllUsedLayers(step))
                    {
                        if (m.GetMatrixLayerType(LayerNames) == MatrixLayerType.Signal)
                        {
                            LNames += LayerNames + "; ";
                        }
                    }
                    foreach (IODBObject obj in NetList.GetAllNetObjects(parent))
                    {
                        obj.FreeText = "layer: " + LNames;
                    }
                }
            }
            if (tt == TextType.NetLength)
            {
                foreach (INet NetList in step.GetNets())
                {
                    double length = CalculateNetLenth(NetList.GetAllNetObjects(parent)) / 100;
                    if (parent.GetUnit())
                    {
                        length *= 2.54f;
                    }
                    foreach (IODBObject obj in NetList.GetAllNetObjects(parent))
                    {
                        obj.FreeText = "Netlength: " + Math.Round(length, 2);
                    }
                }
            }
            parent.ShowFreeTextInfoOnAllLayer = true;
            parent.UpdateView();
        }
Example #33
0
 public static swm.Matrix ToWpf(this IMatrix matrix)
 {
     return((swm.Matrix)matrix.ControlObject);
 }
Example #34
0
 protected internal abstract double NormInf(IMatrix A);
Example #35
0
        /// <summary>
        /// Records the network activity
        /// </summary>
        /// <param name="context">The graph context</param>
        /// <param name="data">The list of incoming signals</param>
        /// <param name="output">Output signal</param>
        /// <param name="backpropagation">Backpropagation creator (optional)</param>
        protected void _AddHistory(IContext context, IReadOnlyList <IncomingChannel> data, IMatrix output, Func <IBackpropagation> backpropagation)
        {
            var sources = data.Select(d => d.Source).ToList();

            context.AddForward(new TrainingAction(this, new MatrixGraphData(output), sources), backpropagation);
        }
Example #36
0
 public Backpropagation(FeedForward source, IMatrix input) : base(source)
 {
     _input = input;
 }
Example #37
0
 protected internal abstract IMatrix Rank1I(double alpha, IVector x, IVector y, IMatrix A);
Example #38
0
 public void MultiplyTransform(IMatrix matrix)
 {
     TransformStack.MultiplyTransform(matrix);
 }
Example #39
0
 protected internal abstract IMatrix CopyI(IMatrix A, IMatrix B);
Example #40
0
 public void RestoreTransform()
 {
     transform = transforms.Pop();
 }
Example #41
0
 /// <summary>
 /// Indicates whether the this IMatrix is equal to another IMatrix.
 /// </summary>
 /// <param name="other">
 /// A <see cref="IMatrix"/> to compare with this object.
 /// </param>
 /// <returns>
 /// It returns true if the this IMatrix is equal to <paramref name="other"/>; otherwise, false.
 /// </returns>
 public bool Equals(IMatrix other)
 {
     return(Equals((object)other));
 }
Example #42
0
 public void MultiplyTransform(IMatrix matrix)
 {
     transform.Append(matrix);
 }
        public void Report_Via_Pad()
        {
            var excelType = Type.GetTypeFromProgID("Excel.Application");

            dynamic excel = Activator.CreateInstance(excelType);

            excel.Visible = true;
            excel.Workbooks.Add();
            //////

            StringBuilder sb = new StringBuilder();

            IStep   step = Parent.GetCurrentStep();
            IMatrix m    = Parent.GetMatrix();

            foreach (INet NetList in step.GetNets())
            {
                foreach (IODBObject obj in NetList.GetAllNetObjects(Parent))
                {
                    if (m.GetMatrixLayerType(obj.GetParentLayerName()) == MatrixLayerType.Drill)
                    {
                        if (obj.Type == IObjectType.Pad)
                        {
                            IPadSpecifics ps = (IPadSpecifics)obj.GetSpecifics();
                            float         x  = ps.Location.X;
                            float         Y  = ps.Location.Y;
                            if (Parent.GetUnit())
                            {
                                float unit = 25.4f / 1000;
                                x = x * unit;
                                Y = Y * unit;
                            }
                            sb.Append("Via;" + obj.NetName + ";" + x.ToString("N3") + ";" + Y.ToString("N3") + Environment.NewLine);
                        }
                    }
                    else
                    if (obj.GetParentLayerName().ToLower() == m.GetTopSignalLayer().ToLower())
                    {
                        if (obj.Type == IObjectType.Pad)
                        {
                            IPadSpecifics ps = (IPadSpecifics)obj.GetSpecifics();
                            if (ps.Type != PCBI.Symbol_Type.r)
                            {
                                float x = ps.Location.X;
                                float Y = ps.Location.Y;
                                if (Parent.GetUnit())
                                {
                                    float unit = 25.4f / 1000;
                                    x = x * unit;
                                    Y = Y * unit;
                                }
                                sb.Append("PAD_top;" + obj.NetName + ";" + x.ToString("N3") + ";" + Y.ToString("N3") + Environment.NewLine);
                            }
                        }
                    }
                    else
                    if (obj.GetParentLayerName().ToLower() == m.GetBotSignalLayer().ToLower())
                    {
                        if (obj.Type == IObjectType.Pad)
                        {
                            IPadSpecifics ps = (IPadSpecifics)obj.GetSpecifics();
                            if (ps.Type != PCBI.Symbol_Type.r)
                            {
                                float x = ps.Location.X;
                                float Y = ps.Location.Y;
                                if (Parent.GetUnit())
                                {
                                    float unit = 25.4f / 1000;
                                    x = x * unit;
                                    Y = Y * unit;
                                }
                                sb.Append("PAD_bot;" + obj.NetName + ";" + x.ToString("N3") + ";" + Y.ToString("N3") + Environment.NewLine);
                            }
                        }
                    }
                }
            }
            //////

            //string LVText = "Type\tNetName\tposx\tposy" + Environment.NewLine + sb.ToString();
            string     LVText       = "Type;NetName;posx;posy" + Environment.NewLine + sb.ToString();
            string     LVCsv        = sb.ToString();
            DataObject LVDataObject = new DataObject();

            LVDataObject.SetData(DataFormats.Text, false, LVText);
            LVDataObject.SetData(DataFormats.CommaSeparatedValue, false, LVCsv);
            Clipboard.SetDataObject(LVDataObject, true);

            excel.ActiveSheet.Paste();

            //release the object
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
        }
Example #44
0
 public void UpdateWeights(IMatrix delta, ILearningContext context)
 {
     _updater.Update(_weight, delta, context);
 }
Example #45
0
 public abstract IMatrix Zero(IMatrix param1);
Example #46
0
 public virtual IMatrix Rank1(IVector x, IMatrix A)
 {
     return(Rank1(1.0, x, A));
 }
Example #47
0
 /// <summary> Constructor for AbstractMatrix, same size as A.</summary>
 protected AbstractMatrix(IMatrix A) : this(A.RowCount, A.ColumnCount)
 {
 }
            private void CreateNewDrillODBLayer(PCBI.Automation.IFilter filter, string newLayerName, IPCBIWindow parent, List <IODBObject> currIODBObjectList, bool activateLayer)
            {
                if (currIODBObjectList.Count == 0)
                {
                    return;
                }

                IODBLayer layer = filter.CreateEmptyODBLayer(newLayerName, parent.GetCurrentStep().Name);
                Dictionary <string, int> shapeList = new Dictionary <string, int>();

                foreach (IODBObject obj in currIODBObjectList)
                {
                    if (obj.Type == IObjectType.Pad)
                    {
                        IPadSpecificsD specPad = (IPadSpecificsD)obj.GetSpecificsD();
                        if (!shapeList.ContainsKey(specPad.ODBSymbol_String))
                        {
                            int newShapeIndex = IFilter.AddToolFromODBString(layer, specPad.ODBSymbol_String, shapeList.Count);
                            shapeList.Add(specPad.ODBSymbol_String, newShapeIndex);
                        }
                        IODBObject     pad       = filter.CreatePad(layer);
                        IPadSpecificsD padInfosD = (IPadSpecificsD)obj.GetSpecificsD();
                        padInfosD.ShapeIndex = shapeList[specPad.ODBSymbol_String];
                        pad.SetSpecifics(padInfosD, shapeList[specPad.ODBSymbol_String]);
                    }
                    else if (obj.Type == IObjectType.Line)
                    {
                        ILineSpecificsD specLine = (ILineSpecificsD)obj.GetSpecificsD();
                        if (!shapeList.ContainsKey(specLine.ODBSymbol_String))
                        {
                            int newShapeIndex = IFilter.AddToolFromODBString(layer, specLine.ODBSymbol_String, shapeList.Count);
                            shapeList.Add(specLine.ODBSymbol_String, newShapeIndex);
                        }
                        IODBObject      line           = filter.CreateLine(layer);
                        ILineSpecificsD lineSpecificsD = (ILineSpecificsD)obj.GetSpecificsD();
                        lineSpecificsD.ShapeIndex = shapeList[specLine.ODBSymbol_String];
                        line.SetSpecifics(lineSpecificsD);
                    }
                    else if (obj.Type == IObjectType.Arc)
                    {
                        IArcSpecificsD specArc = (IArcSpecificsD)obj.GetSpecificsD();
                        if (!shapeList.ContainsKey(specArc.ODBSymbol_String))
                        {
                            int newShapeIndex = IFilter.AddToolFromODBString(layer, specArc.ODBSymbol_String, shapeList.Count);
                            shapeList.Add(specArc.ODBSymbol_String, newShapeIndex);
                        }
                        IODBObject     arc           = filter.CreateArc(layer);
                        IArcSpecificsD specificsArcD = (IArcSpecificsD)obj.GetSpecificsD();
                        specificsArcD.ShapeIndex = shapeList[specArc.ODBSymbol_String];
                        arc.SetSpecifics(specificsArcD);
                    }
                    else if (obj.Type == IObjectType.Surface)
                    {
                        IODBObject         surface           = filter.CreatePolygon(layer);
                        ISurfaceSpecificsD surfaceSpecificsD = (ISurfaceSpecificsD)obj.GetSpecificsD();
                        surface.SetSpecifics(surfaceSpecificsD);
                    }
                    else if (obj.Type == IObjectType.Text)
                    {
                        IODBObject      text           = filter.CreateText(layer);
                        ITextSpecificsD textSpecificsD = (ITextSpecificsD)obj.GetSpecificsD();
                        text.SetSpecifics(textSpecificsD);
                    }
                }
                if (activateLayer)
                {
                    layer.EnableLayer(true);
                }

                IMatrix matrix = parent.GetMatrix();

                matrix.SetMatrixLayerType(layer.LayerName, MatrixLayerType.Drill);
                matrix.SetMatrixLayerContext(layer.LayerName, MatrixLayerContext.Board);
            }
Example #49
0
 protected internal abstract IVector MultAddI(double alpha, IMatrix A, IVector x, double beta, IVector y, IVector z);
Example #50
0
 public virtual IVector MultAdd(IMatrix A, IVector x, double beta, IVector y, IVector z)
 {
     return(MultAdd(1.0, A, x, beta, y, z));
 }
Example #51
0
 public virtual IMatrix Rank1(double alpha, IVector x, IMatrix A)
 {
     return(Rank1(alpha, x, x, A));
 }
Example #52
0
 public abstract double[,] GetArrayCopy(IMatrix param1);
Example #53
0
 public CylinderFigure(IMatrix transformation, IMaterial material)
     : this(transformation, material, double.NegativeInfinity, double.PositiveInfinity, false)
 {
 }
Example #54
0
        public IMatrix Eliminate(IMatrix coefficients, IMatrix outputs)
        {
            if (coefficients.Width != coefficients.Height)
            {
                throw new InvalidOperationException("The coefficient matrix should be squared.");
            }

            if (outputs.Width != 1)
            {
                throw new InvalidOperationException("The width of the outputs vector should equal to 1.");
            }

            if (coefficients.Height != outputs.Height)
            {
                throw new InvalidOperationException("The height of the coefficient matrix and outputs vector should match.");
            }

            var roots = Matrix.Zeros(coefficients.Height, 1);
            var mergedCoefficients = new double[coefficients.Height, coefficients.Width + 1];

            for (int i = 0; i < coefficients.Height; i++)
            {
                for (int j = 0; j < coefficients.Width + 1; j++)
                {
                    mergedCoefficients[i, j] = j != coefficients.Width
                        ? coefficients[i, j]
                        : outputs[i, 0];
                }
            }

            // Coefficients matrix triangulation
            for (var i = 0; i < coefficients.Height - 1; i++)
            {
                var pivot = mergedCoefficients[i, i];

                for (var j = i + 1; j < coefficients.Width; j++)
                {
                    var factor = mergedCoefficients[j, i] / pivot;

                    for (var k = 0; k < coefficients.Width + 1; k++)
                    {
                        mergedCoefficients[j, k] -= factor * mergedCoefficients[i, k];
                    }

                    if (mergedCoefficients[j, j] == 0)
                    {
                        throw new InvalidOperationException("Coefficient matrix has linear dependent rows.");
                    }
                }
            }

            // Reverse triangulation
            for (var i = coefficients.Height - 1; i >= 0; i--)
            {
                var rowSum = 0.0;

                for (var j = i + 1; j < coefficients.Width; j++)
                {
                    rowSum += mergedCoefficients[i, j] * roots[j, 0];
                }

                roots[i, 0] = (mergedCoefficients[i, coefficients.Width] - rowSum) / mergedCoefficients[i, i];
            }

            return(roots);
        }
Example #55
0
 public double GetConsistencyIndex(IMatrix <double> matrix)
 {
     return(_consistencyIndex);
 }
            internal void doWork(IPCBIWindow parent, bool splitRoutItem, bool activateNewLayer)
            {
                IStep   step   = parent.GetCurrentStep();
                IMatrix matrix = parent.GetMatrix();
                IFilter filter = new IFilter(parent);

                //if true the new layer need to be activated
                activateNewCreatedLayer = activateNewLayer;

                //sets the bool if rout should be used
                withRout = splitRoutItem;

                foreach (string currLayerName in matrix.GetAllDrillLayerNames())
                {
                    Dictionary <string, List <IODBObject> > allNewLayerDict = new Dictionary <string, List <IODBObject> >();

                    drill_ = new List <IODBObject>();

                    drillPlatedNormal    = new List <IODBObject>();
                    drillNonPlatedNormal = new List <IODBObject>();
                    drillViaNormal       = new List <IODBObject>();

                    drillRout          = new List <IODBObject>();
                    drillPlatedRout    = new List <IODBObject>();
                    drillNonPlatedRout = new List <IODBObject>();
                    drillViaRout       = new List <IODBObject>();

                    noAttributesPadsLayerNameCreated    = false;
                    noAttributesNotPadsLayerNameCreated = false;

                    platedLayerNameCreatedRout    = false;
                    nonPlatedLayerNameCreatedRout = false;
                    viaLayerNameCreatedRout       = false;

                    platedLayerNameCreatedNormal    = false;
                    nonPlatedLayerNameCreatedNormal = false;
                    viaLayerNameCreatedNormal       = false;

                    //only activate layer can be splitted
                    if (activateNewCreatedLayer)
                    {
                        if (!step.GetActiveLayerList().Contains(step.GetLayer(currLayerName)))
                        {
                            continue;
                        }
                    }

                    //checks if the layer is a splitted layer
                    if ((currLayerName.Length > 7 && currLayerName.Substring(currLayerName.Length - 7, 7).Equals("_plated")) || (currLayerName.Length > 4 && currLayerName.Substring(currLayerName.Length - 4, 4).Equals("_via")))
                    {
                        continue;
                    }

                    //checks if the new layer wasn't already splitted last time
                    foreach (string allOtherLayerName in matrix.GetAllDrillLayerNames())
                    {
                        if (activateNewCreatedLayer)
                        {
                            string searchedLayerName = currLayerName.ToLower() + "_plated";
                            if (allOtherLayerName.ToLower().Equals(searchedLayerName))
                            {
                                step.GetLayer(searchedLayerName).EnableLayer(true);
                            }
                            searchedLayerName = currLayerName.ToLower() + "_non_plated";
                            if (allOtherLayerName.ToLower().Equals(searchedLayerName))
                            {
                                step.GetLayer(searchedLayerName).EnableLayer(true);
                            }
                            searchedLayerName = currLayerName.ToLower() + "_via";
                            if (allOtherLayerName.ToLower().Equals(searchedLayerName))
                            {
                                step.GetLayer(searchedLayerName).EnableLayer(true);
                            }
                        }
                        if (allOtherLayerName.ToLower().Equals(currLayerName.ToLower() + "_plated") || allOtherLayerName.ToLower().Equals(currLayerName.ToLower() + "_non_plated") || allOtherLayerName.ToLower().Equals(currLayerName.ToLower() + "_via"))
                        {
                            skipLayerWasAlreadySplitted = true;
                            continue;
                        }
                    }

                    //if it was already splitted then skip it
                    if (skipLayerWasAlreadySplitted)
                    {
                        skipLayerWasAlreadySplitted = false;
                        continue;
                    }

                    //checks if layer is a drilllayer
                    if (matrix.GetMatrixLayerType(currLayerName) == MatrixLayerType.Drill)
                    {
                        ILayer         lay     = step.GetLayer(currLayerName);
                        List <IObject> objects = lay.GetAllLayerObjects();
                        foreach (IODBObject currObj in objects)
                        {
                            Dictionary <PCBI.FeatureAttributeEnum, string> objDict = currObj.GetAttributesDictionary();
                            if (objDict.Count != 0)
                            {
                                if (objDict.ContainsKey(PCBI.FeatureAttributeEnum.drill))
                                {
                                    if (currObj.Type == IObjectType.Pad)
                                    {
                                        #region Rout
                                        if (withRout)
                                        {
                                            if (objDict[PCBI.FeatureAttributeEnum.drill] == "non_plated")
                                            {
                                                drillNonPlatedNormal.Add(currObj);
                                                if (!nonPlatedLayerNameCreatedNormal)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_non_plated", drillNonPlatedNormal);
                                                    nonPlatedLayerNameCreatedNormal = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "plated")
                                            {
                                                drillPlatedNormal.Add(currObj);
                                                if (!platedLayerNameCreatedNormal)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_plated", drillPlatedNormal);
                                                    platedLayerNameCreatedNormal = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "via")
                                            {
                                                drillViaNormal.Add(currObj);
                                                if (!viaLayerNameCreatedNormal)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_via", drillViaNormal);
                                                    viaLayerNameCreatedNormal = true;
                                                }
                                            }
                                            else
                                            {
                                                drill_.Add(currObj);
                                                if (!noAttributesPadsLayerNameCreated)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_", drill_);
                                                    noAttributesPadsLayerNameCreated = true;
                                                }
                                            }
                                        }
                                        #endregion
                                        #region Without Rout
                                        else
                                        {
                                            if (objDict[PCBI.FeatureAttributeEnum.drill] == "non_plated")
                                            {
                                                drillNonPlatedRout.Add(currObj);
                                                if (!nonPlatedLayerNameCreatedRout)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_non_plated_rout", drillNonPlatedRout);
                                                    nonPlatedLayerNameCreatedRout = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "plated")
                                            {
                                                drillPlatedRout.Add(currObj);
                                                if (!platedLayerNameCreatedRout)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_plated_rout", drillPlatedRout);
                                                    platedLayerNameCreatedRout = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "via")
                                            {
                                                drillViaRout.Add(currObj);
                                                if (!viaLayerNameCreatedRout)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_via_rout", drillViaRout);
                                                    viaLayerNameCreatedRout = true;
                                                }
                                            }
                                            else
                                            {
                                                drill_.Add(currObj);
                                                if (!noAttributesPadsLayerNameCreated)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_", drill_);
                                                    noAttributesPadsLayerNameCreated = true;
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (withRout)
                                    {
                                        #region Line-Arcs-Surfaces-Text + Rout
                                        if (objDict[PCBI.FeatureAttributeEnum.drill] == "non_plated")
                                        {
                                            drillNonPlatedRout.Add(currObj);
                                            if (!nonPlatedLayerNameCreatedRout)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName + "_non_plated", drillNonPlatedRout);
                                                nonPlatedLayerNameCreatedRout = true;
                                            }
                                        }
                                        else if (objDict[PCBI.FeatureAttributeEnum.drill] == "plated")
                                        {
                                            drillPlatedRout.Add(currObj);
                                            if (!platedLayerNameCreatedRout)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName + "_plated", drillPlatedRout);
                                                platedLayerNameCreatedRout = true;
                                            }
                                        }
                                        else if (objDict[PCBI.FeatureAttributeEnum.drill] == "via")
                                        {
                                            drillViaRout.Add(currObj);
                                            if (!viaLayerNameCreatedRout)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName + "_via", drillViaRout);
                                                viaLayerNameCreatedRout = true;
                                            }
                                        }
                                        else
                                        {
                                            drillRout.Add(currObj);
                                            if (!noAttributesNotPadsLayerNameCreated)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName, drillRout);
                                                noAttributesNotPadsLayerNameCreated = true;
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                            else
                            {
                                #region No Attributes + Rout
                                if (withRout)
                                {
                                    if (currObj.Type == IObjectType.Pad)
                                    {
                                        drill_.Add(currObj);
                                        if (!noAttributesPadsLayerNameCreated)
                                        {
                                            allNewLayerDict.Add(currLayerName + "_", drill_);
                                            noAttributesPadsLayerNameCreated = true;
                                        }
                                    }
                                    else
                                    {
                                        drillRout.Add(currObj);
                                        if (!noAttributesNotPadsLayerNameCreated)
                                        {
                                            allNewLayerDict.Add("rout_" + currLayerName, drillRout);
                                            noAttributesNotPadsLayerNameCreated = true;
                                        }
                                    }
                                }
                                #endregion
                                #region No Attributes Without Rout
                                else
                                {
                                    if (currObj.Type == IObjectType.Pad)
                                    {
                                        drill_.Add(currObj);
                                        if (!noAttributesPadsLayerNameCreated)
                                        {
                                            allNewLayerDict.Add(currLayerName + "_", drill_);
                                            noAttributesPadsLayerNameCreated = true;
                                        }
                                    }
                                }
                                #endregion
                            }
                        }

                        if (allNewLayerDict.Count > 1) //wenn alle vom gleichen Typ sind muss nicht gesplittet werden!
                        {
                            foreach (string currNewLayerName in allNewLayerDict.Keys)
                            {
                                filter = new IFilter(parent);
                                CreateNewDrillODBLayer(filter, currNewLayerName, parent, allNewLayerDict[currNewLayerName], activateNewCreatedLayer);
                            }
                        }
                    }
                }
                matrix.UpdateDataAndList();
            }
Example #57
0
 public double[] GetWeights(IMatrix <double> matrix)
 {
     return(_weights);
 }
        public IGradientDescentOptimisation Create(IGradientDescentOptimisation prev, IMatrix template,
                                                   IPropertySet propertySet)
        {
            var cache =
                propertySet.LinearAlgebraProvider.CreateZeroMatrix(template.RowCount, template.ColumnCount);

            return(new AdaGrad(cache, prev));
        }
Example #59
0
 /// <summary>
 /// Sets data
 /// </summary>
 /// <param name="data">The node signal</param>
 /// <param name="source">The source node</param>
 public void SetData(IMatrix data, INode source)
 {
     Data   = data;
     Source = source;
 }
Example #60
0
 public abstract int Cardinality(IMatrix param1);