//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); }
protected OptimizationParameterList FindBestParams(string peptide, Set <Hla> candidateHlaSet, Set <Hla> hlaWithLinkZero, Dictionary <string, Set <Hla> > patientList, //Dictionary<string, Dictionary<string,double>> reactTable, out double score) { //SpecialFunctions.CheckCondition(false, "Regression test this to be sure that switch to new optimization method didn't change anything important - cmk 5/1/2006"); Set <Hla> knownHlaSet = KnownTable(peptide); TrueCollection trueCollection = TrueCollection.GetInstance(candidateHlaSet, knownHlaSet); OptimizationParameterList qmrrParamsThisPeptide = CreateQmrrParamsStartForTheseCandidateHlas(trueCollection.CreateHlaAssignmentAsSet(), hlaWithLinkZero); //OptimizationParameterList qmrrParamsThisPeptide = CreateQmrrParamsX(causePrior, leakProbability, trueCollection.CreateHlaAssignmentAsSet()); ModelLikelihoodFactories modelLikelihoodFactories = ModelLikelihoodFactories.GetInstanceLinkPerHla(qmrrParamsThisPeptide, trueCollection.CreateHlaAssignmentAsSet()); QmrrPartialModelCollection singletonQmrrPartialModelCollection = QmrrPartialModelCollection.GetInstance( peptide, modelLikelihoodFactories, qmrrParamsThisPeptide, patientList, ReactTableUnfiltered, _knownTable, HlaFactory.Name //!!!would it be better to pass the actual factory??? ); BestSoFar <double, TrueCollection> bestSoFar = BestSoFar <double, TrueCollection> .GetInstance(SpecialFunctions.DoubleGreaterThan); bestSoFar.Compare(double.NegativeInfinity, trueCollection); Dictionary <string, BestSoFar <double, TrueCollection> > peptideToBestHlaAssignmentSoFar = new Dictionary <string, BestSoFar <double, TrueCollection> >(); peptideToBestHlaAssignmentSoFar.Add(peptide, bestSoFar); QmrrlModelMissingParametersCollection aQmrrlModelMissingParametersCollection = QmrrlModelMissingParametersCollection.GetInstance(modelLikelihoodFactories, singletonQmrrPartialModelCollection, peptideToBestHlaAssignmentSoFar); OptimizationParameterList qmrrParamsEnd = aQmrrlModelMissingParametersCollection.FindBestParams(qmrrParamsThisPeptide, out score); return(qmrrParamsEnd); }