using System; using System.Collections.Generic; public class Onehot { private List tags = new List(); public List> onehot = new List>(); private float totalNum; public void Initialize(List inputTags) { tags = inputTags; totalNum = tags.Count; for (int i = 0; i < totalNum; i++) { List thisOnehot = new List(); for (int j = 0; j < totalNum; j++) thisOnehot.Add(0f); thisOnehot[i] = 1f; onehot.Add(thisOnehot); } } public List Encoder(string name = null) { if (name == null) { List allZeroOnehot = new List(); for (int j = 0; j < totalNum; j++) allZeroOnehot.Add(0); return allZeroOnehot; } else { try { return onehot[tags.IndexOf(name)]; } catch (ArgumentOutOfRangeException) { List allZeroOnehot = new List(); for (int j = 0; j < totalNum; j++) allZeroOnehot.Add(0); return allZeroOnehot; } } } public string Decoder(List thisOnehot) { return tags[onehot.IndexOf(thisOnehot)]; } }