1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math4.legacy.linear;
19
20 import java.util.Iterator;
21 import java.util.NoSuchElementException;
22
23 import org.apache.commons.math4.legacy.analysis.FunctionUtils;
24 import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
25 import org.apache.commons.math4.legacy.analysis.function.Add;
26 import org.apache.commons.math4.legacy.analysis.function.Divide;
27 import org.apache.commons.math4.legacy.analysis.function.Multiply;
28 import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
29 import org.apache.commons.math4.legacy.exception.MathArithmeticException;
30 import org.apache.commons.math4.legacy.exception.MathUnsupportedOperationException;
31 import org.apache.commons.math4.legacy.exception.NotPositiveException;
32 import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
33 import org.apache.commons.math4.legacy.exception.OutOfRangeException;
34 import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
35 import org.apache.commons.math4.core.jdkmath.JdkMath;
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 JdkMath.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 JdkMath.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 += JdkMath.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 = JdkMath.max(norm, JdkMath.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 += JdkMath.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 = JdkMath.max(JdkMath.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;
757
758
759 private Entry e = new Entry();
760
761
762 @Override
763 public boolean hasNext() {
764 return i < dim;
765 }
766
767
768 @Override
769 public Entry next() {
770 if (i < dim) {
771 e.setIndex(i++);
772 return e;
773 } else {
774 throw new NoSuchElementException();
775 }
776 }
777
778
779
780
781
782
783 @Override
784 public void remove() throws MathUnsupportedOperationException {
785 throw new MathUnsupportedOperationException();
786 }
787 };
788 }
789
790
791
792
793
794
795
796
797
798
799
800 public RealVector map(UnivariateFunction function) {
801 return copy().mapToSelf(function);
802 }
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817 public RealVector mapToSelf(UnivariateFunction function) {
818 Iterator<Entry> it = iterator();
819 while (it.hasNext()) {
820 final Entry e = it.next();
821 e.setValue(function.value(e.getValue()));
822 }
823 return this;
824 }
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839 public RealVector combine(double a, double b, RealVector y)
840 throws DimensionMismatchException {
841 return copy().combineToSelf(a, b, y);
842 }
843
844
845
846
847
848
849
850
851
852
853
854
855
856 public RealVector combineToSelf(double a, double b, RealVector y)
857 throws DimensionMismatchException {
858 checkVectorDimensions(y);
859 for (int i = 0; i < getDimension(); i++) {
860 final double xi = getEntry(i);
861 final double yi = y.getEntry(i);
862 setEntry(i, a * xi + b * yi);
863 }
864 return this;
865 }
866
867
868
869
870
871
872
873
874
875
876
877 public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor) {
878 final int dim = getDimension();
879 visitor.start(dim, 0, dim - 1);
880 for (int i = 0; i < dim; i++) {
881 visitor.visit(i, getEntry(i));
882 }
883 return visitor.end();
884 }
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899 public double walkInDefaultOrder(final RealVectorPreservingVisitor visitor,
900 final int start, final int end)
901 throws NumberIsTooSmallException, OutOfRangeException {
902 checkIndices(start, end);
903 visitor.start(getDimension(), start, end);
904 for (int i = start; i <= end; i++) {
905 visitor.visit(i, getEntry(i));
906 }
907 return visitor.end();
908 }
909
910
911
912
913
914
915
916
917
918
919
920
921
922 public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor) {
923 return walkInDefaultOrder(visitor);
924 }
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941 public double walkInOptimizedOrder(final RealVectorPreservingVisitor visitor,
942 final int start, final int end)
943 throws NumberIsTooSmallException, OutOfRangeException {
944 return walkInDefaultOrder(visitor, start, end);
945 }
946
947
948
949
950
951
952
953
954
955
956
957 public double walkInDefaultOrder(final RealVectorChangingVisitor visitor) {
958 final int dim = getDimension();
959 visitor.start(dim, 0, dim - 1);
960 for (int i = 0; i < dim; i++) {
961 setEntry(i, visitor.visit(i, getEntry(i)));
962 }
963 return visitor.end();
964 }
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979 public double walkInDefaultOrder(final RealVectorChangingVisitor visitor,
980 final int start, final int end)
981 throws NumberIsTooSmallException, OutOfRangeException {
982 checkIndices(start, end);
983 visitor.start(getDimension(), start, end);
984 for (int i = start; i <= end; i++) {
985 setEntry(i, visitor.visit(i, getEntry(i)));
986 }
987 return visitor.end();
988 }
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002 public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor) {
1003 return walkInDefaultOrder(visitor);
1004 }
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021 public double walkInOptimizedOrder(final RealVectorChangingVisitor visitor,
1022 final int start, final int end)
1023 throws NumberIsTooSmallException, OutOfRangeException {
1024 return walkInDefaultOrder(visitor, start, end);
1025 }
1026
1027
1028 protected class Entry {
1029
1030 private int index;
1031
1032
1033 public Entry() {
1034 setIndex(0);
1035 }
1036
1037
1038
1039
1040
1041
1042 public double getValue() {
1043 return getEntry(getIndex());
1044 }
1045
1046
1047
1048
1049
1050
1051 public void setValue(double value) {
1052 setEntry(getIndex(), value);
1053 }
1054
1055
1056
1057
1058
1059
1060 public int getIndex() {
1061 return index;
1062 }
1063
1064
1065
1066
1067
1068
1069 public void setIndex(int index) {
1070 this.index = index;
1071 }
1072 }
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096 @Override
1097 public boolean equals(Object other)
1098 throws MathUnsupportedOperationException {
1099 throw new MathUnsupportedOperationException();
1100 }
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110 @Override
1111 public int hashCode() throws MathUnsupportedOperationException {
1112 throw new MathUnsupportedOperationException();
1113 }
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129 protected class SparseEntryIterator implements Iterator<Entry> {
1130
1131 private final int dim;
1132
1133 private Entry current;
1134
1135 private Entry next;
1136
1137
1138 protected SparseEntryIterator() {
1139 dim = getDimension();
1140 current = new Entry();
1141 next = new Entry();
1142 if (next.getValue() == 0) {
1143 advance(next);
1144 }
1145 }
1146
1147
1148
1149
1150
1151
1152 protected void advance(Entry e) {
1153 if (e == null) {
1154 return;
1155 }
1156 do {
1157 e.setIndex(e.getIndex() + 1);
1158 } while (e.getIndex() < dim && e.getValue() == 0);
1159 if (e.getIndex() >= dim) {
1160 e.setIndex(-1);
1161 }
1162 }
1163
1164
1165 @Override
1166 public boolean hasNext() {
1167 return next.getIndex() >= 0;
1168 }
1169
1170
1171 @Override
1172 public Entry next() {
1173 int index = next.getIndex();
1174 if (index < 0) {
1175 throw new NoSuchElementException();
1176 }
1177 current.setIndex(index);
1178 advance(next);
1179 return current;
1180 }
1181
1182
1183
1184
1185
1186
1187 @Override
1188 public void remove() throws MathUnsupportedOperationException {
1189 throw new MathUnsupportedOperationException();
1190 }
1191 }
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211 public static RealVector unmodifiableRealVector(final RealVector v) {
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221 return new RealVector() {
1222
1223
1224
1225
1226
1227 @Override
1228 public RealVector mapToSelf(UnivariateFunction function)
1229 throws MathUnsupportedOperationException {
1230 throw new MathUnsupportedOperationException();
1231 }
1232
1233
1234 @Override
1235 public RealVector map(UnivariateFunction function) {
1236 return v.map(function);
1237 }
1238
1239
1240 @Override
1241 public Iterator<Entry> iterator() {
1242 final Iterator<Entry> i = v.iterator();
1243 return new Iterator<Entry>() {
1244
1245 private final UnmodifiableEntry e = new UnmodifiableEntry();
1246
1247
1248 @Override
1249 public boolean hasNext() {
1250 return i.hasNext();
1251 }
1252
1253
1254 @Override
1255 public Entry next() {
1256 e.setIndex(i.next().getIndex());
1257 return e;
1258 }
1259
1260
1261
1262
1263
1264
1265
1266 @Override
1267 public void remove() throws MathUnsupportedOperationException {
1268 throw new MathUnsupportedOperationException();
1269 }
1270 };
1271 }
1272
1273
1274 @Override
1275 public Iterator<Entry> sparseIterator() {
1276 final Iterator<Entry> i = v.sparseIterator();
1277
1278 return new Iterator<Entry>() {
1279
1280 private final UnmodifiableEntry e = new UnmodifiableEntry();
1281
1282
1283 @Override
1284 public boolean hasNext() {
1285 return i.hasNext();
1286 }
1287
1288
1289 @Override
1290 public Entry next() {
1291 e.setIndex(i.next().getIndex());
1292 return e;
1293 }
1294
1295
1296
1297
1298
1299
1300
1301 @Override
1302 public void remove()
1303 throws MathUnsupportedOperationException {
1304 throw new MathUnsupportedOperationException();
1305 }
1306 };
1307 }
1308
1309
1310 @Override
1311 public RealVector copy() {
1312 return v.copy();
1313 }
1314
1315
1316 @Override
1317 public RealVector add(RealVector w)
1318 throws DimensionMismatchException {
1319 return v.add(w);
1320 }
1321
1322
1323 @Override
1324 public RealVector subtract(RealVector w)
1325 throws DimensionMismatchException {
1326 return v.subtract(w);
1327 }
1328
1329
1330 @Override
1331 public RealVector mapAdd(double d) {
1332 return v.mapAdd(d);
1333 }
1334
1335
1336
1337
1338
1339
1340
1341 @Override
1342 public RealVector mapAddToSelf(double d)
1343 throws MathUnsupportedOperationException {
1344 throw new MathUnsupportedOperationException();
1345 }
1346
1347
1348 @Override
1349 public RealVector mapSubtract(double d) {
1350 return v.mapSubtract(d);
1351 }
1352
1353
1354
1355
1356
1357
1358
1359 @Override
1360 public RealVector mapSubtractToSelf(double d)
1361 throws MathUnsupportedOperationException {
1362 throw new MathUnsupportedOperationException();
1363 }
1364
1365
1366 @Override
1367 public RealVector mapMultiply(double d) {
1368 return v.mapMultiply(d);
1369 }
1370
1371
1372
1373
1374
1375
1376
1377 @Override
1378 public RealVector mapMultiplyToSelf(double d)
1379 throws MathUnsupportedOperationException {
1380 throw new MathUnsupportedOperationException();
1381 }
1382
1383
1384 @Override
1385 public RealVector mapDivide(double d) {
1386 return v.mapDivide(d);
1387 }
1388
1389
1390
1391
1392
1393
1394
1395 @Override
1396 public RealVector mapDivideToSelf(double d)
1397 throws MathUnsupportedOperationException {
1398 throw new MathUnsupportedOperationException();
1399 }
1400
1401
1402 @Override
1403 public RealVector ebeMultiply(RealVector w)
1404 throws DimensionMismatchException {
1405 return v.ebeMultiply(w);
1406 }
1407
1408
1409 @Override
1410 public RealVector ebeDivide(RealVector w)
1411 throws DimensionMismatchException {
1412 return v.ebeDivide(w);
1413 }
1414
1415
1416 @Override
1417 public double dotProduct(RealVector w)
1418 throws DimensionMismatchException {
1419 return v.dotProduct(w);
1420 }
1421
1422
1423 @Override
1424 public double cosine(RealVector w)
1425 throws DimensionMismatchException, MathArithmeticException {
1426 return v.cosine(w);
1427 }
1428
1429
1430 @Override
1431 public double getNorm() {
1432 return v.getNorm();
1433 }
1434
1435
1436 @Override
1437 public double getL1Norm() {
1438 return v.getL1Norm();
1439 }
1440
1441
1442 @Override
1443 public double getLInfNorm() {
1444 return v.getLInfNorm();
1445 }
1446
1447
1448 @Override
1449 public double getDistance(RealVector w)
1450 throws DimensionMismatchException {
1451 return v.getDistance(w);
1452 }
1453
1454
1455 @Override
1456 public double getL1Distance(RealVector w)
1457 throws DimensionMismatchException {
1458 return v.getL1Distance(w);
1459 }
1460
1461
1462 @Override
1463 public double getLInfDistance(RealVector w)
1464 throws DimensionMismatchException {
1465 return v.getLInfDistance(w);
1466 }
1467
1468
1469 @Override
1470 public RealVector unitVector() throws MathArithmeticException {
1471 return v.unitVector();
1472 }
1473
1474
1475
1476
1477
1478
1479
1480 @Override
1481 public void unitize() throws MathUnsupportedOperationException {
1482 throw new MathUnsupportedOperationException();
1483 }
1484
1485
1486 @Override
1487 public RealMatrix outerProduct(RealVector w) {
1488 return v.outerProduct(w);
1489 }
1490
1491
1492 @Override
1493 public double getEntry(int index) throws OutOfRangeException {
1494 return v.getEntry(index);
1495 }
1496
1497
1498
1499
1500
1501
1502
1503 @Override
1504 public void setEntry(int index, double value)
1505 throws MathUnsupportedOperationException {
1506 throw new MathUnsupportedOperationException();
1507 }
1508
1509
1510
1511
1512
1513
1514
1515 @Override
1516 public void addToEntry(int index, double value)
1517 throws MathUnsupportedOperationException {
1518 throw new MathUnsupportedOperationException();
1519 }
1520
1521
1522 @Override
1523 public int getDimension() {
1524 return v.getDimension();
1525 }
1526
1527
1528 @Override
1529 public RealVector append(RealVector w) {
1530 return v.append(w);
1531 }
1532
1533
1534 @Override
1535 public RealVector append(double d) {
1536 return v.append(d);
1537 }
1538
1539
1540 @Override
1541 public RealVector getSubVector(int index, int n)
1542 throws OutOfRangeException, NotPositiveException {
1543 return v.getSubVector(index, n);
1544 }
1545
1546
1547
1548
1549
1550
1551
1552 @Override
1553 public void setSubVector(int index, RealVector w)
1554 throws MathUnsupportedOperationException {
1555 throw new MathUnsupportedOperationException();
1556 }
1557
1558
1559
1560
1561
1562
1563
1564 @Override
1565 public void set(double value)
1566 throws MathUnsupportedOperationException {
1567 throw new MathUnsupportedOperationException();
1568 }
1569
1570
1571 @Override
1572 public double[] toArray() {
1573 return v.toArray();
1574 }
1575
1576
1577 @Override
1578 public boolean isNaN() {
1579 return v.isNaN();
1580 }
1581
1582
1583 @Override
1584 public boolean isInfinite() {
1585 return v.isInfinite();
1586 }
1587
1588
1589 @Override
1590 public RealVector combine(double a, double b, RealVector y)
1591 throws DimensionMismatchException {
1592 return v.combine(a, b, y);
1593 }
1594
1595
1596
1597
1598
1599
1600
1601 @Override
1602 public RealVector combineToSelf(double a, double b, RealVector y)
1603 throws MathUnsupportedOperationException {
1604 throw new MathUnsupportedOperationException();
1605 }
1606
1607
1608 class UnmodifiableEntry extends Entry {
1609
1610 @Override
1611 public double getValue() {
1612 return v.getEntry(getIndex());
1613 }
1614
1615
1616
1617
1618
1619
1620
1621 @Override
1622 public void setValue(double value)
1623 throws MathUnsupportedOperationException {
1624 throw new MathUnsupportedOperationException();
1625 }
1626 }
1627 };
1628 }
1629 }