change Ray Tag result as Onehot, Observation State: -targetStates 6 -inTargetArea 1 -remainTime 1 -gunReady 1 -my Obs 4 -tag onehot 19*2 -tag dis 19
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
public class Onehot
|
|
{
|
|
private List<string> tags = new List<string>();
|
|
public List<List<float>> onehot = new List<List<float>>();
|
|
private float totalNum;
|
|
public void initialize(List<string> inputTags)
|
|
{
|
|
tags = inputTags;
|
|
totalNum = tags.Count;
|
|
for (int i = 0; i < totalNum; i++)
|
|
{
|
|
List<float> thisOnehot = new List<float>();
|
|
for (int j = 0; j < totalNum; j++) thisOnehot.Add(0f);
|
|
thisOnehot[i] = 1f;
|
|
onehot.Add(thisOnehot);
|
|
}
|
|
}
|
|
public List<float> encoder(string name = null)
|
|
{
|
|
if (name == null)
|
|
{
|
|
List<float> allZeroOnehot = new List<float>();
|
|
for (int j = 0; j < totalNum; j++) allZeroOnehot.Add(0);
|
|
return allZeroOnehot;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
return onehot[tags.IndexOf(name)];
|
|
}catch(ArgumentOutOfRangeException)
|
|
{
|
|
List<float> allZeroOnehot = new List<float>();
|
|
for (int j = 0; j < totalNum; j++) allZeroOnehot.Add(0);
|
|
return allZeroOnehot;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string decoder(List<float> thisOnehot)
|
|
{
|
|
return tags[onehot.IndexOf(thisOnehot)];
|
|
}
|
|
}
|