# training

This method is to control the training of the mental command and facial expression detections. Before you start a training, you should [subscribe](https://emotiv.gitbook.io/cortex-api/data-subscription/subscribe) to the "sys" data stream.

See [BCI](https://emotiv.gitbook.io/cortex-api/bci) for details.

## Parameters

| Name        | Type     | Required | Description                                                                                                                                                        |
| ----------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| cortexToken | `string` | yes      | A token returned by [authorize](https://emotiv.gitbook.io/cortex-api/authentication/authorize).                                                                    |
| session     | `string` | yes      | A session id returned by [createSession](https://emotiv.gitbook.io/cortex-api/session/createsession). The training will be for the headset linked to this session. |
| detection   | `string` | yes      | Must be "mentalCommand" or "facialExpression".                                                                                                                     |
| status      | `string` | yes      | Control what this method does, like start the training, or cancel it... Available status depends on which **detection** you selected.                              |
| action      | `string` | yes      | The action you want to train. Available actions depends on which **detection** you selected.                                                                       |

### status

To get the available status for a detection, call [getDetectionInfo](https://emotiv.gitbook.io/cortex-api/bci/getdetectioninfo), and check the field **controls** of the result object. Or you can check this list:

| Status | Description                                                   |
| ------ | ------------------------------------------------------------- |
| start  | Start a new training for the specified **action**.            |
| accept | Accept a successful training and add it to the profile.       |
| reject | Reject a successful training. It is not added to the profile. |
| reset  | Cancel the current training.                                  |
| erase  | Erase all the training data for the specified **action**.     |

### action

To get the available actions for a detection, call [getDetectionInfo](https://emotiv.gitbook.io/cortex-api/bci/getdetectioninfo), and check the field **actions** of the result object.

However, note that for the facial expression detection, only these actions can be trained: "neutral", "surprise", "frown", "smile", "clench".

## Result

The result is an object containing these fields:

| Name    | Type     | Description                            |
| ------- | -------- | -------------------------------------- |
| action  | `string` | The **action** you set in the request. |
| status  | `string` | The **status** you set in the request. |
| message | `string` | A success message.                     |

## Examples

### Start a training

Start a mental command training for the action "push".

{% tabs %}
{% tab title="Request" %}

```javascript
{
    "id": 14,
    "jsonrpc": "2.0",
    "method": "training",
    "params": {
        "action": "push",
        "cortexToken": "xxx",
        "detection": "mentalCommand",
        "session": "f3a35fd0-9163-4cc4-ab30-4ed224369f91",
        "status": "start"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 14,
    "jsonrpc": "2.0",
    "result": {
        "action": "push",
        "message": "Set up training successfully",
        "status": "start"
    }
}
```

{% endtab %}
{% endtabs %}

### Accept a training

Accept a successful training for the action "push".

{% tabs %}
{% tab title="Request" %}

```javascript
{
    "id": 15,
    "jsonrpc": "2.0",
    "method": "training",
    "params": {
        "action": "push",
        "cortexToken": "xxx",
        "detection": "mentalCommand",
        "session": "f3a35fd0-9163-4cc4-ab30-4ed224369f91",
        "status": "accept"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 15,
    "jsonrpc": "2.0",
    "result": {
        "action": "push",
        "message": "Set up training successfully",
        "status": "accept"
    }
}
```

{% endtab %}
{% endtabs %}
