date.iterator.count.pic.PlotTest.scala Maven / Gradle / Ivy
package date.iterator.count.pic
import java.util
import date.iterator.count.isodata.ISOData
import date.iterator.count.util.CalculationUtil
//import breeze.linalg.DenseVector
import breeze.plot._
import com.saaavsaaa.client.event.EventCenter
import date.iterator.count.event.{IteratorEventType, PlotTestListener}
import date.iterator.count.isodata.Cluster
object PlotTest {
private val expectK = 15 // 预期的聚类中心数目;
private val totalLoopI = 20 // 迭代运算的次数。
private val theta_S = 3 //θS 一个类中样本距离分布的标准差阈值。类内最大标准差分量应小于 θs
private val theta_c = 1 //θc 两个聚类中心间的最小距离,若小于此数,两个聚类需进行合并;
private val pointSize = 5000
private val initK = 5
val sourceCol = "features"
def main(args: Array[String]): Unit = {
val f = Figure("saaav")
//curve(f)
//stepByStep(f)
// TODO: 生成验证节点写入文本,读出使用
val isoData: ISOData = new ISOData(expectK, totalLoopI, theta_S, theta_c, initK, CalculationUtil.testPoints(pointSize))
val clusters: util.List[Cluster] = isoData.calculate()
test(clusters, f)
}
import breeze.linalg._
def curve(f: Figure): Unit = {
val p = f.subplot(0)
val x = linspace(0.0, 2.0)
p += plot(x, x ^:^ 2.0)
p += plot(x, x ^:^ 3.0, '.')
p.xlabel = "x axis"
p.ylabel = "y axis"
f.saveas("E:\\Github\\Iterator\\out\\lllll.png")
}
def stepByStep(f: Figure): Unit = {
EventCenter.INSTANCE.updateListener(IteratorEventType.PLOT, new PlotTestListener(f))
EventCenter.INSTANCE.start()
}
def test(clusters: util.List[Cluster], f: Figure): Unit = {
println("plot cluster size : " + clusters.size())
val p = f.subplot(0)
var xAxis: scala.collection.immutable.List[Double] = List()
var yAxis: scala.collection.immutable.List[Double] = List()
var xCenter: scala.collection.immutable.List[Double] = List()
var yCenter: scala.collection.immutable.List[Double] = List()
val clustersIterator = clusters.iterator()
while (clustersIterator.hasNext) {
val eachCluster : Cluster = clustersIterator.next()
println("plot : " + eachCluster.toString)
val pointsIterator = eachCluster.getPoints.iterator()
while (pointsIterator.hasNext) {
val eachPoint = pointsIterator.next()
xAxis = eachPoint.getValues.values().toArray.apply(0).asInstanceOf[Double] +: xAxis
yAxis = eachPoint.getValues.values().toArray.apply(1).asInstanceOf[Double] +: yAxis
}
p += plot(xAxis, yAxis, '.')
xCenter = eachCluster.getCenter.getValues.values().toArray.apply(0).asInstanceOf[Double] +: xCenter
yCenter = eachCluster.getCenter.getValues.values().toArray.apply(1).asInstanceOf[Double] +: yCenter
}
p += plot(xCenter, yCenter, '+')
//p += scatter(xCenter, yCenter, 3)
p.xlabel = "avg_interval"
p.ylabel = "cst_value"
// f.saveas("E:\\Github\\Iterator\\out\\scatter" + pointSize + ".png")
val p2 = f.subplot(2, 1, 1)
p2 += plot(xCenter, yCenter, '+')
p2.title = "Center distribution"
// f.saveas("E:\\Github\\Iterator\\out\\centers" + pointSize + ".png")
}
}