Förutsägelse
POST http://localhost:5000/v1/prediction
Hämta den rekommenderade nästa åtgärden från en exporterad Bonsai hjärna.
Sökvägsparametrar
Inga.
HTTP-svar
Svarskod | Svarstyp | Description |
---|---|---|
200 (OK) | Relevant svarsobjekt | POST anropet slutfördes |
400 (felaktig begäran) | Felmeddelande | Något i begäran är felaktigt |
500 (internt fel) | Felmeddelande | Ett ohanterat undantag inträffade |
503 (tjänsten är inte tillgänglig) | Felmeddelande | Resursbegränsningar hindrade hjärnan från att svara |
Begära objekt
Bonsai anpassar följande JSON-mall under exporten baserat på indelningsfilen som används för att träna hjärnan.
{
'StateName1' : 'StateData1',
'StateName2' : {
'Subfield1': 'SubData1'
'Subfield2': 'SubData2'
},
'StateName3' : 'StateData3',
...
'StateNameN' : 'StateDataN',
}
Malltoken
Token | Description |
---|---|
StateName |
VALFRI. Variabelnamn för konceptindata. |
Viktigt
Om du väljer att ange tillståndsdata utan motsvarande fält för tillståndsnamn måste värdena visas i samma ordning som de visas i indatafilen.
Svarsobjekt
Bonsai anpassar följande JSON-mall under exporten baserat på indelningsfilen som används för att träna hjärnan.
{
'ActionName1' : 'Result1',
'ActionName2' : 'Result2',
'ActionName3' : {
'Subfield1': 'SubResult1'
'Subfield2': 'SubResult2'
},
...
'ActionNameN' : 'ResultN',
}
Malltoken
Token | Description |
---|---|
ActionName |
Konceptutdatavariabelnamn. |
Result |
Värdet som returneras av hjärnan Bonsai för motsvarande åtgärdsvariabel. |
Exempel
Anta att du har följande definitioner i indelningsfilen:
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'])