Mercurial > hg > nsaunier > traffic-intelligence
annotate python/tests/prediction.txt @ 1016:9b53be469a36
getting ready for pull request
| author | Wendlasida |
|---|---|
| date | Mon, 04 Jun 2018 15:51:03 -0400 |
| parents | 933670761a57 |
| children |
| rev | line source |
|---|---|
|
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
1 >>> from prediction import * |
|
942
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
2 >>> import moving, storage, utils |
|
941
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
3 >>> from numpy import absolute, array |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 |
|
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
5 >>> et = PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0)) |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 >>> et.predictPosition(4) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
7 (4.0...,0.0...) |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
8 >>> et.predictPosition(1) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
9 (1.0...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
10 |
|
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
11 >>> et = PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0), moving.NormAngle(0.1,0), maxSpeed = 2) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
12 >>> et.predictPosition(10) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
13 (15.5...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
14 >>> et.predictPosition(11) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
15 (17.5...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
16 >>> et.predictPosition(12) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
17 (19.5...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
18 |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
19 >>> import random |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
20 >>> acceleration = lambda: random.uniform(-0.5,0.5) |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
21 >>> steering = lambda: random.uniform(-0.1,0.1) |
|
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
22 >>> et = PredictedTrajectoryRandomControl(moving.Point(0,0),moving.Point(1,1), acceleration, steering, maxSpeed = 2) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
23 >>> p = et.predictPosition(500) |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
24 >>> from numpy import max |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
25 >>> max(et.getPredictedSpeeds()) <= 2. |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
26 True |
|
289
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
27 |
|
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
28 >>> p = moving.Point(3,4) |
|
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
29 >>> sp = SafetyPoint(p, 0.1, 0) |
|
289
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
30 >>> print(sp) |
|
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
31 3 4 0.1 0 |
|
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
32 |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
33 >>> et1 = PredictedTrajectoryConstant(moving.Point(-5.,0.), moving.Point(1.,0.)) |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
34 >>> et2 = PredictedTrajectoryConstant(moving.Point(0.,-5.), moving.Point(0.,1.)) |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
35 >>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 10) |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
36 >>> collision |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
37 True |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
38 >>> t |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
39 5 |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
40 >>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 5) |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
41 >>> collision |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
42 True |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
43 >>> t |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
44 5 |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
45 >>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 4) |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
46 >>> collision |
|
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
466
diff
changeset
|
47 False |
|
941
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
48 |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
49 >>> proto = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'feature', [1204])[0] |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
50 >>> proto.getPositions().computeCumulativeDistances() |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
51 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.5, 0.5), proto.getVelocityAt(10)*0.9, proto, True) |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
52 >>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.9) < 1e-5 |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
53 True |
|
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
945
diff
changeset
|
54 >>> for t in range(int(proto.length())): x=et.predictPosition(t) |
|
941
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
55 >>> traj = et.getPredictedTrajectory() |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
56 >>> traj.computeCumulativeDistances() |
|
945
05d4302bf67e
working motion pattern prediction with rotation and features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
942
diff
changeset
|
57 >>> absolute(array(traj.distances).mean() - et.initialSpeed < 1e-3) |
|
941
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
58 True |
|
c5191acb025f
added test for motion prediction at constant speed with prototype
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
59 |
|
942
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
60 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.6, 0.6), proto.getVelocityAt(10)*0.7, proto, False) |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
61 >>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.7) < 1e-5 |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
62 True |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
63 >>> proto = moving.MovingObject.generate(1, moving.Point(-5.,0.), moving.Point(1.,0.), moving.TimeInterval(0,10)) |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
64 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(0)+moving.Point(0., 1.), proto.getVelocityAt(0)*0.5, proto, False) |
|
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
945
diff
changeset
|
65 >>> for t in range(int(proto.length()/0.5)): x=et.predictPosition(t) |
|
942
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
66 >>> et.predictPosition(10) # doctest:+ELLIPSIS |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
67 (0.0...,1.0...) |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
68 >>> et.predictPosition(12) # doctest:+ELLIPSIS |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
69 (1.0...,1.0...) |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
70 |
|
ab13aaf41432
implemented motion prediction with prototypes at constant ratio, with tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
941
diff
changeset
|
71 |
