コード例 #1
0
        /// <summary>
        /// Initialization assumptions: LambdaA and LambdaB are 1. ie, both bases are evolving at the average rate.
        /// P_A = (1-P_B) = empiricalLeafMargin. Note however that the empiricalLeafMargin is measured for base a; base B could be entirely different.
        /// However, we need to keep the interface the same as for the other DiscreteDistributions, so it's not clear how to pass that information
        /// in. For now we assume symmetry.
        /// </summary>
        public override OptimizationParameterList GetParameters(bool useConditionalParameter)
        {
            //Random random = new Random();
            //double pAB = rand.NextDouble();
            //double pAb = (1 - pAB) * rand.NextDouble();
            //double paB = (1 - pAB - pAb) * rand.NextDouble();
            //double lA = 3000 * rand.NextDouble();
            //double lB = 3000 * rand.NextDouble();

            double pAB = InitialParamVals == null ? EmpiricalEquilibrium / 2 : InitialParamVals[(int)ParameterIndex.P_AB].Value;
            double pAb = InitialParamVals == null ? EmpiricalEquilibrium / 2 : InitialParamVals[(int)ParameterIndex.P_Ab].Value;
            double paB = InitialParamVals == null ? (1 - EmpiricalEquilibrium) / 2 : InitialParamVals[(int)ParameterIndex.P_aB].Value;
            double lA  = InitialParamVals == null ? 1 : InitialParamVals[(int)ParameterIndex.Lambda_A].Value;
            double lB  = InitialParamVals == null ? 1 : InitialParamVals[(int)ParameterIndex.Lambda_B].Value;

            OptimizationParameterList optList = OptimizationParameterList.GetInstance();

            optList.Add((int)ParameterIndex.P_AB, OptimizationParameter.GetProbabilityInstance("P_TT", pAB, true));
            optList.Add((int)ParameterIndex.P_Ab, OptimizationParameter.GetProbabilityInstance("P_TF", pAb, true));
            optList.Add((int)ParameterIndex.P_aB, OptimizationParameter.GetProbabilityInstance("P_FT", paB, true));
            optList.Add((int)ParameterIndex.Lambda_A, OptimizationParameter.GetPositiveFactorInstance("Lambda_A", lA, true));
            optList.Add((int)ParameterIndex.Lambda_B, OptimizationParameter.GetPositiveFactorInstance("Lambda_B", lB, true));

            optList.SetCheckConditions(CheckParameterConstraints);
            return(optList);
        }
コード例 #2
0
        protected virtual OptimizationParameterList GetParameters(bool useConditionalParameter, bool zeroVariance)
        {
            // ignore the initial parameter settings.

            OptimizationParameterList paramStart = OptimizationParameterList.GetInstance(
                OptimizationParameter.GetPositiveFactorInstance("Alpha", 1, true),
                //OptimizationParameter.GetProbabilityInstance("Alpha", .5, true),
                OptimizationParameter.GetPositiveFactorInstance("Variance", 10000, true),
                //OptimizationParameter.GetPositiveFactorInstance("AlphaVariance", 10000, true),
                OptimizationParameter.GetTanInstance("Delta", 0, useConditionalParameter, -1000, 1000),
                OptimizationParameter.GetTanInstance("Mean", 0, true, -1000, 1000),
                zeroVariance ? OptimizationParameter.GetPositiveFactorInstance("vNoise", 0, false)
                             : OptimizationParameter.GetPositiveFactorInstance("vNoise", 75, true)
                );

            //TEMPORARY TESTING!!!!!!!
            //paramStart["Alpha"].Value = 0.165267457;
            //paramStart["AlphaVariance"].Value = 6952.429217;
            //paramStart["Delta"].Value = -23.71002634;
            //paramStart["Delta"].DoSearch = true;
            paramStart["Mean"].Value     = 24.71176471;
            paramStart["Variance"].Value = 35.224;
            //paramStart["vNoise"].Value = 35.4194535;

            return(paramStart);
        }
コード例 #3
0
        private static void ComputeIidScores(int[] fisherCounts, out List <Score> nullScores, out Score altScore)
        {
            int tt  = fisherCounts[(int)TwoByTwo.ParameterIndex.TT];
            int tf  = fisherCounts[(int)TwoByTwo.ParameterIndex.TF];
            int ft  = fisherCounts[(int)TwoByTwo.ParameterIndex.FT];
            int ff  = fisherCounts[(int)TwoByTwo.ParameterIndex.FF];
            int sum = SpecialFunctions.Sum(fisherCounts);

            double pi0 = (double)(tt + tf) / sum;
            double pi1 = (double)(tt + ft) / sum;
            double ptt = (double)tt / sum;
            double ptf = (double)tf / sum;
            double pft = (double)ft / sum;
            double pff = (double)ff / sum;

            OptimizationParameterList nullParamsLeft = OptimizationParameterList.GetInstance(
                OptimizationParameter.GetProbabilityInstance("Pi", pi0, true));
            OptimizationParameterList nullParamsRight = OptimizationParameterList.GetInstance(
                OptimizationParameter.GetProbabilityInstance("Pi", pi1, true));

            OptimizationParameterList altParams = OptimizationParameterList.GetInstance(
                OptimizationParameter.GetProbabilityInstance("P_TT", ptt, true),
                OptimizationParameter.GetProbabilityInstance("P_TF", ptf, true),
                OptimizationParameter.GetProbabilityInstance("P_FT", pft, true));

            ComputeIidScoresGivenParams(fisherCounts, nullParamsLeft, nullParamsRight, altParams, out nullScores, out altScore);
        }
        //public override bool TryDeriveParametersFromFisherCounts(int[] fisherCounts, out OptimizationParameterList parameters)
        //{
        //    parameters = null;
        //    if (fisherCounts.Length != 4)
        //    {
        //        return false;
        //    }

        //    int tt = fisherCounts[(int)TwoByTwo.ParameterIndex.TT];
        //    int tf = fisherCounts[(int)TwoByTwo.ParameterIndex.TF];
        //    int ft = fisherCounts[(int)TwoByTwo.ParameterIndex.FT];
        //    int ff = fisherCounts[(int)TwoByTwo.ParameterIndex.FF];
        //    int total = tt+tf+ft+ff;

        //    double predP = (double)(tt + tf) / total;
        //    double targP = (double)(tt + ft) / total;

        //    if (Math.Max(predP, targP) != 1 && Math.Min(predP, targP) != 0)
        //    {
        //        return false;
        //    }

        //    parameters = GetParameters();
        //    if (targP == 0 || targP == 1)
        //    {
        //        parameters[(int)ParameterIndex.Equilibrium].Value = targP;
        //        parameters[(int)ParameterIndex.Lambda].Value = 0;
        //    }
        //}

        private OptimizationParameterList GetParameters(bool useConditionalParameter, double empericalEq, OptimizationParameterList initParams)
        {
            if (initParams != null)
            {
                OptimizationParameterList cloneList  = (OptimizationParameterList)initParams.Clone();
                OptimizationParameter     parameter1 = cloneList[(int)ParameterIndex.Predictor1];
                parameter1.DoSearch = useConditionalParameter || PredictorParametersInSequence;
                OptimizationParameter parameter2 = cloneList[(int)ParameterIndex.Predictor2];
                parameter2.DoSearch = useConditionalParameter && Use2PredictorParameters;
                if (!useConditionalParameter)
                {
                    if (!PredictorParametersInSequence)
                    {
                        parameter1.Value = 0.0;
                    }
                    parameter2.Value = 0.0;
                }
                return(cloneList);
            }
            else
            {
                OptimizationParameterList optList = OptimizationParameterList.GetInstance();

                optList.Add((int)ParameterIndex.Predictor1, OptimizationParameter.GetProbabilityInstance("selection_pressure", 0, useConditionalParameter || PredictorParametersInSequence));
                optList.Add((int)ParameterIndex.Predictor2, OptimizationParameter.GetProbabilityInstance("secondary_selection_pressure", 0, useConditionalParameter && Use2PredictorParameters));
                optList.Add((int)ParameterIndex.Lambda, OptimizationParameter.GetPositiveFactorInstance("lambda", 1, true));
                optList.Add((int)ParameterIndex.Equilibrium, OptimizationParameter.GetProbabilityInstance("pi", empericalEq, true));


                return(optList);
            }
        }
コード例 #5
0
        protected override OptimizationParameterList GetParameters(bool useConditionalParameter, bool zeroVariance)
        {
            OptimizationParameterList parameters = base.GetParameters(useConditionalParameter, zeroVariance);
            OptimizationParameter     alpha      = parameters["Alpha"];

            alpha.Value = 10000;
            //alpha.Value = double.PositiveInfinity;
            alpha.DoSearch = false;
            return(parameters);
        }
コード例 #6
0
        private IEnumerator <string> GetEnumerator(OptimizationParameter parameter)
        {
            var stepParameter = parameter as OptimizationStepParameter;

            if (stepParameter == null)
            {
                throw new InvalidOperationException("");
            }

            return(new OptimizationStepParameterEnumerator(stepParameter));
        }
コード例 #7
0
        public OptimizationParameterList CloneWithNewValuesForSearch(List <double> point)
        {
            List <OptimizationParameter> parameterCollection = new List <OptimizationParameter>();

            for (int iParam = 0; iParam < Count; ++iParam)
            {
                OptimizationParameter clone = AsParameterArray[iParam].Clone();
                clone.ValueForSearch = point[iParam];
                parameterCollection.Add(clone);
            }
            return(GetInstance2(parameterCollection));
        }
コード例 #8
0
        public override OptimizationParameterList GetParameters(int[] fisherCounts, OptimizationParameterList initParams)
        {
            double pAB, pAb, paB, lA, lB;

            if (initParams != null)
            {
                pAB = initParams[(int)ParameterIndex.P_AB].Value;
                pAb = initParams[(int)ParameterIndex.P_Ab].Value;
                paB = initParams[(int)ParameterIndex.P_aB].Value;
                lA  = initParams[(int)ParameterIndex.Lambda_A].Value;
                lB  = initParams[(int)ParameterIndex.Lambda_B].Value;
            }
            else if (fisherCounts.Length == 4)
            {
                double sum = (double)SpecialFunctions.Sum(fisherCounts);
                lA  = lB = 1;
                pAB = fisherCounts[(int)TwoByTwo.ParameterIndex.TT];
                pAb = fisherCounts[(int)TwoByTwo.ParameterIndex.TF];
                paB = fisherCounts[(int)TwoByTwo.ParameterIndex.FT];
            }
            else if (fisherCounts.Length == 2) // primarily for backward compatability testing
            {
                double empiricalEquilibrium = (double)fisherCounts[(int)DistributionDiscreteConditional.DistributionClass.True] / (fisherCounts[0] + fisherCounts[1]);
                lA  = lB = 1;
                pAB = empiricalEquilibrium / 2;
                pAb = empiricalEquilibrium / 2;
                paB = (1 - empiricalEquilibrium) / 2;
            }
            else
            {
                throw new ArgumentException("Cannot parse fisher counts of length " + fisherCounts.Length);
            }


            //double pAB = initParams == null ? empiricalEquilibrium / 2 : initParams[(int)ParameterIndex.P_AB].Value;
            //double pAb = initParams == null ? empiricalEquilibrium / 2 : initParams[(int)ParameterIndex.P_Ab].Value;
            //double paB = initParams == null ? (1 - empiricalEquilibrium) / 2 : initParams[(int)ParameterIndex.P_aB].Value;
            //double lA = initParams == null ? 1 : initParams[(int)ParameterIndex.Lambda_A].Value;
            //double lB = initParams == null ? 1 : initParams[(int)ParameterIndex.Lambda_B].Value;

            OptimizationParameterList optList = OptimizationParameterList.GetInstance();

            optList.Add((int)ParameterIndex.P_AB, OptimizationParameter.GetProbabilityInstance("P_TT", pAB, true));
            optList.Add((int)ParameterIndex.P_Ab, OptimizationParameter.GetProbabilityInstance("P_TF", pAb, true));
            optList.Add((int)ParameterIndex.P_aB, OptimizationParameter.GetProbabilityInstance("P_FT", paB, true));
            optList.Add((int)ParameterIndex.Lambda_A, OptimizationParameter.GetPositiveFactorInstance("Lambda_A", lA, true));
            optList.Add((int)ParameterIndex.Lambda_B, OptimizationParameter.GetPositiveFactorInstance("Lambda_B", lB, true));

            optList.SetCheckConditions(CheckParameterConstraints);
            return(optList);
        }
コード例 #9
0
        /// <summary>
        /// Calculates number od data points for step based optimization parameter based on min/max and step values
        /// </summary>
        private int Estimate(OptimizationParameter parameter)
        {
            var stepParameter = parameter as OptimizationStepParameter;

            if (stepParameter == null)
            {
                throw new InvalidOperationException($"Cannot estimate parameter of type {parameter.GetType().FullName}");
            }

            if (!stepParameter.Step.HasValue)
            {
                throw new InvalidOperationException("Optimization parameter cannot be estimated due to step value is not initialized");
            }

            return((int)Math.Floor((stepParameter.MaxValue - stepParameter.MinValue) / stepParameter.Step.Value) + 1);
        }
        public override OptimizationParameterList GetParameters(bool useConditionalParameter, bool zeroVariance)
        {
            // alpha is confounded with variance in this case, so we fix it at 1.
            OptimizationParameterList parameters = base.GetParameters(useConditionalParameter, zeroVariance);
            OptimizationParameter     alphaParam = parameters["Alpha"];

            alphaParam.ConvertToPositiveFactorInstance();
            alphaParam.Value = 1.0;
            //alphaParam.Value = 1.0;
            //alphaParam.DoSearch = false;

            // TEMPORARY!!!!
            //parameters["Mean"].Value = 10.13;
            //parameters["AlphaVariance"].Value = 2.18 * 2.18;
            return(parameters);
        }
コード例 #11
0
        //private static OptimizationParameterList CreateQmrrParamsX(double causePrior, double leakProbability, Set<string> candidateHlaSet)
        //{
        //    List<Parameter> parameterCollection = new List<Parameter>();
        //    parameterCollection.Add(Parameter.GetProbabilityInstance("causePrior", causePrior, false));
        //    foreach (string hla in candidateHlaSet)
        //    {
        //        if (hla == "B1599")
        //        {
        //            Parameter aParameter = Parameter.GetProbabilityInstance("link" + hla, 0, false);
        //            parameterCollection.Add(aParameter);
        //        }
        //        else
        //        {
        //            Parameter aParameter = Parameter.GetProbabilityInstance("link" + hla, .5, true);
        //            parameterCollection.Add(aParameter);
        //        }
        //    }
        //    parameterCollection.Add(Parameter.GetProbabilityInstance("leakProbability", leakProbability, false));
        //    parameterCollection.Add(Parameter.GetPositiveFactorInstance("useKnownList", 1, false));
        //    OptimizationParameterList qmrrParamsStart = OptimizationParameterList.GetInstance2(parameterCollection);
        //    return qmrrParamsStart;
        //}



        //private static Dictionary<string, string> LoadOriginalParameters(string directory)
        //{
        //    string parameterFileName = string.Format(@"{0}\{1}", directory, "NoisyOr.Parameters.TwoCause.UseKnown.txt");//!!!const
        //    string header = "dataset	varyFitFactor	score	causePrior	fitFactor	leakProbability	link	useKnownList";
        //    foreach (Dictionary<string, string> row in SpecialFunctions.TabFileTable(parameterFileName, header, false))
        //    {
        //        bool varyFitFactor = bool.Parse(row["varyFitFactor"]);
        //        if (!varyFitFactor)
        //        {
        //            return row;
        //        }
        //    }
        //    Debug.Fail("Didn't find expected line");
        //    return null;
        //}



        //static Dictionary<string, Set<string>> LoadOriginalPeptideToHlaSet(string directory)
        //{
        //    string fileName = string.Format(@"{0}\{1}", directory, @"NoisyOr.HlasPerPeptide.hivmodel.TwoCauseFalse.UseKnownTrue.txt");


        //    Dictionary<string, Set<string>> originalPeptideToHlaSet = new Dictionary<string, Set<string>>();
        //    string header = "Peptide	HLAAssignment	LogLikelihood";
        //    foreach (Dictionary<string, string> row in SpecialFunctions.TabFileTable(fileName, header, false))
        //    {
        //        string peptide = row["Peptide"];
        //        Set<string> hlaSet = Set<string>.GetInstance(row["HLAAssignment"].Split(';'));
        //        originalPeptideToHlaSet.Add(peptide, hlaSet);
        //    }
        //    return originalPeptideToHlaSet;
        //}

        public static QmrrModelAllPeptides CreateSimpleModel(string directory, string casename, bool useKnownList)
        {
            OptimizationParameterList qmrrParamsStart = OptimizationParameterList.GetInstance(
                OptimizationParameter.GetProbabilityInstance("causePrior", .01, true),
                OptimizationParameter.GetProbabilityInstance("link", .5, true),
                OptimizationParameter.GetProbabilityInstance("leakProbability", .003, true),
                OptimizationParameter.GetPositiveFactorInstance("useKnownList", useKnownList ? 1 : 0, false)
                );


            ModelLikelihoodFactories modelLikelihoodFactories = ModelLikelihoodFactories.GetInstanceThreeParamSlow(qmrrParamsStart);

            double depth   = 1.5;
            string dataset = string.Format(@"{0}\{1}", directory, casename);
            QmrrModelAllPeptides qmrrModel = QmrrModelAllPeptides.GetInstance(modelLikelihoodFactories, dataset, qmrrParamsStart, depth, "noConstraints");

            return(qmrrModel);
        }
コード例 #12
0
        private IEnumerator <string> GetEnumerator(OptimizationParameter parameter)
        {
            var staticOptimizationParameter = parameter as StaticOptimizationParameter;

            if (staticOptimizationParameter != null)
            {
                return(new List <string> {
                    staticOptimizationParameter.Value
                }.GetEnumerator());
            }

            var stepParameter = parameter as OptimizationStepParameter;

            if (stepParameter == null)
            {
                throw new InvalidOperationException("");
            }

            return(new OptimizationStepParameterEnumerator(stepParameter));
        }
コード例 #13
0
        /// <summary>
        /// Initialization assumptions: LambdaA and LambdaB are 1. ie, both bases are evolving at the average rate.
        /// P_A = (1-P_B) = empiricalLeafMargin. Note however that the empiricalLeafMargin is measured for base a; base B could be entirely different.
        /// However, we need to keep the interface the same as for the other DiscreteDistributions, so it's not clear how to pass that information
        /// in. For now we assume symmetry.
        /// </summary>
        public override OptimizationParameterList GetParameters(bool useConditionalParameter)
        {
            double pHLA    = InitialParamVals == null ? 0.1 : InitialParamVals[(int)ParameterIndex.P_Hla].Value;
            double pAA     = InitialParamVals == null ? EmpiricalEquilibrium : InitialParamVals[(int)ParameterIndex.P_AA].Value;
            double lAA     = InitialParamVals == null ? 1 : InitialParamVals[(int)ParameterIndex.ETimesLambaA].Value;
            double lHLA    = InitialParamVals == null ? 1 : InitialParamVals[(int)ParameterIndex.Lambda_Hla].Value;
            double erRatio = InitialParamVals == null ? 0 : InitialParamVals[(int)ParameterIndex.RTimesLambdaA].Value;
            //double r = InitialParamVals == null ? 0 : InitialParamVals[(int)ParameterIndex.P_r].Value;

            OptimizationParameterList optList = OptimizationParameterList.GetInstance();

            optList.Add((int)ParameterIndex.P_AA, OptimizationParameter.GetProbabilityInstance("P_AA", pAA, true));
            optList.Add((int)ParameterIndex.P_Hla, OptimizationParameter.GetProbabilityInstance("P_Hla", pHLA, true));
            optList.Add((int)ParameterIndex.ETimesLambaA, OptimizationParameter.GetPositiveFactorInstance("Lambda_AA", lAA, true));
            optList.Add((int)ParameterIndex.Lambda_Hla, OptimizationParameter.GetPositiveFactorInstance("Lambda_Hla", lHLA, true));
            optList.Add((int)ParameterIndex.RTimesLambdaA, OptimizationParameter.GetPositiveFactorInstance("E_R_Ratio", erRatio, true));
            //optList.Add((int)ParameterIndex.ERLogRatio, OptimizationParameter.GetTanInstance("E_R_Ratio", erRatio, true, -10, 10));
            //optList.Add((int)ParameterIndex.P_r, OptimizationParameter.GetProbabilityInstance("r", r, true));  // DON'T LEARN R FOR NOW

            //optList.SetCheckConditions(CheckParameterConstraints);
            return(optList);
        }
コード例 #14
0
        public override OptimizationParameterList GetParameters(bool useConditionalParameter)
        {
            if (InitialParamVals != null)
            {
                OptimizationParameterList cloneList  = InitialParamVals.Clone();
                OptimizationParameter     parameter1 = cloneList[(int)ParameterIndex.Predictor1];
                parameter1.DoSearch = useConditionalParameter || PredictorParametersInSequence;
                OptimizationParameter parameter2 = cloneList[(int)ParameterIndex.Predictor2];
                parameter2.DoSearch = useConditionalParameter && Use2PredictorParameters;
                if (!useConditionalParameter)
                {
                    if (!PredictorParametersInSequence)
                    {
                        parameter1.Value = 0.0;
                    }
                    parameter2.Value = 0.0;
                }
                return(cloneList);
            }

            //double initLambda = InitialParamVals == null ? 1 : InitialParamVals[(int)ParameterIndex.Lambda].Value;
            //double initParam = InitialParamVals == null ? 0 : InitialParamVals[(int)ParameterIndex.Predictor].Value;
            //double initEmp = InitialParamVals == null ? EmpiricalEquilibrium : InitialParamVals[(int)ParameterIndex.Equilibrium].Value;

            OptimizationParameterList optList = OptimizationParameterList.GetInstance();

            //optList.Add((int)ParameterIndex.Predictor, OptimizationParameter.GetProbabilityInstance("parameter", initParam, useConditionalParameter));
            //optList.Add((int)ParameterIndex.Lambda, OptimizationParameter.GetPositiveFactorInstance("lambda", initLambda, true));
            //optList.Add((int)ParameterIndex.Equilibrium, OptimizationParameter.GetProbabilityInstance("x", initEmp, true));

            optList.Add((int)ParameterIndex.Predictor1, OptimizationParameter.GetProbabilityInstance("selection_pressure", 0, useConditionalParameter || PredictorParametersInSequence));
            optList.Add((int)ParameterIndex.Predictor2, OptimizationParameter.GetProbabilityInstance("secondary_selection_pressure", 0, useConditionalParameter && Use2PredictorParameters));
            optList.Add((int)ParameterIndex.Lambda, OptimizationParameter.GetPositiveFactorInstance("lambda", 1, true));
            optList.Add((int)ParameterIndex.Equilibrium, OptimizationParameter.GetProbabilityInstance("pi", EmpiricalEquilibrium, true));


            return(optList);
        }
コード例 #15
0
        protected OptimizationParameterList CreateQmrrParamsStartForTheseCandidateHlas(Set <Hla> trueHlaSet, Set <Hla> hlaWithLinkZero)
        {
            List <OptimizationParameter> parameterCollection = new List <OptimizationParameter>();

            parameterCollection.Add(OptimizationParameter.GetProbabilityInstance("causePrior", .5, false));
            foreach (Hla hla in trueHlaSet)
            {
                bool fixAtZero = hlaWithLinkZero.Contains(hla);
                OptimizationParameter aParameter = OptimizationParameter.GetProbabilityInstance("link" + hla, fixAtZero ? 0 : .5, !fixAtZero);
                parameterCollection.Add(aParameter);
            }
            if (LeakProbabilityOrNull == null)
            {
                parameterCollection.Add(OptimizationParameter.GetProbabilityInstance("leakProbability", .01, true));
            }
            else
            {
                parameterCollection.Add(OptimizationParameter.GetProbabilityInstance("leakProbability", (double)LeakProbabilityOrNull, false));
            }
            parameterCollection.Add(OptimizationParameter.GetPositiveFactorInstance("useKnownList", 1, false));
            OptimizationParameterList qmrrParamsStart = OptimizationParameterList.GetInstance2(parameterCollection);

            return(qmrrParamsStart);
        }
