GaitAuth™ Model Training

UnifyID GaitAuth™ models are trained for each user of your mobile application. Training can be performed by completing the following steps:

  1. Create a new model instance for your user
  2. Collect gait features for your user to train the model
  3. Initiate the training process for the model

Training Guidelines

Correctly training a model is a critical step for successful GaitAuth usage. Following the guidelines below can helps ensure the training data accurately captures the intended user’s typical behavior and gait.

  • Our recommended training duration is 7 days. This allows data to be collected across a variety of situations (eg, weekdays and weekends) to more comprehensively capture what typical walking patterns look like.
  • Do not let others carry your phone. If others carry your phone during the training period, then they may be able to impersonate you.
  • Carry and walk with your phone as you normally would. The goal of the training period is to observe your normal walking patterns. Carrying your phone in unnatural ways will make it more difficult to understand typical behaviors. As well, behaviors that are common, but not seen during the training period, may not be learned.
  • Carrying your phone close to your body generally works best. While carrying your phone in the natural way is more important, gait-based authentication generally works best if you carry the phone on your body, e.g. in a pants pocket.
  • Consider your use case. The more representative your walking behavior is of your intended use case, the better the results will be.

Create a Gait Model

The first step to train a model is to create a new model instance. After creating a model instance, be sure to persist the model identifier. The identifier is required to re-load the same model in the future.

Creating a model is required before you can do any of the following:

  • Collect and add training data
  • Initiate the training process
  • Load the trained model
  • Score gait features

Android

Create a model by calling the createModel method on the global GaitAuth instance:

try {
    GaitModel gaitModel = GaitAuth.getInstance().createModel();
    // Persist model.getId() for later usage
} catch (GaitModelException e) {
    // Error creating model
}

Be sure to make all GaitAuth SDK method calls off of the main UI thread as some may trigger network activity. See the Android documentation on processes and threads and background tasks for more information.

Be sure to only access the GaitAuth SDK instance after successful SDK initialization. GaitAuth.getInstance() will return null before the SDK is fully initialized.

iOS

Create a model by calling gaitAuth.createModel:

gaitAuth.createModel { result in
    switch result {
    case .success(let gaitModel):
        // Persist gaitModel.id for later usage
    case .failure(let error):
        // Error creating model
    }
}

Collect Training Data

GaitAuth collects data that represents the manner in which a user walks in units called “features”. Features are used during training as well as scoring, and the methods used to collect the data are the same.

Start Feature Collection

Android

try {
    GaitAuth.getInstance().registerListener(new FeatureEventListener() {
        @Override
        public void onNewFeature(GaitFeature gaitFeature) {
            // Add gaitFeature to a collection for later usage
        }
    });
} catch (GaitAuthException e) {
    // Error registering listener
}

iOS

To begin collecting features, call gaitAuth.startFeatureUpdates:

gaitAuth.startFeatureUpdates(to: DispatchQueue.main) { result in
    switch result {
    case .success(let features):
        // Add features to collection
    case .failure(let error):
        // Error extracting features
    }
}

When your app is put into the background on iOS, unless you have a background mode enabled it will stop collecting features. If you would like to continue to collect features while the app is not in the foreground, you will need to enable a background mode that is appropriate for your use case.

Stop Feature Collection

Android

Stop feature collection by using the unregisterAllListeners method. This will stop all updates to all registered FeatureEventListener instances.

GaitAuth.getInstance().unregisterAllListeners();

iOS

To stop collecting features, call gaitAuth.stopFeatureUpdates. This will stop updates to all locations where gaitAuth.startFeatureUpdates was called.

gaitAuth.stopFeatureUpdates()

Storing Collected Features

Storing feature data for later use can be helpful in the following situations:

  • Adding larger batches of training data leads to more efficient invocations of GaitModel.add.
  • If model training is unsuccessful, you can use the stored features to begin training a new model.

In some cases, training a model can be unsuccessful due to the quality of the model produced. To handle these situations, it is recommended that you persist features in the app until you’ve confirmed that model training was successful. In the event of unsuccessful training, this saved data will be helpful when creating a new model because all of the features must be added to the new model.

