Пример #1
0
        // End ReadClusterLabel_File


        // Write label-cluster results into a file
        public static void WriteColor_Cluster(string fname, string[] labels, int[] ColorValues, int dataPoints,
                                              bool append)
        {
            try
            {
                StreamWriter sw = null;

                if (!string.IsNullOrEmpty(fname))
                {
                    sw = new StreamWriter(fname, append, Encoding.UTF8);
                }

                if (sw != null)
                {
                    for (int i = 0; i < dataPoints; i++)
                    {
                        string stripped = labels[i].Trim(new[] { ' ', '\t' });
                        sw.WriteLine(String.Format(stripped + "\t" + ColorValues[i].ToString() + ".0000000000"));
                    }
                }

                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed writing data on " + fname + " " + e);

                throw (e);
            }
        }
Пример #2
0
        // End WriteColor_Cluster

        // Write Point-cluster results into a file
        public static void WritePointCluster(string fname, int[] ColorValues, int dataPoints)
        {
            try
            {
                StreamWriter sw = null;

                if (!string.IsNullOrEmpty(fname))
                {
                    sw = new StreamWriter(fname, false, Encoding.UTF8);
                }

                if (sw != null)
                {
                    for (int i = 0; i < dataPoints; i++)
                    {
                        sw.WriteLine(String.Format((i + 1).ToString() + " " + ColorValues[i].ToString()));
                    }
                }
                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed writing data on " + fname + " " + e);

                throw (e);
            }
        }
Пример #3
0
 public static void SetupHotsunforRotateMDS()
 {
     PointVectorDimension = ManxcatCentral.Configuration.LocalVectorDimension;
     if (PointVectorDimension == 3)
     {
         Hotsun.npar = 7;
     }
     else if (PointVectorDimension == 2)
     {
         Hotsun.npar = 4;
     }
     else
     {
         Exception e = SALSAUtility.SALSAError("Unsupported Dimension " + PointVectorDimension.ToString());
     }
     Hotsun.ndata = SALSAUtility.PointCount_Global * PointVectorDimension;
     Hotsun.ParameterVectorDimension = 1;
     GenericManxcat.SetupGenericManxcat();
     return;
 }
Пример #4
0
        // End WritePointCluster

        public static bool ReadString_File(string StringFileName, String[] LabelArray, ref int NumberofLines)
        {
            NumberofLines = 0;

            try
            {
                // Check if file exists
                if (!File.Exists(StringFileName))
                {
                    Exception e = SALSAUtility.SALSAError("File " + StringFileName + " does not exists.");

                    throw (e);
                }

                // Create a new stream to read from a file
                using (StreamReader sr = File.OpenText(StringFileName))
                {
                    // Read contents of a file, line by line, into a string
                    String inputLineStr;

                    while ((inputLineStr = sr.ReadLine()) != null)
                    {
                        if (inputLineStr.Length < 2)
                        {
                            continue; //replace empty line
                        }
                        LabelArray[NumberofLines] = inputLineStr.Trim();
                        ++NumberofLines;
                    }
                    sr.Close();
                }
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed to read data from " + StringFileName + " " + e);

                throw (e);
            }

            return(true);
        }
Пример #5
0
        // End Initialize() in MDSLinearAlgebra

        //  MaxIndicator = 0 Find Maximum Eigenvalue of Matrix
        //  MaxIndicator = 1 Find Maximum Eigenvalue of (Maximizr - Matrix)
        public static int PowerIterate(Desertwind Solution, int MaxIndicator, double Maximizer,
                                       out double PowerEigenvalue)
        {
            if (DistributedNewIteratedVector == null)
            {
                Initialize();
            }
            Hotsun.UseDiagonalScaling       = true;
            Hotsun.AddMarquardtQDynamically = false;

            //  Set up Initial Power Vectors
            SetInitialPowerVector(DistributedNewIteratedVector);
            double AdotA = SALSABLAS.VectorScalarProduct(DistributedNewIteratedVector, DistributedNewIteratedVector);

            int somethingtodo       = 0;
            int PowerIterationCount = 0;

            PowerEigenvalue = -1.0;
            while (true)
            {
                // Iterate over Power Multiplications by Chisq Matrix

                //  Normalize Current A and move from New to Old

                double OldNorm = 1.0 / Math.Sqrt(AdotA);
                SALSABLAS.LinearCombineVector(DistributedOldIteratedVector, OldNorm,
                                              DistributedNewIteratedVector, 0.0, DistributedNewIteratedVector);

                //  Make a Global Vector of DistributedOldIteratedVector
                ManxcatCentral.MakeVectorGlobal(DistributedOldIteratedVector, GlobalOldIteratedVector);

                //  Form Chisq Matrix Product with Old Vector
                if (Hotsun.FullSecondDerivative)
                {
                    UserRoutines.GlobalMatrixVectorProduct(DistributedNewIteratedVector, Solution, true,
                                                           Hotsun.GlobalParameter, GlobalOldIteratedVector);
                }
                else
                {
                    UserRoutines.GlobalMatrixVectorProduct(DistributedNewIteratedVector, Solution, false,
                                                           Hotsun.GlobalParameter, GlobalOldIteratedVector);
                }

                //  Correct case MaxIndicator = 1
                if (MaxIndicator > 0)
                {
                    SALSABLAS.LinearCombineVector(DistributedNewIteratedVector, -1.0, DistributedNewIteratedVector,
                                                  Maximizer, DistributedOldIteratedVector);
                }
                SALSABLAS.LinearCombineVector(DistributedNewIteratedVector, 1.0, DistributedNewIteratedVector,
                                              Hotsun.addonforQcomputation, DistributedOldIteratedVector);

                //  Form Scalar Products
                double NewEigenvalue = SALSABLAS.VectorScalarProduct(DistributedNewIteratedVector,
                                                                     DistributedOldIteratedVector);
                AdotA = SALSABLAS.VectorScalarProduct(DistributedNewIteratedVector, DistributedNewIteratedVector);

                ++PowerIterationCount;
                somethingtodo = -1;
                if (SALSAUtility.MPI_Rank == 0)
                {
                    if (PowerIterationCount > 10 && (NewEigenvalue > 0.0))
                    {
                        // Arbitary criteria for starting +tests
                        somethingtodo = 0;
                        double scaleit = 1.0;
                        if (MaxIndicator > 0)
                        {
                            scaleit = Hotsun.extraprecision;
                        }
                        if (Math.Abs(NewEigenvalue - PowerEigenvalue) > PowerEigenvalue * scaleit * Hotsun.eigenvaluechange)
                        {
                            ++somethingtodo;
                        }
                        double delta = AdotA - NewEigenvalue * NewEigenvalue; // (Ax- Eigenvalue*Axold)**2
                        if (Math.Abs(delta) > NewEigenvalue * NewEigenvalue * scaleit * Hotsun.eigenvectorchange)
                        {
                            ++somethingtodo;
                        }
                    }
                }
                PowerEigenvalue = NewEigenvalue;

                if (SALSAUtility.MPI_Size > 1)
                {
                    SALSAUtility.StartSubTimer(SALSAUtility.MPIBROADCASTTiming);
                    SALSAUtility.MPI_communicator.Broadcast(ref somethingtodo, 0);
                    SALSAUtility.StopSubTimer(SALSAUtility.MPIBROADCASTTiming);
                }
                if (PowerIterationCount >= Hotsun.PowerIterationLimit)
                {
                    somethingtodo = -2;
                    break;
                }
                if (somethingtodo == 0)
                {
                    somethingtodo = PowerIterationCount;
                    break;
                }
            } // End while over PowerIterationCounts

            return(somethingtodo);
        }
