Пример #1
0
void Run()
{
   typedef PixelDifferenceFeature TFeature;
   SplatDatabase database;
   typedef dtf::database_traits<decltype(database)> data_traits;
   dtf::factor_graph<data_traits> graph;

   // Add unary
   dtf::factor<data_traits, 1, TFeature> unary;
   unary[0] = dtf::offset_t(0, 0);
   AddFactor(graph, unary);

   // Add horizontal pairwise
   dtf::factor<data_traits, 2, TFeature> horz;
   horz[0] = dtf::offset_t(0, 0);
   horz[1] = dtf::offset_t(1, 0);
   AddFactor(graph, horz);

   // Add vertical pairwise
   dtf::factor<data_traits, 2, TFeature> vert;
   vert[0] = dtf::offset_t(0, 0);
   vert[1] = dtf::offset_t(0, 1);
   AddFactor(graph, vert);

   dtf::objective<decltype(database)> function(graph, database);
   if (!function.check_derivative(3.0, 10))
      throw std::exception("check_derivative failed.");
   dtf::learning::OptimizeWeights(graph, database);
}
Пример #2
0
static
void ProcessTable(GF2X& f, vec_pair_GF2X_long& factors, 
                  const GF2XModulus& F, long limit, const vec_GF2X& tbl,
                  long d, long verbose)

