Completed
Push — master ( b4252e...a98e6f )
by Simon
01:25
created

hyperactive.memory.memory.LongTermMemory._get_func_str()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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