Esempio n. 1
0
def run_seism_experiment():
    input_file = "eQnoise.csv"
    generate_data.run(input_file)
    print("time is :%f secs" % ((clk.time() - t0) / 60.))
    model_params = swarm_over_data()
    print("time is :%f secs" % ((clk.time() - t0) / 60.))
    print(model_params)
    if PLOT:
        pass
        #output = NuPICPlotOutput("sine3_output", show_anomaly_score=True)
    else:
        output = NuPICFileOutput("eQnoise_output", show_anomaly_score=True)
    print("time is :%f min" % ((clk.time() - t0) / 60.))
    model = ModelFactory.create(model_params)
    model.enableInference({"predictedField": "acc"})

    with open(input_file, "rb") as data_input:
        csv_reader = csv.reader(data_input)

        # skip header rows
        csv_reader.next()
        csv_reader.next()
        csv_reader.next()

        # the real data
        for row in csv_reader:
            time = float(row[0])
            acc_value = float(row[1])
            result = model.run({"acc": acc_value})
            output.write(time, acc_value, result, prediction_step=PSTEPS)

    output.close()
    print("time is :%f min" % ((clk.time() - t0) / 60.))
Esempio n. 2
0
def run(fname="verylargeseism_out"):
    print("reading %s" % input_file)
    print("using this model: ", model_params)
    model = ModelFactory.create(model_params)
    model.enableInference({"predictedField": "acc"})
    print("created nupic model in :%f min" % ((clk.time() - t0) / 60.))
    print("will output predictions and anomalies \n in this file: %s" % fname)

    output = NuPICFileOutput(fname, show_anomaly_score=True)
    with open(input_file, "rb") as data_input:
        csv_reader = csv.reader(data_input)

        # skip header rows
        csv_reader.next()
        csv_reader.next()
        csv_reader.next()

        # the real data
        for row in csv_reader:
            time = float(row[0])
            acc_value = float(row[1])
            result = model.run({"acc": acc_value})
            output.write(time, acc_value, result, prediction_step=PSTEPS)

    output.close()
    print("time is :%f min" % ((clk.time() - t0) / 60.))
Esempio n. 3
0
def predict():
    from model_0 import model_params
    input_file = "sine.csv"
    model = ModelFactory.create(model_params.MODEL_PARAMS)
    model.enableInference({"predictedField": "sine"})

    output = NuPICFileOutput("sine_output", show_anomaly_score=True)

    with open(input_file, "rb") as sine_input:
        csv_reader = csv.reader(sine_input)

        # skip header rows
        csv_reader.next()
        csv_reader.next()
        csv_reader.next()

        # the real data
        for row in csv_reader:
            angle = float(row[0])
            sine_value = float(row[1])
            result = model.run({"sine": sine_value})
            output.write(angle, sine_value, result, prediction_step=1)
    output.close()
    for i in range(Data.shape[1]):
        input_file = '/opt/share_code_data/' + str(Data.columns[i]) + '.csv'
        with open(input_file, "rb") as sine_input:
            csv_reader = csv.reader(sine_input)
            # the real data

            # skip header rows
            csv_reader.next()
            csv_reader.next()
            csv_reader.next()

            for row in csv_reader:
                timeS = row[0]
                value = float(row[6])
                result = model.run({"value": value})
                output.write(timeS, value, result, prediction_step=3)

#对leftD数据进行操作
maxl = 0
maxi = -1
for i in range(leftD.shape[1]):  #找出最长的非0序列
    if maxl < len(np.nonzero(leftD.iloc[:, i] == 0)):
        maxl = len(np.nonzero(leftD.iloc[:, i] == 0))
        maxi = i
if maxi != -1:
    data = leftD.values[np.nonzero(leftD.values[:, maxi] != 0)[0],
                        maxi]  #swarm只考虑非0数据
    paras = swarm(data, number=maxi, col=leftD.columns[maxi])  #运行swarm
    print('paras: ', paras)  #best params
    model = ModelFactory.create(paras)
    model.enableInference({"predictedField": "value"})