This example shows the detection of a circular pattern in high-dimensional data.
The data contains seven mesurements of electric power consumption for a single household over two years, for a daily sampling.
This can be interpreted as 700 points (on per day) in R^7.
The distance matrix between these points is computed using TableDistanceMatrix.
Using the distance matrix, a clustering of the input data is performed using ParaView's K-means algorithm (with k=8).
The points are then embedded in 3D using MDS, with DimensionReduction.
At this point, the 2-dimensional Rips complex is computed with RipsComplex from the high-dimensional point cloud, and shown in 3D via MDS projection.
Finally an infinitely persistent 1-cycle is extracted from the Rips complex with PersistentGenerators, on the diameter function.
This cycle captures a circular pattern present in the data, implying that in
practice, continuous displacements from one cluster to another are
likely to imply transformations through other clusters present along the cycle.
The python script saves the resulting point cloud, Rips complex and output cycle as vtk files.
#!/usr/bin/env pythonfromparaview.simpleimport*# create a new 'CSV Reader'household_part1_ID_dailycsv=CSVReader(FileName=["household_part1_ID_daily.csv"])household_part1_ID_dailycsv.HaveHeaders=0# create a new 'TTK DimensionReduction'tTKDimensionReduction1=TTKDimensionReduction(Input=household_part1_ID_dailycsv,ModulePath="default")tTKDimensionReduction1.InputColumns=["Field 2","Field 3","Field 4","Field 5","Field 6","Field 7","Field 8",]tTKDimensionReduction1.Method="Principal Component Analysis"tTKDimensionReduction1.Components=3# create a new 'TTK TableDistanceMatrix'tTKTableDistanceMatrix1=TTKTableDistanceMatrix(Input=tTKDimensionReduction1)tTKTableDistanceMatrix1.InputColumns=["Field 2","Field 3","Field 4","Field 5","Field 6","Field 7","Field 8",]# create a new 'Table To Points'tableToPoints1=TableToPoints(Input=tTKDimensionReduction1)tableToPoints1.XColumn="Component_0"tableToPoints1.YColumn="Component_1"tableToPoints1.ZColumn="Component_2"tableToPoints1.KeepAllDataArrays=1# create a new 'K Means'kMeans1=KMeans(Input=tableToPoints1,ModelInput=None)kMeans1.VariablesofInterest=["Component_0","Component_1","Component_2"]kMeans1.k=8# create a new 'TTK RipsComplex'tTKRipsComplex1=TTKRipsComplex(Input=tTKTableDistanceMatrix1)tTKRipsComplex1.SelectFieldswithaRegexp=1tTKRipsComplex1.Regexp="Dist.*"tTKRipsComplex1.Diameterepsilon=18.0# create a new 'Cell Data to Point Data'cellDatatoPointData1=CellDatatoPointData(Input=tTKRipsComplex1)cellDatatoPointData1.CellDataArraytoprocess=["Diameter"]# create a new 'Threshold'threshold1=Threshold(Input=cellDatatoPointData1)threshold1.Scalars=["POINTS","Diameter"]threshold1.LowerThreshold=9.0threshold1.UpperThreshold=17.38239404772305# create a new 'TTK PersistentGenerators'tTKPersistentGenerators1=TTKPersistentGenerators(Input=threshold1)tTKPersistentGenerators1.ScalarField=["POINTS","Diameter"]tTKPersistentGenerators1.PruneHandlesGenerators=1SaveData("PersistentGeneratorsHouseholdAnalysis_cycle.vtp",tTKPersistentGenerators1)SaveData("PersistentGeneratorsHouseholdAnalysis_points.vtp",OutputPort(kMeans1,1))SaveData("PersistentGeneratorsHouseholdAnalysis_ripsComplex.vtu",tTKRipsComplex1)
To run the above Python script, go to your ttk-data directory and enter the following command: