You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: JointBayesian.m
    path of file: ./repos/FaceVerification
    
    the code of the file until where you have to start completion: function [mappedX, mapping] = JointBayesian(X, labels)
% Joint Bayesian
% Chen D, Cao X, Wang L, et al. Bayesian face revisited: A joint formulation, ECCV 2012.
% 
% programmed by happynear

    
function [mappedX, mapping] = JointBayesian(X, labels)
% Joint Bayesian
% Chen D, Cao X, Wang L, et al. Bayesian face revisited: A joint formulation, ECCV 2012.
% 
% programmed by happynear
% https://github.com/happynear
    m = length(labels);
    n = size(X,2);
	
	% Make sure labels are nice
	[classes, bar, labels] = unique(labels);
    nc = length(classes);
	
	% Intialize Sw
	Sw = zeros(size(X, 2), size(X, 2));
    
   cur = {};
    withinCount = 0;
    numberBuff = zeros(1000,1);
%     numberInvert = zeros(1000,1);
    maxNumberInOneClass = [];
    for i=1:nc
        % Get all instances with class i
        cur{i} = X(labels == i,:);
        if size(cur{i},1)>1
            withinCount = withinCount + size(cur{i},1);
        end