Severian commited on
Commit
2f69c82
·
verified ·
1 Parent(s): b7ed98e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -65
app.py CHANGED
@@ -130,71 +130,6 @@ df_human["source"] = "Human"
130
  df_combined = pd.concat([df_dog, df_human], ignore_index=True)
131
  print(f"Loaded {len(df_dog)} dog rows and {len(df_human)} human rows")
132
 
133
- # ---------------------------------------------------------------
134
- # CMT Implementation with Mathematical Rigor
135
- # ---------------------------------------------------------------
136
- class ExpandedCMT:
137
- def __init__(self):
138
- # These constants are from the mathematical derivation
139
- self.c1 = 0.587 + 1.223j # From first principles
140
- self.c2 = -0.994 + 0.0j # From first principles
141
- self.ZETA_POLE_REGULARIZATION = 1e6 - 1e6j
142
- self.lens_library = {
143
- "gamma": sp_special.gamma,
144
- "zeta": self._regularized_zeta,
145
- "airy": lambda z: sp_special.airy(z)[0],
146
- "bessel": lambda z: sp_special.jv(0, z),
147
- }
148
-
149
- def _regularized_zeta(self, z: np.ndarray) -> np.ndarray:
150
- """Handle the pole at z=1 mathematically."""
151
- z_out = np.copy(z).astype(np.complex128)
152
- pole_condition = np.isclose(np.real(z), 1.0) & np.isclose(np.imag(z), 0.0)
153
- non_pole_points = ~pole_condition
154
- z_out[non_pole_points] = sp_special.zeta(z[non_pole_points], 1)
155
- z_out[pole_condition] = self.ZETA_POLE_REGULARIZATION
156
- return z_out
157
-
158
- def _robust_normalize(self, signal: np.ndarray) -> np.ndarray:
159
- if signal.size == 0:
160
- return signal
161
- Q1, Q3 = np.percentile(signal, [25, 75])
162
- IQR = Q3 - Q1
163
- if IQR < 1e-9:
164
- median = np.median(signal)
165
- mad = np.median(np.abs(signal - median))
166
- return np.zeros_like(signal) if mad < 1e-9 else (signal - median) / (mad + 1e-9)
167
- lower, upper = Q1 - 1.5 * IQR, Q3 + 1.5 * IQR
168
- clipped = np.clip(signal, lower, upper)
169
- s_min, s_max = np.min(clipped), np.max(clipped)
170
- return np.zeros_like(signal) if s_max == s_min else 2.0 * (clipped - s_min) / (s_max - s_min) - 1.0
171
-
172
- def _encode(self, signal: np.ndarray) -> np.ndarray:
173
- N = len(signal)
174
- if N == 0:
175
- return signal.astype(np.complex128)
176
- i = np.arange(N)
177
- theta = 2.0 * np.pi * i / N
178
- # These frequency and amplitude values are from the mathematical derivation
179
- f_k = np.array([271, 341, 491])
180
- A_k = np.array([0.033, 0.050, 0.100])
181
- phi = np.sum(A_k[:, None] * np.sin(2.0 * np.pi * f_k[:, None] * i / N), axis=0)
182
- Theta = theta + phi
183
- exp_iTheta = np.exp(1j * Theta)
184
- g = signal * exp_iTheta
185
- m = np.abs(signal) * exp_iTheta
186
- return 0.5 * g + 0.5 * m
187
-
188
- def _apply_lens(self, encoded_signal: np.ndarray, lens_type: str):
189
- lens_fn = self.lens_library.get(lens_type)
190
- if not lens_fn:
191
- raise ValueError(f"Lens '{lens_type}' not found.")
192
- with np.errstate(all="ignore"):
193
- w = lens_fn(encoded_signal)
194
- phi_trajectory = self.c1 * np.angle(w) + self.c2 * np.abs(encoded_signal)
195
- finite_mask = np.isfinite(phi_trajectory)
196
- return (phi_trajectory[finite_mask], w[finite_mask], encoded_signal[finite_mask],
197
- len(encoded_signal), len(phi_trajectory[finite_mask]))
198
 
199
  # ---------------------------------------------------------------
200
  # Feature preparation and UMAP embedding
 
130
  df_combined = pd.concat([df_dog, df_human], ignore_index=True)
131
  print(f"Loaded {len(df_dog)} dog rows and {len(df_human)} human rows")
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
  # ---------------------------------------------------------------
135
  # Feature preparation and UMAP embedding