-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSublevel-Set-TDA.py
71 lines (53 loc) · 1.98 KB
/
Sublevel-Set-TDA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
Created on Mon May 18 22:44:06 2020
@author: afran
"""
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import os
import sys
from ripser import ripser
from scipy import sparse
from persim import plot_diagrams
from persim import PersImage
from sklearn.svm import LinearSVC
from utils import *
###########################################################################
# Computing Mean of Each Signal & Normalizing Signal
print("Computing Mean of Each Signal & Normalizing Signal")
mean_normalize("./Dummy_Dataset/")
# Computing Maximum Magnitude Point Across All Samples
print("Computing Maximum Magnitude Point Across All Samples")
max_magnitude = find_max_magnitude("./Mean_Normalized_Signals/")
# Range Enforcing All Signals
print("Range Enforcing All Signals")
range_enforce("./Mean_Normalized_Signals/", max_magnitude)
# Persistence Diagram Generation
print("Generating Persistence Diagrams")
generate_persistence_diagrams("./Range_Enforced_Signals/")
# Persistence Image Generation - Persistence Image Parameters Subject to User Tuning
print("Generating Persistence Images")
reduction = 0.08
pixel = 100
spreadval = 0.015
rangemin = -0.7
rangemax = 0.7
generate_persistence_images("./Persistence_Diagrams/", reduction, pixel, spreadval, rangemin, rangemax)
# SVM Classification - Parameters for SVM Classification Subject to User Tuning
###############################
print("....................................")
print("....................................")
print("....................................")
print("Beginning SVM Classification")
SVM_random_state=None
SVM_dual=True
SVM_penalty='l2'
SVM_max_iter=1000
SVM_C=1.0
accuracy = SVM_leave_one_classify("./Persistence_Images/", SVM_random_state, SVM_dual, SVM_penalty, SVM_max_iter, SVM_C)
print("....................................")
print("....................................")
print("....................................")
print ("The SVM is " + str(accuracy*100) + " percent accurate")