Exemplo n.º 1
0
    def __init__(self, x, y):
        C = self.__class__
        models = []
        # for each coloumn of y
        for yi in y.T:

            # write the file
            xy = np.column_stack((x, np.ones(yi.size), yi))
            hdr = str(xy.shape).replace('(', '').replace(')',
                                                         '').replace(',', '')
            s = str(xy).replace('[', '').replace(']', '')
            fops.write_data(C.IFILE, hdr + '\n' + s)
            # run klinreg
            U.strict_call([C.KLINREG, C.IFILE, C.K, '-d'])
            # read the output
            affine_funs = np.loadtxt(C.MODELFILE)

        for yi in y.T:
            model = skl_lm.TheilSenRegressor(copy_X=True,
                                             fit_intercept=True,
                                             n_jobs=1)
            #model = skl_lm.HuberRegressor(fit_intercept=True)
            model.fit(x, yi)
            models.append(model)
            coefs.append(model.coef_)
            intercepts.append(model.intercept_)

        self.coef = np.array(coefs)
        self.intercept = np.array(intercepts)

        # TODO: hack!
        self.fit_error_ = cons.zero2ic(x.ndim)
Exemplo n.º 2
0
def test_pickling(pwa_rep, pickle_fname):
    pickled_pwa_w = pickle.dumps(pwa_rep, pickle.HIGHEST_PROTOCOL)
    fops.write_data(pickle_fname, pickled_pwa_w)
    pickled_pwa_r = fops.get_data(pickle_fname)
    return pickle.loads(pickled_pwa_r)
Exemplo n.º 3
0
def main(pickle_file, sal_module_name):
    pwa_rep = get_pwa_model(pickle_file)
    sal_trans_sys = vdp_pwa2sal(pwa_rep, sal_module_name)
    sal_file = sal_module_name + '.sal'
    fops.write_data(sal_file, str(sal_trans_sys))
Exemplo n.º 4
0
 def dump(self):
     fops.write_data(self.sal_file, str(self.sal_trans_sys).encode())
     return
Exemplo n.º 5
0
 def dump(self):
     sal_file = self.module_name + '.sal'
     fops.write_data(sal_file, str(self.sal_trans_sys))
     return
Exemplo n.º 6
0
def test_pickling(pwa_rep, pickle_fname):
    pickled_pwa_w = pickle.dumps(pwa_rep, pickle.HIGHEST_PROTOCOL)
    fops.write_data(pickle_fname, pickled_pwa_w)
    pickled_pwa_r = fops.get_data(pickle_fname)
    return pickle.loads(pickled_pwa_r)
Exemplo n.º 7
0
def main(pickle_file, sal_module_name):
    pwa_rep = get_pwa_model(pickle_file)
    sal_trans_sys = vdp_pwa2sal(pwa_rep, sal_module_name)
    sal_file = sal_module_name + '.sal'
    fops.write_data(sal_file, str(sal_trans_sys))
Exemplo n.º 8
0
def pretty_print(sys, prop, vs, pwa_model, init_cons, final_cons, init_ps,
                 final_ps, fname_constructor, sys_name, model_type, *args):
    sep = '-' * 20
    s = []

    s += ['system: {}'.format(sys)]
    s += ['type: {}'.format(type(sys))]
    s += [sep]

    s += ['prop: {}'.format(prop)]
    s += ['type: {}'.format(type(prop))]
    s += [sep]

    s += ['variables: {}'.format(vs)]
    s += ['type: {} of {}'.format(type(vs), type(list(vs)[0]))]
    s += [sep]

    s += ['pwa-model: {}'.format(pwa_model)]
    s += ['type: {}'.format(type(pwa_model))]
    s += [sep]

    s += ['constraints on the INITIAL states: {}'.format(init_cons)]
    s += ['type: {}'.format(type(init_cons))]
    s += [sep]

    s += ['constraints on the ERROR/FINAL states: {}'.format(final_cons)]
    s += ['type: {}'.format(type(final_cons))]
    s += [sep]

    s += ['Initial locations: {}'.format(init_ps)]
    s += ['type: {} of {}'.format(type(init_ps), type(list(init_ps)[0]))]
    s += [sep]

    s += ['Final locations:{}'.format(final_ps)]
    s += ['type:{} of {}'.format(type(final_ps), type(list(final_ps)[0]))]
    s += [sep]

    s += [
        'convinience function for constructing a filename by prepending the path of the directory and the name of the fname_constructortem and time stamp to a string: {}'
        .format(fname_constructor)
    ]
    s += [
        'usage: fname_constructor("example_dump.log") := {}'.format(
            fname_constructor('example_dump.log'))
    ]
    s += [sep]

    s += ['name of the sys_nametem: {}'.format(sys_name)]
    s += ['type: {}'.format(type(sys_name))]
    s += [sep]

    s += ['type of pwa_model: {}'.format(model_type)]
    s += ['type: {}'.format(type(model_type))]
    s += [sep]

    s += pretty_print_pwa_model(pwa_model)

    fname = fname_constructor('pretty_print_bmc_args')
    fops.write_data(fname, '\n'.join(s))

    print(TERM.green('pretty printing output: {}'.format(fname)))
    print('exiting...')
    exit(0)
    return