Beispiel #1
0
        private static int[] getPattern(int index)
        {
            int n = (int)Math.Pow(index, (1.0 / 3.0));

            index -= (n * n * n);
            int[] p = new int[3];
            foreach (int i in LinearAlgebra.range(p.Length))
            {
                p[i] = n;
            }

            if (index == 0)
            {
                return(p);
            }
            index--;
            int v = index % 3;

            index = index / 3;
            if (index < n)
            {
                p[v] = index % n;
                return(p);
            }
            index     -= n;
            p[v]       = index / n;
            p[++v % 3] = index % n;
            return(p);
        }
Beispiel #2
0
 public void calcEigen()
 {
     if (!isEigenCalculated)
     {
         Matrix eigenV;
         Lambda            = LinearAlgebra.EigenPowerMethod(this, out eigenV);
         EigenV            = eigenV.getList();
         isEigenCalculated = true;
     }
 }
Beispiel #3
0
        public static Dictionary <int, int> binDataOne(List <double> data, int numBins)
        {
            Dictionary <int, int> dataBins = new Dictionary <int, int>();

            foreach (int i in LinearAlgebra.range(numBins))
            {
                dataBins.Add(i, 0);
            }
            return(binDataOne(data, dataBins));
        }
        protected void PlotLines(Graphics gfx, int extendX, int extendY)
        // PlotLines – performs all the drawing operations needed to visualize the density vectors.
        { // widths and heights are mixed up
            drawBackground(gfx, extendX, extendY);

            float lineWidth = 2f;

            //if (data.Count > drawAreaWidth / stripHeight)
            stripHeight = (float)drawAreaWidth / (data.Count) - stripSpacing;

            SolidBrush brush = new SolidBrush(Color.Black);

            int maxLabels = (int)numLabels.Value;

            int skipLabel = (labels.Count + maxLabels - 1) / maxLabels;

            foreach (int i in LinearAlgebra.range(data.Count))
            {
                int maxLines = (int)(data[i].Count * (float)numYmax.Value);
                int minLines = (int)(data[i].Count * (float)numYmin.Value);

                lineWidth = (float)drawAreaHight / (maxLines - minLines);
                float x = drawAreaX + (i * (stripHeight + stripSpacing));

                for (int j = minLines; j < maxLines; j++)
                {
                    setBrush(ref brush, data[i][j]);

                    float y = lineWidth + drawAreaY + lineWidth * (j - minLines);

                    gfx.FillRectangle(brush, x, (drawAreaHight + 2 * drawAreaY) - y, stripHeight, lineWidth);
                }

                //if (!labelsAdded) VLabel(labels[i], x , labelY);
                if (i % skipLabel == 0) // skip excessive labels
                {
                    VLabel(gfx, labels[i], x, labelY, true);
                }
            }
            //drawBrush.Dispose();
            //drawFont.Dispose();
            //this.Update();
            labelsAdded = true;
        }
Beispiel #5
0
        protected virtual void PlotLines(float R, float G, float B)
        // PlotLines – performs all the drawing operations needed to visualize the density vectors.
        {
            drawBackground();

            int lineWidth = 2;

            if (data.Count > drawAreaHight / stripHeight)
            {
                stripHeight = drawAreaHight / (data.Count + 2);
            }

            foreach (int i in LinearAlgebra.range(data.Count))
            {
                lineWidth = drawAreaWidth / data[i].Count;
                int y = drawAreaHight + drawAreaY - stripHeight - (i * (stripHeight + stripSpacing));

                foreach (int j in LinearAlgebra.range(data[i].Count))
                {
                    int color = (int)(255 * ((double)data[i][j] * (double)numGain.Value));
                    if (color > 255)
                    {
                        color = 255;
                    }
                    SolidBrush brush = new SolidBrush(Color.FromArgb((int)(R * color), (int)(G * color), (int)(B * color)));

                    //Console.WriteLine("i: " + i + "j: " + j);
                    int x = 2 + drawAreaX + lineWidth * j;

                    graphics.FillRectangle(brush, x, y, lineWidth, stripHeight);
                }

                if (!labelsAdded)
                {
                    addLabel(y, labels[i]);
                }
            }
            this.Update();
            labelsAdded = true;
        }
        public void BarbasiAlbert(int links, int clusters)
        {
            if (clusters <= 1)
            {
                BarbasiAlbert(links);
            }
            else
            {
                int clusterSize = size / clusters;
                if (clusterSize * clusters != size)
                {
                    size = clusterSize * clusters;
                }

                adjMatrix = createMatrix(size);
                foreach (int i in range(clusters))
                {
                    var subNet = barbasiAlbert(clusterSize, links);
                    LinearAlgebra.insertMat <double>(adjMatrix, subNet, i);
                }
                // connect the clusters together.
                foreach (int i in range(clusters, 1))
                {
                    foreach (int j in range(clusters, 1))
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        foreach (int k in range(links))
                        {
                            connectClustersRand(i, j, clusterSize);
                        }
                    }
                }
            }
        }
Beispiel #7
0
 public void copy(Matrix B)
 {
     LinearAlgebra.mCopy(B, this);
 }
Beispiel #8
0
 public void scalarMult(double scalar)
 {
     LinearAlgebra.scalarMult(this, scalar);
 }
Beispiel #9
0
 public List <double[]> matMultiply(List <double[]> B)
 {
     return((LinearAlgebra.MatMultiply(this, new Matrix(B))).getList());
 }
Beispiel #10
0
 public Matrix matMultiply(Matrix B)
 {
     return(LinearAlgebra.MatMultiply(this, B));
 }