-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMetaLearner.py
More file actions
65 lines (46 loc) · 2.27 KB
/
MetaLearner.py
File metadata and controls
65 lines (46 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from Utility import Utility
import numpy as np
class MetaLearner:
def __init__(self):
self._decisionMatrix = {} # Feature Lambda - List of Entries
# [A.1, A.2, B.1, B.2]
self._lambdaID = {} # Index - Feature Lambda
self._lastFeatures = [] # List of Feature Lambdas
def getJSON(self):
outData = {}
for idKey, feature in self._lambdaID.items():
outData[idKey] = self._decisionMatrix[feature]
return outData
def putJSON(self, data):
for idStr, valStrList in data.items():
idKey = Utility.safeCast(idStr, int, -1)
if idKey in self._lambdaID and len(valStrList) == 4:
valList = []
for i in range(4):
valList.append(Utility.safeCast(valStrList[i], int, 0))
self._decisionMatrix[self._lambdaID[idKey]] = valList
def addLambda(self, featureLambda):
# featureLambda # Input : {Capsule, List of Observations}, {Observed Axioms (Capsule), List of Observations}
# # Output : Boolean
self._decisionMatrix[featureLambda] = np.array([0, 0, 0, 0])
self._lambdaID[len(self._lambdaID)] = featureLambda
def checkResults(self, observations : dict, observedAxioms : dict):
totalDecision = np.array([0, 0, 0, 0])
self._lastFeatures = []
for featureLambda in self._decisionMatrix.keys():
if featureLambda(observations, observedAxioms) is True:
totalDecision = np.add(totalDecision, self._decisionMatrix[featureLambda])
self._lastFeatures.append(featureLambda)
maxEntry = np.argmax(totalDecision)
if maxEntry == 0:
return "A non-activated parent capsule is missing a route."
elif maxEntry == 1:
return "A parent capsule is missing."
elif maxEntry == 2:
return "An attribute is lacking training data."
elif maxEntry == 3:
return "An attribute is missing."
def applyOracle(self, oracleDecision : int):
# oracleDecision # Trigger Index
for featureLambda in self._lastFeatures:
self._decisionMatrix[featureLambda][oracleDecision] += 1