Exemple #1
0
        static public QmrrPartialModel GetInstance(ModelLikelihoodFactories modelLikelihoodFactories,
                                                   string peptide,
                                                   Dictionary <string, double> patientToAnyReaction,
                                                   Set <Hla> knownHlaSet,
                                                   Dictionary <string, Set <Hla> > patientList,
                                                   OptimizationParameterList qmrrParamsStart
                                                   )
        {
            QmrrPartialModel aQmrrPartialModel = new QmrrPartialModel();

            aQmrrPartialModel.QmrrParamsStart      = qmrrParamsStart;
            aQmrrPartialModel.Peptide              = peptide;
            aQmrrPartialModel.PatientToAnyReaction = patientToAnyReaction;
            aQmrrPartialModel.PatientList          = patientList;
            aQmrrPartialModel.KnownHlaSet          = knownHlaSet;
            aQmrrPartialModel.CreateHlaList();
            aQmrrPartialModel.CreateSwitchableHlasWithRespondingPatients();
            aQmrrPartialModel.ModelLikelihoodFactories = modelLikelihoodFactories;
            if (modelLikelihoodFactories != null)
            {
                aQmrrPartialModel.LogLikelihoodOfCompleteModelConditionedOnKnownHlas = modelLikelihoodFactories.PartialModelDelegateFactory(aQmrrPartialModel);
            }
            else
            {
                aQmrrPartialModel.LogLikelihoodOfCompleteModelConditionedOnKnownHlas = null;
            }
            return(aQmrrPartialModel);
        }
        private void ReportPerHla(OptimizationParameterList qmrrParams, Dictionary <string, BestSoFar <double, TrueCollection> > peptideToBestHlaAssignmentSoFar,
                                  string directory, string name)
        {
            string fileName = string.Format(@"{0}\NoisyOr.PeptideHlaProbability.{1}.new.txt", directory, name);

            using (StreamWriter output = File.CreateText(fileName))
            {
                output.WriteLine(SpecialFunctions.CreateTabString("Peptide", "HLA", "LogOdds", "Probability"));
                foreach (QmrrPartialModel qmrrPartialModel in QmrrPartialModelCollection)
                {
                    QmrrModelMissingAssignment         aQmrrModelMissingAssignment = QmrrModelMissingAssignment.GetInstance(ModelLikelihoodFactories, qmrrPartialModel, qmrrParams);
                    BestSoFar <double, TrueCollection> bestHlaAssignment           = peptideToBestHlaAssignmentSoFar[qmrrPartialModel.Peptide];
                    Set <Hla> trueCollectionFullAsSet = new Set <Hla>(bestHlaAssignment.Champ);

                    double loglikelihoodFull = bestHlaAssignment.ChampsScore;
                    foreach (Hla hla in trueCollectionFullAsSet)
                    {
                        bool known = qmrrPartialModel.KnownHlaSet.Contains(hla);
                        if (!known)
                        {
                            Set <Hla>      allLessOne            = trueCollectionFullAsSet.SubtractElement(hla);
                            TrueCollection trueCollectionWithout = TrueCollection.GetInstance(allLessOne);
                            double         loglikelihoodWithout  = aQmrrModelMissingAssignment.LogLikelihoodOfCompleteModelConditionedOnKnownHlas(trueCollectionWithout);
                            double         logOdds            = loglikelihoodFull - loglikelihoodWithout;
                            double         probabilityFull    = Math.Exp(loglikelihoodFull);
                            double         probabilityWithout = Math.Exp(loglikelihoodWithout);
                            double         probability        = probabilityFull / (probabilityFull + probabilityWithout);
                            Debug.Assert(logOdds >= 0); // real assert
                            output.WriteLine(SpecialFunctions.CreateTabString(qmrrPartialModel.Peptide, hla, logOdds, probability));
                        }
                    }
                }
            }
        }
        internal OptimizationParameterList FindBestParams(OptimizationParameterList qmrrParamsStart, out double logLikelihood)
        {
            OptimizationParameterList qmrrParamsEnd = qmrrParamsStart.Clone();

            logLikelihood = GridSearch.Optimize(ScoreParameterList, qmrrParamsEnd, 10, 10);
            return(qmrrParamsEnd);
        }
