Exemplo n.º 1
0
        // End ReInitializeAccum()

        public static void AddupChisqContributions(Desertwind TotalSolution)
        {
            // Sum over Threads

            int NumberParms = SummedoverThreadsAccum.VectorSize;
            int SecondSize  = SummedoverThreadsAccum.SecondSize;

            for (int ThreadNo = 0; ThreadNo < SALSAUtility.ThreadCount; ThreadNo++)
            {
                SummedoverThreadsAccum.chisq += LocalAccum[ThreadNo].chisq;
                for (int iparm = 0; iparm < NumberParms; iparm++)
                {
                    SummedoverThreadsAccum.first[iparm] += LocalAccum[ThreadNo].first[iparm];
                }
                for (int iparm = 0; iparm < SecondSize; iparm++)
                {
                    SummedoverThreadsAccum.second[iparm] += LocalAccum[ThreadNo].second[iparm];
                }
            }

            //  Sum over MPI Processes
            ChisqFirstandSecond UsethisAccum = SummedoverThreadsAccum;

            if (SALSAUtility.MPI_Size > 1)
            {
                UsethisAccum = SummedoverProcessesAccum;
                SummedoverProcessesAccum.chisq = SALSAUtility.MPI_communicator.Allreduce(SummedoverThreadsAccum.chisq,
                                                                                         Operation <double> .Add);
                SummedoverProcessesAccum.first = SALSAUtility.MPI_communicator.Allreduce(SummedoverThreadsAccum.first,
                                                                                         Operation <double> .Add);
                SummedoverProcessesAccum.second = SALSAUtility.MPI_communicator.Allreduce(
                    SummedoverThreadsAccum.second, Operation <double> .Add);
            }

            //  Put into Hotsun Form
            TotalSolution.Chisquared = UsethisAccum.chisq;
            Hotsun.zerocr            = UsethisAccum.chisq;
            int linearcount = 0;

            for (int iparm1 = 0; iparm1 < NumberParms; iparm1++)
            {
                TotalSolution.first[iparm1][0] = UsethisAccum.first[iparm1];
                for (int iparm2 = iparm1; iparm2 < NumberParms; iparm2++)
                {
                    double tmp = UsethisAccum.second[linearcount];
                    linearcount++;
                    TotalSolution.FullMatrix[iparm1, iparm2][0, 0]      = tmp;
                    TotalSolution.FullMatrix[iparm2, iparm1][0, 0]      = tmp;
                    TotalSolution.ExactFullMatrix[iparm1, iparm2][0, 0] = tmp;
                    TotalSolution.ExactFullMatrix[iparm2, iparm1][0, 0] = tmp;
                }
            }
            // SALSAUtility.SALSAPrint(0, "Second Deriv " + TotalSolution.FullMatrix[5, 6][0, 0].ToString("E4"));
        }
Exemplo n.º 2
0
        // end SolveMatrix(double[][] Answer, Desertwind Solution)

        public static void GlobalMatrixVectorProduct(double[][] DistributedVector, Desertwind Solution, bool useexact,
                                                     double[][] GlobalxVector, double[][] GlobalVectoronRight)
        {
            // DistributedVector = Matrix (calculated using GlobalxVector) . GlobalVectoronRight
            // In generic case, Matrix is fully calculated and does not use GlobalxVector

            double[, ][,] Matrix;
            if (useexact)
            {
                Matrix = Solution.ExactFullMatrix;
            }
            else
            {
                Matrix = Solution.FullMatrix;
            }

            for (int GlobalIndex1 = 0; GlobalIndex1 < Hotsun.npar; GlobalIndex1++)
            {
                if (Hotsun.FixedParameter[GlobalIndex1][0])
                {
                    DistributedVector[GlobalIndex1][0] = 0.0;
                }
                else
                {
                    double tmp = 0.0;
                    for (int GlobalIndex2 = 0; GlobalIndex2 < Hotsun.npar; GlobalIndex2++)
                    {
                        if (Hotsun.FixedParameter[GlobalIndex2][0])
                        {
                            continue;
                        }
                        double MatrixElement = Matrix[GlobalIndex1, GlobalIndex2][0, 0];
                        if (Hotsun.UseDiagonalScaling)
                        {
                            MatrixElement *= Hotsun.sqdginv[GlobalIndex1][0] * Hotsun.sqdginv[GlobalIndex2][0];
                        }
                        if (Hotsun.AddMarquardtQDynamically && (GlobalIndex1 == GlobalIndex2))
                        {
                            MatrixElement += Hotsun.Q;
                        }
                        tmp += MatrixElement * GlobalVectoronRight[GlobalIndex2][0];
                    } // End GlobalIndex2
                    DistributedVector[GlobalIndex1][0] = tmp;
                }     // End varied parameter
            }         // End GlobalIndex1
        }
Exemplo n.º 3
0
        // End AddupChisqContributions(ChisqFirstandSecond[] SubTotal, Desertwind TotalSolution)

        public static void FindQlimits(Desertwind Solution, ref double Qhigh, ref double Qlow, ref int ReasontoStop1,
                                       ref int ReasontoStop2)
        {
            if (Hotsun.FullSecondDerivative)
            {
                FindTraceandNorm(Solution.ExactFullMatrix, ref Hotsun.ChisqMatrixTrace, ref Hotsun.ChisqMatrixNorm);
            }
            else
            {
                FindTraceandNorm(Solution.FullMatrix, ref Hotsun.ChisqMatrixTrace, ref Hotsun.ChisqMatrixNorm);
            }

            var ConventionalMatrix = new double[Hotsun.npar, Hotsun.npar];

            // Set Up Matrix to find eigenvalues
            // Scale but do NOT add Q
            double[, ][,] Matrix;
            if (Hotsun.FullSecondDerivative)
            {
                Matrix = Solution.ExactFullMatrix;
            }
            else
            {
                Matrix = Solution.FullMatrix;
            }

            //  Set actual matrix
            for (int GlobalIndex1 = 0; GlobalIndex1 < Hotsun.npar; GlobalIndex1++)
            {
                for (int GlobalIndex2 = 0; GlobalIndex2 < Hotsun.npar; GlobalIndex2++)
                {
                    double MatrixElement = Matrix[GlobalIndex1, GlobalIndex2][0, 0];
                    if (Hotsun.UseDiagonalScaling)
                    {
                        MatrixElement *= Hotsun.sqdginv[GlobalIndex1][0] * Hotsun.sqdginv[GlobalIndex2][0];
                    }
                    ConventionalMatrix[GlobalIndex1, GlobalIndex2] = MatrixElement;
                } // End GlobalIndex2
            }     // End GlobalIndex1
              // Find Minimum and Maximum eigenvalue of ConventionalMatrix


            // Begin Added by smbeason 5/17/2009
            LMatrix lmatrix = LMatrix.Create(ConventionalMatrix);
            EigenvalueDecomposition eigenValueDecomp = lmatrix.EigenvalueDecomposition;

            double minEigenValue = double.MaxValue;
            double maxEigenValue = double.MinValue;

            //Assuming you want on the real part...
            for (int i = 0; i < eigenValueDecomp.RealEigenvalues.Length; i++)
            {
                minEigenValue = Math.Min(minEigenValue, eigenValueDecomp.RealEigenvalues[i]);
                maxEigenValue = Math.Max(maxEigenValue, eigenValueDecomp.RealEigenvalues[i]);
            }
            // End Added by smbeason 5/17/2009

            ReasontoStop1 = 1;
            ReasontoStop2 = 1;
            Qlow          = minEigenValue;
            Qhigh         = maxEigenValue;
            return;
        }
Exemplo n.º 4
0
        // End FindTraceandNorm(double[,][,] Matrix, double[][] GlobalxVector, ref double Trace, ref double Norm)

        public static bool SolveMatrix(double[][] Answer, Desertwind Solution)
        {
            var ConventionalMatrix = new double[Hotsun.npar, Hotsun.npar];
            var ConventionalFirst  = new double[Hotsun.npar, 1];
            var ConventionalAnswer = new double[Hotsun.npar][];

            for (int GlobalIndex1 = 0; GlobalIndex1 < Hotsun.npar; GlobalIndex1++)
            {
                ConventionalAnswer[GlobalIndex1] = new double[1];
            }

            double[, ][,] Matrix;
            if (Hotsun.FullSecondDerivative)
            {
                Matrix = Solution.ExactFullMatrix;
            }
            else
            {
                Matrix = Solution.FullMatrix;
            }

            //  Set actual matrix
            for (int GlobalIndex1 = 0; GlobalIndex1 < Hotsun.npar; GlobalIndex1++)
            {
                if (Hotsun.FixedParameter[GlobalIndex1][0])
                {
                    ConventionalFirst[GlobalIndex1, 0] = 0.0;
                }
                else
                {
                    ConventionalFirst[GlobalIndex1, 0] = Solution.first[GlobalIndex1][0] * Hotsun.sqdginv[GlobalIndex1][0];
                }

                for (int GlobalIndex2 = 0; GlobalIndex2 < Hotsun.npar; GlobalIndex2++)
                {
                    double MatrixElement = Matrix[GlobalIndex1, GlobalIndex2][0, 0];
                    if (Hotsun.UseDiagonalScaling)
                    {
                        MatrixElement *= Hotsun.sqdginv[GlobalIndex1][0] * Hotsun.sqdginv[GlobalIndex2][0];
                    }
                    if (GlobalIndex1 == GlobalIndex2)
                    {
                        if (Hotsun.AddMarquardtQDynamically)
                        {
                            MatrixElement += Hotsun.Q;
                        }
                    }
                    ConventionalMatrix[GlobalIndex1, GlobalIndex2] = MatrixElement;
                } // End GlobalIndex2
            }     // End GlobalIndex1

            // Form ConventionalMatrix-1 * ConventionalFirst

            LMatrix cMatrix       = LMatrix.Create(ConventionalMatrix);
            LMatrix RightHandSide = LMatrix.Create(ConventionalFirst);
            var     Fred          = new LU(cMatrix);
            LMatrix MatrixAnswer  = Fred.Solve(RightHandSide);

            ConventionalAnswer = MatrixAnswer;


            for (int GlobalIndex1 = 0; GlobalIndex1 < Hotsun.npar; GlobalIndex1++)
            {
                Answer[GlobalIndex1][0] = ConventionalAnswer[GlobalIndex1][0] * Hotsun.sqdginv[GlobalIndex1][0];
            }
            bool success = true;

            return(success);
        }
