locked
Initializing VariableArray and setting its' priors runtime RRS feed

  • Question

  • I am following the Infer.NET 101 document that shows how to modify application such that "AverageTime" and "TrafficNoise" variable priors can be updated in online setting.

    <g class="gr_ gr_29 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" data-gr-id="29" id="29">First</g> the priors are set:

    AverageTimePrior = Variable.New<Gaussian>();
    TrafficNoisePrior = Variable.New<Gamma>();

    Second, the random variables themselves are defined (data type, distribution):

    AverageTime = Variable.Random<double, Gaussian>(AverageTimePrior);
    TrafficNoise = Variable.Random<double, Gamma>(TrafficNoisePrior);

    During runtime, "<g class="gr_ gr_32 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="32" id="32">TravelTimes</g>" variable is observed with data (dependent on "AverageTime" and "<g class="gr_ gr_33 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="33" id="33">TrafficNoise</g>") and with <g class="gr_ gr_30 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="30" id="30">Gaussian</g> distribution. Inference engine infers posteriors for "AverageTime" and "<g class="gr_ gr_50 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="50" id="50">TrafficNoise</g>". These posteriors are then used as priors for the two random variables in next rounds of learning with new batches of data.

    In my application, I need to define, infer and use as priors in next learning rounds an array of variables. I understand that for a single variable the construction "Variable.New<Gaussian>()" is used.

    Variable<int> numWorkers = Variable.New<int>();
    Range m = new Range(numWorkers);
    
    VariableArray<Discrete> Tprior;
    VariableArray<int> T;
    
    Tprior[m] = Variable.New<Discrete>().ForEach(m);
    
    T[m] = Variable.Random<int, Discrete>(Tprior[m]).ForEach(m);

    How to do this for an array? Would something like the code shown above work?

    • Edited by usptact Friday, August 25, 2017 11:45 PM
    Friday, August 25, 2017 11:26 PM

Answers

  • You are close.  Use Variable.Array<Discrete> and omit ForEach(m).
    • Marked as answer by usptact Wednesday, August 30, 2017 4:34 AM
    Saturday, August 26, 2017 9:25 AM
    Owner

All replies

  • Grammarly extension really messed up the post. I try to edit them out but the post gets flagged as spam... what to do?

    Friday, August 25, 2017 11:30 PM
  • You are close.  Use Variable.Array<Discrete> and omit ForEach(m).
    • Marked as answer by usptact Wednesday, August 30, 2017 4:34 AM
    Saturday, August 26, 2017 9:25 AM
    Owner