Пример #6
0
        // End PowerIterate()

        //  Solve for Distributed Answer = (Matrix-1) First
        //  Note RealMatrixSize takes account of forced zero parameters which does not crop up in explicit
        //  algorithm as implemented in Matrix Vector Multiplier
        public static bool ConjugateGradientSolver(double[][] Answer, Desertwind Solution, bool useexact,
                                                   double[][] GlobalxVector, double[][] DistributedRHS,
                                                   ref int NumberofIterations, int RealMatrixSize, double LimitonNormofR)
        {
            bool matrixsuccess = true;

            //  Initialize
            SALSABLAS.zrword(Answer); // Zero Solution x called xshift in Manxcat and stored in Answer
            SALSABLAS.CopyVector(DistributedCGVector_R, DistributedRHS, 0, SALSAUtility.PointCount_Process);
            // Set R(0) = RHS
            double InitialRNorm = SALSABLAS.VectorScalarProduct(DistributedCGVector_R, DistributedCGVector_R);
            double RNormTest    = InitialRNorm * LimitonNormofR; // Limit for Test on Iteration of Norm of R
            var    SaveRNorm    = new double[RealMatrixSize + 1];

            SaveRNorm[0] = InitialRNorm;
            int CountSteps = 0;

            double lastrho    = 1.0;
            double currentrho = 1.0;

            //  Loop over Conjugate Gradient Steps
            while (true)
            {
                // Set value of rho
                lastrho    = currentrho;
                currentrho = SALSABLAS.VectorScalarProduct(DistributedCGVector_R, DistributedCGVector_R);

                // Set Vector P
                ++CountSteps;
                if (CountSteps == 1)
                {
                    SALSABLAS.CopyVector(DistributedCGVector_P, DistributedCGVector_R, 0,
                                         SALSAUtility.PointCount_Process);
                }
                else
                {
                    SALSABLAS.LinearCombineVector(DistributedCGVector_P, currentrho / lastrho, DistributedCGVector_P,
                                                  1.0, DistributedCGVector_R);
                }

                //  Make a Global Vector of DistributedCGVector_P
                ManxcatCentral.MakeVectorGlobal(DistributedCGVector_P, GlobalCGVector_P);

                //  Distributed Q = Matrix . Global P
                UserRoutines.GlobalMatrixVectorProduct(DistributedCGVector_Q, Solution, useexact,
                                                       Hotsun.GlobalParameter, GlobalCGVector_P);

                //  New Answer is Old answer + (Current Rho / (P dot Q)) Vector P
                double PdotQ = SALSABLAS.VectorScalarProduct(DistributedCGVector_P, DistributedCGVector_Q);
                double alpha = currentrho / PdotQ;
                SALSABLAS.LinearCombineVector(Answer, alpha, DistributedCGVector_P, 1.0, Answer);

                // New residual R = Old Residual - (Current Rho / (P dot Q)) Vector Q
                SALSABLAS.LinearCombineVector(DistributedCGVector_R, -alpha, DistributedCGVector_Q, 1.0,
                                              DistributedCGVector_R);

                //  See if we can or should End
                double CurrentRNorm = SALSABLAS.VectorScalarProduct(DistributedCGVector_R, DistributedCGVector_R);
                SaveRNorm[CountSteps] = CurrentRNorm;
                bool TestRNorm = CurrentRNorm <= RNormTest;
                SALSAUtility.SynchronizeMPIvariable(ref TestRNorm);
                if (TestRNorm)
                {
                    matrixsuccess = true;
                    break;
                }

                // Singular Matrix
                if (CountSteps >= RealMatrixSize)
                {
                    matrixsuccess = false;
                    ManxcatCentral.MakeVectorGlobal(DistributedCGVector_R, GlobalCGVector_R);
                    if (SALSAUtility.MPI_Rank == 0)
                    {
                        SALSAUtility.SALSAPrint(0, " CG Failure after " + RealMatrixSize.ToString() + " Steps");
                        string ListofNorms = "";
                        int    Normindex   = CountSteps;
                        for (int inorm = 0; inorm < 10; inorm++)
                        {
                            ListofNorms += " " + SaveRNorm[Normindex].ToString("E4");
                            --Normindex;
                            if (Normindex < 0)
                            {
                                break;
                            }
                        }
                        SALSAUtility.SALSAPrint(0, "Last 10 Norms " + ListofNorms);

                        string fname = ManxcatCentral.ResultDirectoryName + "\\BadCGVector" +
                                       Hotsun.TotalCGFailures.ToString();
                        var    sw           = new StreamWriter(fname, false, Encoding.UTF8);
                        double fractionnorm = 1.0 / Math.Sqrt(CurrentRNorm);
                        try
                        {
                            for (int GlobalPointIndex = 0;
                                 GlobalPointIndex < SALSAUtility.PointCount_Global;
                                 GlobalPointIndex++)
                            {
                                string Coordinates    = "";
                                int    UsedPointIndex = SALSAUtility.NaivetoActualUsedOrder[GlobalPointIndex];
                                double pointsize      = 0.0;
                                for (int LocalVectorIndex = 0;
                                     LocalVectorIndex < Hotsun.ParameterVectorDimension;
                                     LocalVectorIndex++)
                                {
                                    Coordinates += GlobalCGVector_R[UsedPointIndex][LocalVectorIndex].ToString("E4") +
                                                   "\t";
                                    pointsize += GlobalCGVector_R[UsedPointIndex][LocalVectorIndex] *
                                                 GlobalCGVector_R[UsedPointIndex][LocalVectorIndex];
                                }
                                pointsize = Math.Sqrt(pointsize) * fractionnorm;
                                sw.WriteLine(
                                    String.Format((GlobalPointIndex).ToString() + "\t" + Coordinates + " " +
                                                  pointsize.ToString("E4")));
                            }

                            sw.Flush();
                            sw.Close();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed writing data in CG Solver " + e);
                            throw (e);
                        }
                    }
                    break;
                }
            } // End Loop over Conjugate Gradient Steps

            NumberofIterations = CountSteps;
            return(matrixsuccess);
        }
Пример #7
0
        public static void WriteRotateMDS(string fname, int OutputOption, double[][] param, double[][] perr)
        {
            int LocalVectorDimension = param[0].GetLength(0);

            if (LocalVectorDimension != perr[0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions Labels " + LocalVectorDimension.ToString() + " Perr " +
                                        perr[0].GetLength(0).ToString());
            }

            ManxcatSection Configuration = ManxcatCentral.Configuration;

            // set current cosmic scaling
            for (int LocalVectorIndex1 = 0; LocalVectorIndex1 < PointVectorDimension; LocalVectorIndex1++)
            {
                for (int LocalVectorIndex2 = 0; LocalVectorIndex2 < PointVectorDimension; LocalVectorIndex2++)
                {
                    CurrentCosmicScaling[LocalVectorIndex1, LocalVectorIndex2] =
                        SavedCosmicScaling[Hotsun.BestChisqLoop][LocalVectorIndex1, LocalVectorIndex2];
                }
            }

            // Write SALSA Properties File Header
            if (OutputOption == 0)
            {
                int filetype = 2;
                if ((SALSAUtility.NumberFixedPoints > 0) ||
                    (SALSAUtility.NumberVariedPoints < SALSAUtility.NumberOriginalPoints))
                {
                    filetype = 4;
                }
                RotationFileProperties.GroupName               = "MDS Run:" + Configuration.RunNumber.ToString();
                RotationFileProperties.FileGenerationType      = filetype;
                RotationFileProperties.OriginalPointStartIndex = 0;
                RotationFileProperties.LocalPointStartIndex    = 0;

                //  Rotation parameters
                RotationFileProperties.NumberRotationParameters = Hotsun.npar;
                RotationFileProperties.RotationParameters       = "";
                for (int CountRotPars = 0; CountRotPars < Hotsun.npar; CountRotPars++)
                {
                    RotationFileProperties.RotationParameters += " " + param[CountRotPars][0].ToString("E4") + ",";
                }
                for (int Cosmicdiagonals = 0; Cosmicdiagonals < PointVectorDimension; Cosmicdiagonals++)
                {
                    RotationFileProperties.RotationParameters += " " +
                                                                 CurrentCosmicScaling[Cosmicdiagonals, Cosmicdiagonals].
                                                                 ToString("E4") + ",";
                }
                // Comment should have key features of Run
                string OldComment = RotationFileProperties.Comment;
                if (OldComment != "")
                {
                    OldComment += "\n";
                }
                OldComment += "MDS ROTATION Run " + Configuration.RunNumber.ToString() + " Start Time " +
                              SALSAUtility.startTime.ToLocalTime() + " *** ";
                OldComment += "\n RotationOption " + Configuration.RotationOption + " First Scale " +
                              FirstScale.ToString("E4") + " Second Scale " + SecondScale.ToString()
                              + "\n First Mean";
                for (int PointIndex = 0; PointIndex < PointVectorDimension; PointIndex++)
                {
                    OldComment += " " + FirstMean[PointIndex].ToString("E4");
                }
                OldComment += " Second Mean";
                for (int PointIndex = 0; PointIndex < PointVectorDimension; PointIndex++)
                {
                    OldComment += " " + SecondMean[PointIndex].ToString("E4");
                }
                RotationFileProperties.Comment = OldComment;

                SALSA_Properties.WriteDataPointFile(fname, ManxcatCentral.Configuration.Write2Das3D, "all ",
                                                    RotationFileProperties,
                                                    RotationPointProperties, SALSAUtility.NumberOriginalPoints);
                return;
            }

            //  Option OutputOption = 1 -- write ROTATED Second Data
            try
            {
                StreamWriter sw = null;
                if (!string.IsNullOrEmpty(fname))
                {
                    sw = new StreamWriter(fname, false, Encoding.UTF8);
                }
                if (sw != null)
                {
                    double[] FullTranslation;
                    double[,] FullRotation;
                    SetupFinalTransforamation(param, out FullTranslation, out FullRotation);

                    for (int UsedDataPoint = 0; UsedDataPoint < SALSAUtility.PointCount_Global; UsedDataPoint++)
                    {
                        var Vector = new double[PointVectorDimension];
                        MatrixVectorProduct(Vector, FullRotation, SecondData[UsedDataPoint]);
                        VectorSum(Vector, FullTranslation, +1.0, Vector);

                        string Coordinates   = "";
                        int    SingleCluster = 1;

                        for (int LocalVectorIndex = 0; LocalVectorIndex < PointVectorDimension; LocalVectorIndex++)
                        {
                            Coordinates += Vector[LocalVectorIndex].ToString("E4") + "\t";
                        }
                        sw.WriteLine(
                            String.Format((UsedDataPoint + 1).ToString() + "\t" + Coordinates + SingleCluster.ToString()));
                    }
                }

                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed writing data" + e);
                throw (e);
            }
        }