Exemplo n.º 5
0
        // Frequency, in iterations, with which to write out MDS coordinates.

        public static void SetupManxcat()
        {
            //  Set Hotsun Input parameters
            maxit  = ManxcatCentral.Configuration.Maxit;
            nbadgo = ManxcatCentral.Configuration.Nbadgo;
            ChisqChangePerPoint = ManxcatCentral.Configuration.ChisqChangePerPoint;
            rho                        = ManxcatCentral.Configuration.FletcherRho;
            Omega                      = ManxcatCentral.Configuration.Omega;
            OmegaOption                = ManxcatCentral.Configuration.OmegaOption;
            sigma                      = ManxcatCentral.Configuration.FletcherSigma;
            QHighInitialFactor         = ManxcatCentral.Configuration.QHighInitialFactor;
            QgoodReductionFactor       = ManxcatCentral.Configuration.QgoodReductionFactor;
            QLimitscalculationInterval = ManxcatCentral.Configuration.QLimitscalculationInterval;
            InitialSteepestDescents    = ManxcatCentral.Configuration.InitialSteepestDescents;
            timmax                     = ManxcatCentral.Configuration.TimeCutmillisec;
            CGResidualLimit            = ManxcatCentral.Configuration.CGResidualLimit;
            PowerIterationLimit        = ManxcatCentral.Configuration.PowerIterationLimit;
            eigenvaluechange           = ManxcatCentral.Configuration.Eigenvaluechange;
            eigenvectorchange          = ManxcatCentral.Configuration.Eigenvectorchange;
            extraprecision             = ManxcatCentral.Configuration.Extraprecision;
            addonforQcomputation       = ManxcatCentral.Configuration.AddonforQcomputation;
            derivtest                  = ManxcatCentral.Configuration.Derivtest;
            dellim                     = ChisqChangePerPoint; // Set dellim for current size problem (original Manxcat didn't do this)
            CoordinateWriteFrequency   = ManxcatCentral.Configuration.CoordinateWriteFrequency;

            //  Parameters for Loop over Choices

            int NumberofPoints = Number_VectorParameters;

            InitializationLoops = ManxcatCentral.Configuration.InitializationLoops;
            InitLoopChisq       = new double[InitializationLoops];

            diag                 = new double[NumberofPoints][];
            sqdginv              = new double[NumberofPoints][];
            GlobalParameter      = new double[NumberofPoints][];
            UtilityGlobalVector1 = new double[NumberofPoints][];
            FixedParameter       = new bool[NumberofPoints][];

            for (int LongIndex = 0; LongIndex < NumberofPoints; LongIndex++)
            {
                diag[LongIndex]    = new double[ParameterVectorDimension];
                sqdginv[LongIndex] = new double[ParameterVectorDimension];
                ;
                GlobalParameter[LongIndex]      = new double[ParameterVectorDimension];
                UtilityGlobalVector1[LongIndex] = new double[ParameterVectorDimension];
                FixedParameter[LongIndex]       = new bool[ParameterVectorDimension];

                for (int LocalVectorIndex = 0; LocalVectorIndex < ParameterVectorDimension; LocalVectorIndex++)
                {
                    FixedParameter[LongIndex][LocalVectorIndex] = false;
                }
            }

            int LocalNumberofPoints = Number_VectorParameters;

            if (DecomposeParameters)
            {
                LocalNumberofPoints = SALSAUtility.PointCount_Process;
            }

            perr = new double[LocalNumberofPoints][];
            UtilityLocalVector1 = new double[LocalNumberofPoints][];
            UtilityLocalVector2 = new double[LocalNumberofPoints][];

            for (int LongIndex = 0; LongIndex < LocalNumberofPoints; LongIndex++)
            {
                perr[LongIndex] = new double[ParameterVectorDimension];
                UtilityLocalVector1[LongIndex] = new double[ParameterVectorDimension];
                UtilityLocalVector2[LongIndex] = new double[ParameterVectorDimension];
            }

            CurrentSolution    = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            BestSolution       = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            PreviousSolution   = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            BestLoopedSolution = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            SearchSolution1    = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            SearchSolution2    = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            SearchSolution3    = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
            SearchSolution4    = new Desertwind(LocalNumberofPoints, ParameterVectorDimension);
        }