Пример #1
0
    def optimize_hypers(self, comp, vals, labels):
        # First the GP to observations
        mygp = gp.GP(self.cov_func.__name__)
        mygp.real_init(comp.shape[1], vals)
        mygp.optimize_hypers(comp, vals)
        self.mean = mygp.mean
        self.ls = mygp.ls
        self.amp2 = mygp.amp2
        self.noise = mygp.noise

        # Now the GP to times
        timegp = gp.GP(self.cov_func.__name__)
        timegp.real_init(comp.shape[1], labels)
        timegp.optimize_hypers(comp, labels)
        self.constraint_mean = timegp.mean
        self.constraint_amp2 = timegp.amp2
        self.constraint_noise = timegp.noise
        self.constraint_ls = timegp.ls

        # Save hyperparameter samples
        self.hyper_samples.append((self.mean, self.noise, self.amp2, self.ls))
        self.constraint_hyper_samples.append(
            (self.constraint_mean, self.constraint_noise, self.constraint_amp2,
             self.constraint_ls))
        self.dump_hypers()
Пример #2
0
    def __init__(self):

        # read the bag file LOCATION from a json file:
        try:
            with open('bagfile_location.json') as f:
                data = json.load(f)
                self.bagfile = data["bagfile_path"]
        except IOError:
            print(
                "Please create a JSON file containing the location of your " +
                "bag file. \nCreate a dictionary, set the key \"bagfile_path\" equal "
                +
                "to the path, and save to a file named \"bagfile_location.json\"."
            )
            return

        # variable for sensor topic
        self.sensor_topic = '/kf1/simulated_sensor/raw'
        self.counter = 0

        print("Reading bagfile \"" + self.bagfile + "\"")
        self.bag = rosbag.Bag(self.bagfile)

        sensor_msg_cnt = self.bag.get_message_count(self.sensor_topic)
        print("Read %d messages from the bagfile. " % sensor_msg_cnt)

        # initialize arrays to contain gps_data and sensor_data

        self.gps_data = np.zeros((sensor_msg_cnt, 2))
        self.sensor_data = np.zeros((sensor_msg_cnt, 1))

        # initialize variables
        self.cur_data = None
        self.cur_data_lat = None
        self.cur_data_long = None

        self.gaussian = gp.GP()

        # subscribers
        self.sensor = rospy.Subscriber("/kf1/simulated_sensor/raw",
                                       Measurement, self.callback)
        #self.goto = rospy.Subscriber("/kf1/waypoint_goto_result", Int8, self.goto_hotspot)

        #self.goto = rospy.Subscriber("/kf1/waypoint_goto_result", Int8, self.callback_chloro)
        print("after callback")

        rospy.wait_for_message("/kf1/simulated_sensor/raw", Measurement)
        #rospy.wait_for_message("/kf1/waypoint_goto_result", Int8)

        print("received message")

        self.go_to = rospy.ServiceProxy('/kf1/goto', Goto)

        #self.set_waypoint(self.go_to)
        self.controller()
    def optimize_hypers(self, comp, vals):
        mygp = gp.GP(self.cov_func.__name__)
        mygp.real_init(comp.shape[1], vals)
        mygp.optimize_hypers(comp, vals)
        self.mean = mygp.mean
        self.ls = mygp.ls
        self.amp2 = mygp.amp2
        self.noise = mygp.noise

        # Save hyperparameter samples
        self.hyper_samples.append((self.mean, self.noise, self.amp2, self.ls))
        self.dump_hypers()

        return
Пример #4
0
    generation = 100
    skip = 5
    input_path = args.input_path
    output_path = args.output_path

    if args.population:
        population = args.population
    if args.perturbation:
        perturbation = args.perturbation
    if args.generation:
        generation = args.generation
    if args.skip:
        skip = args.skip

    print("* Scanning original malware sample")
    fbytes = open(input_path, "rb").read()
    original = gp.origin(input_path, fbytes)

    with open(output_path, "a") as wf:
        wf.write("original file: " + input_path + "\nVT result: " +
                 str(original.vt_result) + "\nVT detection list:" +
                 str(original.vt_dlist) + "\n\n")
    print("\nOriginal file: " + input_path)
    print("VirusTotal detection rate: " + str(original.vt_result))
    print("")

    print("* Starting GP malware generation\n")
    print("* 1 generation\n")
    g = gp.GP(fbytes, population, perturbation, output_path, skip)
    g.generation(original, generation)
Пример #5
0
        self.bag.close()

    def show_sensor_data(self, save_to_file=False):

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        ax.scatter(self.gps_data[:, 0], self.gps_data[:, 1], self.sensor_data)
        if save_to_file:
            plt.savefig("sensor_data.pdf")
        else:
            plt.show()


if __name__ == "__main__":

    rospy.init_node('gp_movement', anonymous=True)

    n = node()

    print("after node")

    process = gp.GP(n.gps_data, n.sensor_data)
    print("after gp")
    model = process.gaussian_proc()

    while not rospy.is_shutdown():
        rospy.spin()

#data_sub = ()