public static Space ToRandomVariableSpace(this JToken json0)
{
JObject json = (JObject)json0;
if (json.Property("discrete") != null)
{
float[] values = json.Property("discrete").Value.Values<float>().ToArray();
string[] labels =
Utils.Try(() => json.Property("labels").Value.Values<string>().ToArray(), null);
var zipped =
labels != null
? values.Zip(labels, (v,l) => new Tuple<float, string>(v, l))
: values.Select(v => new Tuple<float, string>(v, ""));
return Space.NewDiscrete(new FSharpMap<float, string>(zipped));
}
else
{
throw new Exception();
}
}