/// <summary> /// Convert a BrainParametersProto to a BrainParameters struct. /// </summary> /// <param name="bpp">An instance of a brain parameters protobuf object.</param> /// <returns>A BrainParameters struct.</returns> public static BrainParameters ToBrainParameters(this BrainParametersProto bpp) { var bp = new BrainParameters { vectorActionSize = bpp.VectorActionSize.ToArray(), vectorActionDescriptions = bpp.VectorActionDescriptions.ToArray(), vectorActionSpaceType = (SpaceType)bpp.VectorActionSpaceType }; return(bp); }
/// <summary> /// Convert a BrainParametersProto to a BrainParameters struct. /// </summary> /// <param name="bpp">An instance of a brain parameters protobuf object.</param> /// <returns>A BrainParameters struct.</returns> public static BrainParameters ToBrainParameters(this BrainParametersProto bpp) { var bp = new BrainParameters { VectorActionSize = bpp.VectorActionSizeDeprecated.ToArray(), VectorActionDescriptions = bpp.VectorActionDescriptionsDeprecated.ToArray(), VectorActionSpaceType = (SpaceType)bpp.VectorActionSpaceTypeDeprecated }; return(bp); }
/// <summary> /// Converts a Brain into to a Protobuf BrainInfoProto so it can be sent /// </summary> /// <returns>The BrainInfoProto generated.</returns> /// <param name="bp">The instance of BrainParameter to extend.</param> /// <param name="name">The name of the brain.</param> /// <param name="isTraining">Whether or not the Brain is training.</param> public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining) { var brainParametersProto = new BrainParametersProto { VectorActionSize = { bp.vectorActionSize }, VectorActionSpaceType = (SpaceTypeProto)bp.vectorActionSpaceType, BrainName = name, IsTraining = isTraining }; brainParametersProto.VectorActionDescriptions.AddRange(bp.vectorActionDescriptions); return(brainParametersProto); }
/// <summary> /// Converts a BrainParameters into to a BrainParametersProto so it can be sent. /// </summary> /// <returns>The BrainInfoProto generated.</returns> /// <param name="bp">The instance of BrainParameter to extend.</param> /// <param name="name">The name of the brain.</param> /// <param name="isTraining">Whether or not the Brain is training.</param> public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining) { var brainParametersProto = new BrainParametersProto { VectorActionSizeDeprecated = { bp.VectorActionSize }, VectorActionSpaceTypeDeprecated = (SpaceTypeProto)bp.VectorActionSpaceType, BrainName = name, IsTraining = isTraining }; if (bp.VectorActionDescriptions != null) { brainParametersProto.VectorActionDescriptionsDeprecated.AddRange(bp.VectorActionDescriptions); } return(brainParametersProto); }
/// <summary> /// Converts a BrainParameters into to a BrainParametersProto so it can be sent. /// </summary> /// <returns>The BrainInfoProto generated.</returns> /// <param name="bp">The instance of BrainParameter to extend.</param> /// <param name="name">The name of the brain.</param> /// <param name="isTraining">Whether or not the Brain is training.</param> public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining) { // Disable deprecation warnings so we can set legacy fields #pragma warning disable CS0618 var brainParametersProto = new BrainParametersProto { VectorActionSpaceTypeDeprecated = (SpaceTypeProto)bp.VectorActionSpaceType, BrainName = name, IsTraining = isTraining, ActionSpec = ToActionSpecProto(bp.ActionSpec), }; if (bp.VectorActionSize != null) { brainParametersProto.VectorActionSizeDeprecated.AddRange(bp.VectorActionSize); } if (bp.VectorActionDescriptions != null) { brainParametersProto.VectorActionDescriptionsDeprecated.AddRange(bp.VectorActionDescriptions); } #pragma warning restore CS0618 return(brainParametersProto); }
/// <summary> /// Converts an ActionSpec into to a Protobuf BrainInfoProto so it can be sent. /// </summary> /// <returns>The BrainInfoProto generated.</returns> /// <param name="actionSpec"> Description of the action spaces for the Agent.</param> /// <param name="name">The name of the brain.</param> /// <param name="isTraining">Whether or not the Brain is training.</param> public static BrainParametersProto ToBrainParametersProto(this ActionSpec actionSpec, string name, bool isTraining) { var brainParametersProto = new BrainParametersProto { BrainName = name, IsTraining = isTraining }; var actionSpecProto = new ActionSpecProto { NumContinuousActions = actionSpec.NumContinuousActions, NumDiscreteActions = actionSpec.NumDiscreteActions, }; if (actionSpec.BranchSizes != null) { actionSpecProto.DiscreteBranchSizes.AddRange(actionSpec.BranchSizes); } brainParametersProto.ActionSpec = actionSpecProto; var supportHybrid = Academy.Instance.TrainerCapabilities == null || Academy.Instance.TrainerCapabilities.HybridActions; if (!supportHybrid) { actionSpec.CheckAllContinuousOrDiscrete(); if (actionSpec.NumContinuousActions > 0) { brainParametersProto.VectorActionSizeDeprecated.Add(actionSpec.NumContinuousActions); brainParametersProto.VectorActionSpaceTypeDeprecated = SpaceTypeProto.Continuous; } else if (actionSpec.NumDiscreteActions > 0) { brainParametersProto.VectorActionSizeDeprecated.AddRange(actionSpec.BranchSizes); brainParametersProto.VectorActionSpaceTypeDeprecated = SpaceTypeProto.Discrete; } } // TODO handle ActionDescriptions? return(brainParametersProto); }
/// <summary> /// Converts an ActionSpec into to a Protobuf BrainInfoProto so it can be sent. /// </summary> /// <returns>The BrainInfoProto generated.</returns> /// <param name="actionSpec"> Description of the action spaces for the Agent.</param> /// <param name="name">The name of the brain.</param> /// <param name="isTraining">Whether or not the Brain is training.</param> public static BrainParametersProto ToBrainParametersProto(this ActionSpec actionSpec, string name, bool isTraining) { actionSpec.CheckNotHybrid(); var brainParametersProto = new BrainParametersProto { BrainName = name, IsTraining = isTraining }; if (actionSpec.NumContinuousActions > 0) { brainParametersProto.VectorActionSize.Add(actionSpec.NumContinuousActions); brainParametersProto.VectorActionSpaceType = SpaceTypeProto.Continuous; } else if (actionSpec.NumDiscreteActions > 0) { brainParametersProto.VectorActionSize.AddRange(actionSpec.BranchSizes); brainParametersProto.VectorActionSpaceType = SpaceTypeProto.Discrete; } // TODO handle ActionDescriptions? return(brainParametersProto); }