コード例 #1
0
def getAdditionalIntermediate(stateList, step, viewPoint, detail=False):
    # 指定したステップ番号のデータを取得する
    bState = stateList[step]
    # 取得したデータに対して次の状態を予測する
    aState = manager.predictwithViewPoint(bState, viewPoint)
    # 予測した状態に最も近い状態を stateList から推定する
    output = None
    tempdiff = 1000000000
    for state in stateList:
        if state["step"] <= bState["step"]:
            continue
        curError = manager.calcDifference(state, aState)
        if detail == True:
            debugLine = "[DynamicalProgramming]getAdditionalIntermediate:"
            debugLine += "step:" + str(state["step"])
            debugLine += "\t\terror:" + str(curError)
            print(debugLine)
        # もしtempdiff より小さくなったなら更新する
        if curError < tempdiff:
            tempdiff = curError
            output = state
        # もし tempdiff + RANGE 以上になったなら,
        # もうその先で更新の見込みはないとして終了する
        # elif curError >= tempdiff + 1500:
        elif curError >= 5 * tempdiff:
            print("TOKEN")
            break
    return output
コード例 #2
0
def getWorstData(stateDict, detail=False):
    if detail == True:
        print("[predictMatching]getWorstData:start")
    # TODO 暫定的に「ステップ数の遠いデータにはペナルティ」としよう
    # 本質的ではないので他の方法を考える
    bMean = int(
        sum([b["step"]
             for b in stateDict["before"]]) / len(stateDict["before"]))
    aMean = int(
        sum([a["step"]
             for a in stateDict["after"]]) / len(stateDict["before"]))
    output = {}
    output["score"] = 0
    output["worstIndex"] = -1
    output["worstScore"] = 0
    for i in range(len(stateDict["before"])):
        if detail == True:
            log = "step " + str(i) + "/" + str(len(stateDict["before"]))
            print("[predictMatching]getWorstData:" + log)
        # 学習データをコピーし,テストデータ分をポップ
        tempDict = copy.deepcopy(stateDict)
        tempTest = {}
        tempTest["before"] = tempDict["before"].pop(i)
        tempTest["after"] = tempDict["after"].pop(i)
        tempTest["fname"] = tempDict["fname"].pop(i)
        tempTest["isadd"] = tempDict["isadd"].pop(i)
        # 学習データで学習を行う
        vp = manager.getViewPoint(tempDict)
        # 学習した観点でテストデータの推定を行う
        predicted = manager.predictwithViewPoint(tempTest["before"], vp)
        # 推定結果と実際の状態とのずれを計算する
        error = manager.calcDifference(predicted, tempTest["after"])
        # TODO ステップ数のずれを考慮する
        # TODO 他の方法を考える
        tempsteprate = 2
        error += tempsteprate * (tempTest["before"]["step"] -
                                 bMean) * (tempTest["before"]["step"] - bMean)
        error += tempsteprate * (tempTest["after"]["step"] -
                                 aMean) * (tempTest["after"]["step"] - aMean)
        # ずれが最大を更新したら記録する
        output["score"] += error
        if error > output["worstScore"]:
            if detail == True:
                print("[predictMatching]getWorstData:   updateWorst")
            output["worstIndex"] = i
            output["worstScore"] = error
    # score は平均化
    output["score"] /= len(stateDict["before"])
    if detail == True:
        print("[predictMatching]getWorstData:score:" + str(output["score"]))
    return output
コード例 #3
0
def reproduction(initState, matchingDict):
    manager.show(initState)
    state = copy.deepcopy(initState)
    for vp in matchingDict["viewpoint"]:
        state = manager.predictwithViewPoint(state, vp)
        manager.show(state)