Пример #8
0
        // End SetupHotsunforMDS

        public static void SetupRotateMDS()
        {
            if (Hotsun.InitializationLoops < 2)
            {
                Hotsun.InitializationLoops = 2;
                Hotsun.InitLoopChisq       = new double[Hotsun.InitializationLoops];
                ManxcatCentral.Configuration.InitializationLoops = Hotsun.InitializationLoops;
            }
            Hotsun.bnderrLimit = 10;

            if (SALSAUtility.NumberFixedPoints > 0)
            {
                Exception e = SALSAUtility.SALSAError(" Fixed Points not Allowed in Rotations");
                throw (e);
            }
            RotationOption = ManxcatCentral.Configuration.RotationOption; // set Rotation Option
            RotationOption_GenerateTestInput = RotationOption / 100;
            // Control special test inputs = 0 normal -- don't generate points to rotate;
            //  RotationOption_GenerateTestInput = 1 full inversion;
            //  RotationOption_GenerateTestInput = 2  invert x and y only;
            //  RotationOption_GenerateTestInput = 3 invert x only
            //  RotationOption_GenerateTestInput = 4 set new file = old file
            RotationOption        = RotationOption - 100 * RotationOption_GenerateTestInput;
            RotationOption_invert = RotationOption / 10;
            // Control how to control scaling in fit. = 0 force scaling positive so when cosmic scaling improper, one cannot fit proper rotation
            // RotationOption_invert = 1 allow scaling to be negative which can allow fit to be trapped in wring proper/improper domain for all starts.
            // If RotationOption_invert=0 then every other initialization loop is proper (0 1 ..) or improper (1 3 ...)
            //  Note initial angle values are 0 for initialization loops 0 1nd 1, they are random for later loops
            //  Angles are forced to lie between -PI  and PI
            RotationOption = RotationOption - 10 * RotationOption_invert;
            // RotationOption = 0 usual Chisq; = 1 Each term divided by magnitude of original point so one minimizes realative errors squared

            PointVectorDimension = SALSAUtility.GlobalFileProperties.LocalVectorDimension;
            if (PointVectorDimension != SALSAUtility.GlobalFileProperties.LocalVectorDimension)
            {
                Exception e =
                    SALSAUtility.SALSAError(" Inconsistent Small Dimension in Rotations " +
                                            PointVectorDimension.ToString());
                throw (e);
            }

            int InitializationFileType       = -1;
            int InitializationNumberofPoints = -1;

            //  Set Reference Points
            if (SALSA_ProcessVariedandFixed.AreValuesSet(SALSAUtility.GlobalPointProperties))
            {
                SALSAUtility.SALSAPrint(2,
                                        " Reference Points Taken from basic Labels File " +
                                        ManxcatCentral.Configuration.DataLabelsFileName);
            }
            else
            {
                // Set up Values of Used Points from Initialization File
                var InitializationFileProperties  = new SALSAFileProperties();
                var InitializationPointProperties = new SALSADataPointProperties[SALSAUtility.NumberOriginalPoints];

                string OriginalMDSFileName = ManxcatCentral.Configuration.InitializationFileName;
//                if (!OriginalMDSFileName.Contains(":") || !OriginalMDSFileName.Contains("$"))
//                    OriginalMDSFileName = ManxcatCentral.Configuration.ControlDirectoryName + "\\" + OriginalMDSFileName;
                SALSAUtility.SALSAPrint(2, " Reference Points Taken from Initialization File " + OriginalMDSFileName);

                // Begin Changes saliya 03/25/11
                // Note. I think we can agree on the zero based indices. The following should be removed then.
                if (OriginalMDSFileName.Contains("SIMPLE"))
                {
                    InitializationFileProperties.LocalPointStartIndex = 1;
                }
                // End Changes saliya 03/25/11

                SALSA_Properties.ReadDataPointFile(OriginalMDSFileName, ref InitializationFileType,
                                                   InitializationFileProperties, ref InitializationPointProperties,
                                                   ref InitializationNumberofPoints);
                if ((SALSAUtility.NumberOriginalPoints < InitializationNumberofPoints) ||
                    (InitializationFileProperties.NumberOriginalPoints != SALSAUtility.NumberOriginalPoints))
                {
                    Exception e =
                        SALSAUtility.SALSAError(" Inconsistent Initialization File Point Counts " +
                                                InitializationNumberofPoints.ToString() + " or "
                                                + InitializationFileProperties.NumberOriginalPoints.ToString() +
                                                " Expected is " + SALSAUtility.NumberOriginalPoints.ToString());
                    throw (e);
                }

                for (int InitialIndex = 0; InitialIndex < InitializationNumberofPoints; InitialIndex++)
                {
                    int OriginalIndex = InitializationPointProperties[InitialIndex].OriginalPointNumber;
                    if (!InitializationPointProperties[InitialIndex].valuesset)
                    {
                        continue;
                    }
                    SALSAUtility.GlobalPointProperties[OriginalIndex].x = InitializationPointProperties[InitialIndex].x;
                    SALSAUtility.GlobalPointProperties[OriginalIndex].y = InitializationPointProperties[InitialIndex].y;
                    SALSAUtility.GlobalPointProperties[OriginalIndex].z = InitializationPointProperties[InitialIndex].z;

                    SALSAUtility.GlobalPointProperties[OriginalIndex].valuesset =
                        InitializationPointProperties[InitialIndex].valuesset;
                }


                if (!SALSA_ProcessVariedandFixed.AreValuesSet(SALSAUtility.GlobalPointProperties))
                {
                    Exception e = SALSAUtility.SALSAError(" Reference Points Not set");
                    throw (e);
                }
            }

            // Now Read Points to be Rotated
            // Set up Values of Used Points from Rotation File
            int RotationFileType = -1;

            RotationFileProperties  = new SALSAFileProperties();
            RotationPointProperties = new SALSADataPointProperties[SALSAUtility.NumberOriginalPoints];
            if (RotationOption_GenerateTestInput == 0)
            {
                int    RotationNumberofPoints = -1;
                string RotationFileName       = ManxcatCentral.Configuration.RotationLabelsFileName;
//                if (!RotationFileName.Contains(":"))
//                    RotationFileName = ManxcatCentral.Configuration.ControlDirectoryName + "\\" + RotationFileName;
                if (RotationFileName.Contains("SIMPLE"))
                {
                    RotationFileProperties.LocalPointStartIndex = 1;
                }
                SALSAUtility.SALSAPrint(2, " Points to be rotated Taken from File " + RotationFileName);
                SALSA_Properties.ReadDataPointFile(RotationFileName, ref RotationFileType, RotationFileProperties,
                                                   ref RotationPointProperties, ref RotationNumberofPoints);
                if ((SALSAUtility.NumberOriginalPoints < RotationNumberofPoints) ||
                    (RotationFileProperties.NumberOriginalPoints != SALSAUtility.NumberOriginalPoints))
                {
                    Exception e =
                        SALSAUtility.SALSAError(" Inconsistent Rotation File Point Counts " +
                                                RotationNumberofPoints.ToString() + " or "
                                                + RotationFileProperties.NumberOriginalPoints.ToString() +
                                                " Expected is " + SALSAUtility.NumberOriginalPoints.ToString());
                    throw (e);
                }
                if (!SALSA_ProcessVariedandFixed.AreValuesSet(RotationPointProperties))
                {
                    Exception e = SALSAUtility.SALSAError(" Points to rotate Not set");
                    throw (e);
                }
            } // End normal case when we read file of points to be rotated
            else
            {
                // Generate file to be Rotated
                RotationFileType = InitializationFileType;
                for (int PointIndex = 0; PointIndex < SALSAUtility.NumberOriginalPoints; PointIndex++)
                {
                    RotationPointProperties[PointIndex] = new SALSADataPointProperties();
                }

                double fudgex = 1.0;
                double fudgey = 1.0;
                double fudgez = 1.0;
                if (RotationOption_GenerateTestInput == 1)
                {
                    SALSAUtility.SALSAPrint(2, " Points to be rotated generated as -x -y -z ");
                    fudgex = -1.0;
                    fudgey = -1.0;
                    fudgez = -1.0;
                }
                if (RotationOption_GenerateTestInput == 2)
                {
                    SALSAUtility.SALSAPrint(2, " Points to be rotated generated as -x -y +z ");
                    fudgex = -1.0;
                    fudgey = -1.0;
                }
                if (RotationOption_GenerateTestInput == 3)
                {
                    SALSAUtility.SALSAPrint(2, " Points to be rotated generated as -x +y +z ");
                    fudgex = -1.0;
                }
                if (RotationOption_GenerateTestInput >= 4)
                {
                    SALSAUtility.SALSAPrint(2, " Points to be rotated generated as +x +y +z ");
                }
                for (int GlobalPointIndex = 0; GlobalPointIndex < SALSAUtility.PointCount_Global; GlobalPointIndex++)
                {
                    int OriginalIndex = SALSAUtility.UsedPointtoOriginalPointMap[GlobalPointIndex];
                    RotationPointProperties[OriginalIndex].x = fudgex *
                                                               SALSAUtility.GlobalPointProperties[OriginalIndex].x;
                    ;
                    RotationPointProperties[OriginalIndex].y = fudgey *
                                                               SALSAUtility.GlobalPointProperties[OriginalIndex].y;
                    RotationPointProperties[OriginalIndex].z = fudgez *
                                                               SALSAUtility.GlobalPointProperties[OriginalIndex].z;
                    RotationPointProperties[OriginalIndex].valuesset =
                        SALSAUtility.GlobalPointProperties[OriginalIndex].valuesset;
                }
            }

            //  Set up operational data
            FirstData  = new double[SALSAUtility.PointCount_Global][]; // Initial point data
            SecondData = new double[SALSAUtility.PointCount_Global][];
            ;                                                          // Second point data
            FirstMean  = new double[PointVectorDimension];             // Mean of initial point data
            SecondMean = new double[PointVectorDimension];
            for (int GlobalPointIndex = 0; GlobalPointIndex < SALSAUtility.PointCount_Global; GlobalPointIndex++)
            {
                FirstData[GlobalPointIndex]  = new double[PointVectorDimension];
                SecondData[GlobalPointIndex] = new double[PointVectorDimension];
            }

            //  Process Data
            ProcessPointData(SALSAUtility.GlobalPointProperties, FirstData, FirstMean, out FirstScale);
            ProcessPointData(RotationPointProperties, SecondData, SecondMean, out SecondScale);
            ScalePosition = 6;
            if (PointVectorDimension == 2)
            {
                ScalePosition = 3;
            }

            NumberSubRotations = 3;
            if (PointVectorDimension == 2)
            {
                NumberSubRotations = 1;
            }

            // This holds the inversion transformation
            CurrentCosmicScaling = new double[PointVectorDimension, PointVectorDimension];
            SavedCosmicScaling   = new double[Hotsun.InitializationLoops][, ];
            for (int scalingindex = 0; scalingindex < Hotsun.InitializationLoops; scalingindex++)
            {
                SavedCosmicScaling[scalingindex] = new double[PointVectorDimension, PointVectorDimension];
            }

            // If ManxcatCentral.MetadataforRun.MinimumDistance  is positive, it is absolute Minimum Distance
            // If ManxcatCentral.MetadataforRun.MinimumDistance  is negative, it is - multiplier of System Average
            if (ManxcatCentral.Configuration.MinimumDistance < 0)
            {
                MinimumDistance = -ManxcatCentral.Configuration.MinimumDistance * FirstScale;
            }
            else
            {
                MinimumDistance = ManxcatCentral.Configuration.MinimumDistance;
            }

            string firstM  = "";
            string secondM = "";

            for (int LocalVectorIndex = 0; LocalVectorIndex < PointVectorDimension; LocalVectorIndex++)
            {
                firstM  += FirstMean[LocalVectorIndex].ToString("E4") + " ";
                secondM += SecondMean[LocalVectorIndex].ToString("E4") + " ";
            }
            SALSAUtility.SALSAPrint(0,
                                    " First Scale " + FirstScale.ToString("E4") + " Second Scale " +
                                    SecondScale.ToString("E4") + " First Mean " + firstM + " Second Mean " + secondM);
        }
