Exemple #1
0
        public static void Main(string[] args)
        {
            //SpecialFunctions.CheckDate(2010, 4, 16);
            //double[][] ragged = new double[][]{new double[]{1,2,3},new double[]{4,5,6}};
            //TestIt(ragged);
            //double[,] twoD = new double[,] {{ 1, 2, 3 },{ 4, 5, 6 } };
            ////TestIt(twoD);Nope
            //var sparse = SparseMatrix<string, string, double>.CreateEmptyInstance(new[] { "key1", "key2" }, new[] { "cid1" }, double.NaN);
            //TestIt(sparse);


            ////BioMatrixSample.BioMatrixSample.DemoMatrix(Console.Out);
            ////Bio.Matrix.MatrixUnitTest.MainTest(doOutOfRangeTest: true, parallelOptions: new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount });
            //return;

            Console.WriteLine(Environment.MachineName);
            Console.WriteLine(Helper.CreateDelimitedString(" ", args));

            try
            {
                ShoUtils.SetShoDirEnvironmentVariable(1);

                ArgumentCollection argumentCollection = new CommandArguments(args);

                if (argumentCollection.ExtractOptionalFlag("help"))
                {
                    Console.WriteLine("");
                    Console.WriteLine(UsageMessage);
                    return;
                }

                bool useCorrel = argumentCollection.ExtractOptionalFlag("correl");
                //bool doubleUp = argCollection.ExtractOptionalFlag("doubleUp");
                ParallelOptions parallelOptions = new ParallelOptions {
                    MaxDegreeOfParallelism = argumentCollection.ExtractOptional("MaxDegreeOfParallelism", Environment.ProcessorCount)
                };
                int randomSeed           = argumentCollection.ExtractOptional <int>("randomSeed", (int)MachineInvariantRandom.GetSeedUInt("Eigenstrat"));
                int?randomRowCountOrNull = argumentCollection.ExtractOptional <int?>("randomRowCount", null);


                argumentCollection.CheckNoMoreOptions(3);
                int    maxValue           = argumentCollection.ExtractNext <int>("maxValue");
                string inputDenseFileName = argumentCollection.ExtractNext <string>("inputDenseFile");
                string outputCovFileName  = argumentCollection.ExtractNext <string>("outputCovFile");
                argumentCollection.CheckThatEmpty();

                Console.WriteLine("Reading input file " + inputDenseFileName);
                //var originalMatrix = MatrixFactorySSC.Parse(inputDenseFileName, '?', parallelOptions);

                Console.WriteLine("Using 'GetInstanceFromDenseAnsi' How about 'GetInstanceFromRowKeysAnsi', too?");
                using (var originalMatrix = RowKeysAnsi.GetInstanceFromDenseAnsi(inputDenseFileName, parallelOptions))
                {
                    Matrix <string, string, char> matrixOptionallyCutDown;
                    if (null != randomRowCountOrNull)
                    {
                        Random random        = new Random(randomSeed);
                        var    sampleRowKeys = SpecialFunctions.SelectRandom(originalMatrix.RowKeys, randomRowCountOrNull.Value, ref random);
                        matrixOptionallyCutDown = originalMatrix.SelectRowsView(sampleRowKeys);
                    }
                    else
                    {
                        matrixOptionallyCutDown = originalMatrix;
                    }

                    var gMatrix = matrixOptionallyCutDown.ConvertValueView(new CharToDoubleWithLimitsConverter(maxValue), double.NaN);

                    //DenseMatrix<string, string, double>.CreateDefaultInstance
                    var xMatrix = StandardizeGToCreateX <ShoMatrix>(maxValue, gMatrix, ShoMatrix.CreateDefaultInstance, parallelOptions);

                    var psiMatrix = CreatePsiTheMatrixOfCovarianceValues(useCorrel, xMatrix, /*isOKToDestroyXMatrix*/ true, parallelOptions);

                    Console.WriteLine("Writing output file " + outputCovFileName);
                    psiMatrix.WriteDense(outputCovFileName);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("");
                Console.WriteLine(exception.Message);
                if (exception.InnerException != null)
                {
                    Console.WriteLine(exception.InnerException.Message);
                }

                Console.WriteLine("");
                Console.WriteLine(UsageMessage);

                Console.WriteLine(exception.StackTrace);
                throw new Exception("", exception);
            }
        }