TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
cherrypi::UnitAttributeFeaturizer Struct Referenceabstract

Abstract base class for featurizing unit attributes in a sparse manner. More...

#include <unitsfeatures.h>

Inherited by cherrypi::UnitFlagsFeaturizer, cherrypi::UnitPresenceFeaturizer, cherrypi::UnitStatFeaturizer, cherrypi::UnitTypeDefoggerFeaturizer, and cherrypi::UnitTypeFeaturizer.

Classes

struct  Data
 

Public Types

using UnitFilter = std::function< bool(Unit *)>
 
using TensorDest = torch::TensorAccessor< float, 1 >
 

Public Member Functions

virtual ~UnitAttributeFeaturizer ()=default
 
virtual Data extract (State *state, UnitsInfo::Units const &units, Rect const &boundingBox=Rect())
 Extract unit features for a given set of units. More...
 
Data extract (State *state, Rect const &boundingBox=Rect())
 Extract unit features for all live units. More...
 
Data extract (State *state, UnitFilter filter, Rect const &boundingBox=Rect())
 Extract unit features for all live units that pass the given filter. More...
 
FeatureData toSpatialFeature (Data const &data, SubsampleMethod pooling=SubsampleMethod::Sum) const
 Embeds the unit attribute data into a spatial feature. More...
 
void toSpatialFeature (FeatureData *dest, Data const &data, SubsampleMethod pooling=SubsampleMethod::Sum) const
 Embeds the unit attribute data into a spatial feature. More...
 

Public Attributes

std::shared_ptr< BaseJitterjitter = std::make_shared<NoJitter>()
 Optional jittering of unit positions. More...
 
CustomFeatureType type
 
std::string name
 
int numChannels
 

Protected Member Functions

virtual void extractUnit (TensorDest acc, Unit *unit)=0
 Reimplement this in actual featurizers. More...
 

Detailed Description

Abstract base class for featurizing unit attributes in a sparse manner.

General usage of sub-classes for actual feature extraction boils down to calling extract() with a desired subset of units to featurize. The resulting data is sparse wrt positions, i.e. it contains a tensor of positions for each unit and the accompanying data as defined by a featurizer implementation.

toSpatialFeature() will transform the given data to a FeatureData object, i.e. it will place the feature data at the respective positions.

Optionally, users can set a jittering method that will be accounted for in extract().

Member Typedef Documentation

using cherrypi::UnitAttributeFeaturizer::TensorDest = torch::TensorAccessor<float, 1>
using cherrypi::UnitAttributeFeaturizer::UnitFilter = std::function<bool(Unit*)>

Constructor & Destructor Documentation

virtual cherrypi::UnitAttributeFeaturizer::~UnitAttributeFeaturizer ( )
virtualdefault

Member Function Documentation

UnitAttributeFeaturizer::Data cherrypi::UnitAttributeFeaturizer::extract ( State state,
UnitsInfo::Units const &  units,
Rect const &  boundingBox = Rect() 
)
virtual

Extract unit features for a given set of units.

Reimplemented in cherrypi::UnitTypeMDefoggerFeaturizer.

UnitAttributeFeaturizer::Data cherrypi::UnitAttributeFeaturizer::extract ( State state,
Rect const &  boundingBox = Rect() 
)

Extract unit features for all live units.

UnitAttributeFeaturizer::Data cherrypi::UnitAttributeFeaturizer::extract ( State state,
UnitFilter  filter,
Rect const &  boundingBox = Rect() 
)

Extract unit features for all live units that pass the given filter.

virtual void cherrypi::UnitAttributeFeaturizer::extractUnit ( TensorDest  acc,
Unit unit 
)
protectedpure virtual

Reimplement this in actual featurizers.

This function is expected to set acc[0], ..., acc[numChannels-1]

Implemented in cherrypi::UnitStatFeaturizer, cherrypi::UnitFlagsFeaturizer, cherrypi::UnitTypeDefoggerFeaturizer, cherrypi::UnitTypeFeaturizer, and cherrypi::UnitPresenceFeaturizer.

FeatureData cherrypi::UnitAttributeFeaturizer::toSpatialFeature ( Data const &  data,
SubsampleMethod  pooling = SubsampleMethod::Sum 
) const

Embeds the unit attribute data into a spatial feature.

void cherrypi::UnitAttributeFeaturizer::toSpatialFeature ( FeatureData dest,
Data const &  data,
SubsampleMethod  pooling = SubsampleMethod::Sum 
) const

Embeds the unit attribute data into a spatial feature.

This version will re-use the tensor memory of the given feature data instance.

Member Data Documentation

std::shared_ptr<BaseJitter> cherrypi::UnitAttributeFeaturizer::jitter = std::make_shared<NoJitter>()

Optional jittering of unit positions.

std::string cherrypi::UnitAttributeFeaturizer::name
int cherrypi::UnitAttributeFeaturizer::numChannels
CustomFeatureType cherrypi::UnitAttributeFeaturizer::type

The documentation for this struct was generated from the following files: