source: src/main/java/agents/anac/y2019/harddealer/math3/linear/FieldVector.java

Last change on this file was 204, checked in by Katsuhide Fujita, 5 years ago

Fixed errors of ANAC2019 agents

  • Property svn:executable set to *
File size: 11.1 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package agents.anac.y2019.harddealer.math3.linear;
18
19import agents.anac.y2019.harddealer.math3.Field;
20import agents.anac.y2019.harddealer.math3.FieldElement;
21import agents.anac.y2019.harddealer.math3.exception.DimensionMismatchException;
22import agents.anac.y2019.harddealer.math3.exception.MathArithmeticException;
23import agents.anac.y2019.harddealer.math3.exception.NotPositiveException;
24import agents.anac.y2019.harddealer.math3.exception.NullArgumentException;
25import agents.anac.y2019.harddealer.math3.exception.OutOfRangeException;
26
27/**
28 * Interface defining a field-valued vector with basic algebraic operations.
29 * <p>
30 * vector element indexing is 0-based -- e.g., <code>getEntry(0)</code>
31 * returns the first element of the vector.
32 * </p>
33 * <p>
34 * The various <code>mapXxx</code> and <code>mapXxxToSelf</code> methods operate
35 * on vectors element-wise, i.e. they perform the same operation (adding a scalar,
36 * applying a function ...) on each element in turn. The <code>mapXxx</code>
37 * versions create a new vector to hold the result and do not change the instance.
38 * The <code>mapXxxToSelf</code> versions use the instance itself to store the
39 * results, so the instance is changed by these methods. In both cases, the result
40 * vector is returned by the methods, this allows to use the <i>fluent API</i>
41 * style, like this:
42 * </p>
43 * <pre>
44 * RealVector result = v.mapAddToSelf(3.0).mapTanToSelf().mapSquareToSelf();
45 * </pre>
46 * <p>
47 * Note that as almost all operations on {@link FieldElement} throw {@link
48 * NullArgumentException} when operating on a null element, it is the responsibility
49 * of <code>FieldVector</code> implementations to make sure no null elements
50 * are inserted into the vector. This must be done in all constructors and
51 * all setters.
52 * <p>
53 *
54 * @param <T> the type of the field elements
55 * @since 2.0
56 */
57public interface FieldVector<T extends FieldElement<T>> {
58
59 /**
60 * Get the type of field elements of the vector.
61 * @return type of field elements of the vector
62 */
63 Field<T> getField();
64
65 /**
66 * Returns a (deep) copy of this.
67 * @return vector copy
68 */
69 FieldVector<T> copy();
70
71 /**
72 * Compute the sum of {@code this} and {@code v}.
73 * @param v vector to be added
74 * @return {@code this + v}
75 * @throws DimensionMismatchException if {@code v} is not the same size as {@code this}
76 */
77 FieldVector<T> add(FieldVector<T> v) throws DimensionMismatchException;
78
79 /**
80 * Compute {@code this} minus {@code v}.
81 * @param v vector to be subtracted
82 * @return {@code this - v}
83 * @throws DimensionMismatchException if {@code v} is not the same size as {@code this}
84 */
85 FieldVector<T> subtract(FieldVector<T> v) throws DimensionMismatchException;
86
87 /**
88 * Map an addition operation to each entry.
89 * @param d value to be added to each entry
90 * @return {@code this + d}
91 * @throws NullArgumentException if {@code d} is {@code null}.
92 */
93 FieldVector<T> mapAdd(T d) throws NullArgumentException;
94
95 /**
96 * Map an addition operation to each entry.
97 * <p>The instance <strong>is</strong> changed by this method.</p>
98 * @param d value to be added to each entry
99 * @return for convenience, return {@code this}
100 * @throws NullArgumentException if {@code d} is {@code null}.
101 */
102 FieldVector<T> mapAddToSelf(T d) throws NullArgumentException;
103
104 /**
105 * Map a subtraction operation to each entry.
106 * @param d value to be subtracted to each entry
107 * @return {@code this - d}
108 * @throws NullArgumentException if {@code d} is {@code null}
109 */
110 FieldVector<T> mapSubtract(T d) throws NullArgumentException;
111
112 /**
113 * Map a subtraction operation to each entry.
114 * <p>The instance <strong>is</strong> changed by this method.</p>
115 * @param d value to be subtracted to each entry
116 * @return for convenience, return {@code this}
117 * @throws NullArgumentException if {@code d} is {@code null}
118 */
119 FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException;
120
121 /**
122 * Map a multiplication operation to each entry.
123 * @param d value to multiply all entries by
124 * @return {@code this * d}
125 * @throws NullArgumentException if {@code d} is {@code null}.
126 */
127 FieldVector<T> mapMultiply(T d) throws NullArgumentException;
128
129 /**
130 * Map a multiplication operation to each entry.
131 * <p>The instance <strong>is</strong> changed by this method.</p>
132 * @param d value to multiply all entries by
133 * @return for convenience, return {@code this}
134 * @throws NullArgumentException if {@code d} is {@code null}.
135 */
136 FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException;
137
138 /**
139 * Map a division operation to each entry.
140 * @param d value to divide all entries by
141 * @return {@code this / d}
142 * @throws NullArgumentException if {@code d} is {@code null}.
143 * @throws MathArithmeticException if {@code d} is zero.
144 */
145 FieldVector<T> mapDivide(T d)
146 throws NullArgumentException, MathArithmeticException;
147
148 /**
149 * Map a division operation to each entry.
150 * <p>The instance <strong>is</strong> changed by this method.</p>
151 * @param d value to divide all entries by
152 * @return for convenience, return {@code this}
153 * @throws NullArgumentException if {@code d} is {@code null}.
154 * @throws MathArithmeticException if {@code d} is zero.
155 */
156 FieldVector<T> mapDivideToSelf(T d)
157 throws NullArgumentException, MathArithmeticException;
158
159 /**
160 * Map the 1/x function to each entry.
161 * @return a vector containing the result of applying the function to each entry.
162 * @throws MathArithmeticException if one of the entries is zero.
163 */
164 FieldVector<T> mapInv() throws MathArithmeticException;
165
166 /**
167 * Map the 1/x function to each entry.
168 * <p>The instance <strong>is</strong> changed by this method.</p>
169 * @return for convenience, return {@code this}
170 * @throws MathArithmeticException if one of the entries is zero.
171 */
172 FieldVector<T> mapInvToSelf() throws MathArithmeticException;
173
174 /**
175 * Element-by-element multiplication.
176 * @param v vector by which instance elements must be multiplied
177 * @return a vector containing {@code this[i] * v[i]} for all {@code i}
178 * @throws DimensionMismatchException if {@code v} is not the same size as {@code this}
179 */
180 FieldVector<T> ebeMultiply(FieldVector<T> v)
181 throws DimensionMismatchException;
182
183 /**
184 * Element-by-element division.
185 * @param v vector by which instance elements must be divided
186 * @return a vector containing {@code this[i] / v[i]} for all {@code i}
187 * @throws DimensionMismatchException if {@code v} is not the same size as {@code this}
188 * @throws MathArithmeticException if one entry of {@code v} is zero.
189 */
190 FieldVector<T> ebeDivide(FieldVector<T> v)
191 throws DimensionMismatchException, MathArithmeticException;
192
193 /**
194 * Returns vector entries as a T array.
195 * @return T array of entries
196 * @deprecated as of 3.1, to be removed in 4.0. Please use the {@link #toArray()} method instead.
197 */
198 @Deprecated
199 T[] getData();
200
201 /**
202 * Compute the dot product.
203 * @param v vector with which dot product should be computed
204 * @return the scalar dot product of {@code this} and {@code v}
205 * @throws DimensionMismatchException if {@code v} is not the same size as {@code this}
206 */
207 T dotProduct(FieldVector<T> v) throws DimensionMismatchException;
208
209 /**
210 * Find the orthogonal projection of this vector onto another vector.
211 * @param v vector onto which {@code this} must be projected
212 * @return projection of {@code this} onto {@code v}
213 * @throws DimensionMismatchException if {@code v} is not the same size as {@code this}
214 * @throws MathArithmeticException if {@code v} is the null vector.
215 */
216 FieldVector<T> projection(FieldVector<T> v)
217 throws DimensionMismatchException, MathArithmeticException;
218
219 /**
220 * Compute the outer product.
221 * @param v vector with which outer product should be computed
222 * @return the matrix outer product between instance and v
223 */
224 FieldMatrix<T> outerProduct(FieldVector<T> v);
225
226 /**
227 * Returns the entry in the specified index.
228 *
229 * @param index Index location of entry to be fetched.
230 * @return the vector entry at {@code index}.
231 * @throws OutOfRangeException if the index is not valid.
232 * @see #setEntry(int, FieldElement)
233 */
234 T getEntry(int index) throws OutOfRangeException;
235
236 /**
237 * Set a single element.
238 * @param index element index.
239 * @param value new value for the element.
240 * @throws OutOfRangeException if the index is not valid.
241 * @see #getEntry(int)
242 */
243 void setEntry(int index, T value) throws OutOfRangeException;
244
245 /**
246 * Returns the size of the vector.
247 * @return size
248 */
249 int getDimension();
250
251 /**
252 * Construct a vector by appending a vector to this vector.
253 * @param v vector to append to this one.
254 * @return a new vector
255 */
256 FieldVector<T> append(FieldVector<T> v);
257
258 /**
259 * Construct a vector by appending a T to this vector.
260 * @param d T to append.
261 * @return a new vector
262 */
263 FieldVector<T> append(T d);
264
265 /**
266 * Get a subvector from consecutive elements.
267 * @param index index of first element.
268 * @param n number of elements to be retrieved.
269 * @return a vector containing n elements.
270 * @throws OutOfRangeException if the index is not valid.
271 * @throws NotPositiveException if the number of elements if not positive.
272 */
273 FieldVector<T> getSubVector(int index, int n)
274 throws OutOfRangeException, NotPositiveException;
275
276 /**
277 * Set a set of consecutive elements.
278 * @param index index of first element to be set.
279 * @param v vector containing the values to set.
280 * @throws OutOfRangeException if the index is not valid.
281 */
282 void setSubVector(int index, FieldVector<T> v) throws OutOfRangeException;
283
284 /**
285 * Set all elements to a single value.
286 * @param value single value to set for all elements
287 */
288 void set(T value);
289
290 /**
291 * Convert the vector to a T array.
292 * <p>The array is independent from vector data, it's elements
293 * are copied.</p>
294 * @return array containing a copy of vector elements
295 */
296 T[] toArray();
297
298}
Note: See TracBrowser for help on using the repository browser.