Пример #9
0
        // End VectorSum(double[] VTotal, double[] V2, double sign, double[] V1)

        public static void InitializeParameters(Desertwind Solution, int CountStartingPoints)
        {
            // Inversion
            InvertSolution = false;
            if ((CountStartingPoints / 2) * 2 != CountStartingPoints)
            {
                InvertSolution = true;
            }

            for (int LocalVectorIndex1 = 0; LocalVectorIndex1 < PointVectorDimension; LocalVectorIndex1++)
            {
                for (int LocalVectorIndex2 = 0; LocalVectorIndex2 < PointVectorDimension; LocalVectorIndex2++)
                {
                    CurrentCosmicScaling[LocalVectorIndex1, LocalVectorIndex2] = 0.0;
                }
                CurrentCosmicScaling[LocalVectorIndex1, LocalVectorIndex1] = 1.0;
            }
            if (InvertSolution)
            {
                for (int LocalVectorIndex1 = 0; LocalVectorIndex1 < PointVectorDimension; LocalVectorIndex1++)
                {
                    CurrentCosmicScaling[LocalVectorIndex1, LocalVectorIndex1] = -1.0;
                }
                if (PointVectorDimension == 2)
                {
                    CurrentCosmicScaling[0, 0] = 1.0;
                }
            }
            for (int LocalVectorIndex1 = 0; LocalVectorIndex1 < PointVectorDimension; LocalVectorIndex1++)
            {
                for (int LocalVectorIndex2 = 0; LocalVectorIndex2 < PointVectorDimension; LocalVectorIndex2++)
                {
                    SavedCosmicScaling[CountStartingPoints][LocalVectorIndex1, LocalVectorIndex2] =
                        CurrentCosmicScaling[LocalVectorIndex1, LocalVectorIndex2];
                }
            }

            //  Scaling
            double Scale = FirstScale / SecondScale;

            if (ScaleOption == 0)
            {
                Solution.param[ScalePosition][0] = Scale;
            }
            else
            {
                ScaleA1 = 0.5 * (ScaleAlpha + 1.0 / ScaleAlpha);
                ScaleA2 = 0.5 * Math.Abs(ScaleAlpha - 1.0 / ScaleAlpha);
                Solution.param[ScalePosition][0] = Math.Asin((ScaleA1 - 1.0) / ScaleA2);
                ScaleA1 *= Scale;
                ScaleA2 *= Scale;
            }

            var Randobject   = new Random();
            var RandomAngles = new double[3];

            if (SALSAUtility.MPI_Rank == 0)
            {
                for (int irand = 0; irand < 3; irand++)
                {
                    RandomAngles[irand] = Randobject.NextDouble();
                }
            }
            if (SALSAUtility.MPI_Size > 1)
            {
                SALSAUtility.StartSubTimer(SALSAUtility.MPIBROADCASTTiming);
                SALSAUtility.MPI_communicator.Broadcast(ref RandomAngles, 0);
                SALSAUtility.StopSubTimer(SALSAUtility.MPIBROADCASTTiming);
            }


            //  Translation and Rotation
            for (int LocalVectorIndex = 0; LocalVectorIndex < PointVectorDimension; LocalVectorIndex++)
            {
                Solution.param[LocalVectorIndex][0] = FirstMean[LocalVectorIndex] - Scale *
                                                      CurrentCosmicScaling[LocalVectorIndex, LocalVectorIndex] *
                                                      SecondMean[LocalVectorIndex];
                if (PointVectorDimension == 3)
                {
                    Solution.param[LocalVectorIndex + PointVectorDimension][0] = 0.0;
                    if (CountStartingPoints > 1)
                    {
                        Solution.param[LocalVectorIndex + PointVectorDimension][0] = Math.PI *
                                                                                     RandomAngles[LocalVectorIndex];
                    }
                }
            }
            if (PointVectorDimension == 2)
            {
                Solution.param[2][0] = 0.0;
                if (CountStartingPoints > 1)
                {
                    Solution.param[2][0] = Math.PI * RandomAngles[0];
                }
            }
        }
Пример #10
0
        // End UpdateManxcatMDS_Option12_TraditionalDirectory

        public static bool ReadMDSCluster_File(string MDSClusterFileName, String[] InitialString, int[] ColorValue,
                                               ref int NumberofPoints)
        {
            NumberofPoints = 0;

            try
            {
                // Check if file exists
                if (!File.Exists(MDSClusterFileName))
                {
                    Exception e = SALSAUtility.SALSAError("File " + MDSClusterFileName + " does not exists");

                    throw (e);
                }

                // Create a new stream to read from a file
                using (StreamReader sr = File.OpenText(MDSClusterFileName))
                {
                    // Read contents of a file, line by line, into a string
                    String inputLineStr;
                    int    newlabelnumber = -1;

                    while ((inputLineStr = sr.ReadLine()) != null)
                    {
                        if (inputLineStr.Length < 2)
                        {
                            continue; //replace empty line
                        }
                        inputLineStr = inputLineStr.Trim(new[] { ' ', '\t' });

                        try
                        {
                            // Parse each record string
                            inputLineStr = inputLineStr.Replace("\t\t", "\t");
                            string[] split = inputLineStr.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            newlabelnumber = Convert.ToInt32(split[0]);

                            if (split.Length != Hotsun.ParameterVectorDimension + 2)
                            {
                                Console.WriteLine(" Bad Line "
                                                  + split.Length + " " + NumberofPoints + " " + inputLineStr);
                            }

                            // Begin Changes saliya 3/22/11
                            // Note. This seems unnecessary. Let's agree on zero based indices
//                            if ((NumberofPoints + 1) != newlabelnumber)
//                            {
//                                Exception e = SALSAUtility.SALSAError("Unexpected Label Number "
//                                    + newlabelnumber + " Expected " + NumberofPoints + "+1");
//
//                                throw (e);
//                            }
                            // End Changes saliya 3/22/11

                            inputLineStr = split[0];

                            for (int i = 1; i < (split.Length - 1); i++)
                            {
                                inputLineStr += "\t" + split[i];
                            }
                            InitialString[NumberofPoints] = inputLineStr;

                            ColorValue[NumberofPoints] = (int)Convert.ToDouble(split[split.Length - 1]);
                            ++NumberofPoints;
                        }
                        catch (Exception e)
                        {
                            SALSAUtility.SALSAError("Failed to load data array " + inputLineStr + " "
                                                    + " "
                                                    + NumberofPoints.ToString() + " " + newlabelnumber.ToString() + " " +
                                                    e);

                            throw (e);
                        }
                    }

                    sr.Close();
                }
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed to read data from " + MDSClusterFileName + " " + e);

                throw (e);
            }

            if (NumberofPoints != SALSAUtility.PointCount_Global)
            {
                Exception e = SALSAUtility.SALSAError("Incorrect #Points in File "
                                                      + NumberofPoints + " Expected " + SALSAUtility.PointCount_Global);

                throw (e);
            }

            return(true);
        }
