Example #1
0
        public double OneCycleSimple(decimal wheightValue)
        {
            double totalError = 0;

            Parallel.For(0, matrix.Positions.Count, i =>
                         //for (int i = 0; i < matrix.Positions.Count; i++)
            {
                OrganismData od1 = matrix.Positions[i];
                double error     = CalculateStress(od1, od1.PosX, od1.PosY, wheightValue);

                totalError += error;

                if (CalculateStress(od1, od1.PosX - 1, od1.PosY, wheightValue) < error)
                {
                    od1.PosX--;
                }
                else if (CalculateStress(od1, od1.PosX + 1, od1.PosY, wheightValue) < error)
                {
                    od1.PosX++;
                }

                if (CalculateStress(od1, od1.PosX, od1.PosY - 1, wheightValue) < error)
                {
                    od1.PosY--;
                }
                else if (CalculateStress(od1, od1.PosX, od1.PosY + 1, wheightValue) < error)
                {
                    od1.PosY++;
                }
            }
                         );


            return(totalError);
        }
Example #2
0
        public MatrixData(string theMatrix, Dictionary <string, int> fileLabelDictionary)
        {
            string[] lines = Regex.Split(theMatrix, "\n");

            string[] labels = new string[0];

            int lineCounter = 0;

            SpringSizeMatrix = new double[0, 0];
            ElasticConstants = new double[0, 0];

            for (int l = 0; l < lines.Length; l++)
            {
                string[] cols = Regex.Split(lines[l], ",");
                if (lineCounter == 0)
                {
                    labels = new string[cols.Length - 1];
                    for (int i = 1; i < cols.Length; i++)
                    {
                        labels[i - 1] = cols[i];
                    }
                    SpringSizeMatrix = new double[cols.Length - 1, cols.Length - 1];
                    ElasticConstants = new double[cols.Length - 1, cols.Length - 1];
                }
                else
                {
                    for (int i = 1; i < cols.Length; i++)
                    {
                        double size = Math.Abs(100 - double.Parse(cols[i]));
                        SpringSizeMatrix[lineCounter - 1, i - 1] = size;

                        if (size > maxDistance)
                        {
                            maxDistance = size;
                        }
                        if (size < minDistance)
                        {
                            minDistance = size;
                        }

                        ElasticConstants[lineCounter - 1, i - 1] = 1;
                    }
                }
                lineCounter++;
            }


            Positions = new List <OrganismData>(labels.Length);
            for (int i = 0; i < labels.Length; i++)
            {
                OrganismData o = new OrganismData(labels[i], i, fileLabelDictionary[labels[i]]);
                Positions.Add(o);
            }
        }
Example #3
0
        internal void CalculateWheights()
        {
            List <int> labels = originalSparseMatrix.ExtractLabels();

            foreach (int label in labels)
            {
                List <sparseMatrixRow> rows     = originalSparseMatrix.theMatrixInRows.FindAll(a => a.Lable == label);
                sparseMatrixRow        centroid = centroids.Find(a => a.Lable == label);

                rows.Sort((a, b) => pTools.DotProduct(b.Values, centroid.Values).CompareTo(pTools.DotProduct(a.Values, centroid.Values)));


                for (int i = 0; i < rows.Count; i++)
                {
                    OrganismData o = matrix.Positions.Find(a => a.Name.Equals(rows[i].FileName));
                    o.Weight = 1 / (double)(1 + i);
                }
            }
        }
Example #4
0
        private double CalculateStress(OrganismData od, double x, double y, decimal weightValue)
        {
            double errorRMS = 0;

            int org = matrix.Positions.IndexOf(od);

            for (int i = 0; i < matrix.Positions.Count; i++)
            {
                OrganismData theOrg = matrix.Positions[i];

                List <double> v = new List <double>()
                {
                    theOrg.PosX - x, theOrg.PosY - y
                };

                errorRMS += Math.Pow(PatternTools.pTools.Norm(v) - matrix.SpringSizeMatrix[org, i], 2) * Math.Pow(od.Weight * theOrg.Weight, (double)weightValue);
            }

            return(errorRMS);
        }