bool ns_machine_analysis_region_data::recalculate_from_saved_movement_quantification(const unsigned long region_id,ns_sql & sql){
	death_time_annotation_set.clear();
	metadata.region_id = region_id;
	//load 3d point cloud

	const ns_time_path_solver_parameters solver_parameters(ns_time_path_solver_parameters::default_parameters(region_id,sql));
	const ns_time_series_denoising_parameters time_series_denoising_parameters(ns_time_series_denoising_parameters::load_from_db(region_id,sql));
	ns_time_path_solver solver;
	solver.load(region_id,sql);
	solver.solve(solver_parameters,time_path_solution);
	time_path_solution.save_to_db(region_id,sql);
	//time_path_solution.load_from_db(region_id,sql);

	//load cached movement quantification
		ns_acquire_for_scope<ns_analyzed_image_time_path_death_time_estimator> death_time_estimator(
				ns_get_death_time_estimator_from_posture_analysis_model(
				image_server.get_posture_analysis_model_for_region(region_id,sql)));

	time_path_image_analyzer.load_completed_analysis(region_id,time_path_solution,time_series_denoising_parameters, &death_time_estimator(),sql);
	death_time_estimator.release();
	//generate annotations from quantification
	
	time_path_image_analyzer.produce_death_time_annotations(death_time_annotation_set);
	
	time_path_image_analyzer.clear_annotations();
	//save annotations
	ns_image_server_results_subject results_subject;
	results_subject.region_id = region_id;
	ns_image_server_results_file censoring_results(image_server.results_storage.machine_death_times(results_subject,ns_image_server_results_storage::ns_censoring_and_movement_transitions,
				"time_path_image_analysis",sql));
	ns_image_server_results_file state_results(image_server.results_storage.machine_death_times(results_subject,ns_image_server_results_storage::ns_worm_position_annotations,
				"time_path_image_analysis",sql));
	ns_acquire_for_scope<std::ostream> censoring_out(censoring_results.output());
	ns_acquire_for_scope<std::ostream> state_out(state_results.output());
	death_time_annotation_set.write_split_file_column_format(censoring_out(),state_out());
	censoring_out.release();
	state_out.release();
	return true;
}
Пример #2
0
void Process(StrLen file_name)
 {
  SplitPath dev_name(file_name);
  SplitName path_name(dev_name.path);
  SplitExt name_ext(path_name.name);

  String in_name;

  if( !name_ext )
    {
     in_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".lang");
    }
  else
    {
     in_name=file_name;
    }

  TrackStage("Load file #.q;",StrLen(Range(in_name)));

  CondLang clang(Range(in_name));

  TrackStage("Build top lang");

  TopLang top(clang);

  TrackStage("Run good test on top lang");

  if( !RunGoodTest(top) ) return;

  TrackStage("Build bottom lang");

  BottomLang bottom(clang);

  TrackStage("Extend bottom lang");

  ExtLang ext_bottom(bottom);

  TrackStage("Process top lang");

  ExtLang ext_top(top);
  LangDiagram diagram(ext_top);
  LangStateMachine<LR1Estimate,LR1MapContext> machine(ext_top,diagram,ext_bottom);

  StateCompress<LR1Estimate> compress(machine);

  TrackStage("LR1) #;",PrintCompressCounts(compress));

  {
   ulen conflicts=0;

   for(auto &est : compress.getProps() ) conflicts+=est.hasConflict();

   if( conflicts )
     {
      String out_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".bad.txt");
      PrintFile out(Range(out_name));

      Putobj(out,clang);

      PrintBad(out,ext_top,compress);

      Printf(Exception,"#; CONFLICTs detected. Not LR1 language.",conflicts);
     }
   else
     {
      TrackStage("No conflicts. LR1 language.");
     }
  }

  StateCompress<LR1Estimate,LR1PropNonEmpty> compress_ne(machine);

  TrackStage("NonEmpty) #;",PrintCompressCounts(compress_ne));

#if 0

  StateCompress<LR1Estimate,LR1PropShiftSet> compress_shift(machine);

  TrackStage("Shift) #;",PrintCompressCounts(compress_shift));

  StateCompress<LR1Estimate,LR1PropValidSet> compress_valid(machine);

  TrackStage("Valid) #;",PrintCompressCounts(compress_valid));

  StateCompress<LR1Estimate,LR1PropRuleSet> compress_rules(machine);

  TrackStage("Rules) #;",PrintCompressCounts(compress_rules));

  StateMap map(compress,compress_ne);

  String out_name=StringCat(dev_name.dev,path_name.path,"Result.txt");
  PrintFile out(Range(out_name));

  PrintFibres(out,compress,compress_ne,map);

  Putobj(out,BindOpt(ext_top,compress_ne));

