import os, sys, inspect, json
import numpy as np

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

try:
    from ..bal import Bal
    from ..mybal import MyBal
    from .util import trainTwo, touchFilter
except Exception: #ImportError
    from bal import Bal
    from mybal import MyBal
    from util import trainTwo

@np.vectorize
def identity(x):
    return x

# init training data
with open("./hand_som.somdata") as f:
    data = json.load(f)

labeled = [(np.array(i['pos']), np.array(i["touch"])) for i in data]

vanila    = Bal(len(data[0]["pos"]), 180, len(data[0]["touch"]))
alphaDes = MyBal(len(labeled[0][0]), 180, len(labeled[0][1]), enhanceLearning=identity)

trainTwo(
    model1=vanila, train1=labeled, name1="processed",
    model2=alphaDes, train2=labeled, name2="alpha dec",
    epoch=1000
)
