/** * Aggregate 0 observations into adjacent smaller bin and compress +group tail. **/ void logistic_normal::aggregate_and_compress_arrays() { m_nB2.allocate(m_y1,m_y2); int i; for( i = m_y1; i <= m_y2; i++ ) { int n = m_b1-1; // index for maximum column each year for ragged objects for(int j = m_b1; j <= m_b2; j++ ) { double op = m_O(i,j)/sum(m_O(i)); if( op > m_dMinimumProportion ) { n ++; } } m_nB2(i) = n; } m_nAgeIndex.allocate(m_y1,m_y2,m_b1,m_nB2); m_Op.allocate(m_y1,m_y2,m_b1,m_nB2); m_Ep.allocate(m_y1,m_y2,m_b1,m_nB2); m_Op.initialize(); m_Ep.initialize(); for( i = m_y1; i <= m_y2; i++ ) { dvector oo = m_O(i) / sum(m_O(i)); dvar_vector ee = m_E(i) / sum(m_E(i)); int k=m_b1; for(int j = m_b1; j <= m_b2; j++ ) { if( oo(j) <= m_dMinimumProportion ) // Check this < gives -Inf need to compress left tails as well. { m_Op(i)(k) += oo(j); m_Ep(i)(k) += ee(j); } else { m_Op(i)(k) += oo(j); m_Ep(i)(k) += ee(j); if( k <=m_nB2(i) ) m_nAgeIndex(i,k) = k; if( k < m_nB2(i) ) k++; } } } }
/** * Add small constant (eps) and renormalize arrays **/ void logistic_normal::add_constant(const double& eps) { int i; m_Op.allocate(m_O); m_Ep.allocate(m_E); m_nB2.allocate(m_y1,m_y2); m_nB2 = m_Op.colmax(); m_nAgeIndex.allocate(m_y1,m_y2,m_b1,m_nB2); for( i = m_y1; i <= m_y2; i++ ) { m_O(i) = m_O(i) + eps; m_Op(i) = m_O(i) / sum(m_O(i)); m_E(i) = m_E(i) + eps; m_Ep(i) = m_E(i) / sum(m_E(i)); m_nAgeIndex(i).fill_seqadd(m_b1,1); } }
void lm_env_stepwise::init_matrix_with_snp(const snp_row &row, arma::uvec &missing, bool *valid) { arma::uvec counts = arma::zeros<arma::uvec>( 2 + 2*m_E.n_cols ); for(int i = 0; i < row.size( ); i++) { if( row[ i ] == 3 ) { missing[ i ] = 1; continue; } double s1 = row[ i ] == 1 ? 1.0 : 0.0; double s2 = row[ i ] == 2 ? 1.0 : 0.0; m_snp_matrix( i, 1 ) = s1; m_snp_matrix( i, 2 ) = s2; m_add_matrix( i, 1 ) = s1; m_add_matrix( i, 2 ) = s2; m_alt_matrix( i, 1 ) = s1; m_alt_matrix( i, 2 ) = s2; m_alt_matrix.row( i ).cols( 1 + 2 + m_E.n_cols, 1 + 2 + 2*m_E.n_cols - 1 ) = m_E.row( i ) * s1; m_alt_matrix.row( i ).cols( 1 + 2 + 2*m_E.n_cols, 1+ 2 + 3*m_E.n_cols - 1 ) = m_E.row( i ) * s2; counts[ 0 ] += s1; counts[ 1 ] += s2; for(int j = 0; j < m_E.n_cols; j++) { double e = ( std::abs( m_E( i, j ) ) > 0.0 ) ? 1.0 : 0.0; counts[ 2 + j ] += e * s1; counts[ 2 + m_E.n_cols + j ] += e * s2; } } *valid = counts.min( ) >= 20; }
void btMaterial::computeE() { const btScalar c = m_e/((1+m_nu)*(1-2*m_nu)); m_E.setZero(); m_E(0,0)=c*(1-m_nu), m_E(0,1)=c*m_nu, m_E(0,2)=c*m_nu, m_E(0,3)=0, m_E(0,4)=0, m_E(0,5)=0; m_E(1,0)=c*m_nu, m_E(1,1)=c*(1-m_nu), m_E(1,2)=c*m_nu, m_E(1,3)=0, m_E(1,4)=0, m_E(1,5)=0; m_E(2,0)=c*m_nu, m_E(2,1)=c*m_nu, m_E(2,2)=c*(1-m_nu), m_E(2,3)=0, m_E(2,4)=0, m_E(2,5)=0; m_E(3,0)=0, m_E(3,1)=0, m_E(3,2)=0, m_E(3,3)=c*(0.5f-m_nu), m_E(3,4)=0, m_E(3,5)=0; m_E(4,0)=0, m_E(4,1)=0, m_E(4,2)=0, m_E(4,3)=0, m_E(4,4)=c*(0.5f-m_nu), m_E(4,5)=0; m_E(5,0)=0, m_E(5,1)=0, m_E(5,2)=0, m_E(5,3)=0, m_E(5,4)=0, m_E(5,5)=c*(0.5f-m_nu); }