Exemplo n.º 1
0
def testSPS():
    from util.util import interval
    from module.Module import Constant
    config = SPSConfig.SPSConfig()
    moduleFactory = ModuleFactory(config)
    modelfactory = ModelFactory(moduleFactory)
    model = modelfactory.get_built()
    ltl = ['U[1, {0}]'.format(730), 'T', 'failure']  # 一年之内系统失效
    checker = Checker(model, ltl, duration=730, fb=False)
    wrapper = ExperimentWrapper(checker, samples_per_param=100)
    trainx = interval(1, 10, 0.5)
    testx = interval(1, 10, 0.1)
    thickness_params = [Constant('SCREEN_THICKNESS', st) for st in trainx]
    wrapper.setconstants([thickness_params])
    result = wrapper.do_expe()
    cases = map(lambda tuple: tuple[0], result)
    labels = map(lambda tuple: tuple[1], result)

    regressor = BPNeuralNetwork()
    regressor.setup(1, 5, 1)
    regressor.train(cases, labels)

    test_cases = map(lambda c: Constant('SCREEN_THICKNESS', c), testx)
    test_labels = [regressor.predict(test_case) for test_case in testx]
    # 对多组参数进行模型验证
    # logger.info("mc begin")
    #
    wrapper.setconstants([test_cases])
    # mcresult = wrapper.modelcheck()
    # mc_labels = map(lambda tuple: tuple[1], mcresult)

    plt.plot(testx, [i[0] for i in test_labels], label='predict')
    # plt.plot(map(lambda const: const.get_value(), test_cases), mc_labels, label='mc')
    plt.show()
Exemplo n.º 2
0
def test():
    model = ModelFactory.get_built()
    model.duration = 730
    model.prepare()
    thrd = StepGenThd(model.gen_next_step(), model.steps_queue)
    thrd.start()
    thrd.join()
    print model.steps_queue.qsize()
Exemplo n.º 3
0
def do_expr_built():
    model = ModelFactory.get_built()
    checker = Checker(model=model, ltl=ltl, duration=TIME_LIMIT_IN_DAYS*2)
    # wrapper = ExperimentWrapper(checker, samples_per_param=SAMPLES_PER_PARAM)
    wrapper = ExperimentWrapper(checker)
    wrapper.setconstants([thickness_cnsts,])
    logger.info("Built model expr began.")
    result = wrapper.do_expe()
    logger.info("Built model expr end.")
    return result
Exemplo n.º 4
0
def test_built():
    built = ModelFactory.get_built()
    built.prepareCommands()
    pr = cProfile.Profile()
    pr.enable()
    result, path = built.gen_random_path(duration=duration)
    pr.disable()
    print "len of path:{}".format(len(path))
    s = StringIO.StringIO()
    sortby = "cumulative"
    ps = pstats.Stats(pr, stream=io.FileIO("./built",
                                           mode='w')).sort_stats(sortby)
    ps.print_stats()
    print s.getvalue()
Exemplo n.º 5
0
def test():
    built = ModelFactory.get_built()
    day_vals = range(1, 311, 50)
    logger.info("day_vals = {}".format(day_vals))
    sb_module = built.getModuleByName("SB")
    sb_fail_cmd = sb_module.getCommand("sb_fail_cmd")
    s3r_module = built.getModuleByName("S3R")
    s3r_fail_cmd = s3r_module.getCommand("s3r_fail_cmd")
    for day_val in day_vals:
        built.setVariable("day", day_val)
        sb_fail_prob = sb_fail_cmd.prob()/4.0
        s3r_fail_prob = s3r_fail_cmd.prob()/4.0
        logger.info("day={}".format(day_val) + ", sb_fail_prob=" + format(sb_fail_prob, '.15e'))
        logger.info("day={}".format(day_val) + ", s3r_fail_prob=" + format(s3r_fail_prob, '.15e'))
Exemplo n.º 6
0
def t2(model=None):
    '''测试built模型运行checker的结果与PRISM中运行的一致'''
    prism_result_x, prism_result_y = get_prism_checking_result()  # (1, 5, 1)
    checker = get_checker(ModelFactory.get_built())
    samplesize = checker.get_sample_size()
    thickness = range(1, 6)
    probs = []
    # logger = get_logger()
    for t in thickness:
        ModelFactory.setParam("SCREEN_THICKNESS", t)
        checker.model.prepare()
        probs.append(checker.run_checker())
    # logger.info("samples={},c={},d={}".format(samplesize, c, d))
    # logger.info(probs)
    for v1, v2 in zip(probs, prism_result_y[-(len(probs)):]):
        pass
Exemplo n.º 7
0
def test_built():
    built = ModelFactory.get_built()
    built.prepare()
    pr = cProfile.Profile()
    pr.enable()
    path = built.get_random_path_V2()
    pr.disable()
    # id1 = id(path[0].ap_set)
    # id2 = id(path[1].ap_set)
    print "len of path:{}".format(len(path))
    s = StringIO.StringIO()
    sortby = "cumulative"
    ps = pstats.Stats(pr, stream=io.FileIO("./built",
                                           mode='w')).sort_stats(sortby)
    ps.print_stats()
    print s.getvalue()
Exemplo n.º 8
0
def getBuiltModel():
    return ModelFactory.get_built()