Prédiction
POST http://localhost:5000/v1/prediction
Obtient l’action suivante recommandée à partir d’un cerveau exporté Bonsai .
Paramètres de chemin d’accès
Aucun.
Réponses HTTP
Response code | Type de réponse | Description |
---|---|---|
200 (OK) | Objet réponse pertinent | POST appel terminé avec succès |
400 (Demande incorrecte) | Message d’erreur | Une erreur dans la demande est incorrecte |
500 (erreur interne) | Message d’erreur | Une exception non gérée s’est produite |
503 (service non disponible) | Message d’erreur | Les contraintes de ressources ont empêché le cerveau de répondre |
Objet Requête
Bonsai personnalise le modèle JSON suivant lors de l’exportation en fonction du fichier INKLING utilisé pour l’apprentissage du cerveau.
{
'StateName1' : 'StateData1',
'StateName2' : {
'Subfield1': 'SubData1'
'Subfield2': 'SubData2'
},
'StateName3' : 'StateData3',
...
'StateNameN' : 'StateDataN',
}
Jetons de modèle
par jeton | Description |
---|---|
StateName |
FACULTATIF. Nom de la variable d’entrée du concept. |
Important
Si vous choisissez de fournir des données d’État sans le champ nom d’état correspondant, les valeurs doivent être répertoriées dans le même ordre que celui dans lequel elles apparaissent dans votre fichier INKLING.
Objet Réponse
Bonsai personnalise le modèle JSON suivant lors de l’exportation en fonction du fichier INKLING utilisé pour l’apprentissage du cerveau.
{
'ActionName1' : 'Result1',
'ActionName2' : 'Result2',
'ActionName3' : {
'Subfield1': 'SubResult1'
'Subfield2': 'SubResult2'
},
...
'ActionNameN' : 'ResultN',
}
Jetons de modèle
par jeton | Description |
---|---|
ActionName |
Nom de la variable de sortie du concept. |
Result |
Valeur retournée par le Bonsai cerveau pour la variable d’action correspondante. |
Exemples
Supposons que vous ayez les définitions suivantes dans votre fichier INKLING :
inkling "2.0"
using Math
using Goal
# Pole and track constants
const TrackLength = 0.5
const MaxPoleAngle = (12 * Math.Pi) / 180
# State info from the simulator
type SimState {
CartPosition: number, # Position of cart in meters
CartVelocity: number, # Velocity of cart in meters/sec
PoleAngle: number, # Current angle of pole in radians
PoleAngularVelocity: number, # Angular velocity of the pole in radians/sec
}
# Possible action results
type SimAction {
# Amount of force in x direction to apply to the cart.
Command: number<-1 .. 1>
}
# Define a concept graph with a single concept
graph (input: SimState): SimAction {
concept BalancePole(input): SimAction {
curriculum {
source simulator (Action: SimAction): SimState {
package "Cartpole"
}
# The objective of training is expressed as a goal with two
# objectives: keep the pole from falling over and stay on the track
goal (State: SimState) {
avoid `Fall Over`:
Math.Abs(State.pole_angle) in Goal.RangeAbove(MaxPoleAngle)
avoid `Out Of Range`:
Math.Abs(State.cart_position) in Goal.RangeAbove(TrackLength / 2)
}
}
}
}
import requests
import json
# General variables
url = "http://localhost:5000"
predictionPath = "/v1/prediction"
headers = {
"Content-Type": "application/json"
}
# Build the endpoint reference
endpoint = url + predictionPath
# Set the request variables
requestBody = {
"CartPosition": 3,
"CartVelocity": 1.5,
"PoleAngle": 0.75,
"PoleAngularVelocity": 0.1
}
# Send the POST request
response = requests.post(
endpoint,
data = json.dumps(requestBody),
headers = headers
)
# Extract the JSON response
prediction = response.json()
# Access the JSON result: full response object
print(prediction)
# Access the JSON result: specific field
print(prediction['Command'])