Пример #11
0
        // End ReadMDSClusterFile

        public static bool ReadClusterLabel_File(string LabelFileName, String[] LabelArray, ref int NumberofLabels)
        {
            NumberofLabels = 0;
            int startnumber = 1;

            try
            {
                // Check if file exists
                if (!File.Exists(LabelFileName))
                {
                    Exception e = SALSAUtility.SALSAError("File " + LabelFileName + " does not exists.");

                    throw (e);
                }

                // Create a new stream to read from a file
                using (StreamReader sr = File.OpenText(LabelFileName))
                {
                    // Read contents of a file, line by line, into a string
                    String inputLineStr;

                    while ((inputLineStr = sr.ReadLine()) != null)
                    {
                        if (inputLineStr.Length < 2)
                        {
                            continue; //replace empty line
                        }
                        inputLineStr = inputLineStr.Trim();

                        try
                        {
                            // Parse each record string
                            string[] split = inputLineStr.Split(new[] { ' ', '\t' }, 2,
                                                                StringSplitOptions.RemoveEmptyEntries);
                            int newlabelnumber = Convert.ToInt32(split[0]);

                            if (NumberofLabels == 0)
                            {
                                startnumber = newlabelnumber;

                                if ((startnumber < 0) || (startnumber > 1))
                                {
                                    Exception e =
                                        SALSAUtility.SALSAError("Unexpected Start Number " + startnumber.ToString());

                                    throw (e);
                                }
                            }

                            if (NumberofLabels != (newlabelnumber + startnumber))
                            {
                                Exception e = SALSAUtility.SALSAError("Unexpected Label Number "
                                                                      + newlabelnumber.ToString() + " Expected " +
                                                                      NumberofLabels.ToString() + " + " +
                                                                      startnumber.ToString());

                                throw (e);
                            }

                            if (split[1].Length <= 0)
                            {
                                Exception e =
                                    SALSAUtility.SALSAError("Zero length label for point " + NumberofLabels.ToString());

                                throw (e);
                            }

                            LabelArray[NumberofLabels] = split[1];
                            ++NumberofLabels;
                        }
                        catch (Exception e)
                        {
                            SALSAUtility.SALSAError("Failed to load data from " + LabelFileName + " " + e);

                            throw (e);
                        }
                    }

                    sr.Close();
                }
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed to read data from " + LabelFileName + " " + e);

                throw (e);
            }

            return(true);
        }
Пример #12
0
        // End UpdateManxcatMDS_Option12_Cluster()

        public static void UpdateManxcatMDS_Option12_TraditionalDirectory()
        {
            string labelFileDirectory     = ManxcatCentral.Configuration.ClusterDirectory; // Input Directory
            string MDSandClusterDirectory = labelFileDirectory + "\\" + ManxcatCentral.Configuration.RunSetLabel +
                                            "-R" + ManxcatCentral.Configuration.RunNumber.ToString() + "-ManxcatMDS";

            // Output Directory

            if (Directory.Exists(MDSandClusterDirectory))
            {
                SALSAUtility.SALSAPrint(0, "The directory " + MDSandClusterDirectory + " exists");
            }
            else
            {
                DirectoryInfo di = Directory.CreateDirectory(MDSandClusterDirectory);
                SALSAUtility.SALSAPrint(0, "The directory " + MDSandClusterDirectory + " was created successfully at "
                                        + Directory.GetCreationTime(MDSandClusterDirectory));
            }

            string[] SMACOFfileEntries  = Directory.GetFiles(MDSandClusterDirectory);
            string   TypicalMDSFileName = ManxcatCentral.Configuration.ReducedVectorOutputFileName;

            if (!TypicalMDSFileName.Contains(":"))
            {
                TypicalMDSFileName = ManxcatCentral.ResultDirectoryName + "\\SIMPLE" + TypicalMDSFileName;
            }

            if (!File.Exists(TypicalMDSFileName))
            {
                Exception e = SALSAUtility.SALSAError(" File " + TypicalMDSFileName + " Does Not Exist");

                throw (e);
            }

            int NumberMDSPoints  = 0;
            var InitialMDSString = new string[SALSAUtility.PointCount_Global];
            var ColorValue       = new int[SALSAUtility.PointCount_Global];

            if (ReadMDSCluster_File(TypicalMDSFileName, InitialMDSString, ColorValue, ref NumberMDSPoints))
            {
                Console.WriteLine(TypicalMDSFileName + " Read Successfully");
            }

            string[] fileEntries = Directory.GetFiles(labelFileDirectory);

            foreach (string LabelFileName in fileEntries)
            {
                if (LabelFileName.Contains(".dot"))
                {
                    continue;
                }

                if (LabelFileName.Contains("Summary"))
                {
                    continue;
                }

                if (LabelFileName.Contains("Timing"))
                {
                    continue;
                }
                string LabelFileName1 = LabelFileName.Replace(labelFileDirectory + "\\", "");
                string coreFileName   = MDSandClusterDirectory + "\\" + "MDSManxcat-" + LabelFileName1;

                if (File.Exists(coreFileName))
                {
                    continue;
                }
                int NumberOfLabels = 0;
                var CategoryLabel  = new string[SALSAUtility.PointCount_Global];
                ReadClusterLabel_File(LabelFileName, CategoryLabel, ref NumberOfLabels);

                if (NumberOfLabels != SALSAUtility.PointCount_Global)
                {
                    Exception e = SALSAUtility.SALSAError(" Illegal Count "
                                                          + NumberOfLabels.ToString() + " in File " + LabelFileName);

                    throw (e);
                }

                var CategoryIndex = new int[SALSAUtility.PointCount_Global];

                for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
                {
                    CategoryIndex[PointIndex] = Convert.ToInt32(CategoryLabel[PointIndex]);
                }
                WriteColor_Cluster(coreFileName, InitialMDSString, CategoryIndex, SALSAUtility.PointCount_Global, false);
                SALSAUtility.SALSAPrint(0, "Traditional Directory MDS Info Added to " + coreFileName);
            }
        }
Пример #13
0
        // End UpdateManxcatMDS_Option12_FamilybyCuts

        public static void UpdateManxcatMDS_Option12_Cluster()
        {
            //  Read Cluster Information with File specified in ConversionInformation
            string ClusterFileName      = ManxcatCentral.Configuration.ConversionInformation;
            int    NumberOfClusterLines = 0;
            var    CategoryLabel        = new string[SALSAUtility.PointCount_Global];

            ReadClusterLabel_File(ClusterFileName, CategoryLabel, ref NumberOfClusterLines);

            if (NumberOfClusterLines != SALSAUtility.PointCount_Global)
            {
                Exception e = SALSAUtility.SALSAError(" Illegal Count "
                                                      + NumberOfClusterLines.ToString() + " in File " + ClusterFileName);

                throw (e);
            }

            var CategoryIndex = new int[SALSAUtility.PointCount_Global];
            int minlabel      = SALSAUtility.PointCount_Global;
            int maxlabel      = 0;

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                CategoryIndex[PointIndex] = Convert.ToInt32(CategoryLabel[PointIndex]);

                if (minlabel > CategoryIndex[PointIndex])
                {
                    minlabel = CategoryIndex[PointIndex];
                }

                if (maxlabel < CategoryIndex[PointIndex])
                {
                    maxlabel = CategoryIndex[PointIndex];
                }
            }

            int TotalNumberClusters = maxlabel - minlabel + 1;
            var ClusterCounts       = new int[TotalNumberClusters];

            for (int Icount = 0; Icount < TotalNumberClusters; Icount++)
            {
                ClusterCounts[Icount] = 0;
            }

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                ++ClusterCounts[CategoryIndex[PointIndex] - minlabel];
            }

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                int Icount = CategoryIndex[PointIndex];
                SALSAUtility.GlobalPointProperties[PointIndex].cluster      = Icount;
                SALSAUtility.GlobalPointProperties[PointIndex].clusterlabel = "Cluster "
                                                                              + Icount.ToString() + " out of "
                                                                              + TotalNumberClusters.ToString() +
                                                                              " Count " +
                                                                              ClusterCounts[Icount - minlabel].ToString();
            }
            SALSAUtility.GlobalFileProperties.ClusterName       = "Clusters from " + ClusterFileName;
            SALSAUtility.GlobalFileProperties.ClusterStartIndex = minlabel;

            string cleandate = SALSAUtility.startTime.ToLocalTime().ToString();

            cleandate = cleandate.Replace(":", ".");
            cleandate = cleandate.Replace(" ", "-");
            string OldComment = SALSAUtility.GlobalFileProperties.Comment;

            if (OldComment != "")
            {
                OldComment += "\n";
            }
            OldComment += "Cluster Information added from " + ClusterFileName + " Time " + cleandate;
            SALSAUtility.GlobalFileProperties.Comment = OldComment;

            //  Write new label file
            string labelfilename = ManxcatCentral.Configuration.DataLabelsFileName;

            if (!labelfilename.Contains(":") && !labelfilename.Contains("$"))
            {
                labelfilename = ManxcatCentral.Configuration.ControlDirectoryName + "\\" + labelfilename;
            }
            SALSA_Properties.WriteDataPointFile(labelfilename, ManxcatCentral.Configuration.Write2Das3D,
                                                "colon,SameFileName ", SALSAUtility.GlobalFileProperties,
                                                SALSAUtility.GlobalPointProperties, SALSAUtility.NumberOriginalPoints);
            SALSAUtility.SALSAPrint(0, "Cluster Info Added to " + labelfilename + " from " + ClusterFileName);
            ManxcatCentral.Configuration.Comment += "\nCluster Info Added to "
                                                    + labelfilename + " from " + ClusterFileName;
        }
