Example #1
0
    def test_sourceprior_save_default(self):
        prior = sourcePrior.SourcePrior("testSourceA")
        prior.save()

        retrievedPrior = sourcePrior.SourcePrior().get_prior(
            source="testSourceA")
        self.assertTrue(retrievedPrior.source == prior.source,
                        "values must be the same")
Example #2
0
    def test_sourceprior_save(self):
        prior = sourcePrior.SourcePrior("testSourceA",
                                        mean=10.0,
                                        variance=100.0,
                                        cov=0.5)
        prior.save()

        retrievedPrior = sourcePrior.SourcePrior().get_prior(
            source="testSourceA")
        self.assertTrue(retrievedPrior.cov == prior.cov,
                        "values must be the same")
Example #3
0
    def getObservedValueEstimate(self, dataPoints, source, property):
        # get the source predicate prior
        self = PropertyPrior().get_prior(source, property)
        kbPrior = sourcePrior.SourcePrior().get_prior(source)
        estimatedMeanVariance = None
        n = len(dataPoints)
        dataY = [y for (_, y) in dataPoints]
        mlMean = statistics.mean(dataY)

        assumedKnownVariance = math.pow(kbPrior.cov * mlMean, 2)

        # if this is the first time predicate is being observed in the source,
        # then use the source prior as the prior variance for the source-predicate variance,
        # and then use the mean of the observed values as the mean of the prior mean.
        # update the source-predicate prior
        # else if the predicate already has a source-property prior entry,
        # then use the Gaussian params to estimate posterior mean and variance

        # if spp != None:
        estimatedMeanVariance = self.posterior(dataPoints,
                                               assumedKnownVariance)

        # update the source priors
        kbPrior.posterior(dataPoints,
                          knownMean=estimatedMeanVariance[0],
                          knownVariance=estimatedMeanVariance[1])
        return estimatedMeanVariance
Example #4
0
 def test_get_source_posterior(self):
     prior = sourcePrior.SourcePrior("testSourceA",
                                     mean=10.0,
                                     variance=100.0,
                                     cov=0.5)
     data = [("A", 20.0), ("B", 25), ("C", 20), ("D", 30.0)]
     posterior = prior.posterior(data, 20.0, 100.0)
     self.assertTrue(posterior[0] > 0, "positive posterior required")
Example #5
0
 def test_get_prop_posterior(self):
     kb_prior = sourcePrior.SourcePrior("testSourceA",
                                        mean=10.0,
                                        variance=100.0)
     kb_prior.save()
     prior = propertyPrior.PropertyPrior("testSourceA",
                                         "propA",
                                         mean=5.0,
                                         variance=10)
     data = [("A", 20.0), ("B", 25), ("C", 20), ("D", 30.0)]
     posterior = prior.posterior(data, knownVariance=100.0)
     self.assertTrue(posterior[0] > 0, "positive posterior required")
Example #6
0
 def test_get_observed_estimate_value(self):
     kb_prior = sourcePrior.SourcePrior("testSourceA",
                                        mean=10.0,
                                        variance=100.0)
     kb_prior.save()
     prior = propertyPrior.PropertyPrior("testSourceA",
                                         "propA",
                                         mean=5.0,
                                         variance=10)
     data = [("A", 20.0), ("B", 25), ("C", 20), ("D", 30.0)]
     posterior = prior.getObservedValueEstimate(data, "testSourceA",
                                                "propA")
     self.assertTrue(posterior[0] > 0, "positive posterior required")