本文整理汇总了C#中Bernoulli.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Bernoulli.Select方法的具体用法?C# Bernoulli.Select怎么用?C# Bernoulli.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bernoulli
的用法示例。
在下文中一共展示了Bernoulli.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JAll_j
private double JAll_j(int index, Bernoulli[] activityPosteriors, Marginals priors)
{
// var prevProbs = activityPosteriors.Select(ia => new Bernoulli(ia)).ToArray();
hypothesisActivityPosteriors = activityPosteriors.Select(ia => new Bernoulli(ia)).ToArray();
// Get datum
// var datum = DataSet.GetSubSet(0, index);
bool trueLabel = DataSet.Labels[0][index];
// Create copies of the Labelled an Unlabelled sets
var labelled = new HashSet<int>(Labelled);
var unlabelled = new HashSet<int>(Unlabelled);
labelled.Add(index);
unlabelled.Remove(index);
// datum.Labels[0][0] = true;
DataSet.Labels[0][index] = true;
// Learn as if positive
// var positivePosteriors = TrainModel.Train(datum, priors, 1);
Marginals positivePosteriors = priors;
try
{
positivePosteriors = TrainModel.Train(DataSet.GetSubSet(0, index), priors, 1);
}
catch (ImproperMessageException)
{
// As fallback use priors
}
// recompute probabilities
CalculateProbabilities(positivePosteriors);
//var jjposl = JL(labelled);
//var jjposu = JU(unlabelled);
var Jjpos = (JAll()) * (1.0 - hypothesisActivityPosteriors[index].GetMean());
// Restore posteriors
labelled.Add(index);
unlabelled.Remove(index);
// datum.Labels[0][0] = false;
DataSet.Labels[0][index] = false;
// Learn as if negative
// var negativePosteriors = TrainModel.Train(datum, priors, 1);
Marginals negativePosteriors = priors;
try
{
negativePosteriors = TrainModel.Train(DataSet.GetSubSet(0, index), priors, 1);
}
catch (ImproperMessageException)
{
// As fallback use priors
}
// recompute probabilities
CalculateProbabilities(negativePosteriors);
//var jjnegl = JL(labelled);
//var jjnegu = JU(unlabelled);
var Jjneg = (JAll()) * (hypothesisActivityPosteriors[index].GetMean());
// restore posteriors
// activityPosteriors = prevProbs;
DataSet.Labels[0][index] = trueLabel;
var voi = Jjpos + Jjneg;
return voi;
}
示例2: GetArgMaxVOI
// /// <summary>
// /// Gets the value of information.
// /// </summary>
// /// <value>The value of information.</value>
// public double[] GetValueOfInformation()
// {
// double jall = JAll();
// return Unlabelled.Select(index => VOI(jall, index)).ToArray();
// }
/// <summary>
/// Gets the argument maxising the Value of information.
/// </summary>
/// <param name="activityPosteriors">Activity posteriors.</param>
/// <param name="priors">Priors.</param>
/// <param name="argMax">Argument max.</param>
/// <param name="maxVal">Max value.</param>
public override void GetArgMaxVOI(Bernoulli[] activityPosteriors, Marginals priors, out int argMax, out double maxVal)
{
hypothesisActivityPosteriors = activityPosteriors.Select(ia => new Bernoulli(ia)).ToArray();
double jall = JAll();
var unlabelled = Unlabelled.ToArray();
argMax = -1;
maxVal = Reversed ? double.PositiveInfinity : double.NegativeInfinity;
var signs = new double[unlabelled.Length];
var vois = new double[unlabelled.Length];
for (int i = 0; i < unlabelled.Length; i++)
{
var index = unlabelled[i];
vois[i] = VOI(jall, index, activityPosteriors, priors);
signs[i] = Math.Sign(vois[i]) / 2.0 + 0.5;
//Console.Write( "." );
//Console.WriteLine( "y_true: {0}", labels[0][ind] );
//Console.WriteLine( "y_hat: {0}", probs[ind] );
//Console.WriteLine( "VOJ_{0}: {1}", ind, voi );
//Console.WriteLine();
if (Reversed)
{
if (vois[i] < maxVal || argMax < 0)
{
maxVal = vois[i];
argMax = index;
}
}
else
{
if (vois[i] > maxVal || argMax < 0)
{
maxVal = vois[i];
argMax = index;
}
}
}
//Console.WriteLine();
//Console.WriteLine( "\n+ivity: {0}", signs.Average() );
}