Commit 07011571 authored by Adam Fekete's avatar Adam Fekete

adding datamodel class and future version of GP

parent a7360329
from DataModel.baseclasses import DataModel
from collections import namedtuple
import numpy as np
### Subsampling from big database ###
### Spliting database in training/testing sets ###
class ForceConfs(DataModel):
def __init__(self, confs=[], force=[]):
"""
:param force: array of forces
:type force: np.array
:param confs: array of configurations
"""
assert len(confs) == len(force)
self.confs = confs
self.force = force
def __str__(self):
out = 'ForceConfs model\n' + \
' # of configuration: {}\n'.format(len(self.confs)) +\
' range of configurations: mean={2}, min={0}, max={1}\n'.format(*self.range())
return out
def __len__(self):
"""
:return: length of the forces/configurations
"""
return len(self.confs)
def range(self):
"""
Determine the minimum and maximum length for a given list of configurations
:return: namedtuple('LengthRange', ['min', 'max', 'mean'])
"""
lengths = [len(conf) for conf in self.confs]
LengthRange = namedtuple('LengthRange', ['min', 'max', 'mean'])
return LengthRange(min=np.min(lengths), max=np.max(lengths), mean=np.mean(lengths))
# return np.min(lengths), np.max(lengths), np.mean(lengths)
def read_json_data(self, filename):
import json
with open(filename, 'r') as jsonfile:
data = json.load(jsonfile)['data']
self.confs = [timestep['confs'] for timestep in data]
self.force = [timestep['force'] for timestep in data]
self.confs = np.asarray(self.confs)
self.force = np.asarray(self.force)
def subsampling(self, train: int = 0, test: int = 0, random: bool = True) -> None:
self.nsample = train + test
if random:
inds = range(len(self))
inds = np.random.choice(inds, size=self.nsample, replace=False)
self.train_confs = self.confs[inds[0:train]]
self.train_force = self.force[inds[train:]]
if __name__ == '__main__':
filename = '../Data/Si_TB_300K.json'
data = ForceConfs()
data.read_json_data(filename)
print(data)
data.subsampling(40,10)
print(len(data.train_confs))
print(len(data.train_force))
print('END')
from .ForceConfs import ForceConfs
__all__ = ["ForceConfs"]
\ No newline at end of file
from abc import ABCMeta
class DataModel(metaclass=ABCMeta):
pass
# from bokeh.plotting import figure, output_file, show
# output_file("test.html")
# p = figure()
# p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
# show(p)
# from plotly import __version__
#
# from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
#
# print(__version__) # requires version >= 1.9.0
#
# from plotly.graph_objs import Scatter, Figure, Layout
#
# plot([Scatter(x=[1, 2, 3], y=[3, 1, 6])])
#
#
# import plotly
# from plotly.graph_objs import Scatter, Layout
#
# plotly.offline.plot({
# "data": [Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
# "layout": Layout(title="hello world")
# })
import plotly
from plotly.graph_objs import Scatter, Layout
plotly.offline.init_notebook_mode()
plotly.offline.iplot({
"data": [Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
"layout": Layout(title="hello world")
})
\ No newline at end of file
from .baseclass import GaussianProcess
from typing import Optional
from typing import Union, List, Dict
class GPVec(GaussianProcess):
def __init__(self,
kernel: Optional[str] = None,
datamodel=None):
"""
sdfdsfdf
:param kernel: Hello
:type kernel: Optional[str]
:param datamodel:
"""
super().__init__()
self.datamodel = datamodel # type: Optional[str]
self.kernel = kernel # kernel functions
pass
def fit(self, X, Y):
pass
def predict(self): pass
# def __repr__(self):
# return "%s(%r)" % (self.__class__, self.__dict__)
def __str__(self):
out = 'GaussianProcess:\n' +\
' datamodel: {}\n'.format(self.datamodel) +\
' kernel: {}\n'.format(self.kernel)
return out
from .GPVec import GPVec
__all__=['GPVec']
\ No newline at end of file
from abc import ABCMeta, abstractmethod, abstractproperty
class GaussianProcess(metaclass=ABCMeta):
# @abstractproperty
# def kernel(self): pass
@abstractmethod
def fit(self): pass
@abstractmethod
def predict(self): pass
class Kernel(metaclass=ABCMeta):
pass
class FeatureSpace(metaclass=ABCMeta):
pass
from GP.baseclass import FeatureSpace
class cov_mat(FeatureSpace):
pass
if __name__ == '__main__':
m = cov_mat()
print(m)
\ No newline at end of file
from .id import id
__all__ = ['id']
if __name__ == '__main__':
pass
from GP.baseclass import Kernel
class id(Kernel):
def __call__(self, *args, **kwargs):
return 1.0
import json
def read_json_data(filename):
with open(filename, 'r') as jsonfile:
data = json.load(jsonfile)
return data['data']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment