Esempio n. 1
0
    def setUp(self):
        self.dim = int(10 + torch.randint(100, (1, 1)).item())
        self.dim = 2

        self.conf_files = []
        for path in glob.glob('./tests/models/*yml'):
            self.conf_files.append(path)
        assert len(self.conf_files) > 0

        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = (1 + torch.randn(self.dim)**2).type(self.type)
        self.models1 = []
        for conf_file in self.conf_files:
            with open(conf_file, 'r') as fid:
                data = fid.read().replace('<feadim>', str(self.dim))
                conf = yaml.load(data)
            model = beer.create_model(conf, self.mean, self.variance)
            self.models1.append(model)

        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = (1 + torch.randn(self.dim)**2).type(self.type)
        self.models2 = []
        for conf_file in self.conf_files:
            with open(conf_file, 'r') as fid:
                data = fid.read().replace('<feadim>', str(self.dim))
                conf = yaml.load(data)
            model = beer.create_model(conf, self.mean, self.variance)
            self.models2.append(model)

        self.weights = (1 + torch.randn(2)**2).type(self.type)
        self.weights /= self.weights.sum()
Esempio n. 2
0
    def setUp(self):
        self.device = 'cpu'
        self.dim = int(10 + torch.randint(100, (1, 1)).item())
        self.npoints = int(1 + torch.randint(100, (1, 1)).item())
        self.data = torch.randn(self.npoints, self.dim).type(self.type)
        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = (1 + torch.randn(self.dim)**2).type(self.type)

        self.conf_files = []
        for path in glob.glob('./tests/models/*yml'):
            if not os.path.basename(path).startswith('normalset') and \
               not os.path.basename(path).startswith('bernoulli'):
                self.conf_files.append(path)
        assert len(self.conf_files) > 0

        self.models = []
        for conf_file in self.conf_files:
            with open(conf_file, 'r') as fid:
                data = fid.read()
                data = data.replace('<feadim>', str(self.dim))
                conf = yaml.load(data)
            model = beer.create_model(conf, self.mean, self.variance)
            self.models.append(model)

        self.acc_stats1 = {
            'shared_key': torch.randn(self.dim).type(self.type),
            'key1': torch.randn(self.dim).type(self.type),
        }
        self.acc_stats2 = {
            'shared_key': torch.randn(self.dim).type(self.type),
            'key2': torch.randn(self.dim).type(self.type),
        }
Esempio n. 3
0
    def setUp(self):
        self.dim = int(1 + torch.randint(100, (1, 1)).item())
        self.npoints = int(1 + torch.randint(100, (1, 1)).item())
        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = 1 + torch.randn(self.dim).type(self.type) ** 2
        self.pseudo_counts = 1e-2 + 100 * torch.rand(1).item()
        self.data = torch.randn(self.npoints, self.dim).type(self.type)
        self.means = torch.randn(self.npoints, self.dim).type(self.type)
        self.vars = torch.randn(self.npoints, self.dim).type(self.type) ** 2

        with open('./tests/models/normal_iso.yml') as fid:
            conf = yaml.load(fid)
        self.model = beer.create_model(conf, self.mean, self.variance)
Esempio n. 4
0
    def test_create_model(self):
        for conf_file in self.conf_files:
            with self.subTest(conf_file=conf_file):
                # Doesn't test the content of the object, just make sure
                # that the creation does not crash and return a valid
                # object.
                with open(conf_file, 'r') as fid:
                    data = fid.read()
                    data = data.replace('<feadim>', str(self.dim))
                    conf = yaml.load(data)
                    model = beer.create_model(conf, self.mean, self.variance)

                self.assertTrue(
                    isinstance(model, beer.BayesianModel)
                    or isinstance(model, torch.nn.Module))
