# source:orange/docs/reference/rst/code/mds-advanced.py@10633:fb05a6f3a235

Revision 10633:fb05a6f3a235, 1.1 KB checked in by mstajdohar, 2 years ago (diff)

Changed obsolete names.

Line
1# Description: Advanced MDS test: 1000 optimization iterations, stress calculation after every 10th
2# Category:    projection
3# Uses:        iris
4# Referenced:  Orange.projection.mds
5# Classes:     Orange.projection.mds.MDS
6
7import Orange
8import math
9
10# Load some data
11iris = Orange.data.Table("iris.tab")
12
13# Construct a distance matrix using Euclidean distance
14dist = Orange.distance.Euclidean(iris)
15matrix = Orange.misc.SymMatrix(len(iris))
16for i in range(len(iris)):
17   for j in range(i + 1):
18       matrix[i, j] = dist(iris[i], iris[j])
19
20# Run the Torgerson approximation and calculate stress
21mds = Orange.projection.mds.MDS(matrix)
22mds.torgerson()
23mds.calc_stress(Orange.projection.mds.KruskalStress)
24
25# Optimization loop; calculate the stress only after each 10 optimization steps:
26for i in range(100):
27    old_stress = mds.avg_stress
28    for j in range(10):
29        mds.smacof_step()
30
31    mds.calc_stress(Orange.projection.mds.KruskalStress)
32    if old_stress * 1e-3 > math.fabs(old_stress - mds.avg_stress):
33        break
34
35# Print the points out
36for (p, e) in zip(mds.points, iris):
37    print p, e
Note: See TracBrowser for help on using the repository browser.