source: src/main/java/agents/anac/y2019/harddealer/math3/stat/clustering/EuclideanDoublePoint.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: 3.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.stat.clustering;
18
19import java.io.Serializable;
20import java.util.Collection;
21import java.util.Arrays;
22
23import agents.anac.y2019.harddealer.math3.util.MathArrays;
24
25/**
26 * A simple implementation of {@link Clusterable} for points with double coordinates.
27 * @since 3.1
28 * @deprecated As of 3.2 (to be removed in 4.0),
29 * use {@link agents.anac.y2019.harddealer.math3.ml.clustering.DoublePoint} instead
30 */
31@Deprecated
32public class EuclideanDoublePoint implements Clusterable<EuclideanDoublePoint>, Serializable {
33
34 /** Serializable version identifier. */
35 private static final long serialVersionUID = 8026472786091227632L;
36
37 /** Point coordinates. */
38 private final double[] point;
39
40 /**
41 * Build an instance wrapping an integer array.
42 * <p>
43 * The wrapped array is referenced, it is <em>not</em> copied.
44 *
45 * @param point the n-dimensional point in integer space
46 */
47 public EuclideanDoublePoint(final double[] point) {
48 this.point = point;
49 }
50
51 /** {@inheritDoc} */
52 public EuclideanDoublePoint centroidOf(final Collection<EuclideanDoublePoint> points) {
53 final double[] centroid = new double[getPoint().length];
54 for (final EuclideanDoublePoint p : points) {
55 for (int i = 0; i < centroid.length; i++) {
56 centroid[i] += p.getPoint()[i];
57 }
58 }
59 for (int i = 0; i < centroid.length; i++) {
60 centroid[i] /= points.size();
61 }
62 return new EuclideanDoublePoint(centroid);
63 }
64
65 /** {@inheritDoc} */
66 public double distanceFrom(final EuclideanDoublePoint p) {
67 return MathArrays.distance(point, p.getPoint());
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 public boolean equals(final Object other) {
73 if (!(other instanceof EuclideanDoublePoint)) {
74 return false;
75 }
76 return Arrays.equals(point, ((EuclideanDoublePoint) other).point);
77 }
78
79 /**
80 * Get the n-dimensional point in integer space.
81 *
82 * @return a reference (not a copy!) to the wrapped array
83 */
84 public double[] getPoint() {
85 return point;
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public int hashCode() {
91 return Arrays.hashCode(point);
92 }
93
94 /** {@inheritDoc} */
95 @Override
96 public String toString() {
97 return Arrays.toString(point);
98 }
99
100}
Note: See TracBrowser for help on using the repository browser.