public Model(SharedVariableArray<Vector> w, Range c, int numChunks) { // Items. numItems = Variable.New<int>().Named("numItems"); i = new Range(numItems).Named("i"); i.AddAttribute(new Sequential()); // The model identifier for the shared variables. model = new MicrosoftResearch.Infer.Models.Model(numChunks).Named("model"); // The weight vector for each submodel. wModel = w.GetCopyFor(model).Named("wModel"); noisePrecision = Variable.New<double>().Named("noisePrecision"); // Arrays of <see cref="Vector"/>-valued items (feature vectors) and integer labels. x = Variable.Array<Vector>(i).Named("x"); y = Variable.Array<int>(i).Named("y"); // For all items... using (Variable.ForEach(i)) { // ...compute the score of this item across all classes... score = BPMUtils.ComputeClassScores(wModel, x[i], noisePrecision); y[i] = Variable.DiscreteUniform(c); // ... and constrain the output. BPMUtils.ConstrainMaximum(y[i], score); } // Inference engine settings (EP). engine.Compiler.UseSerialSchedules = true; engine.ShowProgress = false; }
public Model(ISharedVariableArray<VariableArray<double>, double[][]> w, Range c, int numChunks) { // Items. numItems = Variable.New<int>().Named("numItems"); i = new Range(numItems).Named("i"); i.AddAttribute(new Sequential()); // Features per item. numFeaturesPerItem = Variable.Array<int>(i).Named("numFeaturesPerItem"); fItem = new Range(numFeaturesPerItem[i]).Named("fItem"); // The model identifier for the shared variables. model = new MicrosoftResearch.Infer.Models.Model(numChunks).Named("model"); // The weight vector for each submodel. wModel = w.GetCopyFor(model).Named("wModel"); noisePrecision = Variable.New<double>().Named("noisePrecision"); // Jagged array of feature values - each item is an array of data values // whose indices are given by the corresponding indices[i]. values = Variable.Array(Variable.Array<double>(fItem), i).Named("values"); // Jagged array of indices for the items. indices = Variable.Array(Variable.Array<int>(fItem), i).Named("indices"); // Labels. y = Variable.Array<int>(i).Named("y"); // For all items... using (Variable.ForEach(i)) { // ...compute the score of this item across all classes... score = BPMUtils.ComputeClassScores(wModel, values[i], indices[i], fItem, noisePrecision); y[i] = Variable.DiscreteUniform(c); // ... and constrain the output. BPMUtils.ConstrainMaximum(y[i], score); } // Inference engine settings (EP). engine.Compiler.UseSerialSchedules = true; engine.ShowProgress = false; }