1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math3.linear;
19
20 import java.util.Iterator;
21 import java.util.NoSuchElementException;
22
23 import org.apache.commons.math3.exception.MathUnsupportedOperationException;
24 import org.apache.commons.math3.exception.DimensionMismatchException;
25 import org.apache.commons.math3.exception.NotPositiveException;
26 import org.apache.commons.math3.exception.NumberIsTooSmallException;
27 import org.apache.commons.math3.exception.OutOfRangeException;
28 import org.apache.commons.math3.exception.MathArithmeticException;
29 import org.apache.commons.math3.analysis.FunctionUtils;
30 import org.apache.commons.math3.analysis.function.Add;
31 import org.apache.commons.math3.analysis.function.Multiply;
32 import org.apache.commons.math3.analysis.function.Divide;
33 import org.apache.commons.math3.analysis.UnivariateFunction;
34 import org.apache.commons.math3.exception.util.LocalizedFormats;
35 import org.apache.commons.math3.util.FastMath;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public abstract class RealVector {
60
61
62
63
64
65 public abstract int getDimension();
66
67
68
69
70
71
72
73
74
75 public abstract double getEntry(int index) throws OutOfRangeException;
76
77
78
79
80
81
82
83
84
85 public abstract void setEntry(int index, double value)
86 throws OutOfRangeException;
87
88
89
90
91
92
93
94
95
96 public void addToEntry(int index, double increment)
97 throws OutOfRangeException {
98 setEntry(index, getEntry(index) + increment);
99 }
100
101
102
103
104
105
106
107 public abstract RealVector append(RealVector v);
108
109
110
111
112
113
114
115 public abstract RealVector append(double d);
116
117
118
119
120
121
122
123
124
125
126 public abstract RealVector getSubVector(int index, int n)
127 throws NotPositiveException, OutOfRangeException;
128
129
130
131
132
133
134
135
136 public abstract void setSubVector(int index, RealVector v)
137 throws OutOfRangeException;
138
139
140
141
142
143
144
145 public abstract boolean isNaN();
146
147
148
149
150
151
152
153 public abstract boolean isInfinite();
154
155
156
157
158
159
160
161
162 protected void checkVectorDimensions(RealVector v)
163 throws DimensionMismatchException {
164 checkVectorDimensions(v.getDimension());
165 }
166
167
168
169
170
171
172
173
174 protected void checkVectorDimensions(int n)
175 throws DimensionMismatchException {
176 int d = getDimension();
177 if (d != n) {
178 throw new DimensionMismatchException(d, n);
179 }
180 }
181
182
183
184
185
186
187
188 protected void checkIndex(final int index) throws OutOfRangeException {
189 if (index < 0 ||
190 index >= getDimension()) {
191 throw new OutOfRangeException(LocalizedFormats.INDEX,
192 index, 0, getDimension() - 1);
193 }
194 }
195
196
197
198
199
200
201
202
203
204
205 protected void checkIndices(final int start, final int end)
206 throws NumberIsTooSmallException, OutOfRangeException {
207 final int dim = getDimension();
208 if ((start < 0) || (start >= dim)) {
209 throw new OutOfRangeException(LocalizedFormats.INDEX, start, 0,
210 dim - 1);
211 }
212 if ((end < 0) || (end >= dim)) {
213 throw new OutOfRangeException(LocalizedFormats.INDEX, end, 0,
214 dim - 1);
215 }
216 if (end < start) {
217
218 throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
219 end, start, false);
220 }
221 }
222
223
224
225
226
227
228
229
230
231
232 public RealVector add(RealVector v) throws DimensionMismatchException {
233 checkVectorDimensions(v);
234 RealVector result = v.copy();
235 Iterator<Entry> it = iterator();
236 while (it.hasNext()) {
237 final Entry e = it.next();
238 final int index = e.getIndex();
239 result.setEntry(index, e.getValue() + result.getEntry(index));
240 }
241 return result;
242 }
243
244
245
246
247
248
249
250
251
252
253 public RealVector subtract(RealVector v) throws DimensionMismatchException {
254 checkVectorDimensions(v);
255 RealVector result = v.mapMultiply(-1d);
256 Iterator<Entry> it = iterator();
257 while (it.hasNext()) {
258 final Entry e = it.next();
259 final int index = e.getIndex();
260 result.setEntry(index, e.getValue() + result.getEntry(index));
261 }
262 return result;
263 }
264
265
266
267
268
269
270
271
272 public RealVector mapAdd(double d) {
273 return copy().mapAddToSelf(d);
274 }
275
276
277
278
279
280
281
282
283 public RealVector mapAddToSelf(double d) {
284 if (d != 0) {
285 return mapToSelf(FunctionUtils.fix2ndArgument(new Add(), d));
286 }
287 return this;
288 }
289
290
291
292
293
294
295 public abstract RealVector copy();
296
297
298
299
300
301
302
303
304
305 public double dotProduct(RealVector v) throws DimensionMismatchException {
306 checkVectorDimensions(v);
307 double d = 0;
308 final int n = getDimension();
309 for (int i = 0; i < n; i++) {
310 d += getEntry(i) * v.getEntry(i);
311 }
312 return d;
313 }
314
315
316
317
318
319
320
321
322
323
324
325
326 public double cosine(RealVector v) throws DimensionMismatchException,
327 MathArithmeticException {
328 final double norm = getNorm();
329 final double vNorm = v.getNorm();
330
331 if (norm == 0 ||
332 vNorm == 0) {
333 throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
334 }
335 return dotProduct(v) / (norm * vNorm);
336 }
337
338
339
340
341
342
343
344
345
346 public abstract RealVector ebeDivide(RealVector v)
347 throws DimensionMismatchException;
348
349
350
351
352
353
354
355
356
357 public abstract RealVector ebeMultiply(RealVector v)
358 throws DimensionMismatchException;
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374 public double getDistance(RealVector v) throws DimensionMismatchException {
375 checkVectorDimensions(v);
376 double d = 0;
377 Iterator<Entry> it = iterator();
378 while (it.hasNext()) {
379 final Entry e = it.next();
380 final double diff = e.getValue() - v.getEntry(e.getIndex());
381 d += diff * diff;
382 }
383 return FastMath.sqrt(d);
384 }
385
386
387
388
389
390
391
392
393
394
395
396 public double getNorm() {
397 double sum = 0;
398 Iterator<Entry> it = iterator();
399 while (it.hasNext()) {
400 final Entry e = it.next();
401 final double value = e.getValue();
402 sum += value * value;
403 }
404 return FastMath.sqrt(sum);
405 }
406
407
408
409
410
411
412
413
414
415
416
417 public double getL1Norm() {
418 double norm = 0;
419 Iterator<Entry> it = iterator();
420 while (it.hasNext()) {
421 final Entry e = it.next();
422 norm += FastMath.abs(e.getValue());
423 }
424 return norm;
425 }
426
427
428
429
430
431
432
433
434
435
436
437 public double getLInfNorm() {
438 double norm = 0;
439 Iterator<Entry> it = iterator();
440 while (it.hasNext()) {
441 final Entry e = it.next();
442 norm = FastMath.max(norm, FastMath.abs(e.getValue()));
443 }
444 return norm;
445 }
446
447
448
449
450
451
452
453
454
455
456
457
458 public double getL1Distance(RealVector v)
459 throws DimensionMismatchException {
460 checkVectorDimensions(v);
461 double d = 0;
462 Iterator<Entry> it = iterator();
463 while (it.hasNext()) {
464 final Entry e = it.next();
465 d += FastMath.abs(e.getValue() - v.getEntry(e.getIndex()));
466 }
467 return d;
468 }
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484 public double getLInfDistance(RealVector v)
485 throws DimensionMismatchException {
486 checkVectorDimensions(v);
487 double d = 0;
488 Iterator<Entry> it = iterator();
489 while (it.hasNext()) {
490 final Entry e = it.next();
491 d = FastMath.max(FastMath.abs(e.getValue() - v.getEntry(e.getIndex())), d);
492 }
493 return d;
494 }
495
496
497
498
499
500
501
502 public int getMinIndex() {
503 int minIndex = -1;
504 double minValue = Double.POSITIVE_INFINITY;
505 Iterator<Entry> iterator = iterator();
506 while (iterator.hasNext()) {
507 final Entry entry = iterator.next();
508 if (entry.getValue() <= minValue) {
509 minIndex = entry.getIndex();
510 minValue = entry.getValue();
511 }
512 }
513 return minIndex;
514 }
515
516
517
518
519
520
521
522 public double getMinValue() {
523 final int minIndex = getMinIndex();
524 return minIndex < 0 ? Double.NaN : getEntry(minIndex);
525 }
526
527
528
529
530
531
532
533 public int getMaxIndex() {
534 int maxIndex = -1;
535 double maxValue = Double.NEGATIVE_INFINITY;
536 Iterator<Entry> iterator = iterator();
537 while (iterator.hasNext()) {
538 final Entry entry = iterator.next();
539 if (entry.getValue() >= maxValue) {
540 maxIndex = entry.getIndex();
541 maxValue = entry.getValue();
542 }
543 }
544 return maxIndex;
545 }
546
547
548
549
550
551
552
553 public double getMaxValue() {
554 final int maxIndex = getMaxIndex();
555 return maxIndex < 0 ? Double.NaN : getEntry(maxIndex);
556 }
557
558
559
560
561
562
563
564
565
566 public RealVector mapMultiply(double d) {
567 return copy().mapMultiplyToSelf(d);
568 }
569
570
571
572
573
574
575
576
577 public RealVector mapMultiplyToSelf(double d){
578 return mapToSelf(FunctionUtils.fix2ndArgument(new Multiply(), d));
579 }
580
581
582
583
584
585
586
587
588 public RealVector mapSubtract(double d) {
589 return copy().mapSubtractToSelf(d);
590 }
591
592
593
594
595
596
597
598
599 public RealVector mapSubtractToSelf(double d){
600 return mapAddToSelf(-d);
601 }
602
603
604
605
606
607
608
609
610 public RealVector mapDivide(double d) {
611 return copy().mapDivideToSelf(d);
612 }
613
614
615
616
617
618
619
620
621 public RealVector mapDivideToSelf(double d){
622 return mapToSelf(FunctionUtils.fix2ndArgument(new Divide(), d));
623 }
624
625
626
627
628
629
630
631 public RealMatrix outerProduct(RealVector v) {
632 final int m = this.getDimension();
633 final int n = v.getDimension();
634 final RealMatrix product;
635 if (v instanceof SparseRealVector || this instanceof SparseRealVector) {
636 product = new OpenMapRealMatrix(m, n);
637 } else {
638 product = new Array2DRowRealMatrix(m, n);
639 }
640 for (int i = 0; i < m; i++) {
641 for (int j = 0; j < n; j++) {
642 product.setEntry(i, j, this.getEntry(i) * v.getEntry(j));
643 }
644 }
645 return product;
646 }
647
648
649
650
651
652
653
654
655
656
657
658 public RealVector projection(final RealVector v)
659 throws DimensionMismatchException, MathArithmeticException {
660 final double norm2 = v.dotProduct(v);
661 if (norm2 == 0.0) {
662 throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
663 }
664 return v.mapMultiply(dotProduct(v) / v.dotProduct(v));
665 }
666
667
668
669
670
671
672 public void set(double value) {
673 Iterator<Entry> it = iterator();
674 while (it.hasNext()) {
675 final Entry e = it.next();
676 e.setValue(value);
677 }
678 }
679
680
681
682
683
684
685
686
687 public double[] toArray() {
688 int dim = getDimension();
689 double[] values = new double[dim];
690 for (int i = 0; i < dim; i++) {
691 values[i] = getEntry(i);
692 }
693 return values;
694 }
695
696
697
698
699
700
701
702
703 public RealVector unitVector() throws MathArithmeticException {
704 final double norm = getNorm();
705 if (norm == 0) {
706 throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
707 }
708 return mapDivide(norm);
709 }
710
711
712
713
714
715
716
717 public void unitize() throws MathArithmeticException {
718 final double norm = getNorm();
719 if (norm == 0) {
720 throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
721 }
722 mapDivideToSelf(getNorm());
723 }
724
725
726
727
728
729
730
731
732
733
734
735
736
737 public Iterator<Entry> sparseIterator() {
738 return new SparseEntryIterator();
739 }
740
741
742
743
744
745
746
747
748
749
750
751 public Iterator<Entry> iterator() {
752 final int dim = getDimension();
753 return new Iterator<Entry>() {
754
755
756 private int i = 0;
757
758
759 private Entry e = new Entry();
760
761
762 public boolean hasNext() {
763 return i < dim;
764 }
765
766
767 public Entry next() {
768 if (i < dim) {
769 e.setIndex(i++);
770 return e;
771 } else {
772 throw new NoSuchElementException();
773 }
774 }
775
776
777
778
779
780
781 public void remove() throws MathUnsupportedOperationException {
782 throw new MathUnsupportedOperationException();
783 }
784 };
785 }
786
787
788
789
790
791
792
793
794
795
796
797 public RealVector map(UnivariateFunction function) {
798 return copy().mapToSelf(function);
799 }
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814 public RealVector mapToSelf(UnivariateFunction function) {
815 Iterator<Entry> it = iterator();
816 while (it.hasNext()) {
817 final Entry e = it.next();
818 e.setValue(function.value(e.getValue()));
819 }
820 return this;
821 }
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836 public RealVector combine(double a, double b, RealVector y)
837 throws DimensionMismatchException {
838 return copy().combineToSelf(a, b, y);
839 }
840
841
842
843
844
845
846
847
848
849
850
851
852
853 public RealVector combineToSelf(double a, double b, RealVector y)
854 throws DimensionMismatchException {
855 checkVectorDimensions(y);
856 for (int i = 0; i < getDimension(); i++) {
857 final double xi = getEntry(i);
858 final double yi = y.getEntry(i);
859 setEntry(i, a * xi + b * yi);
860 }
861 return this;
862 }
863
864
865
866
867
868
869
870
871
872
873
874 public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor) {
875 final int dim = getDimension();
876 visitor.start(dim, 0, dim - 1);
877 for (int i = 0; i < dim; i++) {
878 visitor.visit(i, getEntry(i));
879 }
880 return visitor.end();
881 }
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896 public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor,
897 final int start, final int end)
898 throws NumberIsTooSmallException, OutOfRangeException {
899 checkIndices(start, end);
900 visitor.start(getDimension(), start, end);
901 for (int i = start; i <= end; i++) {
902 visitor.visit(i, getEntry(i));
903 }
904 return visitor.end();
905 }
906
907
908
909
910
911
912
913
914
915
916
917
918
919 public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor) {
920 return walkInDefaultOrder(visitor);
921 }
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938 public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor,
939 final int start, final int end)
940 throws NumberIsTooSmallException, OutOfRangeException {
941 return walkInDefaultOrder(visitor, start, end);
942 }
943
944
945
946
947
948
949
950
951
952
953
954 public double walkInDefaultOrder(final RealVectorChangingVisitor visitor) {
955 final int dim = getDimension();
956 visitor.start(dim, 0, dim - 1);
957 for (int i = 0; i < dim; i++) {
958 setEntry(i, visitor.visit(i, getEntry(i)));
959 }
960 return visitor.end();
961 }
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976 public double walkInDefaultOrder(final RealVectorChangingVisitor visitor,
977 final int start, final int end)
978 throws NumberIsTooSmallException, OutOfRangeException {
979 checkIndices(start, end);
980 visitor.start(getDimension(), start, end);
981 for (int i = start; i <= end; i++) {
982 setEntry(i, visitor.visit(i, getEntry(i)));
983 }
984 return visitor.end();
985 }
986
987
988
989
990
991
992
993
994
995
996
997
998
999 public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor) {
1000 return walkInDefaultOrder(visitor);
1001 }
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018 public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor,
1019 final int start, final int end)
1020 throws NumberIsTooSmallException, OutOfRangeException {
1021 return walkInDefaultOrder(visitor, start, end);
1022 }
1023
1024
1025 protected class Entry {
1026
1027 private int index;
1028
1029
1030 public Entry() {
1031 setIndex(0);
1032 }
1033
1034
1035
1036
1037
1038
1039 public double getValue() {
1040 return getEntry(getIndex());
1041 }
1042
1043
1044
1045
1046
1047
1048 public void setValue(double value) {
1049 setEntry(getIndex(), value);
1050 }
1051
1052
1053
1054
1055
1056
1057 public int getIndex() {
1058 return index;
1059 }
1060
1061
1062
1063
1064
1065
1066 public void setIndex(int index) {
1067 this.index = index;
1068 }
1069 }
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093 @Override
1094 public boolean equals(Object other)
1095 throws MathUnsupportedOperationException {
1096 throw new MathUnsupportedOperationException();
1097 }
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107 @Override
1108 public int hashCode() throws MathUnsupportedOperationException {
1109 throw new MathUnsupportedOperationException();
1110 }
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126 protected class SparseEntryIterator implements Iterator<Entry> {
1127
1128 private final int dim;
1129
1130 private Entry current;
1131
1132 private Entry next;
1133
1134
1135 protected SparseEntryIterator() {
1136 dim = getDimension();
1137 current = new Entry();
1138 next = new Entry();
1139 if (next.getValue() == 0) {
1140 advance(next);
1141 }
1142 }
1143
1144
1145
1146
1147
1148
1149 protected void advance(Entry e) {
1150 if (e == null) {
1151 return;
1152 }
1153 do {
1154 e.setIndex(e.getIndex() + 1);
1155 } while (e.getIndex() < dim && e.getValue() == 0);
1156 if (e.getIndex() >= dim) {
1157 e.setIndex(-1);
1158 }
1159 }
1160
1161
1162 public boolean hasNext() {
1163 return next.getIndex() >= 0;
1164 }
1165
1166
1167 public Entry next() {
1168 int index = next.getIndex();
1169 if (index < 0) {
1170 throw new NoSuchElementException();
1171 }
1172 current.setIndex(index);
1173 advance(next);
1174 return current;
1175 }
1176
1177
1178
1179
1180
1181
1182 public void remove() throws MathUnsupportedOperationException {
1183 throw new MathUnsupportedOperationException();
1184 }
1185 }
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205 public static RealVector unmodifiableRealVector(final RealVector v) {
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215 return new RealVector() {
1216
1217
1218
1219
1220
1221 @Override
1222 public RealVector mapToSelf(UnivariateFunction function)
1223 throws MathUnsupportedOperationException {
1224 throw new MathUnsupportedOperationException();
1225 }
1226
1227
1228 @Override
1229 public RealVector map(UnivariateFunction function) {
1230 return v.map(function);
1231 }
1232
1233
1234 @Override
1235 public Iterator<Entry> iterator() {
1236 final Iterator<Entry> i = v.iterator();
1237 return new Iterator<Entry>() {
1238
1239 private final UnmodifiableEntry e = new UnmodifiableEntry();
1240
1241
1242 public boolean hasNext() {
1243 return i.hasNext();
1244 }
1245
1246
1247 public Entry next() {
1248 e.setIndex(i.next().getIndex());
1249 return e;
1250 }
1251
1252
1253
1254
1255
1256
1257
1258 public void remove() throws MathUnsupportedOperationException {
1259 throw new MathUnsupportedOperationException();
1260 }
1261 };
1262 }
1263
1264
1265 @Override
1266 public Iterator<Entry> sparseIterator() {
1267 final Iterator<Entry> i = v.sparseIterator();
1268
1269 return new Iterator<Entry>() {
1270
1271 private final UnmodifiableEntry e = new UnmodifiableEntry();
1272
1273
1274 public boolean hasNext() {
1275 return i.hasNext();
1276 }
1277
1278
1279 public Entry next() {
1280 e.setIndex(i.next().getIndex());
1281 return e;
1282 }
1283
1284
1285
1286
1287
1288
1289
1290 public void remove()
1291 throws MathUnsupportedOperationException {
1292 throw new MathUnsupportedOperationException();
1293 }
1294 };
1295 }
1296
1297
1298 @Override
1299 public RealVector copy() {
1300 return v.copy();
1301 }
1302
1303
1304 @Override
1305 public RealVector add(RealVector w)
1306 throws DimensionMismatchException {
1307 return v.add(w);
1308 }
1309
1310
1311 @Override
1312 public RealVector subtract(RealVector w)
1313 throws DimensionMismatchException {
1314 return v.subtract(w);
1315 }
1316
1317
1318 @Override
1319 public RealVector mapAdd(double d) {
1320 return v.mapAdd(d);
1321 }
1322
1323
1324
1325
1326
1327
1328
1329 @Override
1330 public RealVector mapAddToSelf(double d)
1331 throws MathUnsupportedOperationException {
1332 throw new MathUnsupportedOperationException();
1333 }
1334
1335
1336 @Override
1337 public RealVector mapSubtract(double d) {
1338 return v.mapSubtract(d);
1339 }
1340
1341
1342
1343
1344
1345
1346
1347 @Override
1348 public RealVector mapSubtractToSelf(double d)
1349 throws MathUnsupportedOperationException {
1350 throw new MathUnsupportedOperationException();
1351 }
1352
1353
1354 @Override
1355 public RealVector mapMultiply(double d) {
1356 return v.mapMultiply(d);
1357 }
1358
1359
1360
1361
1362
1363
1364
1365 @Override
1366 public RealVector mapMultiplyToSelf(double d)
1367 throws MathUnsupportedOperationException {
1368 throw new MathUnsupportedOperationException();
1369 }
1370
1371
1372 @Override
1373 public RealVector mapDivide(double d) {
1374 return v.mapDivide(d);
1375 }
1376
1377
1378
1379
1380
1381
1382
1383 @Override
1384 public RealVector mapDivideToSelf(double d)
1385 throws MathUnsupportedOperationException {
1386 throw new MathUnsupportedOperationException();
1387 }
1388
1389
1390 @Override
1391 public RealVector ebeMultiply(RealVector w)
1392 throws DimensionMismatchException {
1393 return v.ebeMultiply(w);
1394 }
1395
1396
1397 @Override
1398 public RealVector ebeDivide(RealVector w)
1399 throws DimensionMismatchException {
1400 return v.ebeDivide(w);
1401 }
1402
1403
1404 @Override
1405 public double dotProduct(RealVector w)
1406 throws DimensionMismatchException {
1407 return v.dotProduct(w);
1408 }
1409
1410
1411 @Override
1412 public double cosine(RealVector w)
1413 throws DimensionMismatchException, MathArithmeticException {
1414 return v.cosine(w);
1415 }
1416
1417
1418 @Override
1419 public double getNorm() {
1420 return v.getNorm();
1421 }
1422
1423
1424 @Override
1425 public double getL1Norm() {
1426 return v.getL1Norm();
1427 }
1428
1429
1430 @Override
1431 public double getLInfNorm() {
1432 return v.getLInfNorm();
1433 }
1434
1435
1436 @Override
1437 public double getDistance(RealVector w)
1438 throws DimensionMismatchException {
1439 return v.getDistance(w);
1440 }
1441
1442
1443 @Override
1444 public double getL1Distance(RealVector w)
1445 throws DimensionMismatchException {
1446 return v.getL1Distance(w);
1447 }
1448
1449
1450 @Override
1451 public double getLInfDistance(RealVector w)
1452 throws DimensionMismatchException {
1453 return v.getLInfDistance(w);
1454 }
1455
1456
1457 @Override
1458 public RealVector unitVector() throws MathArithmeticException {
1459 return v.unitVector();
1460 }
1461
1462
1463
1464
1465
1466
1467
1468 @Override
1469 public void unitize() throws MathUnsupportedOperationException {
1470 throw new MathUnsupportedOperationException();
1471 }
1472
1473
1474 @Override
1475 public RealMatrix outerProduct(RealVector w) {
1476 return v.outerProduct(w);
1477 }
1478
1479
1480 @Override
1481 public double getEntry(int index) throws OutOfRangeException {
1482 return v.getEntry(index);
1483 }
1484
1485
1486
1487
1488
1489
1490
1491 @Override
1492 public void setEntry(int index, double value)
1493 throws MathUnsupportedOperationException {
1494 throw new MathUnsupportedOperationException();
1495 }
1496
1497
1498
1499
1500
1501
1502
1503 @Override
1504 public void addToEntry(int index, double value)
1505 throws MathUnsupportedOperationException {
1506 throw new MathUnsupportedOperationException();
1507 }
1508
1509
1510 @Override
1511 public int getDimension() {
1512 return v.getDimension();
1513 }
1514
1515
1516 @Override
1517 public RealVector append(RealVector w) {
1518 return v.append(w);
1519 }
1520
1521
1522 @Override
1523 public RealVector append(double d) {
1524 return v.append(d);
1525 }
1526
1527
1528 @Override
1529 public RealVector getSubVector(int index, int n)
1530 throws OutOfRangeException, NotPositiveException {
1531 return v.getSubVector(index, n);
1532 }
1533
1534
1535
1536
1537
1538
1539
1540 @Override
1541 public void setSubVector(int index, RealVector w)
1542 throws MathUnsupportedOperationException {
1543 throw new MathUnsupportedOperationException();
1544 }
1545
1546
1547
1548
1549
1550
1551
1552 @Override
1553 public void set(double value)
1554 throws MathUnsupportedOperationException {
1555 throw new MathUnsupportedOperationException();
1556 }
1557
1558
1559 @Override
1560 public double[] toArray() {
1561 return v.toArray();
1562 }
1563
1564
1565 @Override
1566 public boolean isNaN() {
1567 return v.isNaN();
1568 }
1569
1570
1571 @Override
1572 public boolean isInfinite() {
1573 return v.isInfinite();
1574 }
1575
1576
1577 @Override
1578 public RealVector combine(double a, double b, RealVector y)
1579 throws DimensionMismatchException {
1580 return v.combine(a, b, y);
1581 }
1582
1583
1584
1585
1586
1587
1588
1589 @Override
1590 public RealVector combineToSelf(double a, double b, RealVector y)
1591 throws MathUnsupportedOperationException {
1592 throw new MathUnsupportedOperationException();
1593 }
1594
1595
1596 class UnmodifiableEntry extends Entry {
1597
1598 @Override
1599 public double getValue() {
1600 return v.getEntry(getIndex());
1601 }
1602
1603
1604
1605
1606
1607
1608
1609 @Override
1610 public void setValue(double value)
1611 throws MathUnsupportedOperationException {
1612 throw new MathUnsupportedOperationException();
1613 }
1614 }
1615 };
1616 }
1617 }