def generate_samples(self, n):
        '''
        Generate and save samples to
        the SQLite sample db for this
        model.
        '''
        if self.inference_method != 'sample_db':
            raise IncorrectInferenceMethodError(
                'generate_samples() not support for inference method: %s' % \
                self.inference_method)
        valid_samples = 0
        if not hasattr(self, 'sample_ordering'):
            self.sample_ordering = self.discover_sample_ordering()
        fn = [x[0].name for x in self.sample_ordering]
        sdb = self.sample_db
        while valid_samples < n:
            try:
                sample = self.get_sample()
            except InvalidSampleException:
                # TODO: Need to figure
                # out why we get invalid
                # samples.
                continue
            sdb.save_sample([(v.name, v.value) for v in sample])
            valid_samples += 1
        sdb.commit()
        print '%s samples stored in %s' % (n, self.sample_db_filename)
dataset/ETHPy150Open eBay/bayesian-belief-networks/bayesian/factor_graph.py/FactorGraph.generate_samples/original