Fancy-yousa commited on
Commit
cc5b175
·
verified ·
1 Parent(s): 0f332f8

Upload 18 files

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -0
  2. Webapp/app.py +2 -2
  3. complex_com.py +141 -0
Dockerfile CHANGED
@@ -8,4 +8,9 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
9
  COPY . /code
10
 
 
 
 
 
 
11
  CMD ["python", "Webapp/app.py"]
 
8
 
9
  COPY . /code
10
 
11
+ # Fix permissions for Hugging Face Spaces (user 1000)
12
+ RUN chmod -R 777 /code
13
+
14
+ EXPOSE 7860
15
+
16
  CMD ["python", "Webapp/app.py"]
Webapp/app.py CHANGED
@@ -170,5 +170,5 @@ def api_datasets():
170
 
171
 
172
  if __name__ == "__main__":
173
- port = int(os.environ.get("PORT", 5000))
174
- app.run(host="0.0.0.0", port=port, debug=True)
 
170
 
171
 
172
  if __name__ == "__main__":
173
+ port = int(os.environ.get("PORT", 7860))
174
+ app.run(host="0.0.0.0", port=port, debug=False)
complex_com.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ from typing import Dict, Optional
3
+
4
+
5
+ class ComplexityScorer:
6
+ """
7
+ Complexity scoring for feature selection algorithms
8
+ based on instantiated time and space complexity.
9
+ """
10
+
11
+ def __init__(self, alpha: float = 0.7, log_base: float = math.e):
12
+ """
13
+ Parameters
14
+ ----------
15
+ alpha : float
16
+ Weight for time complexity in the final score.
17
+ Typical values: 0.6 ~ 0.8
18
+ log_base : float
19
+ Base of logarithm (default: natural log).
20
+ """
21
+ self.alpha = alpha
22
+ self.log_base = log_base
23
+
24
+ # ------------------------------
25
+ # Core scoring functions
26
+ # ------------------------------
27
+
28
+ def _log(self, x: float) -> float:
29
+ """Logarithm with configurable base."""
30
+ if self.log_base == math.e:
31
+ return math.log(x)
32
+ return math.log(x, self.log_base)
33
+
34
+ def complexity_score(self, value: float, min_value: float) -> float:
35
+ """
36
+ Generic complexity-to-score mapping.
37
+
38
+ Parameters
39
+ ----------
40
+ value : float
41
+ Instantiated complexity value of an algorithm.
42
+ min_value : float
43
+ Minimum complexity among all compared algorithms.
44
+
45
+ Returns
46
+ -------
47
+ score : float
48
+ Normalized score in (0, 1].
49
+ """
50
+ if value <= 0 or min_value <= 0:
51
+ raise ValueError("Complexity values must be positive.")
52
+
53
+ ratio = value / min_value
54
+ return 1.0 / (1.0 + self._log(ratio))
55
+
56
+ def time_score(self, f_t: float, f_t_min: float) -> float:
57
+ """Time complexity score."""
58
+ return self.complexity_score(f_t, f_t_min)
59
+
60
+ def space_score(self, f_s: float, f_s_min: float) -> float:
61
+ """Space complexity score."""
62
+ return self.complexity_score(f_s, f_s_min)
63
+
64
+ def total_score(
65
+ self,
66
+ f_t: float,
67
+ f_t_min: float,
68
+ f_s: float,
69
+ f_s_min: float,
70
+ ) -> float:
71
+ """Combined complexity score."""
72
+ s_t = self.time_score(f_t, f_t_min)
73
+ s_s = self.space_score(f_s, f_s_min)
74
+ return self.alpha * s_t + (1.0 - self.alpha) * s_s
75
+
76
+
77
+ # --------------------------------------
78
+ # Utility: instantiate complexity formula
79
+ # --------------------------------------
80
+
81
+ def instantiate_complexity(
82
+ formula: str,
83
+ n: int,
84
+ d: int,
85
+ k: Optional[int] = None
86
+ ) -> float:
87
+ """
88
+ Instantiate asymptotic complexity formula.
89
+
90
+ Supported variables: n, d, k
91
+
92
+ Examples
93
+ --------
94
+ "n * d**2"
95
+ "n * d * k"
96
+ "d**2"
97
+ "d + k"
98
+ """
99
+ local_vars = {"n": n, "d": d}
100
+ if k is not None:
101
+ local_vars["k"] = k
102
+
103
+ try:
104
+ return float(eval(formula, {"__builtins__": {}}, local_vars))
105
+ except Exception as e:
106
+ raise ValueError(f"Invalid complexity formula: {formula}") from e
107
+
108
+
109
+ n, d, k = 1000, 50, 10
110
+
111
+ algorithms = {
112
+ "mRMR": {"time": "n * d**2", "space": "d**2"},
113
+ "JMIM": {"time": "n * d * k", "space": "d * k"},
114
+ "CFR": {"time": "n * d * k","space": "d + k"},
115
+ "DCSF": {"time": "n * d * k", "space": "d + k"},
116
+ "IWFS": {"time": "n * d * k", "space": "d + k"},
117
+ "MRI": {"time": "n * d * k", "space": "d + k"},
118
+ "MRMD": {"time": "n * d**2", "space": "d**2"},
119
+ "UCRFS": {"time": "n * d + n**2", "space": "n**2"},
120
+
121
+
122
+ }
123
+
124
+ # Instantiate complexities
125
+ time_vals = []
126
+ space_vals = {}
127
+
128
+ for name, comp in algorithms.items():
129
+ f_t = instantiate_complexity(comp["time"], n, d, k)
130
+ f_s = instantiate_complexity(comp["space"], n, d, k)
131
+ time_vals.append(f_t)
132
+ space_vals[name] = (f_t, f_s)
133
+
134
+ f_t_min = min(time_vals)
135
+ f_s_min = min(v[1] for v in space_vals.values())
136
+
137
+ scorer = ComplexityScorer(alpha=0.7)
138
+
139
+ for name, (f_t, f_s) in space_vals.items():
140
+ score = scorer.total_score(f_t, f_t_min, f_s, f_s_min)
141
+ print(f"{name}: complexity score = {score:.4f}")