#endif

  {
   String out_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".txt");
   PrintFile out(Range(out_name));

   Putobj(out,clang);

   Putobj(out,BindOpt(ext_top,compress));
  }

  {
   String out_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".ddl");

   PosPrint<PrintFile> out(Range(out_name));

   Printf(out,"/* #;.ddl */\n\n",name_ext.name);

   Putobj(out,"//include <LangTypes.ddl>\n\n");

   Putobj(out,"Lang lang=\n");

   // lang
   {
    ListPrint<decltype(out)> lang_out(out);

    // atoms
    {
     ListPrint<decltype(lang_out)> atom_out(lang_out);

     for(auto &atom : clang.getAtoms() )
       Printf(atom_out,"{ #; , #; , lang.elements+#; }#;",atom.index,StrLen(atom.name.inner(2,1)),atom.index,EndItem());

     Putobj(atom_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // synts
    {
     ListPrint<decltype(lang_out)> synt_out(lang_out);

     ulen element=clang.getAtomCount();
     ulen top_index=0;

     for(auto &synt : clang.getSynts() )
       {
        Printf(synt_out,"{ #; , #.q; ,",synt.index,synt.name);

        auto kinds=synt.kinds;

        if( !kinds )
          {
           Indent indent(synt_out.getCol());

           Printf(synt_out," { { #; , 0 , \"\" , lang.synts+#; , lang.elements+#; ,#;",top_index,synt.index,element++,AutoIndent());

           auto &top_synt=top.getSynts()[top_index++];

           ListPrint<decltype(synt_out)> rule_out(synt_out);

           for(auto &top_rule : top_synt.rules )
             Printf(rule_out,"lang.top_rules+#;#;",top_rule.index,EndItem());

           Putobj(rule_out,EndList());

           Printf(synt_out,"#;   }#; } ,#;",indent,indent,indent);
          }
        else
          {
           Indent indent(synt_out.getCol());

           Putobj(synt_out,indent);

           ListPrint<decltype(synt_out)> kind_out(synt_out);

           for(auto &kind : kinds )
             {
              Printf(kind_out,"{ #; , #; , #.q; , lang.synts+#; , lang.elements+#; ,#;",top_index,kind.index,kind.name,synt.index,element++,AutoIndent());

              auto &top_synt=top.getSynts()[top_index++];

              ListPrint<decltype(kind_out)> rule_out(kind_out);

              for(auto &top_rule : top_synt.rules )
                Printf(rule_out,"lang.top_rules+#;#;",top_rule.index,EndItem());

              Putobj(rule_out,EndList());

              Printf(kind_out,"\n}#;",EndItem());
             }

           Putobj(kind_out,EndList());

           Putobj(synt_out," ,",indent);
          }

        ListPrint<decltype(synt_out)> rule_out(synt_out);

        for(auto &rule : synt.rules )
          Printf(rule_out,"lang.rules+#;#;",rule.index,EndItem());

        Putobj(rule_out,EndList());

        Putobj(synt_out,"\n}",EndItem());
       }

     Putobj(synt_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // lang
    {
     ListPrint<decltype(lang_out)> synt_out(lang_out);

     for(auto &synt : clang.getSynts() )
       if( synt.is_lang )
         {
          Printf(synt_out,"lang.synts+#;",synt.index);
         }

     Putobj(synt_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // elements
    {
     ListPrint<decltype(lang_out)> elem_out(lang_out);

     ulen element=0;

     for(auto &atom : clang.getAtoms() )
       Printf(elem_out,"{ #; , lang.atoms+#; }#;",element++,atom.index,EndItem());

     for(auto &synt : clang.getSynts() )
       {
        auto len=synt.kinds.len;

        if( !len ) len=1;

        for(ulen i=0; i<len ;i++)
          {
           Printf(elem_out,"{ #; , lang.synts[#;].kinds+#; }#;",element++,synt.index,i,EndItem());
          }
       }

     Putobj(elem_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // rules
    {
     ListPrint<decltype(lang_out)> rule_out(lang_out);

     for(auto &rule : clang.getRules() )
       {
        Printf(rule_out,"{ #; , #.q; , lang.synts[#;].kinds+#; ,#;",rule.index,rule.name,rule.ret->index,rule.getKindIndex(),AutoIndent());

        ListPrint<decltype(rule_out)> arg_out(rule_out);

        for(auto &element : rule.args )
          element.apply( [&] (const CondLangBase::AtomDesc *desc)
                             {
                              Printf(arg_out,"lang.atoms+#;#;",desc->index,EndItem());
                             } ,
                         [&] (const CondLangBase::SyntDesc *desc)
                             {
                              Printf(arg_out,"lang.synts+#;#;",desc->index,EndItem());
                             }
                       );

        Putobj(arg_out,EndList());

        Putobj(rule_out,"\n}",EndItem());
       }

     Putobj(rule_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // top rules
    {
     ListPrint<decltype(lang_out)> rule_out(lang_out);

     for(auto &rule : top.getRules() )
       {
        Printf(rule_out,"{ #; , #.q; , lang.rules+#; , lang.synts[#;].kinds+#; ,#;",
          rule.index,rule.name,rule.map_index,rule.ret->map_index,rule.ret->kind_index,AutoIndent());

        ListPrint<decltype(rule_out)> arg_out(rule_out);

        for(auto &element : rule.args )
          element.apply( [&] (const LangBase::AtomDesc *desc)
                             {
                              Printf(arg_out,"lang.atoms+#;#;",desc->index,EndItem());
                             } ,
                         [&] (const LangBase::SyntDesc *desc)
                             {
                              Printf(arg_out,"lang.synts[#;].kinds+#;#;",desc->map_index,desc->kind_index,EndItem());
                             }
                       );

        Putobj(arg_out,EndList());

        Putobj(rule_out,"\n}",EndItem());
       }

     Putobj(rule_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // states
    {
     ListPrint<decltype(lang_out)> state_out(lang_out);

     for(auto &state : compress.getStateTable() )
       {
        Printf(state_out,"{ #; , lang.finals+#; ,#;",state.index,state.prop_index,AutoIndent());

        ListPrint<decltype(state_out)> trans_out(state_out);

        for(auto &trans : state.transitions )
          Printf(trans_out,"{ lang.elements+#; , lang.states+#; }#;",trans.element,trans.dst->index,EndItem());

        Putobj(trans_out,EndList());

        Putobj(state_out,"\n}",EndItem());
       }

     Putobj(state_out,EndList());
    }

    Putobj(lang_out,EndItem());

    // finals
    {
     ListPrint<decltype(lang_out)> final_out(lang_out);

     ulen atom_count=clang.getAtomCount();

     ulen index=0;

     for(auto &final : compress.getProps() )
       {
        Printf(final_out,"{ #; ,#;",index++,AutoIndent());

        ListPrint<decltype(final_out)> action_out(final_out);

        if( final.hasNull() )
          {
           Printf(action_out,"{ null , null }#;",EndItem());
          }
        else
          {
           auto &alpha=final.getAlpha();

           if( alpha.nonEmpty() )
             {
              Printf(action_out,"{ null , lang.rules+#; }#;",alpha.getPtr()->getIndex()-atom_count,EndItem());
             }
          }

        for(auto &rec : Range(final.getBeta()) )
          {
           if( rec.object.shift )
             {
              Printf(action_out,"{ lang.atoms+#; , null }#;",rec.index.getIndex(),EndItem());
             }
           else
             {
              auto &rules=rec.object.rules;

              if( rules.nonEmpty() )
                {
                 Printf(action_out,"{ lang.atoms+#; , lang.rules+#; }#;",rec.index.getIndex(),rules.getPtr()->getIndex()-atom_count,EndItem());
                }
             }
          }

        Putobj(action_out,EndList());

        Putobj(final_out,"\n}",EndItem());
       }

     Putobj(final_out,EndList());
    }

    Putobj(lang_out,EndItem(),EndList());
   }

   Putobj(out,";\n\n");
  }
Пример #3
0
aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1])
{   uint32_t        locals(b0, b1);
    const uint32_t  *kp = cx->k_sch + nc * cx->n_rnd;
    dec_imvars  /* declare variables for inv_mcol() if needed */

    if(!(cx->n_blk & 2)) return aes_bad;

#if (DEC_UNROLL == FULL)

    state_in((cx->n_rnd & 1 ? b1 : b0), in_blk, kp);
    kp = cx->k_sch + 9 * nc;

    switch(cx->n_rnd)
    {
    case 14:    round(inv_rnd,  b1, b0, kp + 4 * nc);
    case 13:    round(inv_rnd,  b0, b1, kp + 3 * nc);
    case 12:    round(inv_rnd,  b1, b0, kp + 2 * nc);
    case 11:    round(inv_rnd,  b0, b1, kp +     nc);
    case 10:    round(inv_rnd,  b1, b0, kp         );
                round(inv_rnd,  b0, b1, kp -     nc);
                round(inv_rnd,  b1, b0, kp - 2 * nc);
                round(inv_rnd,  b0, b1, kp - 3 * nc);
                round(inv_rnd,  b1, b0, kp - 4 * nc);
                round(inv_rnd,  b0, b1, kp - 5 * nc);
                round(inv_rnd,  b1, b0, kp - 6 * nc);
                round(inv_rnd,  b0, b1, kp - 7 * nc);
                round(inv_rnd,  b1, b0, kp - 8 * nc);
                round(inv_lrnd, b0, b1, kp - 9 * nc);
    }
#else
    {   uint32_t    rnd;

        state_in(b0, in_blk, kp);

#if (DEC_UNROLL == PARTIAL)

        for(rnd = 0; rnd < (cx->n_rnd - 1) >> 1; ++rnd)
        {
            kp -= nc;
            round(inv_rnd, b1, b0, kp);
            kp -= nc;
            round(inv_rnd, b0, b1, kp);
        }

        if(cx->n_rnd & 1)
        {
            l_copy(b1, b0);
        }
        else
        {
            kp -= nc;
            round(inv_rnd,  b1, b0, kp);
        }
#else
        for(rnd = 0; rnd < cx->n_rnd - 1; ++rnd)
        {
            kp -= nc;
            round(inv_rnd, b1, b0, kp);
            l_copy(b0, b1);
        }
#endif
        kp -= nc;
        round(inv_lrnd, b0, b1, kp);
    }
#endif

    state_out(out_blk, b0);
    return aes_good;
}
Пример #4
0
aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1])
{   aes_32t        locals(b0, b1);
    const aes_32t  *kp = cx->k_sch;
    dec_fmvars  /* declare variables for fwd_mcol() if needed */

    if(!(cx->n_blk & 1)) return aes_bad;

#if (ENC_UNROLL == FULL)

    state_in((cx->n_rnd & 1 ? b1 : b0), in_blk, kp); 
    kp += (cx->n_rnd - 9) * nc;

    switch(cx->n_rnd)
    {
    case 14:    round(fwd_rnd,  b1, b0, kp - 4 * nc);
    case 13:    round(fwd_rnd,  b0, b1, kp - 3 * nc);
    case 12:    round(fwd_rnd,  b1, b0, kp - 2 * nc);
    case 11:    round(fwd_rnd,  b0, b1, kp -     nc);
    case 10:    round(fwd_rnd,  b1, b0, kp         );             
                round(fwd_rnd,  b0, b1, kp +     nc);
                round(fwd_rnd,  b1, b0, kp + 2 * nc); 
                round(fwd_rnd,  b0, b1, kp + 3 * nc);
                round(fwd_rnd,  b1, b0, kp + 4 * nc); 
                round(fwd_rnd,  b0, b1, kp + 5 * nc);
                round(fwd_rnd,  b1, b0, kp + 6 * nc); 
                round(fwd_rnd,  b0, b1, kp + 7 * nc);
                round(fwd_rnd,  b1, b0, kp + 8 * nc);
                round(fwd_lrnd, b0, b1, kp + 9 * nc);
    }
#else
    {   aes_32t    rnd;

        state_in(b0, in_blk, kp); 

#if (ENC_UNROLL == PARTIAL)

        for(rnd = 0; rnd < (cx->n_rnd - 1) >> 1; ++rnd)
        {
            kp += nc;
            round(fwd_rnd, b1, b0, kp); 
            kp += nc;
            round(fwd_rnd, b0, b1, kp); 
        }

        if(cx->n_rnd & 1) 
        {
            l_copy(b1, b0);
        }
        else
        {
            kp += nc;
            round(fwd_rnd,  b1, b0, kp); 
        }
#else
        for(rnd = 0; rnd < cx->n_rnd - 1; ++rnd)
        {
            kp += nc;
            round(fwd_rnd, b1, b0, kp); 
            l_copy(b0, b1); 
        }
#endif
        kp += nc;
        round(fwd_lrnd, b0, b1, kp);
    }
#endif

    state_out(out_blk, b0);
    return aes_good;
}