Exemple #1
0
    def todb(self, features, targets):
        """Function to convert numpy arrays to basic db."""
        data = np.concatenate((features, np.reshape(targets,
                                                    (len(targets), 1))),
                              axis=1)
        uid = [str(uuid.uuid4()) for _ in range(len(targets))]
        data = np.concatenate((np.reshape(uid, (len(uid), 1)), data), axis=1)

        descriptors = ['f' + str(i) for i in range(np.shape(features)[1])]
        targets = ['target']
        names = descriptors + targets

        # Set up the database to save system descriptors.
        dd = DescriptorDatabase(db_name=self.db_name, table=self.table)
        dd.create_db(names=names)

        # Fill the database with the data.
        dd.fill_db(descriptor_names=names, data=data)
Exemple #2
0
    def test_storage(self):
        """Test database functions."""
        # Define variables for database to store system descriptors.
        db_name = '/vec_store.sqlite'
        descriptors = ['f' + str(i) for i in range(np.shape(self.data)[1])]
        targets = ['Energy']
        names = descriptors + targets

        # Set up the database to save system descriptors.
        dd = DescriptorDatabase(db_name=wkdir + db_name, table='FingerVector')
        dd.create_db(names=names)

        # Put data in correct format to be inserted into database.
        print('Generate the database')
        new_data = []
        for i, a in zip(self.data, self.all_cand):
            d = []
            d.append(a.info['unique_id'])
            for j in i:
                d.append(j)
            d.append(a.info['key_value_pairs']['raw_score'])
            new_data.append(d)

        # Fill the database with the data.
        dd.fill_db(descriptor_names=names, data=new_data)

        # Test out the database functions.
        train_fingerprint = dd.query_db(names=descriptors)
        train_target = dd.query_db(names=targets)
        print('\nfeature data for candidates:\n', train_fingerprint,
              '\ntarget data for candidates:\n', train_target)

        cand_data = dd.query_db(unique_id='7a216711c2eae02decc04da588c9e592')
        print('\ndata for random candidate:\n', cand_data)

        all_id = dd.query_db(names=['uuid'])
        dd.create_column(new_column=['random'])
        for i in all_id:
            dd.update_descriptor(descriptor='random',
                                 new_data=random(),
                                 unique_id=i[0])
        print('\nretrieve random vars:\n', dd.query_db(names=['random']))

        print('\nretrieved column names:\n', dd.get_column_names())