本文整理汇总了C#中Variable.SetValueRange方法的典型用法代码示例。如果您正苦于以下问题:C# Variable.SetValueRange方法的具体用法?C# Variable.SetValueRange怎么用?C# Variable.SetValueRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable.SetValueRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WetGlassSprinklerRainModel
/// <summary>
/// Constructs a new Glass/Sprinkler/Rain model
/// </summary>
public WetGlassSprinklerRainModel()
{
// Set up the ranges
NumberOfExamples = Variable.New<int>().Named("NofE");
Range N = new Range(NumberOfExamples).Named("N");
// Although all the variables in this example have just 2 states (true/false),
// the example is formulated in a way that shows how to extend to multiple states
Range C = new Range(2).Named("C");
Range S = new Range(2).Named("S");
Range R = new Range(2).Named("R");
Range W = new Range(2).Named("W");
// Define the priors and the parameters
ProbCloudyPrior = Variable.New<Dirichlet>().Named("ProbCloudyPrior");
ProbCloudy = Variable<Vector>.Random(ProbCloudyPrior).Named("ProbCloudy");
ProbCloudy.SetValueRange(C);
// Sprinkler probability table conditioned on cloudiness
CPTSprinklerPrior = Variable.Array<Dirichlet>(C).Named("CPTSprinklerPrior");
CPTSprinkler = Variable.Array<Vector>(C).Named("CPTSprinkler");
CPTSprinkler[C] = Variable<Vector>.Random(CPTSprinklerPrior[C]);
CPTSprinkler.SetValueRange(S);
// Rain probability table conditioned on cloudiness
CPTRainPrior = Variable.Array<Dirichlet>(C).Named("CPTRainPrior");
CPTRain = Variable.Array<Vector>(C).Named("CPTRain"); ;
CPTRain[C] = Variable<Vector>.Random(CPTRainPrior[C]);
CPTRain.SetValueRange(R);
// Wet grass probability table conditioned on sprinkler and rain
CPTWetGrassPrior = Variable.Array(Variable.Array<Dirichlet>(R), S).Named("CPTWetGrassPrior");
CPTWetGrass = Variable.Array(Variable.Array<Vector>(R), S).Named("CPTWetGrass");
CPTWetGrass[S][R] = Variable<Vector>.Random(CPTWetGrassPrior[S][R]);
CPTWetGrass.SetValueRange(W);
// Define the primary variables
Cloudy = Variable.Array<int>(N).Named("Cloudy");
Cloudy[N] = Variable.Discrete(ProbCloudy).ForEach(N);
Sprinkler = AddChildFromOneParent(Cloudy, CPTSprinkler).Named("Sprinkler");
Rain = AddChildFromOneParent(Cloudy, CPTRain).Named("Rain");
WetGrass = AddChildFromTwoParents(Sprinkler, Rain, CPTWetGrass).Named("WetGrass");
}
示例2: CreateModel
public virtual void CreateModel()
{
NumComponents = 2;
Range ComponentRange = new Range(NumComponents);
InferenceEngine = new InferenceEngine(new VariationalMessagePassing());
InferenceEngine.ShowProgress = false;
AverageTimePriors = Variable.Array<Gaussian>(ComponentRange);
TrafficNoisePriors = Variable.Array<Gamma>(ComponentRange);
AverageTime = Variable.Array<double>(ComponentRange);
TrafficNoise = Variable.Array<double>(ComponentRange);
using (Variable.ForEach(ComponentRange))
{
AverageTime[ComponentRange] = Variable.Random<double, Gaussian>(AverageTimePriors[ComponentRange]);
TrafficNoise[ComponentRange] = Variable.Random<double, Gamma>(TrafficNoisePriors[ComponentRange]);
}
//Mixing coefficients
MixingPrior = Variable.New<Dirichlet>();
MixingCoefficients = Variable<Vector>.Random(MixingPrior);
MixingCoefficients.SetValueRange(ComponentRange);
}
示例3: DefineVariablesAndRanges
/// <summary>
/// Initializes the ranges of the variables.
/// </summary>
/// <param name="taskCount">The number of tasks.</param>
/// <param name="labelCount">The number of labels.</param>
protected virtual void DefineVariablesAndRanges(int taskCount, int labelCount)
{
WorkerCount = Variable.New<int>().Named("WorkerCount");
n = new Range(taskCount).Named("n");
c = new Range(labelCount).Named("c");
k = new Range(WorkerCount).Named("k");
// The tasks for each worker
WorkerTaskCount = Variable.Array<int>(k).Named("WorkerTaskCount");
kn = new Range(WorkerTaskCount[k]).Named("kn");
WorkerTaskIndex = Variable.Array(Variable.Array<int>(kn), k).Named("WorkerTaskIndex");
WorkerTaskIndex.SetValueRange(n);
WorkerLabel = Variable.Array(Variable.Array<int>(kn), k).Named("WorkerLabel");
// The background probability vector
BackgroundLabelProbPrior = Variable.New<Dirichlet>().Named("BackgroundLabelProbPrior");
BackgroundLabelProb = Variable<Vector>.Random(BackgroundLabelProbPrior).Named("BackgroundLabelProb");
BackgroundLabelProb.SetValueRange(c);
// The confusion matrices for each worker
ConfusionMatrixPrior = Variable.Array(Variable.Array<Dirichlet>(c), k).Named("ConfusionMatrixPrior");
WorkerConfusionMatrix = Variable.Array(Variable.Array<Vector>(c), k).Named("ConfusionMatrix");
WorkerConfusionMatrix[k][c] = Variable<Vector>.Random(ConfusionMatrixPrior[k][c]);
WorkerConfusionMatrix.SetValueRange(c);
// The unobserved 'true' label for each task
TrueLabel = Variable.Array<int>(n).Attrib(QueryTypes.Marginal).Attrib(QueryTypes.MarginalDividedByPrior).Named("Truth");
TrueLabelConstraint = Variable.Array<Discrete>(n).Named("TruthConstraint");
// Constraint for online learning
TrueLabel[n] = Variable.Discrete(BackgroundLabelProb).ForEach(n);
Variable.ConstrainEqualRandom(TrueLabel[n], TrueLabelConstraint[n]);
// The worker labels
WorkerLabel = Variable.Array(Variable.Array<int>(kn), k).Named("WorkerLabel");
}
示例4: LDATopicInferenceModel
/// <summary>
/// Constructs an LDA model
/// </summary>
/// <param name="sizeVocab">Size of vocabulary</param>
/// <param name="numTopics">Number of topics</param>
public LDATopicInferenceModel(
int sizeVocab,
int numTopics)
{
SizeVocab = sizeVocab;
NumTopics = numTopics;
//---------------------------------------------
// The model
//---------------------------------------------
NumWordsInDoc = Variable.New<int>().Named("NumWordsInDoc");
Range W = new Range(SizeVocab).Named("W");
Range T = new Range(NumTopics).Named("T");
Range WInD = new Range(NumWordsInDoc).Named("WInD");
Theta = Variable.New<Vector>().Named("Theta");
ThetaPrior = Variable.New<Dirichlet>().Named("ThetaPrior");
ThetaPrior.SetValueRange(T);
Theta = Variable<Vector>.Random(ThetaPrior);
PhiPrior = Variable.Array<Dirichlet>(T).Named("PhiPrior");
PhiPrior.SetValueRange(W);
Phi = Variable.Array<Vector>(T).Named("Phi");
Phi[T] = Variable.Random<Vector, Dirichlet>(PhiPrior[T]);
Words = Variable.Array<int>(WInD).Named("Words");
WordCounts = Variable.Array<double>(WInD).Named("WordCounts");
using (Variable.ForEach(WInD))
{
using (Variable.Repeat(WordCounts[WInD]))
{
var topic = Variable.Discrete(Theta).Attrib(new ValueRange(T)).Named("topic");
topic.SetValueRange(T);
using (Variable.Switch(topic))
Words[WInD] = Variable.Discrete(Phi[topic]);
}
}
Engine = new InferenceEngine(new VariationalMessagePassing());
Engine.Compiler.ShowWarnings = false;
}
示例5: DefineVariablesAndRanges
/// <summary>
/// Defines the variables and the ranges of CBCC.
/// </summary>
/// <param name="taskCount">The number of tasks.</param>
/// <param name="labelCount">The number of labels.</param>
protected override void DefineVariablesAndRanges(int taskCount, int labelCount)
{
WorkerCount = Variable.New<int>().Named("WorkerCount");
m = new Range(CommunityCount).Named("m");
n = new Range(taskCount).Named("n");
c = new Range(labelCount).Named("c");
k = new Range(WorkerCount).Named("k");
// The tasks for each worker
WorkerTaskCount = Variable.Array<int>(k).Named("WorkerTaskCount");
kn = new Range(WorkerTaskCount[k]).Named("kn");
WorkerTaskIndex = Variable.Array(Variable.Array<int>(kn), k).Named("WorkerTaskIndex");
WorkerTaskIndex.SetValueRange(n);
WorkerLabel = Variable.Array(Variable.Array<int>(kn), k).Named("WorkerLabel");
// The background probability vector
BackgroundLabelProbPrior = Variable.New<Dirichlet>().Named("BackgroundLabelProbPrior");
BackgroundLabelProb = Variable<Vector>.Random(BackgroundLabelProbPrior).Named("BackgroundLabelProb");
BackgroundLabelProb.SetValueRange(c);
// Community membership
CommunityProbPrior = Variable.New<Dirichlet>().Named("CommunityProbPrior");
CommunityProb = Variable<Vector>.Random(CommunityProbPrior).Named("CommunityProb");
CommunityProb.SetValueRange(m);
Community = Variable.Array<int>(k).Attrib(QueryTypes.Marginal).Attrib(QueryTypes.MarginalDividedByPrior).Named("Community");
CommunityConstraint = Variable.Array<Discrete>(k).Named("CommunityConstraint");
Community[k] = Variable.Discrete(CommunityProb).ForEach(k);
Variable.ConstrainEqualRandom(Community[k], CommunityConstraint[k]);
// Initialiser to break symmetry for community membership
CommunityInit = Variable.Array<Discrete>(k).Named("CommunityInit");
Community[k].InitialiseTo(CommunityInit[k]);
// Community parameters
CommunityScoreMatrixPrior = Variable.Array(Variable.Array<VectorGaussian>(c), m).Named("CommunityScoreMatrixPrior");
CommunityScoreMatrix = Variable.Array(Variable.Array<Vector>(c), m).Named("CommunityScoreMatrix");
CommunityScoreMatrix[m][c] = Variable<Vector>.Random(CommunityScoreMatrixPrior[m][c]);
CommunityConfusionMatrix = Variable.Array(Variable.Array<Vector>(c), m).Named("CommunityConfusionMatrix");
CommunityConfusionMatrix[m][c] = Variable.Softmax(CommunityScoreMatrix[m][c]);
CommunityScoreMatrix.SetValueRange(c);
// Parameters for each worker
ScoreMatrix = Variable.Array(Variable.Array<Vector>(c), k).Attrib(QueryTypes.Marginal).Attrib(QueryTypes.MarginalDividedByPrior).Named("ScoreMatrix");
ScoreMatrixConstraint = Variable.Array(Variable.Array<VectorGaussian>(c), k).Named("ScoreMatrixConstraint");
WorkerConfusionMatrix = Variable.Array(Variable.Array<Vector>(c), k).Named("ConfusionMatrix");
// The unobserved 'true' label for each task
TrueLabel = Variable.Array<int>(n).Attrib(QueryTypes.Marginal).Attrib(QueryTypes.MarginalDividedByPrior).Named("Truth");
TrueLabelConstraint = Variable.Array<Discrete>(n).Named("TruthConstraint");
TrueLabel[n] = Variable.Discrete(BackgroundLabelProb).ForEach(n);
Variable.ConstrainEqualRandom(TrueLabel[n], TrueLabelConstraint[n]);
// The labels given by the workers
WorkerLabel = Variable.Array(Variable.Array<int>(kn), k).Named("WorkerLabel");
}