/// <summary> /// Loads the priors of BCC and CBCC. /// </summary> /// <returns>A BCC posterior instance with the loaded priors.</returns> BCC.Posteriors ToPriors() { int numClasses = Mapping.LabelCount; int numTasks = Mapping.TaskCount; int numWorkers = Mapping.WorkerCount; CommunityModel.Posteriors cbccPriors = new CommunityModel.Posteriors(); BCC.Posteriors priors = IsCommunityModel ? cbccPriors : new BCC.Posteriors(); /// Loads the prior of the background probabilities of the tasks priors.BackgroundLabelProb = BackgroundLabelProb; /// Loads the prior of the confusion matrix of each worker priors.WorkerConfusionMatrix = Util.ArrayInit(numWorkers, w => { string wid = Mapping.WorkerIndexToId[w]; if (WorkerConfusionMatrix.ContainsKey(wid)) { return(Util.ArrayInit(numClasses, lab => WorkerConfusionMatrix[wid][lab])); } else { return(Util.ArrayInit(numClasses, lab => Dirichlet.Uniform(numClasses))); } }); /// Loads the true label constraint of each task priors.TrueLabelConstraint = Util.ArrayInit(numTasks, t => { string tid = Mapping.TaskIndexToId[t]; if (TrueLabelConstraint.ContainsKey(tid)) { return(TrueLabelConstraint[Mapping.TaskIndexToId[t]]); } else { return(Discrete.Uniform(numClasses)); } }); /// Loads the priors of the parameters of CBCC if (IsCommunityModel) { cbccPriors.CommunityConfusionMatrix = CommunityConfusionMatrix; cbccPriors.WorkerScoreMatrixConstraint = Util.ArrayInit(numWorkers, w => { string wid = Mapping.WorkerIndexToId[w]; if (WorkerScoreMatrixConstraint.ContainsKey(wid)) { return(Util.ArrayInit(numClasses, lab => WorkerScoreMatrixConstraint[wid][lab])); } else { return(Util.ArrayInit(numClasses, lab => VectorGaussian.Uniform(numClasses))); } }); cbccPriors.CommunityProb = CommunityProb; cbccPriors.CommunityScoreMatrix = CommunityScoreMatrix; cbccPriors.WorkerCommunityConstraint = Util.ArrayInit(numWorkers, w => { string wid = Mapping.WorkerIndexToId[w]; if (CommunityConstraint.ContainsKey(wid)) { return(CommunityConstraint[wid]); } else { return(Discrete.Uniform(CommunityCount)); } }); } priors.Evidence = ModelEvidence; return(priors); }
BCCPosteriors ToPriors() { int numClasses = Mapping.LabelCount; int numTasks = Mapping.TaskCount; int numWorkers = Mapping.WorkerCount; CBCCPosteriors cbccPriors = new CBCCPosteriors(); BCCPosteriors priors = IsCommunityModel ? cbccPriors : new BCCPosteriors(); priors.BackgroundLabelProb = BackgroundLabelProb; priors.WorkerConfusionMatrix = Util.ArrayInit(numWorkers, w => { string wid = Mapping.WorkerIndexToId[w]; if (WorkerConfusionMatrix.ContainsKey(wid)) { return(Util.ArrayInit(numClasses, c => WorkerConfusionMatrix[wid][c])); } else { return(Util.ArrayInit(numClasses, c => Dirichlet.Uniform(numClasses))); } }); priors.TrueLabelConstraint = Util.ArrayInit(numTasks, t => { string tid = Mapping.TaskIndexToId[t]; if (TrueLabelConstraint.ContainsKey(tid)) { return(TrueLabelConstraint[Mapping.TaskIndexToId[t]]); } else { return(Discrete.Uniform(numClasses)); } }); if (IsCommunityModel) { cbccPriors.CommunityConfusionMatrix = CommunityConfusionMatrix; cbccPriors.WorkerScoreMatrixConstraint = Util.ArrayInit(numWorkers, w => { string wid = Mapping.WorkerIndexToId[w]; if (WorkerScoreMatrixConstraint.ContainsKey(wid)) { return(Util.ArrayInit(numClasses, c => WorkerScoreMatrixConstraint[wid][c])); } else { return(Util.ArrayInit(numClasses, c => VectorGaussian.Uniform(numClasses))); } }); cbccPriors.CommunityProb = CommunityProb; cbccPriors.CommunityScoreMatrix = CommunityScoreMatrix; cbccPriors.WorkerCommunityConstraint = Util.ArrayInit(numWorkers, w => { string wid = Mapping.WorkerIndexToId[w]; if (CommunityConstraint.ContainsKey(wid)) { return(CommunityConstraint[wid]); } else { return(Discrete.Uniform(CommunityCount)); } }); } priors.Evidence = ModelEvidence; return(priors); }