-
Notifications
You must be signed in to change notification settings - Fork 2
5. Extract representative subset
Jonas Schaub edited this page Nov 13, 2025
·
1 revision
To generate a representative subset of your input data, i.e. a set of input data vectors of configurable size that still represents the input dataset diversity as well as possible, the library will cluster the input data with varying vigilance parameter values until the number of clusters equals the number of representatives to identify. The returned representatives are the data vectors closest to the respective cluster vectors.
// Prepare your data as a 2D float array
// Each row represents a data vector
float[][] dataMatrix = {
{0.1f, 0.2f, 0.3f},
{0.2f, 0.1f, 0.4f},
{0.9f, 0.8f, 0.7f},
{0.8f, 0.9f, 0.6f},
{0.15f, 0.25f, 0.35f},
{0.85f, 0.75f, 0.65f},
{0.05f, 0.15f, 0.25f},
{0.95f, 0.85f, 0.75f},
{0.12f, 0.22f, 0.32f},
{0.88f, 0.78f, 0.68f}
};
// Configure clustering parameters
//Maximum number of clusters in interval [2, number of data row vectors of getDataMatrix]
int maximumNumberOfClusters = 10;
//default value
int maximumNumberOfEpochs = 10;
//default value
float convergenceThreshold = 0.99f;
//default value
float learningParameter = 0.01f;
//default value
float offsetForContrastEnhancement = 1.0f;
//default value
long randomSeed = 1L;
//do not preprocess data because it is already in range [0,1]
boolean isDataPreprocessing = false;
// Validate data matrix (same length in all rows, no empty rows, etc.)
if (Utils.isDataMatrixValid(dataMatrix)) {
// Create ART-2a kernel
Art2aKernel art2aKernel = new Art2aKernel(
dataMatrix,
maximumNumberOfClusters,
maximumNumberOfEpochs,
convergenceThreshold,
learningParameter,
offsetForContrastEnhancement,
randomSeed,
isDataPreprocessing
);
int numberOfRepresentatives = 2;
float vigilanceMin = 0.0001f;
float vigilanceMax = 0.9999f;
int numberOfTrialSteps = 32;
//*cluster repeatedly with varying vigilance parameters to get as closely as possible to
// nr. of clusters = the desired number of representatives*
int[] representatives = art2aKernel.getRepresentatives(
numberOfRepresentatives,
vigilanceMin,
vigilanceMax,
numberOfTrialSteps,
false
);
System.out.println("Representative indices: " + Arrays.toString(representatives));
}
Output:
Representative indices: [6, 7]