API Reference
hNMF.model
hnmf.model.HierarchicalNMF(k, unbalanced=0.1, init=None, solver='cd', beta_loss=0, alpha_W=0.0, alpha_H='same', random_state=42, trial_allowance=100, tol=1e-06, maxiter=10000, dtype=np.float64)
Bases: BaseEstimator
Methods:
| Name | Description |
|---|---|
_init_fit |
|
_stack_H_buffer |
|
_stack_clusters |
|
cluster_assignments |
Returns a mapping of features and their assigned cluster(s) |
cluster_features |
Returns the features assigned as a cluster to nodes |
fit |
Fit |
top_discriminative_samples_in_node |
Computes most discriminative samples (node vs rest) |
top_features_in_node |
For a given node, return the top n features and values |
top_nodes_in_feature |
Returns the top nodes for a specified feature |
top_nodes_in_samples |
Returns the top nodes for each sample. |
top_samples_in_nodes |
Returns the top samples for each node |
Attributes:
| Name | Type | Description |
|---|---|---|
H_buffer_ |
NDArray | None
|
|
Hs_ |
NDArray | None
|
|
W_buffer_ |
NDArray | None
|
|
Ws_ |
NDArray | None
|
|
alpha_H |
Literal['same'] | float
|
|
alpha_W |
float
|
|
beta_loss |
Literal['FRO', 0, 'KL', 1, 'IS', 2]
|
|
clusters_ |
NDArray | None
|
|
dtype |
DTypeLike
|
|
init |
Literal[None, 'random', 'nndsvd', 'nndsvda', 'nndsvdar']
|
|
is_leaf_ |
NDArray | None
|
|
k |
int
|
|
maxiter |
int
|
|
n_features_ |
int | None
|
|
n_leaves_ |
int
|
|
n_nodes_ |
int
|
|
n_samples_ |
int | None
|
|
priorities_ |
NDArray | None
|
|
random_state |
RandomState
|
|
solver |
Literal['cd', 'mu']
|
|
splits_ |
NDArray | None
|
|
tol |
float
|
|
tree_ |
NDArray | None
|
|
trial_allowance |
int
|
|
unbalanced |
float
|
|
Source code in src/hnmf/model.py
H_buffer_ = None
instance-attribute
Hs_ = None
instance-attribute
W_buffer_ = None
instance-attribute
Ws_ = None
instance-attribute
alpha_H = alpha_H
instance-attribute
alpha_W = alpha_W
instance-attribute
beta_loss = beta_loss
instance-attribute
clusters_ = None
instance-attribute
dtype = dtype
instance-attribute
init = init
instance-attribute
is_leaf_ = None
instance-attribute
k = k
instance-attribute
maxiter = maxiter
instance-attribute
n_features_ = None
instance-attribute
n_leaves_ = 0
instance-attribute
n_nodes_ = 0
instance-attribute
n_samples_ = None
instance-attribute
priorities_ = None
instance-attribute
random_state = np.random.RandomState(seed=random_state)
instance-attribute
solver = solver
instance-attribute
splits_ = None
instance-attribute
tol = tol
instance-attribute
tree_ = None
instance-attribute
trial_allowance = trial_allowance
instance-attribute
unbalanced = unbalanced
instance-attribute
_init_fit(X, term_subset)
Source code in src/hnmf/model.py
_stack_H_buffer(buffer)
Source code in src/hnmf/model.py
_stack_clusters(clusters)
Source code in src/hnmf/model.py
cluster_assignments(leaves_only=True, include_outliers=True)
Returns a mapping of features and their assigned cluster(s)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
leaves_only
|
bool
|
Whether to return only leaf nodes |
True
|
include_outliers
|
bool
|
If True, include feature_idx keys that are not assigned a cluster. |
True
|
Source code in src/hnmf/model.py
cluster_features(leaves_only=True, include_outliers=True)
Returns the features assigned as a cluster to nodes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
leaves_only
|
bool
|
Whether to return only leaf nodes |
True
|
include_outliers
|
bool
|
If True, features without a node assignment are returned under the key -1 |
True
|
Source code in src/hnmf/model.py
fit(X)
Fit HierarchicalNMF to data
Source code in src/hnmf/model.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
top_discriminative_samples_in_node(node, n=10, sign='abs')
Computes most discriminative samples (node vs rest)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
int
|
|
required |
n
|
int
|
The number of features to return |
10
|
sign
|
Literal['positive', 'negative', 'abs']
|
One of |
'abs'
|
Returns:
| Type | Description |
|---|---|
list of dict with form::
|
sample: Any node: int node_value: float others_value: float |
Source code in src/hnmf/model.py
top_features_in_node(node, n=10)
For a given node, return the top n features and values
Source code in src/hnmf/model.py
top_nodes_in_feature(feature_idx, n=10, leaves_only=True)
Returns the top nodes for a specified feature
Source code in src/hnmf/model.py
top_nodes_in_samples(n=10, leaves_only=True)
Returns the top nodes for each sample.
Source code in src/hnmf/model.py
top_samples_in_nodes(n=10, leaves_only=True)
Returns the top samples for each node
Source code in src/hnmf/model.py
hNMF.helpers
hnmf.helpers
nmfsh_comb_rank2(A, Winit, Hinit, anls_alg, vec_norm, normW, tol, maxiter, dtype)
Source code in src/hnmf/helpers.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |