Ejemplo n.º 1
0
 def _single_credit_cluster(idx):
     vec = np.zeros(feature_dim, dtype=np.int32)
     vec[idx] = 1
     return ApplicantDistribution(
         features=distributions.Constant(mean=vec),
         group_membership=distributions.Constant(group_membership),
         will_default=distributions.Bernoulli(1 - success_probs[idx]))
Ejemplo n.º 2
0
 def test_mixture_returns_components(self):
     my_distribution = distributions.Mixture(components=[
         distributions.Constant((0, )),
         distributions.Constant((1, ))
     ],
                                             weights=[0.1, 0.9])
     rng = np.random.RandomState(seed=100)
     samples = [my_distribution.sample(rng) for _ in range(1000)]
     self.assertSetEqual(set(samples), {(0, ), (1, )})
     self.assertAlmostEqual(np.mean(samples), 0.9, delta=0.1)
Ejemplo n.º 3
0
 def _single_gmm():
   """Returns a mixture of gaussian applicant distributions."""
   return distributions.Mixture(
       components=[
           ApplicantDistribution(
               features=distributions.Gaussian(mean=mean, std=0.5),
               group_membership=distributions.Constant(group),
               will_default=distributions.Bernoulli(p=default_likelihoods[0])),
           ApplicantDistribution(
               features=distributions.Gaussian(
                   mean=np.array(mean) + np.array(intercluster_vec), std=0.5),
               group_membership=distributions.Constant(group),
               will_default=distributions.Bernoulli(p=default_likelihoods[1]))
       ],
       weights=[0.3, 0.7])
Ejemplo n.º 4
0
    def test_improper_distributions_raise_errors(self):
        for p in [-10, -0.9, 1.3]:
            with self.assertRaises(ValueError):
                _ = distributions.Bernoulli(p=p)

        for vec in [
            [0.1, 0.3, 0.5],  # Does not sum to one.
            [0.5, 0.9, -0.4],  # Has negative values.
        ]:
            with self.assertRaises(ValueError):
                _ = distributions.Mixture(
                    weights=vec,
                    components=[distributions.Constant(mean=(0, ))] * len(vec))
Ejemplo n.º 5
0
 def test_constant_returns_the_same_thing(self):
     my_distribution = distributions.Constant(mean=(0, 1, 2))
     rng = np.random.RandomState(seed=100)
     unique_samples = {my_distribution.sample(rng) for _ in range(1000)}
     self.assertEqual(unique_samples, {(0, 1, 2)})