// Samples a TagInputDistribution and returns a TagInputValue with the sampled value. public static TagInputValue sampleInput(TagInputDistribution tagInputDist) { // Sample the IDistribution. // Note that only the IContinuousDistribution and IDiscreteDistribution have a Sample function, // and that the IDistribution by itself does not include a Sample function in the interface. double sampledValue; if (tagInputDist.distribution is IDiscreteDistribution) { sampledValue = ((IDiscreteDistribution)tagInputDist.distribution).Sample(); } else if (tagInputDist.distribution is IContinuousDistribution) { sampledValue = ((IContinuousDistribution)tagInputDist.distribution).Sample(); } else { throw new Exception("tag distribution is not IDiscreteDistribution or IContinuousDistribution."); } // Create a new TagInputValue and populate its fields. TagInputValue tagInputValue; tagInputValue.tag = tagInputDist.tag; tagInputValue.modality = tagInputDist.modality; tagInputValue.value = sampledValue; return(tagInputValue); }
/* * The delegate method for handling collectionChanged events on the filter for detecting touch events. * Only called when the RFIDReader is initializing the BernoulliFilterDict. */ void touchDistributionDelegate(ConcurrentDictionary <string, Bernoulli> touchDict) { foreach (KeyValuePair <string, Bernoulli> item in touchDict) { TagInputDistribution tagDict = new TagInputDistribution(); tagDict.tag = item.Key; tagDict.modality = Modality.touch; tagDict.distribution = item.Value; this.tagFeatureDistributions.Enqueue(tagDict); } }
/* * The delegate method for handling collectionChanged events on the filter for detecting velocity events. * Only called when the RFIDReader is initializing the GaussianFilterDict. */ void velocityDistributionDelegate(ConcurrentDictionary <string, Normal> velocityDict) { foreach (KeyValuePair <string, Normal> item in velocityDict) { TagInputDistribution tagDict = new TagInputDistribution(); tagDict.tag = item.Key; tagDict.modality = Modality.velocity; tagDict.distribution = item.Value; this.tagFeatureDistributions.Enqueue(tagDict); } // Don't trigger another report of tag updates until the application has finished processing // the ones we just enqueued. // Only called in the velocity distribution delegate because it is called second. RFIDReader.shouldReportTagDistributions = false; }