Пример #14
0
        // End  UpdateManxcatMDS_Option12()

        public static void UpdateManxcatMDS_Option12_Functions(bool statistics)
        {
            //  Setup weight: Only used in statistics
            var weights = new double[SALSAUtility.PointCount_Global];

            ManxcatMDS.WeightingOption = ManxcatCentral.Configuration.WeightingOption;
            ManxcatMDS.SetupWeightings(weights);
            string TypicalMDSFileName = "";

            //  Setup MDS: Only used in statistics
            var MDSPoints = new double[SALSAUtility.PointCount_Global, Hotsun.ParameterVectorDimension];

            if (statistics)
            {
                // Set up statistics by reading MDS file
                TypicalMDSFileName = ManxcatCentral.ResultDirectoryName + "\\SIMPLE" +
                                     ManxcatCentral.Configuration.ReducedVectorOutputFileName;

                if (!File.Exists(TypicalMDSFileName))
                {
                    Exception e = SALSAUtility.SALSAError(" File " + TypicalMDSFileName + " Does Not Exist");

                    throw (e);
                }

                int NumberMDSPoints  = 0;
                var InitialMDSString = new string[SALSAUtility.PointCount_Global];
                var ColorValue       = new int[SALSAUtility.PointCount_Global];

                if (ReadMDSCluster_File(TypicalMDSFileName, InitialMDSString, ColorValue, ref NumberMDSPoints))
                {
                    SALSAUtility.SALSAPrint(0, "MDS File " + TypicalMDSFileName + " Read Successfully");
                }

                for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
                {
                    // Extract MDS POints
                    string   inputLineStr = InitialMDSString[PointIndex].Trim();
                    string[] split        = inputLineStr.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    if (split.Length < Hotsun.ParameterVectorDimension)
                    {
                        Exception e =
                            SALSAUtility.SALSAError(" Point " + PointIndex.ToString() + " has wrong number of Entries "
                                                    + inputLineStr + " Entries" + split.Length);

                        throw (e);
                    }

                    for (int VectorIndex = 0; VectorIndex < Hotsun.ParameterVectorDimension; VectorIndex++)
                    {
                        MDSPoints[PointIndex, VectorIndex] = Convert.ToDouble(split[VectorIndex].Trim());
                    }
                }
            } // End set up of Statistics

            //  Set Mapping
            var ClusterLabel  = new int[SALSAUtility.PointCount_Global];
            int NumDivisions  = 10;
            int BasicSize     = SALSAUtility.PointCount_Global / NumDivisions;
            int LeftOver      = SALSAUtility.PointCount_Global - BasicSize * NumDivisions;
            int DivisionCount = 0;
            int Limit         = 0;

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                if (PointIndex >= Limit)
                {
                    ++DivisionCount;
                    Limit += BasicSize;

                    if (LeftOver >= DivisionCount)
                    {
                        ++Limit;
                    }
                }
                ClusterLabel[PointIndex] = DivisionCount;
            }

            String FunctionFileName = ManxcatCentral.Configuration.ConversionInformation;

            if (!FunctionFileName.Contains(":"))
            {
                FunctionFileName = ManxcatCentral.Configuration.ControlDirectoryName + "\\" + FunctionFileName;
            }

            var functionkeys   = new double[SALSAUtility.PointCount_Global];
            var functionlabels = new int[SALSAUtility.PointCount_Global];

            int pickout = -1;

            while (true)
            {
                ++pickout;
                bool   endofdata      = true;
                int    NumberofLines  = 0;
                double sumabs         = 0.0;
                double totalweight    = 0.0;
                double meangamma      = 0.0;
                double vargamma       = 0.0;
                var    meanxyz        = new double[Hotsun.ParameterVectorDimension];
                var    varxyz         = new double[Hotsun.ParameterVectorDimension, Hotsun.ParameterVectorDimension];
                var    correlxyzgamma = new double[Hotsun.ParameterVectorDimension];

                if (statistics)
                {
                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        meanxyz[VectorIndex1] = 0.0;

                        for (int VectorIndex2 = 0; VectorIndex2 < Hotsun.ParameterVectorDimension; VectorIndex2++)
                        {
                            varxyz[VectorIndex1, VectorIndex2] = 0.0;
                        }
                        correlxyzgamma[VectorIndex1] = 0.0;
                    }
                }

                try
                {
                    // Check if file exists
                    if (!File.Exists(FunctionFileName))
                    {
                        Exception e = SALSAUtility.SALSAError("File " + FunctionFileName + " does not exists.");

                        throw (e);
                    }

                    // Create a new stream to read from a file
                    using (StreamReader sr = File.OpenText(FunctionFileName))
                    {
                        // Read contents of a file, line by line, into a string
                        String inputLineStr;

                        while ((inputLineStr = sr.ReadLine()) != null)
                        {
                            inputLineStr = inputLineStr.Trim();
                            string[] split = inputLineStr.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                            if (split.Length <= pickout)
                            {
                                break;
                            }
                            endofdata = false;
                            string usethis = split[pickout].Trim();

                            if (usethis.Length < 1)
                            {
                                continue; //replace empty line
                            }
                            double gamma = Convert.ToDouble(usethis);
                            functionkeys[NumberofLines]   = gamma;
                            functionlabels[NumberofLines] = NumberofLines;
                            sumabs += Math.Abs(gamma);

                            if (statistics)
                            {
                                double wgt = weights[NumberofLines];
                                meangamma   += gamma * wgt;
                                vargamma    += wgt * gamma * gamma;
                                totalweight += wgt;

                                for (int VectorIndex1 = 0;
                                     VectorIndex1 < Hotsun.ParameterVectorDimension;
                                     VectorIndex1++)
                                {
                                    meanxyz[VectorIndex1]        += MDSPoints[NumberofLines, VectorIndex1] * wgt;
                                    correlxyzgamma[VectorIndex1] += MDSPoints[NumberofLines, VectorIndex1] * gamma * wgt;

                                    for (int VectorIndex2 = 0;
                                         VectorIndex2 < Hotsun.ParameterVectorDimension;
                                         VectorIndex2++)
                                    {
                                        varxyz[VectorIndex1, VectorIndex2] += MDSPoints[NumberofLines, VectorIndex1] *
                                                                              MDSPoints[NumberofLines, VectorIndex2] * wgt;
                                    }
                                }
                            }
                            ++NumberofLines;
                        }
                        sr.Close();
                    }
                }
                catch (Exception e)
                {
                    SALSAUtility.SALSAError("Failed to read data from " + FunctionFileName + " " + e);

                    throw (e);
                }

                if (endofdata)
                {
                    break;
                }

                if (NumberofLines != SALSAUtility.PointCount_Global)
                {
                    SALSAUtility.SALSAError("Incorrect Function count read "
                                            + NumberofLines + " Expected " + SALSAUtility.PointCount_Global);
                }

                // Set Statistics
                if (statistics)
                {
                    var    alpha     = new double[Hotsun.ParameterVectorDimension];
                    double alphanorm = 0.0;
                    meangamma = meangamma / totalweight;
                    vargamma  = (vargamma / totalweight) - meangamma * meangamma;

                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        meanxyz[VectorIndex1] = meanxyz[VectorIndex1] / totalweight;
                    }

                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        for (int VectorIndex2 = 0; VectorIndex2 < Hotsun.ParameterVectorDimension; VectorIndex2++)
                        {
                            varxyz[VectorIndex1, VectorIndex2] = (varxyz[VectorIndex1, VectorIndex2] / totalweight) -
                                                                 meanxyz[VectorIndex1] * meanxyz[VectorIndex2];
                        }
                        correlxyzgamma[VectorIndex1] = correlxyzgamma[VectorIndex1] / totalweight -
                                                       meangamma * meanxyz[VectorIndex1];
                        alpha[VectorIndex1] = correlxyzgamma[VectorIndex1] / varxyz[VectorIndex1, VectorIndex1];
                        alphanorm          += alpha[VectorIndex1] * alpha[VectorIndex1];
                    }

                    // invert Matrix to find best alpha
                    var ConventionalFirst  = new double[Hotsun.ParameterVectorDimension, 1];
                    var ConventionalAnswer = new double[Hotsun.ParameterVectorDimension][];
                    var ConventionalMatrix = new double[Hotsun.ParameterVectorDimension, Hotsun.ParameterVectorDimension];

                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        ConventionalAnswer[VectorIndex1]   = new double[1];
                        ConventionalFirst[VectorIndex1, 0] = correlxyzgamma[VectorIndex1] /
                                                             Math.Sqrt(varxyz[VectorIndex1, VectorIndex1]);

                        for (int VectorIndex2 = 0; VectorIndex2 < Hotsun.ParameterVectorDimension; VectorIndex2++)
                        {
                            ConventionalMatrix[VectorIndex1, VectorIndex2] = varxyz[VectorIndex1, VectorIndex2] /
                                                                             Math.Sqrt(
                                varxyz[VectorIndex1, VectorIndex1] *
                                varxyz[VectorIndex2, VectorIndex2]);
                        }
                    }
                    LMatrix cMatrix       = LMatrix.Create(ConventionalMatrix);
                    LMatrix RightHandSide = LMatrix.Create(ConventionalFirst);
                    LMatrix MatrixAnswer  = cMatrix.Solve(RightHandSide);
                    ConventionalAnswer = MatrixAnswer;

                    alphanorm = 0.0;

                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        alpha[VectorIndex1] = ConventionalAnswer[VectorIndex1][0] /
                                              Math.Sqrt(varxyz[VectorIndex1, VectorIndex1]);
                        alphanorm += alpha[VectorIndex1] * alpha[VectorIndex1];
                    }

                    double Fullcorrelation = 0.0;
                    double varalphaxyz     = 0.0;

                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        alpha[VectorIndex1] = alpha[VectorIndex1] / Math.Sqrt(alphanorm);
                        Fullcorrelation    += alpha[VectorIndex1] * correlxyzgamma[VectorIndex1];
                    }

                    for (int VectorIndex1 = 0; VectorIndex1 < Hotsun.ParameterVectorDimension; VectorIndex1++)
                    {
                        for (int VectorIndex2 = 0; VectorIndex2 < Hotsun.ParameterVectorDimension; VectorIndex2++)
                        {
                            varalphaxyz += alpha[VectorIndex1] * alpha[VectorIndex2] * varxyz[VectorIndex1, VectorIndex2];
                        }
                    }
                    Console.WriteLine(varalphaxyz + " " + Fullcorrelation + " " + vargamma);
                    Fullcorrelation = Fullcorrelation / (Math.Sqrt(vargamma * varalphaxyz));
                    SALSAUtility.SALSAPrint(0, "Column "
                                            + pickout.ToString() + " File " + FunctionFileName + " MDS File " +
                                            TypicalMDSFileName +
                                            " Total Weight "
                                            + totalweight.ToString() + " Correlation " +
                                            Fullcorrelation.ToString("F4") + " Direction "
                                            + alpha[0].ToString("F4") + " " + alpha[1].ToString("F4") + " " +
                                            alpha[2].ToString("F4"));
                }

                // Set Divisions
                Array.Sort(functionkeys, functionlabels);
                var PointColors = new int[SALSAUtility.PointCount_Global];

                for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
                {
                    int UnsortedPosition = functionlabels[PointIndex];
                    PointColors[UnsortedPosition] = ClusterLabel[PointIndex];
                }
                string OutputFileExtension = ManxcatCentral.Configuration.ConversionInformation;
                OutputFileExtension = OutputFileExtension.Replace(".dat", "");
                OutputFileExtension = OutputFileExtension.Replace(".txt", "");
                OutputFileExtension = OutputFileExtension + "-" + pickout.ToString() + ".txt";
                string labelFileDirectory = ManxcatCentral.Configuration.ClusterDirectory;
                // Directory for Colors attached to Points
                string OutputFileName = labelFileDirectory + "\\" + OutputFileExtension;
                WritePointCluster(OutputFileName, PointColors, SALSAUtility.PointCount_Global);

                double test = 0.1 * sumabs / NumberofLines;

                for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
                {
                    int UnsortedPosition = functionlabels[PointIndex];

                    if (Math.Abs(functionkeys[UnsortedPosition]) < test)
                    {
                        PointColors[UnsortedPosition] = 0;
                    }
                }

                OutputFileName = OutputFileName.Replace(".txt", "NZ.txt");
                WritePointCluster(OutputFileName, PointColors, SALSAUtility.PointCount_Global);
            } // End while over pickout (columns in data)
            return;
        }
Пример #15
0
        // End UpdateManxcatMDS_Option12_Functions

        public static void UpdateManxcatMDS_Option12_FamilybyCuts()
        {
            String CutFileName = ManxcatCentral.Configuration.ConversionInformation;

            if (!CutFileName.Contains(":"))
            {
                CutFileName = ManxcatCentral.Configuration.ControlDirectoryName + "\\" + CutFileName;
            }

            var inputdata    = new string[SALSAUtility.PointCount_Global];
            int NumberofCuts = 0;

            string FamilyLabel  = "Family";
            int    FamilyNumber = 1;

            if (ManxcatCentral.Configuration.ConversionOption.ToLower().Contains("family2"))
            {
                FamilyNumber = 2;
            }

            ReadString_File(CutFileName, inputdata, ref NumberofCuts);

            if (NumberofCuts <= 0)
            {
                Exception e = SALSAUtility.SALSAError("Too few points "
                                                      + NumberofCuts.ToString() + " in Cut File " + CutFileName);

                throw (e);
            }

            var CutStart      = new int[NumberofCuts];
            var CutLabel      = new string[NumberofCuts];
            int CountFamilies = 0;
            int itmpold       = -2;

            for (int CutPos = 0; CutPos < NumberofCuts; CutPos++)
            {
                string[] split = inputdata[CutPos].Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                int      itmp  = Convert.ToInt32(split[0]);

                if (itmp < 0)
                {
                    FamilyLabel = split[1];
                    continue;
                }

                if (itmp <= itmpold)
                {
                    continue;
                }
                CutStart[CountFamilies] = itmp;
                CutLabel[CountFamilies] = FamilyLabel + "-" + split[1];
                ++CountFamilies;
                itmpold = itmp;
            }

            if (FamilyNumber == 1)
            {
                SALSAUtility.GlobalFileProperties.FamilyName1 = FamilyLabel + " from " + CutFileName;
            }

            if (FamilyNumber == 2)
            {
                SALSAUtility.GlobalFileProperties.FamilyName2 = FamilyLabel + " from " + CutFileName;
            }

            int minlabel      = 1;
            int CurrentFamily = 0;
            var CategoryIndex = new int[SALSAUtility.PointCount_Global];

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                if (CurrentFamily < CountFamilies - 1)
                {
                    if ((PointIndex + 1) >= CutStart[CurrentFamily + 1])
                    {
                        ++CurrentFamily;
                    }
                }
                CategoryIndex[PointIndex] = minlabel + CurrentFamily;
                continue;
            }

            var FamilyCounts = new int[CountFamilies];

            for (int Icount = 0; Icount < CountFamilies; Icount++)
            {
                FamilyCounts[Icount] = 0;
            }

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                ++FamilyCounts[CategoryIndex[PointIndex] - minlabel];
            }

            for (int PointIndex = 0; PointIndex < SALSAUtility.PointCount_Global; PointIndex++)
            {
                int Icount = CategoryIndex[PointIndex];

                if (FamilyNumber == 1)
                {
                    SALSAUtility.GlobalPointProperties[PointIndex].family1      = Icount;
                    SALSAUtility.GlobalPointProperties[PointIndex].familylabel1 = CutLabel[Icount - minlabel] + " "
                                                                                  + Icount.ToString() + " out of "
                                                                                  + CountFamilies.ToString() + " Count " +
                                                                                  FamilyCounts[Icount - minlabel].
                                                                                  ToString();
                }

                if (FamilyNumber == 2)
                {
                    SALSAUtility.GlobalPointProperties[PointIndex].family2      = Icount;
                    SALSAUtility.GlobalPointProperties[PointIndex].familylabel2 = CutLabel[Icount - minlabel] + " "
                                                                                  + Icount.ToString() + " out of "
                                                                                  + CountFamilies.ToString() + " Count " +
                                                                                  FamilyCounts[Icount - minlabel].
                                                                                  ToString();
                }
            }

            string cleandate = SALSAUtility.startTime.ToLocalTime().ToString();

            cleandate = cleandate.Replace(":", ".");
            cleandate = cleandate.Replace(" ", "-");
            string OldComment = SALSAUtility.GlobalFileProperties.Comment;

            if (OldComment != "")
            {
                OldComment += "\n";
            }
            OldComment += "Family"
                          + FamilyNumber.ToString() + " " + FamilyLabel + " Information added from " + CutFileName +
                          " Time " + cleandate;
            SALSAUtility.GlobalFileProperties.Comment = OldComment;

            //  Write new label file
            string labelfilename = ManxcatCentral.Configuration.DataLabelsFileName;

            if (!labelfilename.Contains(":"))
            {
                labelfilename = ManxcatCentral.Configuration.ControlDirectoryName + "\\" + labelfilename;
            }
            SALSA_Properties.WriteDataPointFile(labelfilename, ManxcatCentral.Configuration.Write2Das3D,
                                                "colon,SameFileName ", SALSAUtility.GlobalFileProperties,
                                                SALSAUtility.GlobalPointProperties, SALSAUtility.NumberOriginalPoints);
            SALSAUtility.SALSAPrint(0, "Family"
                                    + FamilyNumber.ToString() + " " + FamilyLabel + " Info Added to " + labelfilename +
                                    " from " + CutFileName);
            ManxcatCentral.Configuration.Comment += "\nFamily"
                                                    + FamilyNumber.ToString() + " " + FamilyLabel + " Info Added to " +
                                                    labelfilename + " from " + CutFileName;
        }
Пример #16
0
        // Write label-cluster results into a file
        public static void WriteMDS(string fname, int OutputOption, double[][] param, double[][] perr)
        {
            int LocalVectorDimension = param[0].GetLength(0);

            if (LocalVectorDimension != perr[0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions Labels " + LocalVectorDimension.ToString() + " Perr " +
                                        perr[0].GetLength(0).ToString());
            }

            ManxcatSection Configuration = ManxcatCentral.Configuration;

            // Write SALSA Properties File Header
            if (OutputOption == 0)
            {
                int filetype = 2;

                if ((SALSAUtility.NumberFixedPoints > 0) ||
                    (SALSAUtility.NumberVariedPoints < SALSAUtility.NumberOriginalPoints))
                {
                    filetype = 4;
                }

                string cleandate = SALSAUtility.startTime.ToLocalTime().ToString();
                cleandate = cleandate.Replace(":", ".");
                cleandate = cleandate.Replace(" ", "-");
                SALSAUtility.GlobalFileProperties.GroupName = "MDSasChisq-" + Configuration.RunSetLabel + "-Run" +
                                                              Configuration.RunNumber.ToString() + "-Date-" + cleandate;
                SALSAUtility.GlobalFileProperties.FileGenerationType      = filetype;
                SALSAUtility.GlobalFileProperties.OriginalPointStartIndex = 0;
                SALSAUtility.GlobalFileProperties.LocalPointStartIndex    = 0;
                SALSAUtility.GlobalFileProperties.NumberOriginalPoints    = SALSAUtility.NumberOriginalPoints;
                SALSAUtility.GlobalFileProperties.NumberPointsinFile      = SALSAUtility.PointCount_Global;

                // Comment should have key features of Run
                string OldComment = SALSAUtility.GlobalFileProperties.Comment;

                if (OldComment != "")
                {
                    OldComment += "\n";
                }
                OldComment += "MDSasChisq " + Configuration.RunNumber.ToString() + " StartTime " + cleandate + " ****";
                OldComment += "\n Distance Input Option " + Configuration.DistanceProcessingOption.ToString() +
                              " Distance Formula " + Configuration.DistanceFormula.ToString() + " Weighting Option " +
                              Configuration.Chisqnorm.ToString() + " Minimum Distance Value " +
                              Configuration.MinimumDistance.ToString();
                OldComment += "\n" + Hotsun.HotsunComment;
                SALSAUtility.GlobalFileProperties.Comment = OldComment;

                for (int GlobalPointIndex = 0; GlobalPointIndex < SALSAUtility.PointCount_Global; GlobalPointIndex++)
                {
                    int    OriginalPointIndex = SALSAUtility.UsedPointtoOriginalPointMap[GlobalPointIndex];
                    int    groupnumber        = -1;
                    string grouplabel         = "Ignored";
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].FixedorVaried = 0;
                    if (ManxcatMDS.PointStatus[GlobalPointIndex] == -1)
                    {
                        groupnumber = 3;
                        grouplabel  = "Deleted";
                    }
                    else
                    {
                        if (SALSAUtility.OriginalPointDisposition[GlobalPointIndex] <= -SALSAUtility.SALSASHIFT)
                        {
                            groupnumber = 2;
                            grouplabel  = "Fixed";
                            SALSAUtility.GlobalPointProperties[GlobalPointIndex].FixedorVaried = 2;
                        }

                        if (SALSAUtility.OriginalPointDisposition[GlobalPointIndex] >= SALSAUtility.SALSASHIFT)
                        {
                            groupnumber = 1;
                            grouplabel  = "Varied";
                            SALSAUtility.GlobalPointProperties[GlobalPointIndex].source = "MDSasChisq-" +
                                                                                          Configuration.RunSetLabel +
                                                                                          "-Run" +
                                                                                          Configuration.RunNumber.
                                                                                          ToString() + "-Date-" +
                                                                                          cleandate;
                            SALSAUtility.GlobalPointProperties[GlobalPointIndex].FixedorVaried = 1;
                        }
                    }
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].group               = groupnumber;
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].grouplabel          = grouplabel;
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].OriginalPointNumber = OriginalPointIndex;
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].LocalPointNumber    = GlobalPointIndex;
                }

                for (int GlobalPointIndex = 0; GlobalPointIndex < SALSAUtility.PointCount_Global; GlobalPointIndex++)
                {
                    if (ManxcatMDS.PointStatus[GlobalPointIndex] == -1)
                    {
                        SALSAUtility.GlobalPointProperties[GlobalPointIndex].valuesset = false;
                        SALSAUtility.GlobalPointProperties[GlobalPointIndex].errorsset = false;
                        continue;
                    }
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].x = param[GlobalPointIndex][0];
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].y = param[GlobalPointIndex][1];

                    if (LocalVectorDimension > 2)
                    {
                        SALSAUtility.GlobalPointProperties[GlobalPointIndex].z = param[GlobalPointIndex][2];
                    }
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].xerr = perr[GlobalPointIndex][0];
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].yerr = perr[GlobalPointIndex][1];

                    if (LocalVectorDimension > 2)
                    {
                        SALSAUtility.GlobalPointProperties[GlobalPointIndex].zerr = perr[GlobalPointIndex][2];
                    }
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].valuesset = true;
                    SALSAUtility.GlobalPointProperties[GlobalPointIndex].errorsset = true;
                }
                if (SALSAUtility.Usedreordered)
                {
                    var NaivePointProperties = new SALSADataPointProperties[SALSAUtility.PointCount_Global];
                    for (int GlobalPointIndex = 0;
                         GlobalPointIndex < SALSAUtility.PointCount_Global;
                         GlobalPointIndex++)
                    {
                        int NaivePointIndex = SALSAUtility.ActualtoNaiveUsedOrder[GlobalPointIndex];
                        NaivePointProperties[NaivePointIndex] =
                            SALSAUtility.GlobalPointProperties[GlobalPointIndex].ShallowCopy();
                    }
                    SALSA_Properties.WriteDataPointFile(fname, ManxcatCentral.Configuration.Write2Das3D, "all ",
                                                        SALSAUtility.GlobalFileProperties,
                                                        NaivePointProperties, SALSAUtility.PointCount_Global);
                    return;
                }
                SALSA_Properties.WriteDataPointFile(fname, ManxcatCentral.Configuration.Write2Das3D, "all ",
                                                    SALSAUtility.GlobalFileProperties,
                                                    SALSAUtility.GlobalPointProperties, SALSAUtility.PointCount_Global);
                return;
            }

            //  Option OutputOption = 1
            // Simple output of Used in ORIGINAL not Loadbalanced Order
            try
            {
                StreamWriter sw = null;

                if (!string.IsNullOrEmpty(fname))
                {
                    sw = new StreamWriter(fname, false, Encoding.UTF8);
                }

                if (sw != null)
                {
                    for (int GlobalPointIndex = 0;
                         GlobalPointIndex < SALSAUtility.PointCount_Global;
                         GlobalPointIndex++)
                    {
                        if (ManxcatMDS.PointStatus[GlobalPointIndex] == -1)
                        {
                            continue;
                        }
                        string Coordinates    = "";
                        int    SingleCluster  = 1;
                        int    UsedPointIndex = SALSAUtility.NaivetoActualUsedOrder[GlobalPointIndex];
                        for (int LocalVectorIndex = 0; LocalVectorIndex < LocalVectorDimension; LocalVectorIndex++)
                        {
                            Coordinates += param[UsedPointIndex][LocalVectorIndex].ToString("E4") + "\t";
                        }

                        sw.WriteLine(
                            String.Format((GlobalPointIndex).ToString() + "\t" + Coordinates + SingleCluster.ToString()));
                    }
                }

                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed writing data" + e);
                throw (e);
            }
        }