date.iterator.count.isodata.Point Maven / Gradle / Ivy
package date.iterator.count.isodata;
import date.iterator.count.util.CalculationUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Point {
// private double y; // 客户价值
// private double x; // avg_interval与最后一次购买时间的差值
//字段名和值
private Map values;
private long id;
public Point() {
values = new HashMap<>();
}
public Point(final Map values) {
this.values = values;
}
/*作为中心点的虚点方法,正常点不可使用,有空建立个Center对象,方法用于聚类拆分时,产生新的虚中心点*/
public Point displaceAxisOpposite(final String key, final Double value) {
double newValue = value;
if (values.containsKey(key)) {
newValue += values.get(key);
}
values.put(key, newValue);
return this;
}
public Point Copy() {
Point point = new Point();
for (String each : values.keySet()) {
point.getValues().put(each, this.values.get(each));
}
return point;
}
@Deprecated
private double standardDeviation(final Point anotherPoint) {
double squaredError = 0;
for (String eachTitle : ISODataConstants.Data_Value_Title) {
Double otherValue = anotherPoint.getValues().get(eachTitle);
Double curretValue = values.get(eachTitle);
squaredError += Math.pow(Math.abs(otherValue - curretValue), 2);
}
squaredError = squaredError / ISODataConstants.Data_Value_Title.length;
return Math.sqrt(squaredError);
}
/*
* 两点间欧式距离
* */
public double distanceEuclidean(final Point anotherPoint) {
return CalculationUtil.distanceEuclidean(this, anotherPoint);
}
/*
* 到各聚类中心的欧式距离
* */
public List calculateCenterDistances(final List clusters) {
List result = new ArrayList<>();
for (Cluster eachCluster : clusters) {
result.add(distanceEuclidean(eachCluster.getCenter()));
}
return result;
}
@Override
public String toString() {
String result = "ID:" + getId() + "---";
for (String eachKey : values.keySet()) {
result += "|" + eachKey + ":" + values.get(eachKey);
}
return result;
}
public Map getValues() {
return values;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}