コード例 #1
0
ファイル: EBSDAccessFunctorsTest.C プロジェクト: Liuux/moose
void
EBSDAccessFunctorsTest::test()
{
  RealVectorValue reference_angle(0.1, 0.2, 0.3);
  Point reference_point1 = Point(9.0, 10.0, 11.0);
  Point reference_point2 = Point(6.0, 7.0, 8.0);

  // Test point data access
  {
    EBSDPointDataPhi1 phi1;
    CPPUNIT_ASSERT( phi1(_point) == _point._phi1 );
    EBSDPointDataPhi phi;
    CPPUNIT_ASSERT( phi(_point) == _point._Phi );
    EBSDPointDataPhi2 phi2;
    CPPUNIT_ASSERT( phi2(_point) == _point._phi2 );

    EBSDPointDataPhase phase;
    CPPUNIT_ASSERT( phase(_point) == _point._phase );
    EBSDPointDataSymmetry symmetry;
    CPPUNIT_ASSERT( symmetry(_point) == _point._symmetry );
    EBSDPointDataFeatureID feature_id;
    CPPUNIT_ASSERT( feature_id(_point) == _point._feature_id );

    for (unsigned int i = 0; i < 3; ++i)
    {
      EBSDPointDataCustom custom(i);
      CPPUNIT_ASSERT( custom(_point) == _point._custom[i] );
    }
  }

  // Test average data access
  {
    RealVectorValue angle = *(_avg._angles);
    CPPUNIT_ASSERT( (angle - reference_angle).size() == 0 );

    EBSDAvgDataPhi1 phi1;
    CPPUNIT_ASSERT( phi1(_avg) == angle(0) );
    EBSDAvgDataPhi phi;
    CPPUNIT_ASSERT( phi(_avg) == angle(1) );
    EBSDAvgDataPhi2 phi2;
    CPPUNIT_ASSERT( phi2(_avg) == angle(2) );

    EBSDAvgDataPhase phase;
    CPPUNIT_ASSERT( phase(_avg) == _avg._phase );
    EBSDAvgDataSymmetry symmetry;
    CPPUNIT_ASSERT( symmetry(_avg) == _avg._symmetry );
    EBSDAvgDataFeatureID feature_id;
    CPPUNIT_ASSERT( feature_id(_avg) == _avg._feature_id );
    EBSDAvgDataLocalID local;
    CPPUNIT_ASSERT( local(_avg) == _avg._local_id );

    for (unsigned int i = 0; i < 3; ++i)
    {
      EBSDAvgDataCustom custom(i);
      CPPUNIT_ASSERT( custom(_avg) == _avg._custom[i] );
    }
  }
}
コード例 #2
0
 void update(Matrix<IndexType, ItorType>* m, ValueType* y, LabelType* is_observed, bool is_skip(ValueType, LabelType)) {
   // The last parameter is log(sigma)
   IndexType nfeature = m->getNFeature();
   for(IndexType instance_id = 0;instance_id < m->getNInstance();instance_id++) {
     if (is_skip(y[instance_id], is_observed[instance_id])) continue;
     double pred = 0, g0 = 0, sigma = exp(ftprl->get_w(z[nfeature], n[nfeature]));
     #pragma omp parallel for reduction(+:pred)
     for(ItorType iter = m->getFeatureItorBegin(instance_id);iter < m->getFeatureItorEnd(instance_id); iter++) {
       IndexType feature_id = m->getFeatureId(iter);
       double value = m->getValue(iter);
       double w = ftprl->get_w(z[feature_id], n[feature_id]);
       pred += value * w;
     }
     double zscore = (pred - y[instance_id]) / sigma;
     double dzscore_dloss = (is_observed[instance_id] ? zscore : - exp(logdnorm(zscore) - logpnorm(zscore)));
     #pragma omp parallel for
     for(ItorType iter = m->getFeatureItorBegin(instance_id);iter < m->getFeatureItorEnd(instance_id); iter++) {
       IndexType feature_id = m->getFeatureId(iter);
       double value = m->getValue(iter);
       double g = dzscore_dloss * value / sigma;
       ftprl->update_zn(g, z + feature_id, n + feature_id);
     }
     { // update sigma
       IndexType &feature_id(nfeature);
       double g = - dzscore_dloss * zscore;
       ftprl->update_zn(g, z + feature_id, n + feature_id);
     }
   }
 }