コード例 #16
0
 private bool Close(OptimizationParameter myValue, OptimizationParameter otherValue, double eps)
 {
     return(Math.Abs(myValue.Value - otherValue.Value) < eps);
 }
コード例 #17
0
        public override OptimizationParameterList GetParameters(int[] fisherCounts, OptimizationParameterList initParams)
        {
            double pHLA;
            double pAA;
            double lAA;
            double lHLA;
            double erRatio;

            if (initParams != null)
            {
                pHLA    = initParams[(int)ParameterIndex.P_Hla].Value;
                pAA     = initParams[(int)ParameterIndex.P_AA].Value;
                lAA     = initParams[(int)ParameterIndex.ETimesLambaA].Value;
                lHLA    = initParams[(int)ParameterIndex.Lambda_Hla].Value;
                erRatio = initParams[(int)ParameterIndex.RTimesLambdaA].Value;
            }
            else if (fisherCounts.Length == 4)
            {
                double sum = (double)SpecialFunctions.Sum(fisherCounts);

                int tt = (int)TwoByTwo.ParameterIndex.TT;
                int tf = (int)TwoByTwo.ParameterIndex.TF;
                int ft = (int)TwoByTwo.ParameterIndex.FT;

                lAA     = lHLA = 1;
                erRatio = 0;
                pHLA    = (fisherCounts[tt] + fisherCounts[tf]) / sum;
                pAA     = (fisherCounts[tt] + fisherCounts[ft]) / sum;
            }
            else if (fisherCounts.Length == 2)  // primarily for backward compatability testing
            {
                double empiricalEquilibrium = (double)fisherCounts[(int)DistributionDiscreteConditional.DistributionClass.True] / (fisherCounts[0] + fisherCounts[1]);
                lAA     = lHLA = 1;
                erRatio = 0;
                pHLA    = 0.1;
                pAA     = empiricalEquilibrium;
            }
            else
            {
                throw new ArgumentException("Cannot parse fisher counts of length " + fisherCounts.Length);
            }


            //double pHLA = initParams == null ? 0.1 : initParams[(int)ParameterIndex.P_Hla].Value;
            //double pAA = initParams == null ? empiricalEquilibrium : initParams[(int)ParameterIndex.P_AA].Value;
            //double lAA = initParams == null ? 1 : initParams[(int)ParameterIndex.ETimesLambaA].Value;
            //double lHLA = initParams == null ? 1 : initParams[(int)ParameterIndex.Lambda_Hla].Value;
            //double erRatio = initParams == null ? 0 : initParams[(int)ParameterIndex.RTimesLambdaA].Value;
            //double r = InitialParamVals == null ? 0 : InitialParamVals[(int)ParameterIndex.P_r].Value;

            OptimizationParameterList optList = OptimizationParameterList.GetInstance();

            optList.Add((int)ParameterIndex.P_AA, OptimizationParameter.GetProbabilityInstance("P_AA", pAA, true));
            optList.Add((int)ParameterIndex.P_Hla, OptimizationParameter.GetProbabilityInstance("P_Hla", pHLA, true));
            optList.Add((int)ParameterIndex.ETimesLambaA, OptimizationParameter.GetPositiveFactorInstance("Lambda_AA", lAA, true));
            optList.Add((int)ParameterIndex.Lambda_Hla, OptimizationParameter.GetPositiveFactorInstance("Lambda_Hla", lHLA, true));
            optList.Add((int)ParameterIndex.RTimesLambdaA, OptimizationParameter.GetPositiveFactorInstance("E_R_Ratio", erRatio, true));
            //optList.Add((int)ParameterIndex.ERLogRatio, OptimizationParameter.GetTanInstance("E_R_Ratio", erRatio, true, -10, 10));
            //optList.Add((int)ParameterIndex.P_r, OptimizationParameter.GetProbabilityInstance("r", r, true));  // DON'T LEARN R FOR NOW

            //optList.SetCheckConditions(CheckParameterConstraints);
            return(optList);
        }
コード例 #18
0
 public void NotIEnumerable(OptimizationParameter optimizationParameter)
 {
     Assert.IsNotInstanceOf <IEnumerable <string> >(optimizationParameter);
 }