exp += m_Data[i][j]*x[offset*dim+j]; denom += Math.exp(exp);
exp[offset] += m_Data[i][j]*x[offset*dim+j]; } double max = exp[Utils.maxIndex(exp)]; double denom = Math.exp(-max); double num = -max; for(int offset=0; offset<m_NumClasses-1; offset++){ denom += Math.exp(exp[offset] - max);
	protected double objectiveFunction(double[] x){	    double nll = 0; // -LogLikelihood	    int dim = m_NumPredictors+1; // Number of variables per class	    	    for(int i=0; i<cls.length; i++){ // ith instance		double denom = 1, num = 0;   // Denominator and numerator of posterior		for(int offset=0; offset<m_NumClasses-1; offset++){ // Which part of x		    double exp=0.0;		    		    for(int j=0; j<dim; j++)			exp += m_Data[i][j]*x[offset*dim+j];		    denom += Math.exp(exp);		    if(cls[i] == offset)     // Class of this instance			num = exp;		}				nll -= weights[i]*(num - Math.log(denom)); // Weighted NLL	    }	    	    // Ridge: note that intercepts NOT included	    for(int offset=0; offset<m_NumClasses-1; offset++){		for(int r=1; r<dim; r++)		    nll += m_Ridge*x[offset*dim+r]*x[offset*dim+r];	    }	    	    return nll;	}