Model_Name  		= "HKY85";
Model_Options 		= 7;
Model_Dimension 	= 4;
Model_EFV_Type		= "Observed In Partition";

function GUIPopulateModelMatrix (ModelMatrixName&, EFV)
{
	if (modelType == 0)
	/* local */
	{
		ModelMatrixName = {{*,trsv,trst,trsv}
						   {trsv,*,trsv,trst}
						   {trst,trsv,*,trsv}
						   {trsv,trst,trsv,*}};
	}
	else
	{
		global			globalVariable_TVTS = 1;
		if (modelType == 1)
		/* global */
		{
			
			ModelMatrixName = {{*,t*globalVariable_TVTS,t,t*globalVariable_TVTS}
							   {t*globalVariable_TVTS,*,t*globalVariable_TVTS,t}
							   {t,t*globalVariable_TVTS,*,t*globalVariable_TVTS}
							   {t*globalVariable_TVTS,t,t*globalVariable_TVTS,*}};
		}
		else
		/* global + gamma */
		{
			global shapeParameter = .5;
			shapeParameter:>0.01;shapeParameter:<100;
			category     categoryVariable = 
						(rateClassCount, EQUAL, MEAN, GammaDist(_x_,shapeParameter,shapeParameter), CGammaDist(_x_,shapeParameter,shapeParameter), 0 , 
				  							1e25,CGammaDist(_x_,shapeParameter+1,shapeParameter));
				  							
			ModelMatrixName = {{*,t*globalVariable_TVTS*categoryVariable,t*categoryVariable,t*globalVariable_TVTS*categoryVariable}
							   {t*globalVariable_TVTS*categoryVariable,*,t*globalVariable_TVTS*categoryVariable,t*categoryVariable}
							   {t*categoryVariable,t*globalVariable_TVTS*categoryVariable,*,t*globalVariable_TVTS*categoryVariable}
							   {t*globalVariable_TVTS*categoryVariable,t*categoryVariable,t*globalVariable_TVTS*categoryVariable,*}};
		}
	}
	return 1;
}

/*-------------------------------------------------------------------------------*/

function	EFVEstimated	(EFVector&, EFVApproximations)
{
	global frequencyVariableA;
	global frequencyVariableC;
	global frequencyVariableG;
	global frequencyVariableT;
	global frequencyVariableSum;

	frequencyVariableA:<1;
	frequencyVariableC:<1;
	frequencyVariableG:<1;
	frequencyVariableT	 :=	Abs(1-frequencyVariableA-frequencyVariableC-frequencyVariableG);
	frequencyVariableSum := frequencyVariableA+frequencyVariableC+frequencyVariableG+frequencyVariableT;

	frequencyVariableA = EFVApproximations[0];
	frequencyVariableC = EFVApproximations[1];
	frequencyVariableG = EFVApproximations[2];

	EFVector = {{frequencyVariableA/frequencyVariableSum},
				{frequencyVariableC/frequencyVariableSum},
				{frequencyVariableG/frequencyVariableSum},
				{frequencyVariableT/frequencyVariableSum}};
				
	return	1;
}