Android

To serialize a collection of gait features for storage, use the GaitAuth.serializeFeatures method:

try {
    byte[] featuresInBytes = GaitAuth.serializeFeatures(features);
    // Persist serialized data
} catch (FeatureCollectionException e) {
    // Error serializing features
}

To retrieve gait features from stored data, use the GaitAuth.deserializeFeatures method:

try {
    List<GaitFeature> features = GaitAuth.deserializeFeatures(featuresInBytes);
    // Capture deserialized features for later usage
} catch (FeatureCollectionException e) {
    // Error deserializing features
}

iOS

To serialize a collection of gait features for storage, use the gaitAuth.serializeFeatures method:

gaitAuth.serializeFeatures(features) { result in
    switch result {
    case .success(let data):
        // Persist serialized data
    case .failure(let error):
        // Error serializing features
}

To retrieve gait features from stored data, use the gaitAuth.deserializeFeatures method:

gaitAuth.deserializeFeatures(data) { result in
    switch result {
    case .success(let features):
        // Assign deserialized features for later usage
    case .failure(let error):
        // Error deserializing features
}

Training a Model

Before a model can be used to score features, you will need to explicitly add the training data to a model object and initiate model training. For best performance, try adding between 100 and 500 features to a model at a time.

Important: Avoid adding duplicate features. Adding too many duplicate features can cause model bias and produce less accurate scores.

Once you have added sufficient training data to the model (we recommend a period of 7 days), you will need to initiate the training process with GaitModel.train. This training process can take a few hours to complete.

Finally, you can refresh the status of a model using the model’s refresh method.

While your model is being trained, you’ll see a status of training. Once complete, the status will change to ready.

If the model fails to train, the model’s status will be failed. In this case, you will need to resolve the error noted in the model’s last error message, create a new model, and start training over again. As noted above, it’s best to persist training data until a model has been successfully trained. This allows you to re-use the training data if the first attempt failed.

Android

To add gait features to a model instance, use the GaitModel.add method:

try {
    gaitModel.add(features);
} catch (GaitModelException e) {
    // Error adding gait features to model
}

To initiate model training, use the GaitModel.train method:

try {
    gaitModel.train();
    // Monitor model status for `ready` or `failed` states
} catch (GaitModelException e) {
    // Error initiating model training
}

To refresh the status of a model, use the GaitModel.refresh method:

try {
    gaitModel.refresh();
    // Monitor model status for `ready` or `failed` states
} catch (GaitModelException e) {
    // Error refreshing model
}

iOS

To add gait features to a model instance, use the GaitModel.add method:

gaitModel.add(features) { error in
    if let error = error {
        // Error adding gait features to model
        return
    }
    // Successfully added gait features to model
}

To initiate model training, use the GaitModel.train method:

gaitModel.train() { error in
    if let error = error {
        // Error initiating model training
        return
    }
    // Monitor gaitModel.status for `ready` or `failed` states
}

To refresh the status of a model, use the GaitModel.refresh method:

gaitModel.refresh() { result in
    switch result {
    case .success(let changeType):
        // Model status refreshed, changeType denotes if there were any changes
        // Check latest gaitModel.status for `ready` or `failed` states
    case .failure(let error):
        // Error refreshing model status
    }
}

Loading a Model

A model will likely need to be persisted between app sessions, so make sure to save the model identifier in an appropriate location. When your app launches again for the same user, you may try to re-load the last active model identifier. The loaded model should be in the same state that it was when last updated in a prior session.

Android

try {
    GaitModel gaitModel = GaitAuth.getInstance().loadModel(modelId);
    // Use loaded model
} catch (GaitModelException e) {
    // Error loading model
}

iOS

gaitAuth.loadModel(withIdentifier: modelIdentifier) { result in
    switch result {
    case .success(let gaitModel):
        // Use loaded model
    case .failure(let error):
        // Error loading model
    }
}

Next Steps

With models created and trained for your users, you can now begin utilizing these models in your authentication flows.

Feature Scoring

Updated: