// 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); }
// 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); } }