/* type BaggedModel struct {
	base.BaseClassifier
	Models             []base.Classifier
	RandomFeatures     int
	lock               sync.Mutex
	selectedAttributes map[int][]base.Attribute, always RandomFeatures in length
}*/
169876
func (b *BaggedModel) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error {
	b.lock.Lock()
	defer b.lock.Unlock()

	pI := func(n string, i int) string {
		return writer.Prefix(prefix, writer.Prefix(n, fmt.Sprintf("%d", i)))
	}

	// Export the number of random features
	randomFeaturesKey := writer.Prefix(prefix, "NUM_RANDOM_FEATURES")
	err := writer.WriteU64ForKey(randomFeaturesKey, uint64(b.RandomFeatures))
	if err != nil {
		return base.DescribeError("Can't write NUM_RANDOM_FEATURES", err)
	}

	// Write the number of classifiers
	classifiersKey := writer.Prefix(prefix, "NUM_CLASSIFIERS")
	err = writer.WriteU64ForKey(classifiersKey, uint64(len(b.Models)))
	if err != nil {
		return base.DescribeError("Can't write NUM_CLASSIFIERS", err)
	}

	// Save the classifiers
	for i, c := range b.Models {
		clsPrefix := fmt.Sprintf("%s/", pI("CLASSIFIERS", i))
		err = c.SaveWithPrefix(writer, clsPrefix)
		if err != nil {
			return base.FormatError(err, "Can't save classifier %d", i)
		}
	}

	// Save the instances template
	err = writer.WriteInstancesForKey(writer.Prefix(prefix, "REFERENCE_INSTANCES"), b.fitOn, false)
	if err != nil {
		return base.DescribeError("Can't write REFERENCE_INSTANCES", err)
	}

	// Save the selectedAttributes map
	selectedAttributesKey := writer.Prefix(prefix, "SELECTED_ATTRIBUTES")
	ser := make(map[int][][]byte)
	for key := range b.selectedAttributes {
		ser[key] = make([][]byte, 0)
		for _, a := range b.selectedAttributes[key] {
			bytes, err := base.SerializeAttribute(a)
			if err != nil {
				return base.DescribeError("Can't serialize Attribute", err)
			}
			ser[key] = append(ser[key], bytes)
		}
	}

	err = writer.WriteJSONForKey(selectedAttributesKey, ser)
	if err != nil {
		return base.DescribeError("Can't write selected attributes map", err)
	}

	return nil
}
100085
func (m *Map) GetModel() *models.BPFMap {
	m.lock.RLock()
	defer m.lock.RUnlock()

	mapModel := &models.BPFMap{
		Path: m.path,
	}

	if m.cache != nil {
		mapModel.Cache = make([]*models.BPFMapEntry, len(m.cache))
		i := 0
		for k, entry := range m.cache {
			model := &models.BPFMapEntry{
				Key:           k,
				DesiredAction: entry.DesiredAction.String(),
			}

			if entry.LastError != nil {
				model.LastError = entry.LastError.Error()
			}

			if entry.Value != nil {
				model.Value = entry.Value.String()
			}
			mapModel.Cache[i] = model
			i++
		}
	}

	return mapModel
}
271524
func ParseModelType(raw string) (ModelType, error) {
	for _, typ := range []ModelType{ModelTypeIAAS, ModelTypeCAAS} {
		if raw == string(typ) {
			return typ, nil
		}
	}
	return "", errors.NotValidf("model type %v", raw)
}
1122168
func getAttributes(m interface{}) map[string]reflect.StructField {
	typ := reflect.TypeOf(m)
	// if a pointer to a struct is passed, get the type of the dereferenced object
	if typ.Kind() == reflect.Ptr {
		typ = typ.Elem()
	}

	// create an attribute data structure as a map of types keyed by a string.
	attrs := make(map[string]reflect.StructField)
	// Only structs are supported so return an empty result if the passed object
	// isn't a struct
	if typ.Kind() != reflect.Struct {
		fmt.Printf("%v type can't have attributes inspected\n", typ.Kind())
		return attrs
	}

	// loop through the struct's fields and set the map
	for i := 0; i < typ.NumField(); i++ {
		p := typ.Field(i)
		if !p.Anonymous {
			attrs[strings.ToLower(p.Name)] = p
		}
	}

	return attrs
}
1338927
func UnmarshalAttributes(b []byte) ([]Attribute, error) {
	var attrs []Attribute
	var i int
	for {
		if i > len(b) || len(b[i:]) == 0 {
			break
		}

		var a Attribute
		if err := (&a).unmarshal(b[i:]); err != nil {
			return nil, err
		}

		if a.Length == 0 {
			i += nlaHeaderLen
			continue
		}

		i += nlaAlign(int(a.Length))

		attrs = append(attrs, a)
	}

	return attrs, nil
}
277088
func NewLazilyFilteredInstances(src FixedDataGrid, f Filter) *LazilyFilteredInstances {

	// Get the Attributes after filtering
	attrs := f.GetAttributesAfterFiltering()

	// Build a set of Attributes which have undergone filtering
	unFilteredMap := make(map[Attribute]bool)
	for _, a := range src.AllAttributes() {
		unFilteredMap[a] = true
	}
	for _, a := range attrs {
		unFilteredMap[a.Old] = false
	}

	// Create the return structure
	ret := &LazilyFilteredInstances{
		f,
		src,
		attrs,
		make(map[Attribute]bool),
		unFilteredMap,
	}

	// Transfer class Attributes
	for _, a := range src.AllClassAttributes() {
		ret.AddClassAttribute(a)
	}
	return ret
}
75741
func ParamsStructFromJSON(value interface{}, shape *Shape, prefixPackageName bool) string {
	f := paramFiller{prefixPackageName: prefixPackageName}
	return util.GoFmt(f.paramsStructAny(value, shape))
}
106529
func InitModels() {
	index := mgo.Index{
		Key:    []string{"key"},
		Unique: false,
	}

	db.EnsureIndex(mongoPersistenLogCollectionName, index)
}
840243
func (f *RelationalModelDefinition) PKAttributes() string {
	var attr []string
	for _, pk := range f.PrimaryKeys {
		attr = append(attr, fmt.Sprintf("%s %s", codegen.Goify(pk.DatabaseFieldName, false), goDatatype(pk, true)))
	}
	return strings.Join(attr, ",")
}
493354
func (inst *DenseInstances) realiseAttributeGroups() error {
	for a := range inst.tmpAttrAgMap {
		// Generate a default AttributeGroup name
		ag := inst.tmpAttrAgMap[a]

		// Augment with some additional information
		// Find out whether this attribute is also a class
		classAttribute := false
		for _, c := range inst.allClassAttributes() {
			if c.Equals(a) {
				classAttribute = true
			}
		}

		// This might result in multiple ClassAttribute groups
		// but hopefully nothing too crazy
		if classAttribute {
			// ag = fmt.Sprintf("CLASS_%s", ag)
		}

		// Create the ag if it doesn't exist
		if agId, ok := inst.agMap[ag]; !ok {
			_, generatingBinClass := inst.ags[agId].(*BinaryAttributeGroup)
			if !generatingBinClass {
				inst.createAttributeGroup(ag, 8)
			} else {
				inst.createAttributeGroup(ag, 0)
			}
		}
		id := inst.agMap[ag]
		p := inst.ags[id]
		err := p.AddAttribute(a)
		if err != nil {
			return err
		}
	}
	return nil
}
982088
func (self *Connection) Model(typeName string) *Model {

	typeNameLC := strings.ToLower(typeName)

	if _, ok := self.modelRegistry[typeNameLC]; ok {

		return self.modelRegistry[typeNameLC]
	}

	panic(fmt.Sprintf("DB: Type '%v' is not registered", typeName))
}
282128
func (m *Mat64Instances) AllClassAttributes() []Attribute {
	ret := make([]Attribute, 0)
	for i := range m.classAttrs {
		if m.classAttrs[i] {
			ret = append(ret, m.attributes[i])
		}
	}

	return ret
}
472363
func (f *FixedAttributeGroup) Attributes() []Attribute {
	ret := make([]Attribute, len(f.attributes))
	// Add Attributes
	for i, a := range f.attributes {
		ret[i] = a
	}
	return ret
}
822694
func (c *ClassifierSerializer) WriteAttributesForKey(key string, attrs []Attribute) error {

	attrCountKey := c.Prefix(key, "ATTR_COUNT")
	err := c.WriteU64ForKey(attrCountKey, uint64(len(attrs)))
	if err != nil {
		return DescribeError("Unable to write ATTR_COUNT", err)
	}
	for i, a := range attrs {
		attrKey := c.Prefix(key, fmt.Sprintf("%d", i))
		err = c.WriteAttributeForKey(attrKey, a)
		if err != nil {
			return DescribeError("Unable to write Attribute", err)
		}
	}
	return nil
}
727905
func (sd *RelationalStoreDefinition) IterateModels(it ModelIterator) error {
	names := make([]string, len(sd.RelationalModels))
	i := 0
	for n := range sd.RelationalModels {
		names[i] = n
		i++
	}
	sort.Strings(names)
	for _, n := range names {
		if err := it(sd.RelationalModels[n]); err != nil {
			return err
		}
	}
	return nil
}
217577
func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
	attrs, err := UnmarshalAttributes(b)
	if err != nil {
		return nil, err
	}

	return &AttributeDecoder{
		// By default, use native byte order.
		ByteOrder: nlenc.NativeEndian(),

		attrs: attrs,
	}, nil
}
803196
func (st *State) inheritedConfigAttributes() (map[string]interface{}, error) {
	rspec, err := st.regionSpec()
	if err != nil {
		return nil, errors.Trace(err)
	}
	configSources := modelConfigSources(st, rspec)
	values := make(attrValues)
	for _, src := range configSources {
		cfg, err := src.sourceFunc()
		if errors.IsNotFound(err) {
			continue
		}
		if err != nil {
			return nil, errors.Annotatef(err, "reading %s settings", src.name)
		}
		for attrName, value := range cfg {
			values[attrName] = value
		}
	}
	return values, nil
}