public override PartialModelDelegate PartialModelDelegateFactory(QmrrPartialModel qmrrPartialModel) { return(delegate(TrueCollection trueCollection, OptimizationParameterList qmrrParams) { return LogLikelihoodOfCompleteModelConditionedOnKnownHlas(qmrrPartialModel, trueCollection, qmrrParams); }); }
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); }
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); }
virtual protected double LogLikelihoodOfCompleteModelConditionedOnKnownHlas(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection, OptimizationParameterList qmrrParams) { double logLikelihood = LogLikelihoodOfCausesConditionedOnKnownHlas(qmrrPartialModel, trueCollection, qmrrParams) + LogLikelihoodOfEffects(qmrrPartialModel, trueCollection, qmrrParams); return(logLikelihood); }
virtual public MissingParametersDelegate MissingParametersDelegateFactory(QmrrPartialModel qmrrPartialModel, TrueCollection trueCollection) { PartialModelDelegate LogLikelihoodOfCompleteModelConditionedOnKnownHlas = PartialModelDelegateFactory(qmrrPartialModel); return(delegate(OptimizationParameterList parameterList) { return LogLikelihoodOfCompleteModelConditionedOnKnownHlas(trueCollection, parameterList); }); }
private int CountReactionsCovered(QmrrPartialModel qmrrPartialModel, Set <Hla> trueHlaSet) { int reactionsCoveredCount = 0; foreach (string patient in qmrrPartialModel.PatientToAnyReaction.Keys) { if (NonEmptyIntersection(qmrrPartialModel.PatientList[patient], trueHlaSet)) { ++reactionsCoveredCount; } } return(reactionsCoveredCount); }
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); }
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); }
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); }
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); }
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); }
internal static QmrrlModelMissingParameters GetInstance(ModelLikelihoodFactories modelLikelihoodFactories, QmrrPartialModel qmrrPartialModel, BestSoFar <double, TrueCollection> bestSoFar) { QmrrlModelMissingParameters aQmrrlModelMissingParameters = new QmrrlModelMissingParameters(); aQmrrlModelMissingParameters.QmrrPartialModel = qmrrPartialModel; aQmrrlModelMissingParameters.TrueCollection = bestSoFar.Champ; aQmrrlModelMissingParameters.ModelLikelihoodFactories = modelLikelihoodFactories; aQmrrlModelMissingParameters.LogLikelihoodOfCompleteModelConditionedOnKnownHlas = modelLikelihoodFactories.MissingParametersDelegateFactory(qmrrPartialModel, bestSoFar.Champ); return(aQmrrlModelMissingParameters); }
abstract public PartialModelDelegate PartialModelDelegateFactory(QmrrPartialModel qmrrPartialModel);
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; }