Skip to content

← machine_learning package

RelaxedSpikeSlabClassification

Classify data instances using binary sparse Bayesian logistic regression with a relaxed (Gaussian) spike-and-slab prior.

This node is designed for the difficult regime where the number of features is much larger than the number of observations and only a small minority of features are expected to be relevant. The model combines a global inclusion probability with per-feature soft inclusion variables and Gaussian slab/spike scales. Variational inference is used for efficient fitting in JAX, and empirical-Bayes updates learn the global inclusion probability and slab scale during optimization by default. This yields posterior inclusion probabilities for each feature together with a posterior-mean weight vector for downstream prediction and interpretation. As with other NeuroPype machine-learning nodes, this method expects a full calibration packet containing both training instances and labels before it can be used for prediction on subsequent data. Version 0.7.0

Ports/Properties

data

Data to process.

  • verbose name: Data
  • default value: None
  • port type: DataPort
  • value type: Packet (can be None)
  • data direction: INOUT

cond_field

The name of the instance data field that contains the conditions to be discriminated. This parameter will be ignored if the packet has previously been processed by a DescribeStatisticalDesign node.

  • verbose name: Cond Field
  • default value: TargetValue
  • port type: StringPort
  • value type: str (can be None)

feature_scaling

Feature scaling to use. The spike-and-slab prior acts on coefficient scale, so standardization is recommended in most cases.

  • verbose name: Feature Scaling
  • default value: std
  • port type: EnumPort
  • value type: str (can be None)

sample_size_factor

Sample size correction factor or effective sample size. When observations are not independent (e.g., multiple trials per participant), the effective information content may be considerably lower than the nominal sample count, causing the posterior to be overconfident. This parameter tempers the likelihood by the factor n_eff/n, reducing the data's influence on the posterior to match the effective information content. Values between 0 and 1 (inclusive) are interpreted as a multiplicative factor applied to the actual number of observations; for instance, if you have 2000 trials from 30 participants, set this to 30/2000 = 0.015. Values > 1 must be integers and are interpreted as an absolute effective sample size; for instance, 30 means that the effective sample size is 30 regardless of the actual number of observations.

  • verbose name: Sample Size Correction
  • default value: 1.0
  • port type: FloatPort
  • value type: float (can be None)

expected_relevant_features

Expected number or fraction of relevant features. Controls the prior inclusion probability for the spike-and-slab gate. Values between 0 and 1 are interpreted as a fraction of the total feature count; values >= 1 must be integers and are interpreted as an absolute count. The default of 0.1 works well for moderate-dimensional problems (p up to ~2000). For very high-dimensional datasets (p > 5000), reduce to 0.02-0.05 to avoid over-selection.

  • verbose name: Expected Relevant Features
  • default value: 0.1
  • port type: FloatPort
  • value type: float (can be None)

initial_slab_scale

Initial scale of the slab (relevant-feature) component on standardized features. This controls how large the coefficients of relevant features are expected to be before the method has seen any data. Larger values give the non-zero coefficients more room to take on large values; smaller values encourage tighter concentration near zero, which can be appropriate when the expected effect sizes are small. When slab-scale learning is enabled (the default), this serves as the starting point for optimization and the final learned value may differ.

  • verbose name: Initial Slab Scale
  • default value: 1.5
  • port type: FloatPort
  • value type: float (can be None)

spike_scale

Scale of the spike (irrelevant-feature) component. This controls how tightly the coefficients of irrelevant features are concentrated around zero. Smaller values enforce stronger suppression of inactive features, producing a cleaner separation between relevant and irrelevant features. Values around 0.01-0.1 are typical; the default of 0.05 works well in most settings. If the method has difficulty distinguishing relevant from irrelevant features, try reducing this value.

  • verbose name: Spike Scale
  • default value: 0.05
  • port type: FloatPort
  • value type: float (can be None)

include_bias

Include a bias (intercept) term. If false, features need to be centered or include a constant feature set to 1.

  • verbose name: Include Bias Term
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

learn_inclusion_probability

Learn the global prior inclusion probability from the data during variational fitting. When enabled, the method adapts how many features it expects to be relevant based on what the data supports, starting from the value implied by the expected relevant features parameter. When disabled, the inclusion probability is fixed at the initial value throughout fitting.

  • verbose name: Learn Inclusion Probability
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

learn_slab_scale

Learn the slab scale from the data during variational fitting. When enabled, the method adapts the expected magnitude of relevant coefficients based on the data, starting from the initial slab scale value. When disabled, the slab scale is fixed at its initial value throughout fitting.

  • verbose name: Learn Slab Scale
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

support_threshold

Threshold on the estimated probability that a feature is relevant. Features whose inclusion probability meets or exceeds this threshold are reported as active in the support mask. The default of 0.5 selects features that are more likely relevant than not (the median probability model).

  • verbose name: Support Threshold
  • default value: 0.5
  • port type: FloatPort
  • value type: float (can be None)

temperature

Temperature parameter that controls how sharply the method distinguishes between included and excluded features during optimization. Lower values produce crisper on/off feature selection decisions, but can make the optimization landscape harder to navigate, potentially leading to poorer solutions. Higher values produce softer decisions that are easier to optimize but may result in less decisive feature selection. The default of 0.67 balances optimization quality with selection sharpness.

  • verbose name: Temperature
  • default value: 0.67
  • port type: FloatPort
  • value type: float (can be None)

num_svi_steps

Number of variational optimization steps. For most problems 2000-3000 steps suffice. High-dimensional datasets (p >> n) may benefit from 4000-5000 steps, especially when using a lower learning rate.

  • verbose name: Number Of Svi Steps
  • default value: 3000
  • port type: IntPort
  • value type: int (can be None)

learning_rate

Initial learning rate for the Adam optimizer. The default of 0.01 works well for most problems. For high-dimensional datasets (p >> n), reducing to 0.005 improves convergence stability; increase the number of SVI steps proportionally when doing so.

  • verbose name: Learning Rate
  • default value: 0.01
  • port type: FloatPort
  • value type: float (can be None)

posterior_samples_for_prediction

Number of random samples drawn from the fitted posterior distribution and used to compute predicted class probabilities. Using multiple samples averages over the remaining uncertainty in the model, generally producing better-calibrated probability estimates. Set to 1 to use only the posterior mean coefficients for prediction (faster, but ignores model uncertainty). The default of 64 is a good balance between prediction quality and speed.

  • verbose name: Posterior Samples For Prediction
  • default value: 64
  • port type: IntPort
  • value type: int (can be None)

random_seed

Random seed. Different values may give slightly different outcomes.

  • verbose name: Random Seed
  • default value: 12345
  • port type: IntPort
  • value type: int (can be None)

initialize_once

Calibrate the model only once. If set to False, then this node will recalibrate itself whenever a non-streaming data chunk is received that has both training labels and associated training instances.

  • verbose name: Calibrate Only Once
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

dont_reset_model

Do not reset the model when the preceding graph is changed. Normally, when certain parameters of preceding nodes are being changed, the model will be reset. If this is enabled, the model will persist, but there is a chance that the model is incompatible when input data format to this node has changed.

  • verbose name: Do Not Reset Model
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

probabilistic

Use probabilistic outputs. If enabled, the node will output for each class the probability that a given trial is of that class; otherwise it will output the most likely class label.

  • verbose name: Output Probabilities
  • default value: True
  • port type: BoolPort
  • value type: bool (can be None)

verbosity

Verbosity level. Higher numbers will produce more extensive diagnostic output.

  • verbose name: Verbosity Level
  • default value: 0
  • port type: IntPort
  • value type: int (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)