Esempio n. 5
0
    def setUp(self):
        self.dim = int(1 + torch.randint(100, (1, 1)).item())
        self.npoints = int(1 + torch.randint(100, (1, 1)).item())
        self.data = torch.randn(self.npoints, self.dim).type(self.type)
        self.means = torch.randn(self.npoints, self.dim).type(self.type)
        self.vars = torch.randn(self.npoints, self.dim).type(self.type) ** 2
        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = 1 + torch.randn(self.dim).type(self.type) ** 2
        cov = (1 + torch.randn(self.dim)).type(self.type)
        self.cov = torch.eye(self.dim).type(self.type) + torch.ger(cov, cov)
        self.pseudo_counts = 1e-2 + 100 * torch.rand(1).item()
        self.ncomp = int(1 + torch.randint(100, (1, 1)).item())
        self.prior_mean = torch.randn(self.dim).type(self.type)

        with open('./tests/models/normalset_full_sharedcov.yml') as fid:
            conf = yaml.load(fid)
        self.model = beer.create_model(conf, self.mean, self.variance)
Esempio n. 6
0
    def setUp(self):
        self.dim = int(10 + torch.randint(100, (1, 1)).item())
        self.dim_subspace = int(1 + torch.randint(self.dim - 1, (1, 1)).item())
        self.npoints = int(1 + torch.randint(100, (1, 1)).item())
        self.data = torch.randn(self.npoints, self.dim).type(self.type)
        self.latent = torch.randn(self.npoints,
                                  self.dim_subspace).type(self.type)
        self.means = torch.randn(self.npoints, self.dim).type(self.type)
        self.vars = torch.randn(self.npoints, self.dim).type(self.type)**2

        # Create the PPCA model
        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = 1 + torch.randn(self.dim).type(self.type)**2
        with open('./tests/models/ppca.yml') as fid:
            conf = yaml.load(fid)
        self.model = beer.create_model(conf, self.mean, self.variance)

        self.dim_subspace = self.model.subspace.shape[0]
Esempio n. 7
0
    def setUp(self):
        self.npoints = int(1 + torch.randint(100, (1, 1)).item())
        self.dim = int(1 + torch.randint(100, (1, 1)).item())
        self.data = torch.randn(self.npoints, self.dim).type(self.type)
        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = 1 + torch.randn(self.dim).type(self.type) ** 2
        self.means = torch.randn(self.npoints, self.dim).type(self.type)
        self.vars = torch.randn(self.npoints, self.dim).type(self.type) ** 2
        self.pseudo_counts = 1e-2 + 100 * torch.rand(1).item()
        self.ncomp = int(1 + torch.randint(100, (1, 1)).item())
        self.weights = (1 + torch.randn(self.ncomp) ** 2).type(self.type)
        self.weights /= self.weights.sum()

        self.mixtures = []
        for path in glob.glob('./tests/models/*yaml'):
            if os.path.basename(path).startswith('mixture'):
                with open(path) as fid:
                    conf = yaml.load(fid)
                    model = beer.create_model(conf, self.mean, self.variance)
                self.mixtures.append(model)
Esempio n. 8
0
    def setUp(self):
        self.dim = int(10 + torch.randint(100, (1, 1)).item())
        self.nclasses = int(1 + torch.randint(20, (1, 1)).item())
        self.dim_subspace1 = int(1 +
                                 torch.randint(self.dim - 1, (1, 1)).item())
        self.dim_subspace2 = int(1 +
                                 torch.randint(self.dim - 1, (1, 1)).item())
        self.npoints = int(1 + torch.randint(100, (1, 1)).item())
        self.data = torch.randn(self.npoints, self.dim).type(self.type)
        self.means = torch.randn(self.npoints, self.dim).type(self.type)
        self.vars = torch.randn(self.npoints, self.dim).type(self.type)**2

        # Create the PLDA model
        self.mean = torch.randn(self.dim).type(self.type)
        self.variance = 1 + torch.randn(self.dim).type(self.type)**2
        with open('./tests/models/plda.yml') as fid:
            conf = yaml.load(fid)
        self.model = beer.create_model(conf, self.mean, self.variance).modelset

        self.dim_subspace1 = self.model.noise_subspace.shape[0]
        self.dim_subspace2 = self.model.class_subspace.shape[0]