Exemple #4
0
        public static ModelLikelihoodFactories GetInstanceCoverage(OptimizationParameterList qmrrParamsStart, string dataset)
        {
            SpecialFunctions.CheckCondition(qmrrParamsStart.Count == 1);
            SpecialFunctions.CheckCondition(qmrrParamsStart.ContainsKey("useKnownList"));
            SpecialFunctions.CheckCondition(!qmrrParamsStart["useKnownList"].DoSearch);
            SpecialFunctions.CheckCondition(qmrrParamsStart["useKnownList"].Value == 0.0 || qmrrParamsStart["useKnownList"].Value == 1.0);

            Coverage aCoverage = new Coverage();

            return(aCoverage);
        }
        public double ScoreParameterList(OptimizationParameterList parameterList)
        {
            double sum = 0.0;

            foreach (QmrrlModelMissingParameters qmrrlModelMissingParameters in Collection)
            {
                double loglikelihood = qmrrlModelMissingParameters.LogLikelihoodOfCompleteModelConditionedOnKnownHlas(parameterList);
                sum += loglikelihood;
            }
            return(sum);
        }
Exemple #6
0
        internal void FindBestQmrrParams(QmrrPartialModelCollection qmrrPartialModelCollection)
        {
            SpecialFunctions.CheckCondition(false, "Regression test this to be sure that switch to new optimization method didn't change anything important - cmk 5/1/2006");

            QmrrlModelMissingParametersCollection aQmrrlModelMissingParametersCollection =
                QmrrlModelMissingParametersCollection.GetInstance(ModelLikelihoodFactories, qmrrPartialModelCollection, PeptideToBestHlaAssignmentSoFar);

            double score;
            OptimizationParameterList qmrrParamsEnd = aQmrrlModelMissingParametersCollection.FindBestParams(BestParamsSoFar.Champ, out score);

            BestParamsSoFar.Compare(score, qmrrParamsEnd);
        }
Exemple #7
0
        static public ModelLikelihoodFactories GetInstanceThreeParamSlow(OptimizationParameterList qmrrParams)
        {
            SpecialFunctions.CheckCondition(qmrrParams.Count == 4);
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("causePrior"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("link"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("leakProbability"));

            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("useKnownList"));
            SpecialFunctions.CheckCondition(!qmrrParams["useKnownList"].DoSearch);
            SpecialFunctions.CheckCondition(qmrrParams["useKnownList"].Value == 0.0 || qmrrParams["useKnownList"].Value == 1.0);


            ThreeParamSlow aThreeParamSlow = new ThreeParamSlow();

            return(aThreeParamSlow);
        }
