Completed
Push — master ( 77ef8d...d45822 )
by Simon
02:00
created

LongTermMemory.__init__()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import numpy as np
7
import pandas as pd
8
9
from .memory_load import MemoryLoad
10
from .memory_dump import MemoryDump
11
12
13
class BaseMemory:
14
    def __init__(self, _space_, _main_args_, _cand_):
15
        self._space_ = _space_
16
        self._main_args_ = _main_args_
17
18
        self.pos_best = None
19
        self.score_best = -np.inf
20
21
        self.memory_type = _main_args_.memory
22
        self.memory_dict = {}
23
        self.memory_dict_new = {}
24
25
        self.meta_data_found = False
26
27
        self.n_dims = None
28
29
30
class ShortTermMemory(BaseMemory):
31
    def __init__(self, _space_, _main_args_, _cand_):
32
        super().__init__(_space_, _main_args_, _cand_)
33
34
35
class LongTermMemory(BaseMemory):
36
    def __init__(self, _space_, _main_args_, _cand_):
37
        super().__init__(_space_, _main_args_, _cand_)
38
39
        self._load_ = MemoryLoad(_space_, _main_args_, _cand_)
40
        self._dump_ = MemoryDump(_space_, _main_args_, _cand_)
41
42
    def load_memory(self, _cand_, _verb_):
43
        self.memory_dict = self._load_._load_memory(_cand_, _verb_, self.memory_dict)
44
45
    def save_memory(self, _main_args_, _opt_args_, _cand_):
46
        self._dump_._save_memory(_main_args_, _opt_args_, _cand_, self.memory_dict_new)
47
48
    def _get_para(self):
49
        results_dict = self._dump_._get_opt_meta_data(self.memory_dict)
50
51
        return pd.DataFrame(results_dict["params"])
52
53
    def _get_score(self):
54
        results_dict = self._dump_._get_opt_meta_data(self.memory_dict)
55
        return pd.DataFrame(results_dict["_score_"], columns=["_score_"])
56
57
    """
58
    def _get_hash(self, object):
59
        return hashlib.sha1(object).hexdigest()
60
61
    def _get_func_str(self, func):
62
        return inspect.getsource(func)
63
64
    def _obj2hash(self):
65
        obj2hash_dict = {}
66
        para_hash_list = self._get_para_hash_list()
67
68
        for para_hash in para_hash_list:
69
            obj = self._read_dill(para_hash)
70
            obj2hash_dict[para_hash] = obj
71
72
        return obj2hash_dict
73
    """
74