{
   if (limit == 0) return;

   if (verbose) cerr << "+";

   GF2X t1;

   if (limit == 1) {
      GCD(t1, f, tbl[0]);
      if (deg(t1) > 0) {
         AddFactor(factors, t1, d, verbose);
         div(f, f, t1);
      }

      return;
   }

   long i;

   t1 = tbl[0];
   for (i = 1; i < limit; i++)
      MulMod(t1, t1, tbl[i], F);

   GCD(t1, f, t1);

   if (deg(t1) == 0) return;

   div(f, f, t1);

   GF2X t2;

   i = 0;
   d = d - limit + 1;

   while (2*d <= deg(t1)) {
      GCD(t2, tbl[i], t1); 
      if (deg(t2) > 0) {
         AddFactor(factors, t2, d, verbose);
         div(t1, t1, t2);
      }

      i++;
      d++;
   }

   if (deg(t1) > 0)
      AddFactor(factors, t1, deg(t1), verbose);
}
Пример #3
0
BOOL CEvaluateResultDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

	LONG lStyle;
	lStyle = GetWindowLong(m_AlgorithmRuntimeList.m_hWnd, GWL_STYLE);
	lStyle &= ~LVS_TYPEMASK;
	lStyle |= LVS_REPORT;
	SetWindowLong(m_AlgorithmRuntimeList.m_hWnd, GWL_STYLE, lStyle);
	DWORD dwStyle = m_AlgorithmRuntimeList.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	dwStyle |= LVS_EX_GRIDLINES;
	m_AlgorithmRuntimeList.SetExtendedStyle(dwStyle);
    
	m_AlgorithmRuntimeList.InsertColumn(0,_T("算法名称"),LVCFMT_CENTER, 50);
	m_AlgorithmRuntimeList.InsertColumn(1,_T("迭代次数"),LVCFMT_CENTER, 50);
	m_AlgorithmRuntimeList.InsertColumn(2,_T("CPU占用率"),LVCFMT_CENTER, 50);
	m_AlgorithmRuntimeList.InsertColumn(3,_T("内存使用"),LVCFMT_CENTER, 100);
	m_AlgorithmRuntimeList.InsertColumn(4,_T("运行时间"),LVCFMT_CENTER, 100);
	m_AlgorithmRuntimeList.EnableWindow(TRUE);

    for (UINT32 i = 0; i < m_Algorithms.size(); ++i)
    {
        AddAlgorithm(m_Algorithms[i], m_AlgorithmResults[i]);
    }

	lStyle = GetWindowLong(m_FactorList.m_hWnd, GWL_STYLE);
	lStyle &= ~LVS_TYPEMASK;
	lStyle |= LVS_REPORT;
	SetWindowLong(m_FactorList.m_hWnd, GWL_STYLE, lStyle);
	dwStyle = m_FactorList.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	dwStyle |= LVS_EX_GRIDLINES;
	m_FactorList.SetExtendedStyle(dwStyle);
    
	m_FactorList.InsertColumn(0,_T("指标名称"),LVCFMT_CENTER, 60);
	m_FactorList.InsertColumn(1,_T("指标值"),LVCFMT_CENTER, 60);

    for (UINT32 i = 0; i < m_Factors.size(); ++i)
    {
        AddFactor(m_Factors[i], m_FactorResults[i]);
    }

    return TRUE;
}
Пример #4
0
void DDF(vec_pair_GF2X_long& factors, const GF2X& ff, long verbose)
{
   GF2X f = ff;

   if (IsZero(f)) Error("DDF: bad args");

   factors.SetLength(0);

   if (deg(f) == 0)
      return;

   if (deg(f) == 1) {
      AddFactor(factors, f, 1, verbose);
      return;
   }


   long GCDTableSize = GF2X_BlockingFactor;

   GF2XModulus F;
   build(F, f);

   long i, d, limit, old_n;
   GF2X g, X;


   vec_GF2X tbl(INIT_SIZE, GCDTableSize);

   SetX(X);

   i = 0;
   SqrMod(g, X, F);
   d = 1;
   limit = GCDTableSize;


   while (2*d <= deg(f)) {

      old_n = deg(f);
      add(tbl[i], g, X);
      i++;
      if (i == limit) {
         ProcessTable(f, factors, F, i, tbl, d, verbose);
         i = 0;
      }

      d = d + 1;
      if (2*d <= deg(f)) {
         // we need to go further

         if (deg(f) < old_n) {
            // f has changed 

            build(F, f);
            rem(g, g, F);
         }

         SqrMod(g, g, F);
      }
   }

   ProcessTable(f, factors, F, i, tbl, d-1, verbose);

   if (!IsOne(f)) AddFactor(factors, f, deg(f), verbose);
}
Пример #5
0
void DDF(vec_pair_ZZ_pX_long& factors, const ZZ_pX& ff, const ZZ_pX& hh, 
         long verbose)
{
   ZZ_pX f = ff;
   ZZ_pX h = hh;

   if (!IsOne(LeadCoeff(f)))
      Error("DDF: bad args");

   factors.SetLength(0);

   if (deg(f) == 0)
      return;

   if (deg(f) == 1) {
      AddFactor(factors, f, 1, verbose);
      return;
   }

   long CompTableSize = 2*SqrRoot(deg(f)); 

   long GCDTableSize = ZZ_pX_BlockingFactor;

   ZZ_pXModulus F;
   build(F, f);

   ZZ_pXArgument H;

   build(H, h, F, min(CompTableSize, deg(f)));

   long i, d, limit, old_n;
   ZZ_pX g, X;


   vec_ZZ_pX tbl(INIT_SIZE, GCDTableSize);

   SetX(X);

   i = 0;
   g = h;
   d = 1;
   limit = GCDTableSize;


   while (2*d <= deg(f)) {

      old_n = deg(f);
      sub(tbl[i], g, X);
      i++;
      if (i == limit) {
         ProcessTable(f, factors, F, i, tbl, d, verbose);
         i = 0;
      }

      d = d + 1;
      if (2*d <= deg(f)) {
         // we need to go further

         if (deg(f) < old_n) {
            // f has changed 

            build(F, f);
            rem(h, h, f);
            rem(g, g, f);
            build(H, h, F, min(CompTableSize, deg(f)));
         }

         CompMod(g, g, H, F);
      }
   }

   ProcessTable(f, factors, F, i, tbl, d-1, verbose);

   if (!IsOne(f)) AddFactor(factors, f, deg(f), verbose);
}