Example #1
0
        public virtual void UpdateProfile()
        {
            double[] parameters  = null;
            double[] eparameters = null;

            MakeParameters(ref eparameters, true);

            InfoStruct = new BoxModelSettings();
            SetInitStruct(ref InfoStruct, null);

            NativeMethods.RhoGenerate(InfoStruct, eparameters, eparameters.Length, _ElectronDensityArray, _BoxElectronDensityArray);

            if (_ReflectivityMap != null)
            {
                MakeParameters(ref parameters, false);
                NativeMethods.FastReflGenerate(InfoStruct, parameters, parameters.Length, _ReflectivityMap);
            }

            InfoStruct.Dispose();

            if (Update != null)
            {
                Update(this, null);
            }
        }
Example #2
0
        public override string DataFit()
        {
            BackupArrays();
            double[] parameters = null;
            int      arrayconst;

            MakeParameters(ref parameters, true);

            m_dCovarArray = new double[parameters.Length];

            InfoStruct = new BoxModelSettings();
            SetInitStruct(ref InfoStruct, null);

            NativeMethods.Rhofit(InfoStruct, parameters, m_dCovarArray, parameters.Length, _fitinfo);

            InfoStruct.Dispose();

            SubRoughTB = parameters[0];
            ZOffsetTB  = parameters[1];

            if (HoldsigmaCB)
            {
                arrayconst = 2;
            }
            else
            {
                arrayconst = 3;
            }

            //Update paramters
            for (int i = 0; i < BoxCountTB; i++)
            {
                LengthArray[i] = parameters[arrayconst * i + 2];

                if (!m_bUseSLD)
                {
                    RhoArray[i] = parameters[arrayconst * i + 3];
                }
                else
                {
                    RhoArray[i] = parameters[arrayconst * i + 3] * SubphaseSLDTB;
                }

                if (HoldsigmaCB)
                {
                    SigmaArray[i] = parameters[0];
                }
                else
                {
                    SigmaArray[i] = parameters[3 * i + 4];
                }
            }

            //Display the fit
            UpdateProfile();


            return(MakeChiSquare());
        }
Example #3
0
        protected virtual void SetInitStruct(ref BoxModelSettings InitStruct, double[] parampercs)
        {
            if (InitStruct.Q == IntPtr.Zero)
            {
                InitStruct.SetArrays(ReflData.Instance.GetQData, ReflData.Instance.GetReflData, ReflData.Instance.GetRErrors,
                                     ReflData.Instance.GetQErrors, parampercs, UL, LL);
            }

            InitStruct.Directory = ReflData.Instance.GetWorkingDirectory;
            InitStruct.Boxes     = BoxCountTB;

            InitStruct.SubSLD = SubphaseSLDTB;
            InitStruct.SupSLD = SuperSLDTB;

            if (WavelengthTB != 0)
            {
                InitStruct.Wavelength = WavelengthTB;
            }

            InitStruct.OneSigma = HoldsigmaCB;

            if (_QSpreadTB != 0)
            {
                InitStruct.QSpread = _QSpreadTB;
            }

            if (_ImpNormCB)
            {
                InitStruct.ImpNorm = _ImpNormCB;
            }

            if (_Z != null)
            {
                MakeZ(false);
                InitStruct.SetZ(_Z, RealRho);
            }

            InitStruct.WriteFiles  = true;
            InitStruct.HighQOffset = HighQOffset;
            InitStruct.LowQOffset  = LowQOffset;
        }
Example #4
0
        public override string DataFit()
        {
            BackupArrays();
            double[] parameters = null;

            MakeParameters(ref parameters, false);

            m_dCovarArray = new double[parameters.Length];

            InfoStruct = new BoxModelSettings();
            SetInitStruct(ref InfoStruct, null);


            NativeMethods.FastReflfit(InfoStruct, parameters, m_dCovarArray, parameters.Length, _fitinfo);

            InfoStruct.Dispose();

            UpdatefromParameterArray(parameters);
            UpdateFit(parameters);


            return(MakeChiSquare());
        }
Example #5
0
        public override string StochFit(double[] parampercs, int iterations)
        {
            double[] parameters      = null;
            string   chosenchisquare = string.Empty;


            MakeParameters(ref parameters, false);

            double[] ParamArray     = new double[1000 * parameters.Length];
            double[] ChiSquareArray = new double[1000];
            double[] CovarArray     = new double[1000 * parameters.Length];
            double[] locinfo        = new double[9 * 1000];
            int      Size           = 0;


            InfoStruct = new BoxModelSettings();
            SetInitStruct(ref InfoStruct, parampercs);
            InfoStruct.Iterations = iterations;


            NativeMethods.ConstrainedStochFit(InfoStruct, parameters, CovarArray, parameters.Length, locinfo, ParamArray, ChiSquareArray, ref Size);

            //Not ideal, will always back up regardless of whether the new model is accepted or not
            BackupArrays();

            if (ModelChooser != null)
            {
                if (ModelChooser(ParamArray, ChiSquareArray, CovarArray, locinfo, Size, parameters.Length, InfoStruct))
                {
                }
            }

            UpdateProfile();
            InfoStruct.Dispose();
            return(ChiSquare.ToString("##.### E-0"));
        }
Example #6
0
 internal static extern void ConstrainedStochFit([MarshalAs(UnmanagedType.LPStruct)] BoxModelSettings InitStruct, double[] parameters, double[] covar, int paramsize, double[] info, double[] ParamArray, double[] chisquarearray, ref int paramarraysize);
Example #7
0
 internal static extern void Rhofit([MarshalAs(UnmanagedType.LPStruct)] BoxModelSettings InitStruct, double[] parameters, double[] covar, int covarsize, double[] info);
Example #8
0
 internal static extern void RhoGenerate([MarshalAs(UnmanagedType.LPStruct)] BoxModelSettings InitStruct, double[] parameters, int parametersize, double[] ED, double[] BoxED);
Example #9
0
 internal static extern void FastReflGenerate([MarshalAs(UnmanagedType.LPStruct)] BoxModelSettings InitStruct, double[] parameters, int parametersize, double[] ReflectivityMap);
        private bool ModelChooserUI(double[] ParamArray, double[] ChiSquareArray, double[] CovarArray, double[] info, int size, int paramcount, BoxModelSettings InfoStruct)
        {
            StochOutputWindow outwin = new StochOutputWindow(ParamArray, size, paramcount, ChiSquareArray, CovarArray, info, ReflCalc);


            if (outwin.ShowDialog() != DialogResult.Cancel)
            {
                outwin.GetParameters(ReflCalc);
                return(true);
            }
            else
            {
                return(false);
            }
        }