alinemol.models¶
ALineMol provides two model families for the ID/OOD benchmarks: a classical machine-learning baseline and fragment-aware graph neural networks.
Classical ML baseline¶
CML is a light wrapper around scikit-learn's RandomForestClassifier exposing
the standard estimator API. It requires no deep-learning dependencies and serves
as the in-distribution reference model.
from alinemol.models.cml import CML
clf = CML()
clf.fit(X_train, y_train)
proba = clf.predict_proba(X_test)
CML
¶
Classical machine-learning baseline classifier.
A thin wrapper around :class:sklearn.ensemble.RandomForestClassifier that
exposes the standard scikit-learn estimator API (fit/predict/
predict_proba/score/get_params/set_params). It provides a
simple, dependency-light baseline for molecular property classification that
can be compared against the graph neural network models in
:mod:alinemol.models.fragGNN.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The underlying |
Example
from alinemol.models.cml import CML clf = CML() clf.fit(X_train, y_train) # doctest: +SKIP preds = clf.predict(X_test) # doctest: +SKIP
fit
¶
Fit the random forest on training features and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix of shape |
required |
y
|
ndarray
|
Target labels of shape |
required |
predict
¶
Predict class labels for X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Predicted class labels of shape |
predict_proba
¶
Predict class probabilities for X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Array of shape |
|
|
per-class probabilities. |
score
¶
Return the mean accuracy on the given test data and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix of shape |
required |
y
|
ndarray
|
True labels of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Mean accuracy in |
get_params
¶
Get parameters of the underlying estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deep
|
bool
|
If |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Mapping of parameter names to their values. |
set_params
¶
Set parameters of the underlying estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**params
|
Estimator parameters to set. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
RandomForestClassifier |
The wrapped estimator with updated |
|
|
parameters. |
Graph neural networks¶
Requires the [gnn] extra
The GNN models depend on torch, torch-geometric, DGL/DGL-LifeSci, and
torch-scatter. Install with pip install -e ".[gnn]" (and a matching
torch-scatter wheel for your torch/CUDA build). They are described here
rather than auto-documented so this documentation builds without the heavy
GNN stack.
FragGNN¶
alinemol.models.fragGNN.FragGNN is a fragment-aware graph neural network built
on GIN/GINE convolutions. It encodes atoms, bonds, and molecular fragments with
dedicated encoders and exchanges information between the atom- and fragment-level
representations via message passing. A smaller variant, FragGNNSmall, is
available for lighter-weight experiments.
Key building blocks live in alinemol.models.layers:
| Layer | Role |
|---|---|
AtomEncoder |
Embeds atom features |
BondEncoder |
Embeds bond features |
FragEncoder |
Embeds fragment-level features |
InterMessage |
Passes messages between atom and fragment views |
MLP |
Generic multi-layer perceptron head |
See the training scripts (scripts/clf_train_gnn.py) for an
end-to-end GNN training example, and the
Hyperparameters reference for the search spaces used to tune them.
Source¶
Full model source is on GitHub.