Пример #1
0
/**
 * Conditional maximum likelihood estimate of the variance scaler:
 *  sigma = [{sum_y (w_y' V^{-1} w_y)/ W_y^2} / sum_y (B_y-1) ]^0.5
 *
 * Conditional on the covariance matrix V and the weights W_y
**/
void logistic_normal::compute_mle_sigma(const dvar3_array& dCor)
{
	int i;

	dvariable SS = 0.0;
	double wt2;
	for( i = m_y1; i <= m_y2; i++ )
	{
		wt2 = m_dWy(i) * m_dWy(i);
		SS += ( m_w(i) * inv(dCor(i)) * m_w(i) ) / wt2;
	}

	m_sig2 = SS/sum(m_nB2-m_b1);
	m_sig  = pow(m_sig2,0.5);
}
Пример #2
0
void Booster::eval(Sample& sample, Result& result) {
    for (int nBase = 0; nBase < m_hp->numBases; nBase++) {
        Result baseResult(*m_numClasses);
        m_bases[nBase]->eval(sample, baseResult);
        baseResult.confidence *= m_w(nBase);
        result.confidence += baseResult.confidence;
    }
    result.confidence.maxCoeff(&result.prediction);
}
Пример #3
0
/**
 * Compute negative loglikelihood:
 *      nll  = t1 + t2 + t3 + t4 + t5 + t6; where:
 *      bym1 = sum_y(B_y-1);
 *      t1   = 0.5*log(2pi) * bym1;
 *      t2   = sum_{by} log(O_{by});
 *      t3   = log(sigma) * bym1;
 *      t4   = 0.5*sum_y log(det(V_y))
 *      t5   = sum_y (By-1)*log(W_y)
 *      t6   = 0.5*sigma^{-2}* sum_y (w'_y V_y^{-1} w_y)/W_y^2
**/
void logistic_normal::compute_negative_loglikelihood()
{

	m_nll.initialize();
	
	double bym1 = sum( dvector(m_nB2-m_b1) - 1.);
	double t1   = 0.5 * log(2. * PI) * bym1;
	double t2   = sum( log(m_Op) );
	dvariable t3   = log(m_sig) * bym1;
	dvariable t4   = 0;
	dvariable t5   = 0;
	dvariable t6   = 0;
	for(int i = m_y1; i <= m_y2; i++ )
	{
		dvar_matrix Vinv = inv(m_V(i));

		t4 += 0.5*log( det(m_V(i)) );
		t5 += (m_nB2(i)-m_b1-1) * log(m_dWy(i));
		t6 += (0.5/(m_dWy(i)*m_dWy(i))) * m_w(i) * Vinv * m_w(i);
	}


	m_nll = t1 + t2 + t3 + t4 + t5 + t6;
}
Пример #4
0
/**
 * Compute residuals between observed and expected proportions for likleihoods & residuals
**/
void logistic_normal::compute_residual_arrays()
{
	m_w.allocate(m_y1,m_y2,m_b1,m_nB2-1);
	// m_s.allocate(m_y1,m_y2,1,m_nB2);

	m_w.initialize();
	// m_s.initialize();
	int i;
	for( i = m_y1; i <= m_y2; i++ )
	{
		// matrix of log_residuals for likelihood.
		int nB = m_nB2(i);
		
		m_w(i) = ( log(m_Op(i)(m_b1,nB-1)) - log(m_Op(i,nB)) )
		        -( log(m_Ep(i)(m_b1,nB-1)) - log(m_Ep(i,nB)) );
		
	}
}