Exemple #8
0
        static public ModelLikelihoodFactories GetInstanceTwoCausePriors(OptimizationParameterList qmrrParams, string dataset)
        {
            SpecialFunctions.CheckCondition(qmrrParams.Count == 5);
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("causePrior"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("fitFactor"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("link"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("leakProbability"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("useKnownList"));
            SpecialFunctions.CheckCondition(!qmrrParams["useKnownList"].DoSearch);
            SpecialFunctions.CheckCondition(qmrrParams["useKnownList"].Value == 0.0 || qmrrParams["useKnownList"].Value == 1.0);

            TwoCausePriors aTwoCausePriors = new TwoCausePriors();

            aTwoCausePriors.SetPeptideToFitUniverse(dataset);
            return(aTwoCausePriors);
        }
        static public double Optimize(FunctionToOptimizeDelegate functionToOptimize,
                                      ref List <double> point, List <double> low, List <double> high,
                                      OptimizationParameterList qmrrParamsStart, int numberOfIterationsOverParameters, double precision, int gridLineCount)
        {
            double eps = 1e-9;



            //Debug.WriteLine(qmrrParamsStart.ToStringHeader());

            double oldScore = double.NaN;

            //Debug.WriteLine(SpecialFunctions.CreateTabString("iterationOverParameters", "iParameter", "Probability", "LogOdds", "Score"));
            for (int iterationOverParameters = 0; iterationOverParameters < numberOfIterationsOverParameters; ++iterationOverParameters)
            {
                double newScore = double.NaN;
                int    doSearchParameterCount = 0;
                for (int iParameter = 0; iParameter < point.Count; ++iParameter)
                {
                    if (qmrrParamsStart.DoSearch(iParameter))
                    {
                        ++doSearchParameterCount;
                        List <double> pointClone = new List <double>(point);

                        BestSoFar <double, double> bestParamSoFar =
                            OneDOptimization(
                                delegate(double parameter) { pointClone[iParameter] = parameter; return(functionToOptimize(pointClone)); },
                                low[iParameter], high[iParameter], precision, gridLineCount);
                        point[iParameter] = bestParamSoFar.Champ;
                        //Debug.WriteLine(SpecialFunctions.CreateTabString(iterationOverParameters, iParameter, SpecialFunctions.Probability(bestParamSoFar.Champ), bestParamSoFar.Champ, bestParamSoFar.ChampsScore));
                        newScore = bestParamSoFar.ChampsScore;

                        //Debug.WriteLine("END ITER:" + SpecialFunctions.CreateTabString2(point) + SpecialFunctions.CreateTabString("", newScore));
                    }
                }
                if ((!double.IsNaN(oldScore) && Math.Abs(oldScore - newScore) < eps) ||
                    doSearchParameterCount < 2)    //If only 0 or 1 searchable params, then one pass is enough
                {
                    oldScore = newScore;
                    break;
                }
                oldScore = newScore;
            }
            return(oldScore);
        }
        public bool Close(OptimizationParameterList other, double eps)
        {
            if (other == null)
            {
                return(false);
            }

            SpecialFunctions.CheckCondition(other.Count == Count);

            for (int iParam = 0; iParam < Count; ++iParam)
            {
                if (!Close(AsParameterArray[iParam], other.AsParameterArray[iParam], eps))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #11
0
        internal static ModelLikelihoodFactories GetInstanceLinkPerHla(OptimizationParameterList qmrrParams, Set <Hla> candidateHlaSet)
        {
            SpecialFunctions.CheckCondition(qmrrParams.Count == 3 + candidateHlaSet.Count);
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("causePrior"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("leakProbability"));
            SpecialFunctions.CheckCondition(qmrrParams.ContainsKey("useKnownList"));
            SpecialFunctions.CheckCondition(!qmrrParams["useKnownList"].DoSearch);
            SpecialFunctions.CheckCondition(qmrrParams["useKnownList"].Value == 1.0);
            foreach (Hla hla in candidateHlaSet)
            {
                string paramName = "link" + hla.ToString();
                SpecialFunctions.CheckCondition(qmrrParams.ContainsKey(paramName));
            }

            LinkPerHla aLinkPerHla = new LinkPerHla();

            return(aLinkPerHla);
        }
        public static OptimizationParameterList GetInstance2(IEnumerable <OptimizationParameter> parameterCollection)
        {
            OptimizationParameterList aQmrrParams = new OptimizationParameterList();

            aQmrrParams.AsSortedDictionary = new SortedDictionary <string, OptimizationParameter>();
            foreach (OptimizationParameter parameter in parameterCollection)
            {
                aQmrrParams.AsSortedDictionary.Add(parameter.Name, parameter);
            }

            //Must do this after because the parameters may get re-ordered.
            aQmrrParams.AsParameterArray = new OptimizationParameter[aQmrrParams.AsSortedDictionary.Count];
            int iParam = -1;

            foreach (OptimizationParameter parameter in aQmrrParams.AsSortedDictionary.Values)
            {
                ++iParam;
                aQmrrParams.AsParameterArray[iParam] = parameter;
            }
            return(aQmrrParams);
        }
Exemple #13
0
        public static QmrrPartialModelCollection GetInstance(string peptide,
                                                             ModelLikelihoodFactories modelLikelihoodFactories,
                                                             OptimizationParameterList qmrrParamsStart,
                                                             Dictionary <string, Set <Hla> > patientList,
                                                             Dictionary <string, Dictionary <string, double> > reactTable,
                                                             Dictionary <string, Set <Hla> > knownTable,
                                                             string hlaFactoryName
                                                             )
        {
            QmrrPartialModelCollection aQmrrPartialModelCollection = new QmrrPartialModelCollection();

            aQmrrPartialModelCollection.HlaFactory = Qmrr.HlaFactory.GetFactory(hlaFactoryName);
            aQmrrPartialModelCollection.OptimizationParameterList = qmrrParamsStart;
            aQmrrPartialModelCollection.SetFileNamesToNull();
            aQmrrPartialModelCollection.PeptideList = new List <string>(new string[] { peptide });
            aQmrrPartialModelCollection.PatientList = patientList;
            aQmrrPartialModelCollection.ReactTable  = reactTable;
            aQmrrPartialModelCollection._knownTable = knownTable;
            aQmrrPartialModelCollection.ModelLikelihoodFactories = modelLikelihoodFactories;
            aQmrrPartialModelCollection.CreateList();
            return(aQmrrPartialModelCollection);
        }
Exemple #14
0
        private void SearchForBestParamsAndHlaAssignments(QmrrPartialModelCollection qmrrPartialModelCollection, double depth)
        {
            int    cStep = 100;
            double eps   = 1e-7;
            OptimizationParameterList oldQmrrParams = null;

            Debug.WriteLine(SpecialFunctions.CreateTabString("depth", "dataset", QmrrParamsStart.ToStringHeader(), "Step", "After", QmrrParamsStart.ToStringHeader(), "Score"));
            for (int iStep = 0; iStep < cStep && !(BestParamsSoFar.Champ.IsClose(oldQmrrParams, eps)); ++iStep)
            {
                oldQmrrParams = BestParamsSoFar.Champ.Clone();

                double hlaAssignmentSumScore = FindBestHlaAssignmentSet(qmrrPartialModelCollection, depth);

                Debug.WriteLine(SpecialFunctions.CreateTabString(depth, qmrrPartialModelCollection.DatasetName,
                                                                 QmrrParamsStart, iStep + 1, "AfterHla", BestParamsSoFar.Champ,
                                                                 hlaAssignmentSumScore));

                FindBestQmrrParams(qmrrPartialModelCollection);

                Debug.WriteLine(SpecialFunctions.CreateTabString(depth, qmrrPartialModelCollection.DatasetName,
                                                                 QmrrParamsStart, iStep + 1, "AfterParam", BestParamsSoFar.Champ, BestParamsSoFar.ChampsScore));
            }
        }
Exemple #15
0
        protected QmmrModelOnePeptide QmmrModelOnePeptideGetInstance(QmrrPartialModel qmrrPartialModel, OptimizationParameterList qmrrParams, double depth)
        {
            QmmrModelOnePeptide aQmmrModelOnePeptide = new QmmrModelOnePeptide();

            aQmmrModelOnePeptide.QmrrModelMissingAssignment = QmrrModelMissingAssignment.GetInstance(ModelLikelihoodFactories, qmrrPartialModel, qmrrParams);
            aQmmrModelOnePeptide.CreateNoSwitchablesHlaAssignment();
            if (depth == 0)
            {
                // do nothing
            }
            else if (depth == Math.Floor(depth))
            {
                SpecialFunctions.CheckCondition(depth > 0);
                aQmmrModelOnePeptide.SetForDepthSearch((int)Math.Floor(depth));
            }
            else
            {
                SpecialFunctions.CheckCondition(depth == 1.5);
                aQmmrModelOnePeptide.SetForBitFlipsAnd1Replacement();
            }
            return(aQmmrModelOnePeptide);
        }
        override protected double LogLikelihoodOfEffects(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams)
        {
            Set <Hla> trueCollectionAsSet = trueCollection.CreateHlaAssignmentAsSet();

            double logOneLessLeakProbability = Math.Log(1.0 - qmrrParams["leakProbability"].Value);

            Dictionary <Hla, double> hlaToLogOneLessLink = new Dictionary <Hla, double>();

            foreach (Hla hla in trueCollectionAsSet)
            {
                double logOneLessLink = Math.Log(1.0 - qmrrParams["link" + hla].Value);
                hlaToLogOneLessLink.Add(hla, logOneLessLink);
            }


            double logLikelihood = 0.0;

            foreach (KeyValuePair <string, Set <Hla> > patientAndHlaList in qmrrPartialModel.PatientList)
            {
                double logLikelihoodNoReactionInThisPatient = logOneLessLeakProbability;
                foreach (Hla hla in patientAndHlaList.Value)
                {
                    if (trueCollectionAsSet.Contains(hla))
                    {
                        double logOneLessLink = hlaToLogOneLessLink[hla];
                        logLikelihoodNoReactionInThisPatient += logOneLessLink;
                    }
                }

                bool didReact = qmrrPartialModel.PatientToAnyReaction.ContainsKey(patientAndHlaList.Key);
                logLikelihood += LogLikelihoodOfThisPatient(logLikelihoodNoReactionInThisPatient, didReact);
            }

            return(logLikelihood);
        }
Exemple #17
0
        virtual protected double LogLikelihoodOfEffects(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams)
        {
            double logOneLessLink            = Math.Log(1.0 - qmrrParams["link"].Value);
            double logOneLessLeakProbability = Math.Log(1.0 - qmrrParams["leakProbability"].Value);

            double logLikelihood = 0.0;

            Set <Hla> trueCollectionAsSet = trueCollection.CreateHlaAssignmentAsSet();

            foreach (KeyValuePair <string, Set <Hla> > patientAndHlaList in qmrrPartialModel.PatientList)
            {
                double logLikelihoodNoReactionInThisPatient =
                    logOneLessLeakProbability
                    + NumberOfPositiveHlas(patientAndHlaList.Value, trueCollectionAsSet) * logOneLessLink;
                bool didReact = qmrrPartialModel.PatientToAnyReaction.ContainsKey(patientAndHlaList.Key);
                logLikelihood += LogLikelihoodOfThisPatient(logLikelihoodNoReactionInThisPatient, didReact);
            }

            return(logLikelihood);
        }
Exemple #18
0
        virtual protected double LogLikelihoodOfCausesConditionedOnKnownHlas(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams)
        {
            double logCausePrior        = Math.Log(qmrrParams["causePrior"].Value);
            double logOneLessCausePrior = Math.Log(1.0 - qmrrParams["causePrior"].Value);

            int trueCountLessKnown = trueCollection.Count - qmrrPartialModel.KnownHlaSet.Count;

            Debug.Assert(trueCountLessKnown >= 0); // real assert
            int falseCount = qmrrPartialModel.HlaList.Count - trueCollection.Count;

            double logLikelihood =
                (double)trueCountLessKnown * logCausePrior
                + (double)falseCount * logOneLessCausePrior;

            return(logLikelihood);
        }
Exemple #19
0
        virtual protected double LogLikelihoodOfCompleteModelConditionedOnKnownHlas(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams)
        {
            double logLikelihood =
                LogLikelihoodOfCausesConditionedOnKnownHlas(qmrrPartialModel, trueCollection, qmrrParams)
                + LogLikelihoodOfEffects(qmrrPartialModel, trueCollection, qmrrParams);

            return(logLikelihood);
        }
        public static QmrrModelAllPeptides GetInstance(ModelLikelihoodFactories modelLikelihoodFactories, string datasetName, OptimizationParameterList qmrrParamsStart, double depth, string hlaFactoryName)
        {
            QmrrModelAllPeptides aQmrrModelAllPeptides = new QmrrModelAllPeptides();

            aQmrrModelAllPeptides.QmrrPartialModelCollection  = QmrrPartialModelCollection.GetInstance(modelLikelihoodFactories, datasetName, qmrrParamsStart, hlaFactoryName);
            aQmrrModelAllPeptides.BestParamsAndHlaAssignments = BestParamsAndHlaAssignments.GetInstance(modelLikelihoodFactories, qmrrParamsStart, aQmrrModelAllPeptides.QmrrPartialModelCollection, depth);
            aQmrrModelAllPeptides.ModelLikelihoodFactories    = modelLikelihoodFactories;
            return(aQmrrModelAllPeptides);
        }
Exemple #21
0
        protected override double LogLikelihoodOfCausesConditionedOnKnownHlas(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams)
        {
            //!!!This could be calculated during the construction of qmrrPartialModel
            Set <Hla> fitUniverse = SpecialFunctions.GetValueOrDefault(PeptideToFitUniverse, qmrrPartialModel.Peptide);

            //Compute with priors
            double unfitCausePrior           = qmrrParams["causePrior"].Value;
            double fitFactor                 = qmrrParams["fitFactor"].Value;
            double fitCausePrior             = unfitCausePrior * fitFactor;
            double logUnfitCausePrior        = Math.Log(unfitCausePrior);
            double logOneLessUnfitCausePrior = Math.Log(1.0 - unfitCausePrior);
            double logFitCausePrior          = Math.Log(fitCausePrior);
            double logOneLessFitCausePrior   = Math.Log(1.0 - fitCausePrior);



            //Tabulate counts
            int unfitTotalCount         = qmrrPartialModel.HlaList.Count - fitUniverse.Count;
            int trueCountLessKnown      = trueCollection.Count - qmrrPartialModel.KnownHlaSet.Count;
            int falseCount              = qmrrPartialModel.HlaList.Count - trueCollection.Count;
            int knownFitCount           = KnownFitCount(fitUniverse, qmrrPartialModel.KnownHlaSet); //!!!could be pretabulated
            int knownUnfitCount         = qmrrPartialModel.KnownHlaSet.Count - knownFitCount;
            int fitTrueCountLessKnown   = FitTrueCount(fitUniverse, trueCollection) - knownFitCount;
            int unfitTrueCountLessKnown = trueCountLessKnown - fitTrueCountLessKnown;
            int fitFalseCount           = fitUniverse.Count - fitTrueCountLessKnown - knownFitCount;
            int unfitFalseCount         = unfitTotalCount - unfitTrueCountLessKnown - knownUnfitCount;


            //Compute logLikelihood
            double logLikelihood =
                (double)unfitTrueCountLessKnown * logUnfitCausePrior
                + (double)unfitFalseCount * logOneLessUnfitCausePrior
                + (double)fitTrueCountLessKnown * logFitCausePrior
                + (double)fitFalseCount * logOneLessFitCausePrior;

            return(logLikelihood);
        }
Exemple #22
0
        //private BestParamsAndHlaAssignments(OptimizationParameterList qmrrParamsStart)
        //{
        //    QmrrParamsStart = qmrrParamsStart;
        //    CreateBestParamsSoFar();
        //    PeptideToBestHlaAssignmentSoFar = null;
        //}

        public static BestParamsAndHlaAssignments GetInstance(ModelLikelihoodFactories modelLikelihoodFactories, OptimizationParameterList qmrrParamsStart, QmrrPartialModelCollection qmrrPartialModelCollection, double depth)
        {
            BestParamsAndHlaAssignments aBestParamsAndHlaAssignments = new BestParamsAndHlaAssignments();

            aBestParamsAndHlaAssignments.QmrrParamsStart = qmrrParamsStart;
            aBestParamsAndHlaAssignments.CreateBestParamsSoFar();
            aBestParamsAndHlaAssignments.ModelLikelihoodFactories = modelLikelihoodFactories;
            aBestParamsAndHlaAssignments.SearchForBestParamsAndHlaAssignments(qmrrPartialModelCollection, depth);
            return(aBestParamsAndHlaAssignments);
        }
        public static QmrrModelMissingAssignment GetInstance(ModelLikelihoodFactories modelLikelihoodFactories, QmrrPartialModel qmrrPartialModel, OptimizationParameterList qmrrParams)
        {
            QmrrModelMissingAssignment aQmrrModelMissingAssignment = new QmrrModelMissingAssignment();

            aQmrrModelMissingAssignment.QmrrPartialModel          = qmrrPartialModel;
            aQmrrModelMissingAssignment.OptimizationParameterList = qmrrParams;
            aQmrrModelMissingAssignment.KnownHlaSet = qmrrPartialModel.KnownHlaSet;
            aQmrrModelMissingAssignment.SwitchableHlasOfRespondingPatients = qmrrPartialModel.SwitchableHlasOfRespondingPatients;
            aQmrrModelMissingAssignment.ModelLikelihoodFactories           = modelLikelihoodFactories;
            aQmrrModelMissingAssignment.LogLikelihoodOfCompleteModelConditionedOnKnownHlas = modelLikelihoodFactories.MissingAssignmentDelegateFactory(qmrrPartialModel, qmrrParams);
            return(aQmrrModelMissingAssignment);
            //SetOfAllHlasCount = qmrrPartialModel.HlaList.Count;
        }
Exemple #24
0
        virtual public MissingAssignmentDelegate MissingAssignmentDelegateFactory(QmrrPartialModel qmrrPartialModel, OptimizationParameterList qmrrParams)
        {
            PartialModelDelegate LogLikelihoodOfCompleteModelConditionedOnKnownHlas = PartialModelDelegateFactory(qmrrPartialModel);

            return(delegate(TrueCollection trueCollection)
            {
                return LogLikelihoodOfCompleteModelConditionedOnKnownHlas(trueCollection, qmrrParams);
            });
        }
        private double LogLikelihoodOfCompleteModelConditionedOnKnownHlas(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams)
        {
            Set <Hla> trueHlaSet            = trueCollection.CreateHlaAssignmentAsSet();
            int       reactionsCoveredCount = CountReactionsCovered(qmrrPartialModel, trueHlaSet);

            SpecialFunctions.CheckCondition(reactionsCoveredCount < 1000);
            int trueCount = trueCollection.Count;

            SpecialFunctions.CheckCondition(trueCount < 1000);
            int falseCount = qmrrPartialModel.HlaList.Count - trueCollection.Count;

            SpecialFunctions.CheckCondition(falseCount < 1000);
            string llAsString    = string.Format("{0:000}.{1:000}{2:000}", reactionsCoveredCount, falseCount, trueCount);
            double logLikelihood = double.Parse(llAsString);

            return(logLikelihood);
        }
Exemple #26
0
        static public QmrrPartialModelCollection GetInstance(ModelLikelihoodFactories modelLikelihoodFactories, string datasetName, OptimizationParameterList qmrrParams, string hlaFactoryName)
        {
            QmrrPartialModelCollection aQmrrPartialModelCollection = new QmrrPartialModelCollection();

            aQmrrPartialModelCollection.HlaFactory = Qmrr.HlaFactory.GetFactory(hlaFactoryName);

            aQmrrPartialModelCollection.OptimizationParameterList = qmrrParams;
            aQmrrPartialModelCollection.SetFileNames(datasetName);
            aQmrrPartialModelCollection.ReadTables();
            aQmrrPartialModelCollection.ModelLikelihoodFactories = modelLikelihoodFactories;
            aQmrrPartialModelCollection.CreateList();
            return(aQmrrPartialModelCollection);
        }