def newInterceptionPoint(self,world_state): """ For times 1 to 20 (in seconds) - finds the ball's position at this time - finds the robot travel time to this point - if the travel time plus some buffer is less than the ball time - Then new interception at this point. Sets driver target. """ # How many seconds ahead of the ball the robot has to arrive at # a point for it to be an 'intercept' point. travel_buffer = 1.0 found = False print "Finding new Interception" for ball_time in [x * 0.1 for x in range(1,50)]: if not found: ball_pos = Predictions.predictBallPos(world_state, ball_time) travel_time = predictRobotMovementTime(world_state, ball_pos) if (travel_time + travel_buffer < ball_time): interceptstring = "Interception at " + str(ball_pos) + " from " + str(world_state.myPos) timestring = "Robot time: " + str(travel_time) + " Ball Time " + str(ball_time) print interceptstring print timestring Log("Intercept",interceptstring) Log("Intercept",timestring) self.driver.target = ball_pos self.interception = True found = True if not found: print "Could not find interception"
def imdisplay(): img = os.listdir( '/Users/Charles/Documents/Spiced/FinalProject/flask/static/images/') images = [] Type = [] cs = [] Wrongcol1 = [] Wrongcol2 = [] for i in img: path = f'/Users/Charles/Documents/Spiced/FinalProject/flask/static/images/{i}' type1, type2, color = pr.prediction(path) images.append(i) #return images,Type1,Type2,Type0 Type0 = type1 + ", " + type2 + ", " + color Type.append(Type0) colorsearch = session.get("cs", None) if colorsearch == color or colorsearch == "": cs.append(1) if type1 == "Environmental" or type2 == "Secondary": Wrongcol1.append(i) Wrongcol2.append(Type0) else: cs.append(0) Wrongcol1.append(i) Wrongcol2.append(Type0) session['wrongcol1'] = Wrongcol1 session['wrongcol2'] = Wrongcol2 return render_template('ImDisplay.html', img=zip(images, Type, cs))
def iterate(self, world_state, frametime): """ Finds a predicted point of the ball in the future to drive to based upon distance from robot to ball. """ self.timer += frametime self.timer2 += frametime instructions = self.driver.iterate(world_state, frametime) if self.timer2 > 0.1: self.timer2 = 0.0 # Get distance between ball and robot. Predict some time in future based on this # For a full span of the pitch (640 pixels) predict 3 seconds in the future. # Shrink this based on distance to the ball dist = distance(world_state.ballPos, world_state.myPos)# + 30 time = (3/640.0) * dist print "Current ball position is: " + str(world_state.ballPos) predicted_ball_pos = Predictions.predictBallPos(world_state, time) print "Target position is: " + str(predicted_ball_pos) if length(world_state.ballVel) > 20: self.go += 1 if self.go >= 3: self.driver.target = predicted_ball_pos else: self.driver.target = world_state.myPos else: self.driver.target = world_state.myPos return instructions
def iterate(self, world_state, frametime): """ Finds a predicted point of the ball in the future to drive to based upon distance from robot to ball. """ self.timer += frametime self.timer2 += frametime instructions = self.driver.iterate(world_state, frametime) if self.timer2 > 0.1: self.timer2 = 0.0 # Get distance between ball and robot. Predict some time in future based on this # For a full span of the pitch (640 pixels) predict 3 seconds in the future. # Shrink this based on distance to the ball dist = distance(world_state.ballPos, world_state.myPos) # + 30 time = (3 / 640.0) * dist print "Current ball position is: " + str(world_state.ballPos) predicted_ball_pos = Predictions.predictBallPos(world_state, time) print "Target position is: " + str(predicted_ball_pos) if length(world_state.ballVel) > 20: self.go += 1 if self.go >= 3: self.driver.target = predicted_ball_pos else: self.driver.target = world_state.myPos else: self.driver.target = world_state.myPos return instructions
def vect_Knn(x_train, x_test, y_train, y_test): vectorizer = TfidfVectorizer(min_df=5, max_df = 0.9, sublinear_tf=True, use_idf=True,ngram_range=(1,4),strip_accents='unicode',lowercase=True) train_corpus_tf_idf = vectorizer.fit_transform(x_train) test_corpus_tf_idf = vectorizer.transform(x_test) model=KNeighborsRegressor(n_neighbors=2) model.fit(train_corpus_tf_idf,y_train) result = model.predict(test_corpus_tf_idf) print("MAE=", mae(result,y_test), "//", "acc=", pred.acc(result,y_test), "MSE=", mse(result,y_test) ) return model.predict(train_corpus_tf_idf),result
def GetSentimentForDF(_df): _df['text'] = _df.text.apply(tp.expand_contractions) _df['text'] = _df.text.apply(tp.scrub_words) _df['text'] = _df.text.apply(tp.remove_accented_chars) print(_df) review_data_loader = Unseen_Dataloader(_df) data = next(iter(review_data_loader)) print(data.keys()) unsen_review_texts, unseen_pred, unseen_pred_probs = pred.Get_unseen_Prediction(md.model,review_data_loader) print("BERT Prediction is made!!!!!") return unseen_pred
def predict_ball(self): #PREDICTIONS #torque coefficients T_r = 36.07956616966136 # torque coefficient for roll T_p = 12.14599781908070 # torque coefficient for pitch T_y = 8.91962804287785 # torque coefficient for yaw #boost vector in car coordinates # boostVector = np.array([self.controller_state.boost * 991.666, 0, 0]) #Get values at tk and tk - 1 self.s_before = self.s_now self.s_now = self.ball.position self.v_before = self.v_now self.v_now = self.ball.velocity # self.p0 = self.p1 #position vector at initial time # self.p1 = self.car.position #position vector at tk+1 # self.v0 = self.v1 #velocity at prior frame # self.v1 = self.car.velocity # self.q0 = self.q1 #Orientation at prior frame # self.q1 = self.CoordinateSystems.Qworld_to_car.conjugate.normalised # self.w0 = self.w1 #angular velocity at prior frame # self.w1 = self.car.angular_velocity # self.a0 = self.a1 #accelreation vector at prior frame # self.a1 = self.CoordinateSystems.toWorldCoordinates(boostVector) # self.T0 = self.T1 #Torque vector at prior frame # self.T1 = np.array([self.controller_state.roll * T_r, self.controller_state.pitch * T_p, self.controller_state.yaw * -1 * T_y]) # aavg = (self.a1 + self.a0) / 2 # vavg = (self.v1 + self.v0 / 2) # predictedp1, predictedv1 = Predictions.predict(self.p0, self.v0, self.q0, self.w0, aavg, self.T0, self.t0, self.t1) self.ballposition = Predictions.predictBallTrajectory( self.ball, self.t1) self.ballerror = Predictions.ballPredictionError( self.s_before, self.s_now, self.v_before, self.v_now, self.t0, self.t1) self.ballerror = self.ballerror**(1 / 2) self.time_to_ground, self.s_ground = Predictions.predict_ball_to_ground( self.ball, self.t1)
def getNextStage(userId, stage, text): if stage is None: return stages[0] option = findOption(stage, text) currentId = stage["id"]; #Фильтр мата: если сматерились, то переходим на стадию "Мат" и отражаем мат для проверки в следующем сообщении if containsSwear(text): reflectSwear(userId) return getSwearResponseJson(stage) if stage["id"] == "Мат": clickedExcuseButton = option is not None if containsExcuses(text) or clickedExcuseButton: return createExcuseStage(userId, stage) else: return getSwearRefusementJson(stage) #################### result = None # Когда текст не подходит по возможным вариантам. if option is None and stage["id"] not in ["Вопрос", "Задание вопроса"]: result = stage result["text"] = "Я тебя не понял. Лучше выбери ответ!" else: nextId = option["nextId"] result = findStageById(nextId) result = result #Вставка предсказания в ответ, если нажали на предсказание if nextId == "Результат предсказания": result["text"] = Predictions.getPrediction(userId) #Установка статуса подписки (Хочу получать предсказания по утрам / хочу прервать подписку) if shouldChangeSubscriptionStatus(result): changeSubscriptionStatus(userId, result) #Подписаться, когда нажали на кнопку подписки if nextId == "Рассылка": Broadcast.subscribe(userId) #Отписаться, когда нажали на кнопку отписки if nextId == "Отписка": Broadcast.unsubscribe(userId) return result
def vect_lasso(x_train, x_test, y_train, y_test): vectorizer = TfidfVectorizer(min_df=5, max_df = 0.9, sublinear_tf=True, use_idf=True,ngram_range=(1,4),strip_accents='unicode',lowercase=True) train_corpus_tf_idf = vectorizer.fit_transform(x_train) test_corpus_tf_idf = vectorizer.transform(x_test) train_tf_idf=np.hstack((train_corpus_tf_idf.toarray(), (train_corpus_tf_idf != 0).sum(1) )) test_tf_idf=np.hstack((test_corpus_tf_idf.toarray(), (test_corpus_tf_idf != 0).sum(1) )) train_tf_idf=sparse.csr_matrix(train_tf_idf) test_tf_idf=sparse.csr_matrix(test_tf_idf) model=linear_model.Lasso(alpha=0.001) model.fit(train_tf_idf,y_train) result = model.predict(test_tf_idf) print("MAE=", mae(result,y_test), "//", "acc=", pred.acc(result,y_test),"//", "MSE=", mse(result,y_test) ) return model.predict(train_tf_idf),result
def predict_car(self): #torque coefficients T_r = 36.07956616966136 # torque coefficient for roll T_p = 12.14599781908070 # torque coefficient for pitch T_y = 8.91962804287785 # torque coefficient for yaw boostVector = np.array( [float(self.controller_state.boost) * (991.666 + 60), 0, 0]) #Get values at tk and tk - 1 self.s_before = self.s_now self.s_now = self.ball.position self.v_before = self.v_now self.v_now = self.ball.velocity self.p0 = self.p1 #position vector at initial time self.p1 = self.car.position #position vector at tk+1 self.v0 = self.v1 #velocity at prior frame self.v1 = self.car.velocity self.q0 = self.q1 #Orientation at prior frame self.q1 = self.CoordinateSystems.Qworld_to_car.conjugate.normalised self.w0 = self.w1 #angular velocity at prior frame self.w1 = self.car.angular_velocity self.a0 = self.a1 #accelreation vector at prior frame self.a1 = self.CoordinateSystems.toWorldCoordinates(boostVector) self.T0 = self.T1 #Torque vector at prior frame self.T1 = np.array([ self.controller_state.roll * T_r, self.controller_state.pitch * T_p, self.controller_state.yaw * -1 * T_y ]) aavg = (self.a1 + self.a0) / 2 vavg = (self.v1 + self.v0) / 2 # def predict(position, velocity, q, omega, a, torques, t0, t1): predictedp1, predictedv1 = Predictions.predict(self.p0, self.v0, self.q0, self.w0, aavg, self.T0, self.t0, self.t1) self.errorv = ((predictedv1 - self.v1) * 100 / self.v1)**2 self.errorp = ((predictedp1 - self.p1) * 100 / self.p1)**2
def newInterceptionPoint(self, world_state): """ For times 1 to 20 (in seconds) - finds the ball's position at this time - finds the robot travel time to this point - if the travel time plus some buffer is less than the ball time - Then new interception at this point. Sets driver target. """ # How many seconds ahead of the ball the robot has to arrive at # a point for it to be an 'intercept' point. travel_buffer = 1.0 found = False print "Finding new Interception" for ball_time in [x * 0.1 for x in range(1, 50)]: if not found: ball_pos = Predictions.predictBallPos(world_state, ball_time) travel_time = predictRobotMovementTime(world_state, ball_pos) if (travel_time + travel_buffer < ball_time): interceptstring = "Interception at " + str( ball_pos) + " from " + str(world_state.myPos) timestring = "Robot time: " + str( travel_time) + " Ball Time " + str(ball_time) print interceptstring print timestring Log("Intercept", interceptstring) Log("Intercept", timestring) self.driver.target = ball_pos self.interception = True found = True if not found: print "Could not find interception"
def makeBroadcastPredictionStage(userId): result = findStageById("Результат предсказания") result["text"] = Predictions.getPrediction(userId) result["options"] = findStageById("Рассылка")["options"] return result
def get_output(self, packet: GameTickPacket) -> SimpleControllerState: #Original Code my_car = packet.game_cars[self.index] ball_location = Vector2(packet.game_ball.physics.location.x, packet.game_ball.physics.location.y) car_location = Vector2(my_car.physics.location.x, my_car.physics.location.y) car_direction = get_car_facing_vector(my_car) car_to_ball = ball_location - car_location #update class data self.car.update(packet.game_cars[self.index]) self.ball.update(packet.game_ball) self.CoordinateSystems.update(self.car, self.ball) self.BallController.update(packet.game_ball) self.ball.x = packet.game_ball.physics.location.x self.ball.y = packet.game_ball.physics.location.y self.ball.z = packet.game_ball.physics.location.z # t = packet.game_info.seconds_elapsed #print(packet.game_cars[self.index]) carBallAngle = getAngle( packet.game_ball.physics.location.x - self.car.x, packet.game_ball.physics.location.z - self.car.z, 0, 0) # print('z:', self.car.z, 'vz:', self.car.vz, 'y:', self.car.y, 'vy:', self.car.vy, 'x:', self.car.x, 'vx:', self.car.vx, 'pitch:', self.car.pitch, 'roll: ', self.car.roll, 'yaw:', self.car.yaw) #fixing pitch since RL uses euler angles pi = math.pi p = float(self.car.pitch) r = float(self.car.roll) y = float(self.car.yaw) curang = float(getXZangle(p, r, y)) # print('actual pitchL', actualPitch[0]) #Create desired and current vectors [x, z, theta, vx, vz, omegay] # self.current = np.matrix([self.car.z, self.car.x, actualPitch, self.car.vz, self.car.vx, self.car.wy]) # self.desired = np.matrix([800, self.car.x, math.pi/4, self.car.vz, self.car.vx, self.car.wy]) self.current = np.matrix([curang, self.car.wy]) self.desired1 = np.matrix([-1 * float(carBallAngle[0]), 0]) self.desired2 = self.desired1 #np.matrix([-2, 0]) #calculate Adesired As = 900 #uu/s2 Ag = np.matrix([0, -650]) theta = carBallAngle Adesired = np.matrix([(As * math.cos(theta)), (As * math.sin(theta))]) Aa = Adesired - Ag Ax = float(Aa.item(0)) Az = float(Aa.item(1)) Ax2 = math.pow(Ax, 2) Az2 = math.pow(Az, 2) A = (math.sqrt(Ax2 + Az2)) boostPercent = A / 991.666 * 100 boostPercent = max(min(boostPercent, 100), 0) thetaActual = getAngle(Aa.item(0), Aa.item(1), 0, 0) # print('Theta actual:', thetaActual, 'Aactual: ', Aa, 'boost percent: ', boostPercent) thetaDesired = np.matrix([-1 * float(thetaActual), 0]) #Quaternion stuff q0 = Quaternion(axis=[1., 0., 0.], radians=self.car.roll) q1 = Quaternion(axis=[0., 1., 0.], radians=self.car.pitch) q2 = Quaternion(axis=[0., 0., 1.], radians=-1 * self.car.yaw) q3 = q0 * q1 * q2 xprime = q3.rotate([1, 0, 0]) qcar = q3.rotate([1., 0., 0.]) # print('xprime: ', xprime, 'q3:', q3) #get point vectors for car and ball ux = np.array([1., 0., 0.]) uy = np.array([0., 1., 0.]) uz = np.array([0., 0., 1.]) Pb = np.array([ packet.game_ball.physics.location.x, packet.game_ball.physics.location.y, packet.game_ball.physics.location.z ]) Pc = np.array([ self.car.x, self.car.y, self.car.z ]) #negate z because z axis for car is pointed downwards Pbc = np.subtract(Pb, Pc) #Get vector to ball from car in car coordinates xyz = np.cross( ux, Pbc) #xyz of quaternion is rotation between Pbc and unit x vector w = math.sqrt(1 * ( (Pbc.item(0)**2) + (Pbc.item(1)**2) + (Pbc.item(2)**2))) + np.dot(ux, Pbc) #scalr of quaternion qbcworld = Quaternion(w=w, x=xyz.item(0), y=xyz.item(1), z=xyz.item(2)) eulerAngles = toEulerAngle( qbcworld.unit) #convert quaternion to euler angles #getting quaternion describing car orientation qw2c = Quaternion(w=0, x=self.car.roll, y=self.car.pitch, z=self.car.yaw) # Pcar = qw2c.unit.rotate(ux) q0 = Quaternion(axis=[1., 0., 0.], radians=self.car.roll) q1 = Quaternion(axis=[0., 1., 0.], radians=self.car.pitch) q2 = Quaternion(axis=[0., 0., -1.], radians=self.car.yaw) q3 = q0.unit * q1.unit * q2.unit Pcar = q3.unit.rotate(ux) # print('pcar', xprime, 'pitch', self.car.pitch) xyzCar = np.cross( ux, Pcar) #xyz of quaternion is rotation between Pbc and unit x vector wCar = math.sqrt(1 * ( (Pcar.item(0)**2) + (Pcar.item(1)**2) + (Pcar.item(2)**2))) + np.dot(ux, Pcar) #scalr of quaternion qcarworld = Quaternion(w=wCar, x=xyzCar.item(0), y=xyzCar.item(1), z=xyzCar.item(2)) #Angular Velocity Inputs to the control algorithm omegades = np.matrix([0, 0, 0]) omegacur = self.CoordinateSystems.w_car #get current position of trajectory time = packet.game_info.seconds_elapsed Pdes, Vdes = self.Trajectory.circularTrajectory(1000, .5, time, 1500) #A, w, t, height # Pdes = np.array([self.ball.x, self.ball.y, self.ball.z]) # Vdes = np.array([self.ball.vx, self.ball.vy, self.ball.vz]) #CONTROL SYSTEM ALGORITHMS #get acceleration vector Pcur = np.array([self.car.x, self.car.y, self.car.z]) Vcur = np.array([self.car.vx, self.car.vy, self.car.vz]) acc, accMagnitude = getAccelerationVector(Pdes, Pcur, Vdes, Vcur) accfix = np.array([-1 * acc.item(0), acc.item(1), acc.item(2)]) boostPercent = accMagnitude / 991.666 * 100 boostPercent = max(min(boostPercent, 100), 0) # print('acc:', acc, 'accmag', accMagnitude) Qworld_to_acceleration_vector = self.CoordinateSystems.createQuaternion_world_at_car( accfix) torques = getTorques(self.CoordinateSystems.Qworld_to_car, Qworld_to_acceleration_vector, omegades, omegacur) #True Proportionanl navigation #Send Data to feedbackcontroller #self.car.printVals(); if (self.counter.count < self.counter.lap1): self.fbController.pitchControl(thetaDesired, self.current) #try only controlling z velocity # self.fbController.pitchControl(self.car.z, self.car.x, self.car.pitch, self.car.vz, self.car.vx, self.car.wz, self.car.z, self.car.x, self.car.pitch, self.car.vz, self.car.vx, self.car.wz) self.counter.increment() if (self.counter.count >= self.counter.lap1) and (self.counter.count < self.counter.lap2): self.fbController.pitchControl(thetaDesired, self.current) # self.fbController.pitchControl(0, 0, 0, 10, 0, 0, self.car.z, self.car.x, self.car.pitch, self.car.vz, self.car.vx, self.car.wz) self.counter.increment() if (self.counter.count >= self.counter.lap2): self.counter.reset() #Setting Controller state from values in controller #boost value # self.controller_state.boost = self.boostCounter.boost(60) # self.controller_state.boost = 1 self.controller_state.boost = self.boostCounter.boost(boostPercent) # # #roll, pitch, yaw values self.controller_state.pitch = max(min(torques.item(1), 1), -1) self.controller_state.roll = max(min(torques.item(0), 1), -1) self.controller_state.yaw = -1 * max( min(torques.item(2), 1), -1 ) #changes in rotations about coordinate system cause z axis changes # self.controller_state.pitch = 0 # self.controller_state.roll = 0 # self.controller_state.yaw = 0 #changes in rotations about coordinate system cause z axis changes # self.controller_state.pitch = 0.0#max(min(torques.item(1), 1), -1) #self.fbController.pitchPercent # self.controller_state.roll = 0.0#max(min(torques.item(0), 1), -1) # self.controller_state.yaw = 1#max(min(torques.item(2), 1), -1) #Make car jump if its on the floor if (packet.game_cars[self.index].has_wheel_contact): self.controller_state.jump = True else: self.controller_state.jump = False #Contol ball for testing functions x, y, z, vi = self.BallController.bounce(500, 500, 300, 1500) Vt = self.BallController.rotateAboutZ(np.matrix([0, 0, 0]), math.pi / 10) p = np.array([-1000, -1000, 100]) v = np.array([800, 0, 1500]) ballpos, ballvel = self.BallController.projectileMotion(p, v) # vx = self.BallController.oscillateX(-1500, 0, 1000) vx = Vt.item(0) vy = Vt.item(1) # vz = 0 #Set ball and car states to set game state for testing ball_state1 = BallState( Physics(location=Vector3(x, y, z), velocity=Vector3(0, 0, vi))) ball_state2 = BallState( Physics(location=Vector3(ballpos[0], ballpos[1], ballpos[2]), velocity=Vector3(ballvel[0], ballvel[1], ballvel[2]))) # ball_state = BallState(Physics(velocity = Vector3(vx, vy, 1))) # , # car_state = CarState(jumped=True, double_jumped=False, boost_amount=0, # physics=Physics(location = Vector3(-1000, 0, 500),velocity=Vector3(0, 0, 0), rotation = Rotator(pitch = eulerAngles.item(1), yaw = eulerAngles.item(2), roll = eulerAngles.item(0)))) car_state = CarState(jumped=True, double_jumped=False, boost_amount=1, physics=Physics( location=Vector3(-500, -1500, 500), velocity=Vector3(0, 0, 0), rotation=Rotator(pitch=math.pi / 1.9, yaw=0.1, roll=0), angular_velocity=Vector3(0, 0, 0))) # car_state2 = CarState(jumped=True, double_jumped=False, boost_amount=0, # physics=Physics(location = Vector3(00, 0, 500),velocity=Vector3(0, 0, 0))) #Pointed down car state for maximum initial error # car_state = CarState(jumped=True, double_jumped=False, boost_amount=1, # physics=Physics(location = Vector3(500, 0, 500),velocity=Vector3(0, 0, 1100), rotation = Rotator(yaw = math.pi/2, pitch = -1*math.pi/2, roll = math.pi/2))) if (self.BallController.release == 0): game_state = GameState(ball=ball_state2, cars={self.index: car_state}) self.set_game_state(game_state) # game_state = GameState(ball = ball_state)#, cars = {self.index: car_state}) # self.set_game_state(game_state) #PREDICTIONS #torque coefficients T_r = 36.07956616966136 # torque coefficient for roll T_p = 12.14599781908070 # torque coefficient for pitch T_y = 8.91962804287785 # torque coefficient for yaw #boost vector in car coordinates boostVector = np.array([self.controller_state.boost * 991.666, 0, 0]) #Get values at tk and tk - 1 self.t0 = self.t1 self.t1 = packet.game_info.seconds_elapsed self.p0 = self.p1 #position vector at initial time self.p1 = self.car.position #position vector at tk+1 self.v0 = self.v1 #velocity at prior frame self.v1 = self.car.velocity self.q0 = self.q1 #Orientation at prior frame self.q1 = self.CoordinateSystems.Qworld_to_car.conjugate.normalised self.w0 = self.w1 #angular velocity at prior frame self.w1 = self.car.angular_velocity self.a0 = self.a1 #accelreation vector at prior frame self.a1 = self.CoordinateSystems.toWorldCoordinates(boostVector) self.T0 = self.T1 #Torque vector at prior frame self.T1 = np.array([ self.controller_state.roll * T_r, self.controller_state.pitch * T_p, self.controller_state.yaw * -1 * T_y ]) aavg = (self.a1 + self.a0) / 2 vavg = (self.v1 + self.v0 / 2) predictedp1, predictedv1 = Predictions.predict(self.p0, self.v0, self.q0, self.w0, aavg, self.T0, self.t0, self.t1) errorv = (predictedv1 - self.v1)**2 errorp = (predictedp1 - self.p1)**2 # print("error^2 v:", errorv, "error^2 p:", errorp) # print("z actual:", self.car.z, "z predicted:", predictedp1[2]) self.data.add(self.v1[0], predictedv1[0], errorv[0], self.t1) #PLOTTING if (self.plotTime0 == None): self.plotTime0 = packet.game_info.seconds_elapsed else: self.plotTime1 = packet.game_info.seconds_elapsed if (self.plotTime1 != None): if ((self.plotTime1 - self.plotTime0) > 10): # self.plotData(self.data) None #RENDERING # self.renderer.begin_rendering() # # #helpful vectors for rendering # car = np.array([self.car.x, self.car.y, self.car.z]).flatten() # ball = np.array([self.ball.x, self.ball.y, self.ball.z]).flatten() # origin = np.array([0,0,0]) # #World coordinate system # self.renderer.draw_line_3d(np.array([0,0,0]), np.array([500,0,0]), self.renderer.red()) # self.renderer.draw_line_3d(np.array([0,0,0]), np.array([0,500,0]), self.renderer.green()) # self.renderer.draw_line_3d(np.array([0,0,0]), np.array([0,0,500]), self.renderer.blue()) # # #Car coordinate system # headingx = 100*self.CoordinateSystems.toWorldCoordinates(np.array([1,0,0])) #multiply by 100 to make line longer # headingy = 100*self.CoordinateSystems.toWorldCoordinates(np.array([0,1,0])) # headingz = 100*self.CoordinateSystems.toWorldCoordinates(np.array([0,0,1])) # self.renderer.draw_line_3d(np.array([self.car.x, self.car.y, self.car.z]), np.array([self.car.x + headingx.item(0), self.car.y + headingx.item(1), self.car.z + headingx.item(2)]), self.renderer.red()) # self.renderer.draw_line_3d(np.array([self.car.x, self.car.y, self.car.z]), np.array([self.car.x + headingy.item(0), self.car.y + headingy.item(1), self.car.z + headingy.item(2)]), self.renderer.green()) # self.renderer.draw_line_3d(np.array([self.car.x, self.car.y, self.car.z]), np.array([self.car.x + headingz.item(0), self.car.y + headingz.item(1), self.car.z + headingz.item(2)]), self.renderer.blue()) # # #Car direction vector on world coordinate system # self.renderer.draw_line_3d(np.array([0,0,0]), np.array([headingx.item(0), headingx.item(1), headingx.item(2)]), self.renderer.red()) # self.renderer.draw_line_3d(np.array([0,0,0]), np.array([headingy.item(0), headingy.item(1), headingy.item(2)]), self.renderer.green()) # self.renderer.draw_line_3d(np.array([0,0,0]), np.array([headingz.item(0), headingz.item(1), headingz.item(2)]), self.renderer.blue()) # # #Draw position of ball after converting from Pball_car to Pball_world # # desired = np.array(self.CoordinateSystems.getVectorToBall_world()).flatten() # # self.renderer.draw_line_3d(car, car + desired, self.renderer.yellow()) # # #Car to ball vector # # # self.renderer.draw_rect_3d(car+desired, 100, 100, 0, self.renderer.teal()) # # #Acceleration vector # a = np.array([accfix.item(0), -1*accfix.item(1),-1*accfix.item(2)]) # self.renderer.draw_line_3d(car, car + a/10, self.renderer.pink()) # # #trajectory vector # self.renderer.draw_line_3d(origin, Pdes, self.renderer.orange()) # # #error rectangles velocities # self.renderer.draw_rect_2d(10,10,int(errorv[0]**(1/2)), 50, True, self.renderer.cyan()) # self.renderer.draw_rect_2d(10,60,int(errorv[1]**(1/2)), 50, True, self.renderer.cyan()) # self.renderer.draw_rect_2d(10,110,int(errorv[2]**(1/2)), 50, True, self.renderer.cyan()) # #text for velocity errors # self.renderer.draw_string_2d(10, 10, 1, 1, "X velocity Error: " + str(errorv[0]**(1/2)), self.renderer.white()) # self.renderer.draw_string_2d(10, 60, 1, 1, "Y velocity Error: " + str(errorv[1]**(1/2)), self.renderer.white()) # self.renderer.draw_string_2d(10, 110, 1, 1, "Z velocity Error: " + str(errorv[2]**(1/2)), self.renderer.white()) # #positions # self.renderer.draw_rect_2d(10,160,int(errorp[0]**(1/2)), 50, True, self.renderer.red()) # self.renderer.draw_rect_2d(10,210,int(errorp[1]**(1/2)), 50, True, self.renderer.red()) # self.renderer.draw_rect_2d(10,260,int(errorp[2]**(1/2)), 50, True, self.renderer.red()) # # self.renderer.draw_string_2d(10, 160, 1, 1, 'X position Error: ' + str(errorp[0]**(1/2)), self.renderer.white()) # self.renderer.draw_string_2d(10, 210, 1, 1, "Y position Error: " + str(errorp[1]**(1/2)), self.renderer.white()) # self.renderer.draw_string_2d(10, 260, 1, 1, "Z position Error: " + str(errorp[2]**(1/2)), self.renderer.white()) # # self.renderer.end_rendering() #printing # print('wx:', self.car.wx, 'wy:', self.car.wy, 'wz:', self.car.wz) return self.controller_state
converted_test = prepro.load("converted_test") #Sinon pour recommancer toute la création de la base : X_train,X_test,y_train,y_test,converted_train,converted_test = prepro.create_dataset(train,test,mot_model) #sauvegarder les bases obtenus : prepro.dump_all(X_train,X_test,y_train,y_test,converted_train,converted_test) """ #### BAG OF WORDS ET LASSO POUR VISUALISATION DES VARIABLES IMPORTANTES #### """ #data pour benchmark avec tf idf X=bow_lasso.transform_bench(pd.concat([train,test])) y=np.hstack((y_train,y_test)) #Regression lineaire pred.eval_std(pred.LinearRegression(),X,y,"regression lineaire",n_bootstrap=10) #8 PPV pred.eval_std(pred.KNeighborsClassifier(n_neighbors=8),X,y,"8 PPV",n_bootstrap=10) #Lasso pred.eval_std(pred.linear_model.LassoCV(cv=3),X,y,"Lasso",n_bootstrap=10) #Visualisation LASSO data_lasso,y_lasso = bow_lasso.prep(data) data_lasso_transformed,_ = bow_lasso.transform(data_lasso) viz_class = bow_lasso.lasso_viz_imp(20) #pour prendre la classe python qui va plot et donner les variables importantes #selon le chemin de regularisation lasso viz_class.fit(data_lasso_transformed,y_lasso) viz_class.estimate()