Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/tests/prediction.txt @ 1028:cc5cb04b04b0
major update using the trafficintelligence package name and install through pip
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 15 Jun 2018 11:19:10 -0400 |
| parents | python/tests/prediction.txt@933670761a57 |
| children | aafbc0bab925 |
comparison
equal
deleted
inserted
replaced
| 1027:6129296848d3 | 1028:cc5cb04b04b0 |
|---|---|
| 1 >>> from prediction import * | |
| 2 >>> import moving, storage, utils | |
| 3 >>> from numpy import absolute, array | |
| 4 | |
| 5 >>> et = PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0)) | |
| 6 >>> et.predictPosition(4) # doctest:+ELLIPSIS | |
| 7 (4.0...,0.0...) | |
| 8 >>> et.predictPosition(1) # doctest:+ELLIPSIS | |
| 9 (1.0...,0.0...) | |
| 10 | |
| 11 >>> et = PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0), moving.NormAngle(0.1,0), maxSpeed = 2) | |
| 12 >>> et.predictPosition(10) # doctest:+ELLIPSIS | |
| 13 (15.5...,0.0...) | |
| 14 >>> et.predictPosition(11) # doctest:+ELLIPSIS | |
| 15 (17.5...,0.0...) | |
| 16 >>> et.predictPosition(12) # doctest:+ELLIPSIS | |
| 17 (19.5...,0.0...) | |
| 18 | |
| 19 >>> import random | |
| 20 >>> acceleration = lambda: random.uniform(-0.5,0.5) | |
| 21 >>> steering = lambda: random.uniform(-0.1,0.1) | |
| 22 >>> et = PredictedTrajectoryRandomControl(moving.Point(0,0),moving.Point(1,1), acceleration, steering, maxSpeed = 2) | |
| 23 >>> p = et.predictPosition(500) | |
| 24 >>> from numpy import max | |
| 25 >>> max(et.getPredictedSpeeds()) <= 2. | |
| 26 True | |
| 27 | |
| 28 >>> p = moving.Point(3,4) | |
| 29 >>> sp = SafetyPoint(p, 0.1, 0) | |
| 30 >>> print(sp) | |
| 31 3 4 0.1 0 | |
| 32 | |
| 33 >>> et1 = PredictedTrajectoryConstant(moving.Point(-5.,0.), moving.Point(1.,0.)) | |
| 34 >>> et2 = PredictedTrajectoryConstant(moving.Point(0.,-5.), moving.Point(0.,1.)) | |
| 35 >>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 10) | |
| 36 >>> collision | |
| 37 True | |
| 38 >>> t | |
| 39 5 | |
| 40 >>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 5) | |
| 41 >>> collision | |
| 42 True | |
| 43 >>> t | |
| 44 5 | |
| 45 >>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 4) | |
| 46 >>> collision | |
| 47 False | |
| 48 | |
| 49 >>> proto = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'feature', [1204])[0] | |
| 50 >>> proto.getPositions().computeCumulativeDistances() | |
| 51 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.5, 0.5), proto.getVelocityAt(10)*0.9, proto, True) | |
| 52 >>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.9) < 1e-5 | |
| 53 True | |
| 54 >>> for t in range(int(proto.length())): x=et.predictPosition(t) | |
| 55 >>> traj = et.getPredictedTrajectory() | |
| 56 >>> traj.computeCumulativeDistances() | |
| 57 >>> absolute(array(traj.distances).mean() - et.initialSpeed < 1e-3) | |
| 58 True | |
| 59 | |
| 60 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.6, 0.6), proto.getVelocityAt(10)*0.7, proto, False) | |
| 61 >>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.7) < 1e-5 | |
| 62 True | |
| 63 >>> proto = moving.MovingObject.generate(1, moving.Point(-5.,0.), moving.Point(1.,0.), moving.TimeInterval(0,10)) | |
| 64 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(0)+moving.Point(0., 1.), proto.getVelocityAt(0)*0.5, proto, False) | |
| 65 >>> for t in range(int(proto.length()/0.5)): x=et.predictPosition(t) | |
| 66 >>> et.predictPosition(10) # doctest:+ELLIPSIS | |
| 67 (0.0...,1.0...) | |
| 68 >>> et.predictPosition(12) # doctest:+ELLIPSIS | |
| 69 (1.0...,1.0...) | |
| 70 | |
| 71 |
