function ests = PostOptMixture(data,ests1,ests2,mu0,alpha,beta,n0,params)

%% Set up parameter bounds and constraints and other options for optimization
opts = optimoptions('patternsearch','MeshTolerance',params.Tolerance,'ConstraintTolerance',params.Tolerance,'StepTolerance',params.Tolerance,'MaxIterations',params.MaxIt,'MaxFunctionEvaluations',params.MaxEval);  %options for patternsearch or fmincon; slight changes needed when changing between them

A = []; %mandatory for patternsearch and fmincon; leave blank
b = []; %mandatory for patternsearch and fmincon; leave blank
Aeq = []; %mandatory for patternsearch and fmincon; leave blank
beq = []; %mandatory for patternsearch and fmincon; leave blank

lb(1) = 0; %set the lower bounds for the Nfreq frequencies

ub(1) = 1; %set the lower bounds for the Nfreq frequencies

in_val = 0.45;
mu1 = ests1(1);
mu2 = ests2(1);
sig1 = ests1(2);
sig2 = ests2(2);

[ests, ~] = patternsearch(@invprobs,in_val,A,b,Aeq,beq,lb,ub,opts);
    function negprobs = invprobs(vals)
       postval = probseval(data,vals,mu0,alpha,beta,n0);
       negprobs = -postval;
    end

function postval = probseval(data,vals)  
    
    postval = 1;
    
    for i = 1:length(data)
        postval1 = (1./sqrt(2.*pi.*sig1.^2)).*(1./data(i)).*exp(-(log(data(i)) - mu1).^2./(2.*sig1.^2));
        postval2 = (1./sqrt(2.*pi.*sig2.^2)).*(1./data(i)).*exp(-(log(data(i)) - mu2).^2./(2.*sig2.^2));
        postval = postval.*(vals(1).*postval1 + (1-vals(1)).*postval2);
    end
end
end