text:
package catalog

// Copyright (c) Microsoft and contributors.  All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

import (
	"github.com/Azure/go-autorest/autorest"
	"github.com/Azure/go-autorest/autorest/date"
	"github.com/Azure/go-autorest/autorest/to"
	"github.com/satori/go.uuid"
	"net/http"
)

// FileType enumerates the values for file type.
type FileType string

const (
	// Assembly specifies the assembly state for file type.
	Assembly FileType = "Assembly"
	// Resource specifies the resource state for file type.
	Resource FileType = "Resource"
)

// DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters is dataLakeAnalytics DataLakeAnalyticsAccount information.
type DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters struct {
	Password *string `json:"password,omitempty"`
	URI      *string `json:"uri,omitempty"`
}

// DdlName is a Data Lake Analytics DDL name item.
type DdlName struct {
	FirstPart  *string `json:"firstPart,omitempty"`
	SecondPart *string `json:"secondPart,omitempty"`
	ThirdPart  *string `json:"thirdPart,omitempty"`
	Server     *string `json:"server,omitempty"`
}

// EntityID is a Data Lake Analytics catalog entity identifier object.
type EntityID struct {
	Name    *DdlName   `json:"name,omitempty"`
	Version *uuid.UUID `json:"version,omitempty"`
}

// ExternalTable is a Data Lake Analytics catalog external table item.
type ExternalTable struct {
	TableName  *string   `json:"tableName,omitempty"`
	DataSource *EntityID `json:"dataSource,omitempty"`
}

// Item is a Data Lake Analytics catalog item.
type Item struct {
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
}

// ItemList is a Data Lake Analytics catalog item list.
type ItemList struct {
	Count    *int32  `json:"count,omitempty"`
	NextLink *string `json:"nextLink,omitempty"`
}

// TypeFieldInfo is a Data Lake Analytics catalog type field information item.
type TypeFieldInfo struct {
	Name *string `json:"name,omitempty"`
	Type *string `json:"type,omitempty"`
}

// USQLAssembly is a Data Lake Analytics catalog U-SQL Assembly.
type USQLAssembly struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string                       `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID                    `json:"version,omitempty"`
	DatabaseName       *string                       `json:"databaseName,omitempty"`
	Name               *string                       `json:"assemblyName,omitempty"`
	ClrName            *string                       `json:"clrName,omitempty"`
	IsVisible          *bool                         `json:"isVisible,omitempty"`
	IsUserDefined      *bool                         `json:"isUserDefined,omitempty"`
	Files              *[]USQLAssemblyFileInfo       `json:"files,omitempty"`
	Dependencies       *[]USQLAssemblyDependencyInfo `json:"dependencies,omitempty"`
}

// USQLAssemblyClr is a Data Lake Analytics catalog U-SQL assembly CLR item.
type USQLAssemblyClr struct {
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	Name               *string    `json:"assemblyClrName,omitempty"`
	ClrName            *string    `json:"clrName,omitempty"`
}

// USQLAssemblyDependencyInfo is a Data Lake Analytics catalog U-SQL dependency information item.
type USQLAssemblyDependencyInfo struct {
	EntityID *EntityID `json:"entityId,omitempty"`
}

// USQLAssemblyFileInfo is a Data Lake Analytics catalog U-SQL assembly file information item.
type USQLAssemblyFileInfo struct {
	Type         FileType `json:"type,omitempty"`
	OriginalPath *string  `json:"originalPath,omitempty"`
	ContentPath  *string  `json:"contentPath,omitempty"`
}

// USQLAssemblyList is a Data Lake Analytics catalog U-SQL assembly CLR item list.
type USQLAssemblyList struct {
	autorest.Response `json:"-"`
	Count             *int32             `json:"count,omitempty"`
	NextLink          *string            `json:"nextLink,omitempty"`
	Value             *[]USQLAssemblyClr `json:"value,omitempty"`
}

// USQLAssemblyListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLAssemblyList) USQLAssemblyListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLCredential is a Data Lake Analytics catalog U-SQL credential item.
type USQLCredential struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	Identity           *string    `json:"identity,omitempty"`
	Name               *string    `json:"credentialName,omitempty"`
	UserName           *string    `json:"userName,omitempty"`
}

// USQLCredentialList is a Data Lake Analytics catalog U-SQL credential item list.
type USQLCredentialList struct {
	autorest.Response `json:"-"`
	Count             *int32            `json:"count,omitempty"`
	NextLink          *string           `json:"nextLink,omitempty"`
	Value             *[]USQLCredential `json:"value,omitempty"`
}

// USQLCredentialListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLCredentialList) USQLCredentialListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLDatabase is a Data Lake Analytics catalog U-SQL database item.
type USQLDatabase struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	Name               *string    `json:"databaseName,omitempty"`
}

// USQLDatabaseList is a Data Lake Analytics catalog U-SQL database item list.
type USQLDatabaseList struct {
	autorest.Response `json:"-"`
	Count             *int32          `json:"count,omitempty"`
	NextLink          *string         `json:"nextLink,omitempty"`
	Value             *[]USQLDatabase `json:"value,omitempty"`
}

// USQLDatabaseListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLDatabaseList) USQLDatabaseListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLDirectedColumn is a Data Lake Analytics catalog U-SQL directed column item.
type USQLDirectedColumn struct {
	Name       *string `json:"name,omitempty"`
	Descending *bool   `json:"descending,omitempty"`
}

// USQLDistributionInfo is a Data Lake Analytics catalog U-SQL distribution information object.
type USQLDistributionInfo struct {
	Type         *int32                `json:"type,omitempty"`
	Keys         *[]USQLDirectedColumn `json:"keys,omitempty"`
	Count        *int32                `json:"count,omitempty"`
	DynamicCount *int32                `json:"dynamicCount,omitempty"`
}

// USQLExternalDataSource is a Data Lake Analytics catalog U-SQL external datasource item.
type USQLExternalDataSource struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	Name               *string    `json:"externalDataSourceName,omitempty"`
	Provider           *string    `json:"provider,omitempty"`
	ProviderString     *string    `json:"providerString,omitempty"`
	PushdownTypes      *[]string  `json:"pushdownTypes,omitempty"`
}

// USQLExternalDataSourceList is a Data Lake Analytics catalog U-SQL external datasource item list.
type USQLExternalDataSourceList struct {
	autorest.Response `json:"-"`
	Count             *int32                    `json:"count,omitempty"`
	NextLink          *string                   `json:"nextLink,omitempty"`
	Value             *[]USQLExternalDataSource `json:"value,omitempty"`
}

// USQLExternalDataSourceListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLExternalDataSourceList) USQLExternalDataSourceListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLIndex is a Data Lake Analytics catalog U-SQL table index item.
type USQLIndex struct {
	Name              *string               `json:"name,omitempty"`
	IndexKeys         *[]USQLDirectedColumn `json:"indexKeys,omitempty"`
	Columns           *[]string             `json:"columns,omitempty"`
	DistributionInfo  *USQLDistributionInfo `json:"distributionInfo,omitempty"`
	PartitionFunction *uuid.UUID            `json:"partitionFunction,omitempty"`
	PartitionKeyList  *[]string             `json:"partitionKeyList,omitempty"`
	StreamNames       *[]string             `json:"streamNames,omitempty"`
	IsColumnstore     *bool                 `json:"isColumnstore,omitempty"`
	IndexID           *int32                `json:"indexId,omitempty"`
	IsUnique          *bool                 `json:"isUnique,omitempty"`
}

// USQLProcedure is a Data Lake Analytics catalog U-SQL procedure item.
type USQLProcedure struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	SchemaName         *string    `json:"schemaName,omitempty"`
	Name               *string    `json:"procName,omitempty"`
	Definition         *string    `json:"definition,omitempty"`
}

// USQLProcedureList is a Data Lake Analytics catalog U-SQL procedure item list.
type USQLProcedureList struct {
	autorest.Response `json:"-"`
	Count             *int32           `json:"count,omitempty"`
	NextLink          *string          `json:"nextLink,omitempty"`
	Value             *[]USQLProcedure `json:"value,omitempty"`
}

// USQLProcedureListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLProcedureList) USQLProcedureListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLSchema is a Data Lake Analytics catalog U-SQL schema item.
type USQLSchema struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	Name               *string    `json:"schemaName,omitempty"`
}

// USQLSchemaList is a Data Lake Analytics catalog U-SQL schema item list.
type USQLSchemaList struct {
	autorest.Response `json:"-"`
	Count             *int32        `json:"count,omitempty"`
	NextLink          *string       `json:"nextLink,omitempty"`
	Value             *[]USQLSchema `json:"value,omitempty"`
}

// USQLSchemaListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLSchemaList) USQLSchemaListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLSecret is a Data Lake Analytics catalog U-SQL secret item.
type USQLSecret struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	Name               *string    `json:"secretName,omitempty"`
	CreationTime       *date.Time `json:"creationTime,omitempty"`
	URI                *string    `json:"uri,omitempty"`
	Password           *string    `json:"password,omitempty"`
}

// USQLTable is a Data Lake Analytics catalog U-SQL table item.
type USQLTable struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string               `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID            `json:"version,omitempty"`
	DatabaseName       *string               `json:"databaseName,omitempty"`
	SchemaName         *string               `json:"schemaName,omitempty"`
	Name               *string               `json:"tableName,omitempty"`
	ColumnList         *[]USQLTableColumn    `json:"columnList,omitempty"`
	IndexList          *[]USQLIndex          `json:"indexList,omitempty"`
	PartitionKeyList   *[]string             `json:"partitionKeyList,omitempty"`
	ExternalTable      *ExternalTable        `json:"externalTable,omitempty"`
	DistributionInfo   *USQLDistributionInfo `json:"distributionInfo,omitempty"`
}

// USQLTableColumn is a Data Lake Analytics catalog U-SQL table column item.
type USQLTableColumn struct {
	Name *string `json:"name,omitempty"`
	Type *string `json:"type,omitempty"`
}

// USQLTableList is a Data Lake Analytics catalog U-SQL table item list.
type USQLTableList struct {
	autorest.Response `json:"-"`
	Count             *int32       `json:"count,omitempty"`
	NextLink          *string      `json:"nextLink,omitempty"`
	Value             *[]USQLTable `json:"value,omitempty"`
}

// USQLTableListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLTableList) USQLTableListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLTablePartition is a Data Lake Analytics catalog U-SQL table partition item.
type USQLTablePartition struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	SchemaName         *string    `json:"schemaName,omitempty"`
	Name               *string    `json:"partitionName,omitempty"`
	ParentName         *DdlName   `json:"parentName,omitempty"`
	IndexID            *int32     `json:"indexId,omitempty"`
	Label              *[]string  `json:"label,omitempty"`
	CreateDate         *date.Time `json:"createDate,omitempty"`
}

// USQLTablePartitionList is a Data Lake Analytics catalog U-SQL table partition item list.
type USQLTablePartitionList struct {
	autorest.Response `json:"-"`
	Count             *int32                `json:"count,omitempty"`
	NextLink          *string               `json:"nextLink,omitempty"`
	Value             *[]USQLTablePartition `json:"value,omitempty"`
}

// USQLTablePartitionListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLTablePartitionList) USQLTablePartitionListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLTableStatistics is a Data Lake Analytics catalog U-SQL table statistics item.
type USQLTableStatistics struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	SchemaName         *string    `json:"schemaName,omitempty"`
	TableName          *string    `json:"tableName,omitempty"`
	Name               *string    `json:"statisticsName,omitempty"`
	UserStatName       *string    `json:"userStatName,omitempty"`
	StatDataPath       *string    `json:"statDataPath,omitempty"`
	CreateTime         *date.Time `json:"createTime,omitempty"`
	UpdateTime         *date.Time `json:"updateTime,omitempty"`
	IsUserCreated      *bool      `json:"isUserCreated,omitempty"`
	IsAutoCreated      *bool      `json:"isAutoCreated,omitempty"`
	HasFilter          *bool      `json:"hasFilter,omitempty"`
	FilterDefinition   *string    `json:"filterDefinition,omitempty"`
	ColNames           *[]string  `json:"colNames,omitempty"`
}

// USQLTableStatisticsList is a Data Lake Analytics catalog U-SQL table statistics item list.
type USQLTableStatisticsList struct {
	autorest.Response `json:"-"`
	Count             *int32                 `json:"count,omitempty"`
	NextLink          *string                `json:"nextLink,omitempty"`
	Value             *[]USQLTableStatistics `json:"value,omitempty"`
}

// USQLTableStatisticsListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLTableStatisticsList) USQLTableStatisticsListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLTableType is a Data Lake Analytics catalog U-SQL table type item.
type USQLTableType struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string          `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID       `json:"version,omitempty"`
	DatabaseName       *string          `json:"databaseName,omitempty"`
	SchemaName         *string          `json:"schemaName,omitempty"`
	Name               *string          `json:"typeName,omitempty"`
	TypeFamily         *string          `json:"typeFamily,omitempty"`
	CSharpName         *string          `json:"cSharpName,omitempty"`
	FullCSharpName     *string          `json:"fullCSharpName,omitempty"`
	SystemTypeID       *int32           `json:"systemTypeId,omitempty"`
	UserTypeID         *int32           `json:"userTypeId,omitempty"`
	SchemaID           *int32           `json:"schemaId,omitempty"`
	PrincipalID        *int32           `json:"principalId,omitempty"`
	IsNullable         *bool            `json:"isNullable,omitempty"`
	IsUserDefined      *bool            `json:"isUserDefined,omitempty"`
	IsAssemblyType     *bool            `json:"isAssemblyType,omitempty"`
	IsTableType        *bool            `json:"isTableType,omitempty"`
	IsComplexType      *bool            `json:"isComplexType,omitempty"`
	Columns            *[]TypeFieldInfo `json:"columns,omitempty"`
}

// USQLTableTypeList is a Data Lake Analytics catalog U-SQL table type item list.
type USQLTableTypeList struct {
	autorest.Response `json:"-"`
	Count             *int32           `json:"count,omitempty"`
	NextLink          *string          `json:"nextLink,omitempty"`
	Value             *[]USQLTableType `json:"value,omitempty"`
}

// USQLTableTypeListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLTableTypeList) USQLTableTypeListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLTableValuedFunction is a Data Lake Analytics catalog U-SQL table valued function item.
type USQLTableValuedFunction struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	SchemaName         *string    `json:"schemaName,omitempty"`
	Name               *string    `json:"tvfName,omitempty"`
	Definition         *string    `json:"definition,omitempty"`
}

// USQLTableValuedFunctionList is a Data Lake Analytics catalog U-SQL table valued function item list.
type USQLTableValuedFunctionList struct {
	autorest.Response `json:"-"`
	Count             *int32                     `json:"count,omitempty"`
	NextLink          *string                    `json:"nextLink,omitempty"`
	Value             *[]USQLTableValuedFunction `json:"value,omitempty"`
}

// USQLTableValuedFunctionListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLTableValuedFunctionList) USQLTableValuedFunctionListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLType is a Data Lake Analytics catalog U-SQL type item.
type USQLType struct {
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	SchemaName         *string    `json:"schemaName,omitempty"`
	Name               *string    `json:"typeName,omitempty"`
	TypeFamily         *string    `json:"typeFamily,omitempty"`
	CSharpName         *string    `json:"cSharpName,omitempty"`
	FullCSharpName     *string    `json:"fullCSharpName,omitempty"`
	SystemTypeID       *int32     `json:"systemTypeId,omitempty"`
	UserTypeID         *int32     `json:"userTypeId,omitempty"`
	SchemaID           *int32     `json:"schemaId,omitempty"`
	PrincipalID        *int32     `json:"principalId,omitempty"`
	IsNullable         *bool      `json:"isNullable,omitempty"`
	IsUserDefined      *bool      `json:"isUserDefined,omitempty"`
	IsAssemblyType     *bool      `json:"isAssemblyType,omitempty"`
	IsTableType        *bool      `json:"isTableType,omitempty"`
	IsComplexType      *bool      `json:"isComplexType,omitempty"`
}

// USQLTypeList is a Data Lake Analytics catalog U-SQL type item list.
type USQLTypeList struct {
	autorest.Response `json:"-"`
	Count             *int32      `json:"count,omitempty"`
	NextLink          *string     `json:"nextLink,omitempty"`
	Value             *[]USQLType `json:"value,omitempty"`
}

// USQLTypeListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLTypeList) USQLTypeListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}

// USQLView is a Data Lake Analytics catalog U-SQL view item.
type USQLView struct {
	autorest.Response  `json:"-"`
	ComputeAccountName *string    `json:"computeAccountName,omitempty"`
	Version            *uuid.UUID `json:"version,omitempty"`
	DatabaseName       *string    `json:"databaseName,omitempty"`
	SchemaName         *string    `json:"schemaName,omitempty"`
	Name               *string    `json:"viewName,omitempty"`
	Definition         *string    `json:"definition,omitempty"`
}

// USQLViewList is a Data Lake Analytics catalog U-SQL view item list.
type USQLViewList struct {
	autorest.Response `json:"-"`
	Count             *int32      `json:"count,omitempty"`
	NextLink          *string     `json:"nextLink,omitempty"`
	Value             *[]USQLView `json:"value,omitempty"`
}

// USQLViewListPreparer prepares a request to retrieve the next set of results. It returns
// nil if no more results exist.
func (client USQLViewList) USQLViewListPreparer() (*http.Request, error) {
	if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 {
		return nil, nil
	}
	return autorest.Prepare(&http.Request{},
		autorest.AsJSON(),
		autorest.AsGet(),
		autorest.WithBaseURL(to.String(client.NextLink)))
}


text:
@interface DropzoneBuilder ()

@property PFObject *loadedDropzone;
@property Region *loadedRegion;

@end

@implementation DropzoneBuilder

- (instancetype)initWithDropzone:(PFObject *)dropzone region:(Region *)region {
    self = [super init];
    if (self) {
        self.loadedDropzone = dropzone;
        self.loadedRegion = region;
    }

    return self;
}

- (Dropzone *)build {

    CLLocationCoordinate2D location = [self buildLocation];
    PFObject *displayObject = self.loadedDropzone[@"DisplayImage"];
    PFFile *displayImageFile = displayObject[@"Data"];
    NSURL *website = [NSURL URLWithString:self.loadedDropzone[@"Website"]];
    NSURL *displayImage = [NSURL URLWithString:displayImageFile.url];

    Dropzone *dropzone = [[Dropzone alloc] initWithObjectId:self.loadedDropzone.objectId
                                                       name:self.loadedDropzone[@"Name"]
                                            descriptionText:self.loadedDropzone[@"Description"]
                                                phoneNumber:self.loadedDropzone[@"PhoneNumber"]
                                                     region:self.loadedRegion
                                                    address:self.loadedDropzone[@"Address"]
                                                   location:location
                                                    website:website
                                            displayImageUrl:displayImage];
    return dropzone;
}

- (CLLocationCoordinate2D)buildLocation {
    PFGeoPoint *loadedLocation = self.loadedDropzone[@"Location"];
    return CLLocationCoordinate2DMake(loadedLocation.latitude, loadedLocation.longitude);
}

@end

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled RSS Feed]]></title><description><![CDATA[Untitled RSS Feed]]></description><link>https://elinep.github.io/blog</link><generator>RSS for Node</generator><lastBuildDate>Thu, 22 Jun 2017 12:51:35 GMT</lastBuildDate><atom:link href="https://elinep.github.io/blog/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Why an activation function ?]]></title><description><![CDATA[

A quick explanation why a neural network with several layers and no activation
function is useless. This might sound trivial but I’m sure you did ask yourself
first time you heard about hidden layer.

Without activation

Consider two layers of neurons. The first layer has \(n\) neurons, the second
layer has one neuron. The input data is the vector \(X\), the intermediate
result is the vector \(X_h\) and the network output is the scalar \(y\).
Neuron’s parameters in the first layer are \(W_{h_i}\) and \(B_{h_i}\).
Neuron’s parameters in the last layer are \(W\) and \(B\). First layer
neuron has \(m\) inputs. There are \(n\) neurons in the first layer.

Figure 1. A generic fully connected two layers network

For each neuron in the first layer we have:

\(x_{h_i} = X \cdot W_{h_i} + B_i\)

Let’s put it in a matrix form:

\(\mathbf{ X_h = X \cdot W_h + B_h }\)

\(W_h = \begin{bmatrix} W_{h_0} \\ W_{h_1} \\ ... \\ W_{h_n} \end{bmatrix}\)
is the \(m \times n\) matrix holding the weights of the first layer,
\(B_h = \begin{bmatrix} B_{h_0} \\ B_{h_1} \\ ... \\ B_{h_n} \end{bmatrix}\)
is a \(n\)-vector holding the bias. Similarly \(X\) is the input
\(m\)-vector and \(X_h\) is the first layer output \(n\)-vector

The output neuron computes:

\(y = W \cdot X_h  + B\)

By composing the two layers, we have:

\(y = W \cdot ( W_h \cdot X + B_h ) + B\)

By expansing, we get:

\(y = W \cdot W_h \cdot X + W \cdot B_h + B\)

Which matches the definition of a single neuron:

\(\mathbf{y = W' \cdot X + B'}\)

with \(W' = W \cdot W_h\) and
\(B' = W \cdot B_h + B\)

Figure 2. The 2 layers network is equivalent to a single neuron

Recursively we can reduce any \(N\)-layers model to a single neuron.
We start with the terminal neuron of the network (layer \(N\)) and its input
(layer \(N-1\)). We then replace the terminal neuron and layer \(N-1\)
by the equivalent single neuron. By repeating this operation you end up with a
single neuron.

With activation

Let’s see what happens when we introduce an activation function. Each scalar output
of the first layer is transformed before entering last neuron.

Figure 3. A generic fully connected two layers network with activation function

When we compose all transformations we obtain:

\(y = W \cdot F_{activation}( W_h \cdot X + B_h ) + B\)

Now we’re stuck, we can’t develop this expression as we did before unless the activation
function is a simple linear transform like \(f(x) = ax+b\) but it is purposely
non linear. With non linear activation functions we can’t simplify the network anymore.
Thanks to the activation function, at least one hidden layer can be justified when
arbitrary non linear transformations must be learned by the network.

]]></description><link>https://elinep.github.io/blog/2017/06/22/why_activation_function.html</link><guid isPermaLink="true">https://elinep.github.io/blog/2017/06/22/why_activation_function.html</guid><category><![CDATA[Blog]]></category><category><![CDATA[Neural network]]></category><pubDate>Thu, 22 Jun 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[Neural Networks from scratch]]></title><description><![CDATA[

In the previous post
we saw the theory about neural network training. It’s time to practice by writing
a basic implementation from scratch in python. The code is available
here.

Objectives

Few goals for our tiny neural network framework :

the network architecture must be easy to define (number of layers, neuron
per layers, …)

we will focus on fully connected network

it must be trainable

no use of specialized package like tensorflow

To test it, we will train the network to approximate a function. I arbitrarily
choose the next one:

\(y = f(x_0,x_1) = x_0 x_1 + 2x_0 + 1\)

\((x_0,x_1) \in \mathbb{R}^2\) and \(y \in \mathbb{R}\)

Figure 1. Our objective function

Code

Block class

AbstractBlock class

We start by defining an abstract class which will be the base class for all the
nodes (neurons, activation function, loss function) in the network.

This class defines 3 methods:

forward(), receives input data and return an output, used for forward
propagation

backward() receives output gradient and return input gradient, used for
backward propagation

update() called during weights update. This function is optional because
blocks like loss/activation functions do not have weights.

class AbstractBlock(object):
    '''
    Abstract class of a block
    a block has multiple input, one output.
    a block must have forward() and backward() methods
    update() method is optional
    '''
    def __init__(self, input_dim):
        self.input_dim = input_dim
        # input data
        self.x = np.zeros(input_dim)
        # output data
        self.y = 0
        # gradient data
        self.grad_x = np.zeros(input_dim)

    '''
    forward pass
    input_data is a vector, each element corresponds to a neuron input
    '''
    def forward(self, input_data):
        raise NotImplementedError('forward not implemented')

    '''
    backward pass
    output_gradient is a scalar
    '''
    def backward(self, output_gradient):
        raise NotImplementedError('backward not implemented')

    '''
    trigger weight update
    '''
    def update(self, learn_rate):
        pass

forward() and backward() do not have default implementation as we don’t know
yet what an AbstractBlock computes.

Neuron class

Now we define the Neuron class which inherits from AbstractBlock and implements
the neuron transformation:

class Neuron(AbstractBlock):
    '''
    Neuron class computing a weighted sum of its input
    '''
    def __init__(self, input_dim):
        super(Neuron, self).__init__(input_dim)
        # initialize random weight
        self.weight = np.random.normal(loc=0.0, scale=0.1, size=(input_dim))
        # initialize bias
        self.bias = 0.0
        # init weight and bias gradient
        self.grad_weight = np.zeros(input_dim)
        self.grad_bias = 0.0

    def forward(self, input_data):
        # save input data
        self.x = input_data
        # compute output
        self.y = np.dot(self.x, self.weight) + self.bias
        return self.y

    def backward(self, output_gradient):
        self.grad_bias = output_gradient
        self.grad_weight = self.x * output_gradient
        self.grad_x = self.weight * output_gradient
        return self.grad_x

    def update(self, learn_rate):
        self.weight += -learn_rate * self.grad_weight
        self.bias += -learn_rate * self.grad_bias

Neuron has some extra initialization compared to AbstractBlock since it has
weight and bias parameters. Weights are randomly initialized while bias is set to
0

def __init__(self, input_dim):
    super(Neuron, self).__init__(input_dim)
    # initialize random weight
    self.weight = np.random.normal(loc=0.0, scale=0.1, size=(input_dim))
    # initialize bias
    self.bias = 0.0
    # init weight and bias gradient
    self.grad_weight = np.zeros(input_dim)
    self.grad_bias = 0.0

forward() implements the neuron definition:

\(Y = f_{neuron}(X,W,B) = \sum\limits_{i=0}^{N}{(X_i \cdot W_i)}+B\)

backward() compute the partial derivative with respect to the parameters (weight, bias)
and the input data (x) and multiply the result by the output gradient (chain rule):

\(G_{W_i} = G_Y \cdot \frac{\partial F_{neuron}(X,W,B)}{\partial W_i}
=G_Y \cdot X_i\)

\(G_{B} = G_Y \cdot \frac{\partial F_{neuron}(X,W,B)}{\partial W_B}
=G_Y \cdot 1\)

\(G_{X_i} = G_Y \cdot \frac{\partial F_{neuron}(X,W,B)}{\partial W_i}
=G_Y \cdot W_i\)

update() implements the gradient descent by incrementing the neuron parameter
with a fraction of the gradient:

\(W_i = W_i - \lambda G_{W_i}\)

\(B = B - \lambda G_{B}\)

Activation class

The activation function is placed right after a neuron. It is a
\(\mathbb{R} \to \mathbb{R}\) as opposite to a neuron which is
\(\mathbb{R}^N \to \mathbb{R}\). It doesn’t have any parameters. Here we implement
the popular relu:

\(Y = f_{relu}(X) = \max(0,X)\)

class Relu(AbstractBlock):
    '''
    Relu activation function block
    '''
    def __init__(self):
        super(Relu, self).__init__(1)

    def forward(self, input_data):
        # save input data
        self.x = input_data
        # compute output
        self.y = max(0.0, self.x)
        return self.y

    def backward(self, output_gradient):
        if self.x > 0:
            self.grad_x = output_gradient
        else:
            self.grad_x = 0.0
        return self.grad_x

backward() is straight forward to implement. The function varies only with its
scalar input:

\(G_X = G_Y \cdot \frac{\partial f_{relu}(X)}{\partial X}
=G_Y \cdot
\Big\{
\begin{matrix}
1 & Y>0 \\
0 & Y \leqslant 0
\end{matrix}\)

strictly speaking the \(f_{relu}(X)\) can not be derived for \(X=0\)
In practice it is not annoying as it affects only one single point and we arbitrarily
choose to extend the derivative from \(X<0\) or \(X>0\)

update() class is not redefined as there are no weights to optimize in an activation
function

Loss class

A loss function computes the error between the output of the network and the expected
output from the training data. We need a way to provide the expected data to a loss block.
We define an AbstractLoss class for this purpose

AbstractLoss class

class AbstractLoss(AbstractBlock):
    '''
    Abstract class of a loss function
    A loss function is a "block" with a setExpectedData() method to set
    the ground truth result of a neural network
    '''
    def __init__(self, input_dim):
        super(AbstractLoss, self).__init__(input_dim)
        self.expected_data = np.zeros(input_dim)

    def setExpectedData(self, expected_data):
        self.expected_data = expected_data

AbstractLoss only adds a new method setExpectedData() to the AbstractBlock.
setExpectedData() is used to pass the ground truth output from the training data.
The expected data are stored to be used later by the forward() method.

LossL2 class

Now we implement a real loss function, the \(L2\) norm:

\(L(Y,\tilde{Y}) = \sum{(Y_i-\tilde{Y_i})^2}\)

class LossL2(AbstractLoss):
    '''
    A loss function that compute the L2 norm between its input_data and
    ground truth data
    '''
    def __init__(self, input_dim):
        super(LossL2, self).__init__(input_dim)

    def forward(self, input_data):
        # save input data
        self.x = input_data
        # compute L2 distance between input data and expected input data
        self.y = np.sum(np.square(self.x - self.expected_data))
        return self.y

    def backward(self):
        self.grad_x = 2 * (self.x - self.expected_data)
        return self.grad_x

backward() takes no argument as we compute the gradient with respect to the
error. The loss function is the first stage for
backward propagation. We only compute the gradient with respect to \(Y\) as
\(\tilde{Y}\) do not varies with the weights of the network.

Network class

We have all the elementary blocks we need. Let’s write a new class to manage them.
The Network class will allow us to build/train and run a network.

building network

First let’s focus on the functions to build the network

When instantiating the Neuron we provide the dimensions of our input and output
data. These informations are used to determine the number of inputs per neuron of
the first layer and the number of neurons of the last layer.

def __init__(self, input_dim, output_dim):
    # data dimensions
    self._input_dim = input_dim
    self._output_dim = output_dim
    # the neuron layer stack
    self._network = []
    # helper to know the number of input for the next neuron layer
    self._last_input_dim = input_dim
    # the loss function will be added later
    self._loss = None
    # current output of the network
    self._last_network_output = np.zeros(output_dim)

We define a method to add a layer of neuron. This method takes an AbstractBlock
as first argument which defines the neuron transformation. The second argument is
the number of neurons for the layer.

'''
Add a layer of neuron fully connected to the previous layer
'''
def addNeuronlayer(self, NeuronClassType, size):
    layer = {
        'data' : [ NeuronClassType(self._last_input_dim) for i in range(size)],
        'input_dim' : self._last_input_dim,
        'output_dim' : size,
        'type' : 'neuron'
    }
    self._network.append(layer)
    self._last_input_dim = size

addNeuronlayer() method adds a fully connected layer. Each neuron of the layer
considers all the output of the previous layer as input.
We instantiate size neurons, add some metadata and stack them into the
self._network array.

We write a similar method to add an activation layer.

'''
Add an activation layer (one activation block per block of the previous layer)
'''
def addActivationLayer(self, ActivationClassType):
    layer = {
        'data' : [ ActivationClassType() for i in range(self._last_input_dim)],
        'input_dim' : self._last_input_dim,
        'output_dim' : self._last_input_dim,
        'type' : 'activation'
    }
    self._network.append(layer)
    pass

Since activation function are placed after each neuron, there is no size argument.
We create as many ActivationClass as neurons in the previous layer.

set loss

The user can set the loss function thanks to the next method

'''
Set the loss function for the optimization
'''
def setLoss(self, LossClass):
    self._loss = LossClass(self._output_dim)

forward/backward propagation through the network

Next method propagates data by iterating over layers and blocks. It returns the
network output.

'''
Process input_data by the network
'''
def _forward(self, input_data):
    layer_input = input_data
    layer_i = 0
    for layer in self._network:
        # temporary layer output
        layer_output = np.zeros(layer['output_dim'])

        if layer['type'] == 'neuron':
            # feed each block of the layer with the input data
            b_i = 0
            for b in layer['data']:
                layer_output[b_i] = b.forward(layer_input)
                b_i += 1
        elif layer['type'] == 'activation':
            # one to one connection between input data and output data elements
            b_i = 0
            for b in layer['data']:
                layer_output[b_i] = b.forward(layer_input[b_i])
                b_i += 1
        else:
            raise ValueError('unknow layer type %s, can not run the network' % layer['type'])

        # current output is the input of the next layer
        layer_input = layer_output
        layer_i += 1

    return layer_output

As we notice, there are two cases:

layer of neuron, the entire output vector of the previous layer is fed to each
neurons since we are implementing a fully connected network.

layer of activation function, only the output of the matching previous layer neuron is fed
to the activation function

The output of the current layer becomes the input of the next layer.

Similarly we have the backward propagation.

'''
Back propagate through the entire network
'''
def _backward(self, output_grad):
    layer_output_grad = output_grad
    layer_i = 0
    for layer in reversed(self._network):
        # temporary layer input gradient
        layer_input_grad = np.zeros(layer['input_dim'])

        if layer['type'] == 'neuron':
            b_i = 0
            for b in layer['data']:
                layer_input_grad += b.backward(layer_output_grad[b_i])
                b_i += 1
        elif layer['type'] == 'activation':
            b_i = 0
            for b in layer['data']:
                layer_input_grad[b_i] = b.backward(layer_output_grad[b_i])
                b_i += 1
        else:
            raise ValueError('unknow layer type %s, can not run the network' % layer['type'])

        layer_output_grad = layer_input_grad
        layer_i += 1
    return

There are also two cases:

layer of neuron, we accumulate the gradient since the output of the previous layer is
connected to multiple neurons.

layer of activation function, we provide a scalar gradient and get a scalar gradient

Training

The training iterates over a set of examples. Each example is forward propagated
through the network. The error is computed thanks to the loss block. We then back
propagate through the loss and the network. Finally we trigger a weight update()
for all block of the network. In the meantime we average the error over the whole
training set to monitor the training behavior. The full training set is presented
epoch times.

'''
Train the network with examples
(X,Y) training data set (each row is an example)
'''
def train(self, X, Y, epoch, learn_rate):
    num_example = X.shape[1]
    loss_historic = np.zeros(epoch)
    for e in range(epoch):
        l_mean = 0.0
        for x, y in zip(X, Y):
            # do forward pass
            network_output = self._forward(x)
            # compute loss
            self._loss.setExpectedData(y)
            l_mean += self._loss.forward(network_output)
            # back propagate
            l_grad = self._loss.backward()
            self._backward(l_grad)
            # update weight
            self._update(learn_rate)
        loss_historic[e] = l_mean / num_example
        print("epoch %d/%d average loss %f" % (e, epoch, loss_historic[e]))
    return loss_historic

    '''
    Trigger a weight update for every block of the network
    '''
    def _update(self, learn_rate):
        for layer in self._network:
            for b in layer['data']:
                b.update(learn_rate)

Running

Finally a method for forward propagation only to use our network once trained.

'''
Process a bunch of input data
'''
def run(self, input_data):
    input_data = input_data.reshape((-1, self._input_dim))
    y = np.zeros((input_data.shape[0], self._output_dim))
    i = 0
    for x in input_data:
        y[i, :] = self._forward(x)
        i += 1
    return y

Main

The main() function prepares the training data, sets up the network, trains it
and displays the results.

Training data

We define a lambda objective function as defined in the introduction. We generate
random input data and process them with our objective function.

# the objective function the network has to mimic
function_to_learn = lambda x0, x1: np.add(np.multiply(x0, x1), 2 * x0) + 1

x_range = 10
# generate random input data
X_train = np.random.uniform(-x_range, x_range, (NUM_EXAMPLES, 2))
# generate matching output data
Y_train = function_to_learn(X_train[:, 0], X_train[:, 1])

Build model

We instantiate a network and stack neuron layers and activation layers. Each layer
has NUM_HIDDEN_NODES neurons and there are NUM_HIDDEN_LAYER layers. We end with
a single neuron which is the output of the network.

model = Network(2, 1)
for h in range(NUM_HIDDEN_LAYER):
    model.addNeuronlayer(Neuron, NUM_HIDDEN_NODES)
    model.addActivationLayer(Relu)
model.addNeuronlayer(Neuron, 1)

Trainning

Finally we set a loss function and start training.

model.setLoss(LossL2)
loss_historic = model.train(X_train, Y_train, NUM_EPOCHS, LEARNING_RATE)

Results

The script displays two figures. First, an overlay of the objective function and
the network function. As we can see both overlay quite nicely.

Figure 2. Network vs Objective function

The error also decreases nicely:

Figure 3. Error over time

In the main function we have all the hyperparameters we can play with:

NUM_HIDDEN_NODES = 10
NUM_HIDDEN_LAYER = 2
NUM_EXAMPLES = 1000
NUM_EPOCHS = 200
LEARNING_RATE = 0.0001

]]></description><link>https://elinep.github.io/blog/2017/06/13/neural_network_from_scratch.html</link><guid isPermaLink="true">https://elinep.github.io/blog/2017/06/13/neural_network_from_scratch.html</guid><category><![CDATA[Blog]]></category><category><![CDATA[Neural network]]></category><category><![CDATA[Python]]></category><pubDate>Tue, 13 Jun 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[Neural Networks Training: basic concepts]]></title><description><![CDATA[

I recently started to be interested in neural networks attracted by all the
magical articles/results that flood the web.
When you see magic, you want to understand the trick. That's my case.
A great resource to study this subject is the
Convolutional Neural Networks course by Standford.
This series of videos is nice and show that neural network concepts are accessible.
There is still few points that struggled me for a while and my modest intent is
that this post freshly written after having watched the video could help for a
better understanding.

What is a neural network ?

OK first, what kind of beast a neural network is and what's its purpose. Well
it's just a giant function that process some input based on some parameters to
compute some output.

Figure 1. Abstract view of a neural network

So basically you present to your network some input data (images, numbers, text)
and it generates an output (images, numbers, text) by computing:

\(Y = f(X,W)\)

Note that the dimensions of \(X\),\(Y\) and \(W\) are generally different.
For example for an image classification task:

\(X\) will be the dimensions of the image (example 128x128)

\(Y\) will be the number of class (example 10) you want to detect

\(W\) can be very large like millions of coefficients

The \(f()\) function is a kind of generic one defined by your network
architecture and depends on:

type of neuron

number of neurons

how neurons interconnect each other

…

Its behavior is driven by the weights. The weights are the parameters you have to
tune so that \(f()\) does something interesting i.e. produces relevant output
given the input and not just garbage.

What is training ?

The goal of training is to find the value of the weights so that the network
generates correct output.

On supervised learning you present examples of input data and expected output.
At the beginning the network will generate outputs far different from the
expected ones.

The difference between output and expected output is used to update the weights
so that the error decreased.

After many example submission and weights optimization cycle, you hope your
network works correctly and can predict correctly new output with unseen data.

So basically network training is a function fitting task.

How do you train ?

OK first we need to measure the error between an expected output and current
output of the network.

This is called a loss function and it is added at the end of the network like this:

Figure 2. Loss function to compute error

The loss function should have several properties:

its input are the output of the network and the output from the training data

its output is a scalar

it should measure properly the error : the more \(Y\) and \(\tilde{Y}\)
are close, the less the error must be

it must be differentiable

There are several ad-hoc loss function that we can use depending on our application.
A very simple one - the \(L2\) norm - consists in summing the square error on
each output dimensions:

\(L(Y,\tilde{Y}) = \sum{(Y_i-\tilde{Y_i})^2}\)

The training consists of finding the weights of the network that minimize the
error. In math language, we perform:

\(\underset{W}{\arg\min{}} L(Y,\tilde{Y})\)

It's not a straight forward job. The problem is that the loss function is on top
of the network which is a giant non linear function. We can't compute the minimum
right away from the data, network and loss function.

How do we do then ? The answer is gradient descent.

Gradient descent

Gradient descent is widely use to optimize function parameter. The basic idea is
to test how the error evolves when slightly modifying each parameter.

Analogy

The famous analogy is a blind folded walker in the mountain looking for the valley.

One possible strategy is to sense the slope by making tiny steps:

make a tiny step forward (X-axis) and sense if you're going uphill or downhill
(i.e. watch how you move on Z-axis). Go back to your position

make a tiny side step (Y-axis) and sense if you're going uphill or downhill
(i.e. watch how you move on Z-axis). Go back to your position

Thanks to this two steps, you know how the slope is oriented and you can make
a step in the correct direction, generally a mixed of X and Y

After several iterations you likely end in the valley, or at least in a local
valley.

The analogy points are:

the altitude (along Z-axis) is the error

your position (along X-axis and Y-axis) are the 2 parameters you want to
optimize to find the minimum error

the tiny steps to sense the slope is the gradient

Simple example

Let's formalize a bit this strategy with an example.
Imagine you have the following loss function:

\(L(w_1,w_2) = (w_1+2)^2+4(w_2-1)^2+3\)

To perform gradient descent, we need to compute the gradient of this loss function.
The gradient is just the set of partial derivative of the loss function for the
weight parameters.

\(
\nabla L(w_1,w_2) =
\begin{bmatrix}
\frac{\partial L(w_1,w_2)}{\partial w_1}
\\
\frac{\partial L(w_1,w_2)}{\partial w_2}
\end{bmatrix}\)

The partial derivatives allows us to evaluate the slope along each axis at any
given position. Our simple loss function is easy to derivate:

\(
\nabla L(w_1,w_2) =
\begin{bmatrix}
\frac{\partial L(w_1,w_2)}{\partial w_1}
\\
\frac{\partial L(w_1,w_2)}{\partial w_2}
\end{bmatrix}
=
\begin{bmatrix}
2w_1+4
\\
8w_2-8
\end{bmatrix}\)

Now that we can compute the slope we can run the algorithm:

evaluate the local gradient at the current position

update the position by making step proportional to the local gradient

go back to 1.

Let's do the first iteration:

we start at a random position \(w_1=-5, w_2=5\)

we evaluate the gradient at this position
\(
\nabla L(-5,5) =
\begin{bmatrix}
\frac{\partial L(-5,5)}{\partial -5}
\\
\frac{\partial L(-5,5)}{\partial 5}
\end{bmatrix}
=
\begin{bmatrix}
2\times-5+4
\\
8\times5-8
\end{bmatrix}
=
\begin{bmatrix}
-6
\\
32
\end{bmatrix}\)
which means that locally the error decreases a bit when \(w_1\) increases,
and the error increases a lot when \(w_2\) increases.
Therefore to go downhill we have to increase \(w_1\) and decrease \(w_2\)

Update current position to go downhill
\(
\begin{bmatrix}
w_1
\\
w_2
\end{bmatrix}
=
\begin{bmatrix}
w_1
\\
w_2
\end{bmatrix}
-
\lambda
\nabla L(w_1,w_2)
=
\begin{bmatrix}
-5+6\lambda
\\
5-32\lambda
\end{bmatrix}\)
where \(\lambda\) is a scalar parameter to control the size of your step

Here is graphically what happens for few iterations with \(\lambda=0.04\):

Figure 3. Gradient descent iterations for a simple function - The red dot, is the initial position. The arrows represents the evaluation of the current gradient (the slope on each axis). The surface is the loss function.

When to stop the algorithm? Generally for neural networks training,
you run it a fix number of times. It is one of your hyperparameter. In the same
time you monitor that your error behave correctly (i.e. decreases)

We presented the basic gradient descent algorithm. It has a disadvantage of being
very slow (you need a lot of iteration to find the best position). There are
clever way to update the position but they all rely on the local gradient
evaluation.

OK so to train a neural network, we need to compute the partial derivative of
the loss:

\(\frac{\partial L(f(X,W),\tilde{Y})}{\partial{W_i}}\)

The problem is that it's not straightforward as \(f()\) can be very complex.
We can't compute it by hand as we did with our little example. We could evaluate
numerically the gradient by running the network with tiny variation on each weight
at a time and monitor the error but it has drawbacks:

it is an approximation

you need to run the network (i.e. evaluate ) as many times as the number of
weights just for one gradient descent iteration which is impractical.

The solution is the backward propagation.

Backward propagation

So far we abstracted the neural network with the function \(Y = f(X,W)\).
Before introducing back propagation, let's see how this function looks like.

Neural networks, under the hood

A neural network is a composition of elementary functions called neurons.
The neuron transformation is quite basic. It combines the input and generate a
scalar output. There are several variants but here is a typical one:

\(Y = f_{neuron}(X,W,B) = \max(0,\sum\limits_{i=0}^{N}{(X_i \cdot W_i)}+B)\)

with \(Y \in \mathbb{R}\), \(X \in \mathbb{R}^N\), \(W \in \mathbb{R}^{N}\)
and \(B \in \mathbb{R}\)

This function simply computes a weighted sum of the input data,
adds a bias and saturates the result with \(\max()\). The \(\max()\) part
is called the activation function.
There are different possible activation functions.

The bias like the weights is a parameter that needs to be trained.
That's why \(B\) is often omitted and included in \(W\) and we simply write: \(Y = f_{neuron}(X,W)\)
with \(W \in \mathbb{R}^{N+1}\)

By chaining several layers of neurons, you obtain a neural network:

Figure 4. A neural network

Backward propagation is a recursive method to evaluate the gradient of
the loss function (i.e. \(\frac{\partial L(Y,\tilde{Y})}{\partial W_i}\))
by considering one simple neuron at a time.

Chain rule

Backward propagation relies on the chain rule.
The chain rule is a method to compute the derivative of the composition of
two functions.

Consider two functions \(y_f=f(x_f)\), \(y_g=g(x_g)\) and compose them
to form a third one:

\(y=h(x)=g(f(x))\)

Figure 5. Composition of two functions

Chain rule states:

\(\frac{df}{dx}(a) = \frac{dg}{df}(f(a)) \cdot \frac{df}{dx}(a)\)

In other word, to derivate a composition of function we simply multiply the
derivative of the underlying functions where they are individually evaluated.

Let's see with an example:

\(f(x)=3x+1\)

\(g(f)=f^2\)

\(h(x)=g(f(x))=(3x+1)^2=9x^2+6x+1\)

By evaluating the derivative of \(h\) on point \(a\) directly we find:

\(\frac{dh}{dx}(a) = 18a+6\)

With the chain rule method we find:

\(\frac{dg}{df}=2f\), \(\frac{df}{dx}=3\)

so,

\(\frac{dg}{df}(f(a))=2f(a)=2(3a+1)\), \(\frac{df}{dx}(a)=3\)

putting all together,

\(\frac{dh}{dx}(a)=\frac{dg}{df}(f(a)) \cdot \frac{df}{dx}(a) = (6a+2) \cdot 3 = 18a+6\)
as expected

From \(f\) point of view, it means that to compute the derivative regarding \(x\)
for a particular value \(a\), we need:

\(\frac{df}{dx}(a)\), the local derivative

\(\frac{dg}{df}(f(a))\) which is the evaluation of the local derivative of
the next « block » i.e. the \(g\) function

Chain rule applied to a network

The idea of back propagation is to apply chain rule on the loss function
\(L(Y,\tilde{Y})\).
For each function of the network (neuron, loss) we will evaluate the gradient of
the output regarding the input that are influenced by the weights of the networks.

Gradient propagation in the loss function

We start by evaluating the gradient of the error on the loss function.
The loss function depends on two variable:

the network output \(Y\) which obviously depends on the weights \(W\).
The gradient \(G_Y\) must be evaluated

the expected output \(\tilde{Y}\) from the training data which does not depend
on the weight. There is no need to compute \(G_{\tilde{Y}}\)

For the loss function we introduced earlier we have:

\(G_{Y_i} = \frac{\partial L(Y,\tilde{Y})}{\partial Y_i}
= \frac{\partial \sum{(Y_i-\tilde{Y_i})^2} }{\partial Y_i}
= 2(Y_i - \tilde{Y}_i)\)

Once the gradient has been evaluated in the loss function, it can flows in the
neurons. We transmit \(G_Y\) to the last neurons of the network which are placed
right before the loss function.
These last neuron will also compute gradient and transmit it to their ancestors
and so on until we reach the first neurons of the network.

Gradient propagation in a neuron

Let’s focus on one neuron and assume we receive the gradient \(G_Y\) from the
next neurons (i.e. all the neurons that use our output as input) or from the loss
function when we are one of the last neurons.

Thanks to the chain rule we compute the following gradients:

the weight gradient \(G_{W_i} = G_Y \cdot \frac{\partial F_{neuron}(X,W)}{\partial W_i}\)
senses the influence of the neuron’s weights on the final error. \(G_{W_i}\)
will be used to update the current neuron weights

the bias gradient \(G_{B} = G_Y \cdot \frac{\partial F_{neuron}(X,W)}{\partial B}\)
for the same reason. \(G_{B}\) will be used to update the current neuron bias

the input gradient \(G_{X_i} = G_Y \cdot \frac{\partial F_{neuron}(X,W)}{\partial X_i}\)
senses the influence of the current neuron input on the final error. \(G_{X_i}\)
will tell to the previous neuron how it should modify its output so that our
output help to decrease the error.

Figure 6. Gradient flow inside a neuron

With the neuron definition we have seen, we obtain:

\({F_{neuron}(X,W,B) = \max(0,\sum\limits_{i=0}^{N}{(X_i \cdot W_i)}+B)} = Y\)

\(G_{W_i} = G_Y \cdot \frac{\partial F_{neuron}(X,W,B)}{\partial W_i}
=G_Y \cdot
\Big\{
\begin{matrix}
X_i & Y>0 \\
0 & Y \leqslant 0
\end{matrix}\)

\(G_{B} = G_Y \cdot \frac{\partial F_{neuron}(X,W,B)}{\partial W_B}
=G_Y \cdot
\Big\{
\begin{matrix}
1 & Y>0 \\
0 & Y \leqslant 0
\end{matrix}\)

\(G_{X_i} = G_Y \cdot \frac{\partial F_{neuron}(X,W,B)}{\partial W_i}
=G_Y \cdot
\Big\{
\begin{matrix}
W_i & Y>0 \\
0 & Y \leqslant 0
\end{matrix}\)

\(G_{X_i}\) are transmitted to previous neurons while \(G_{W_i}\) and
\(G_{B}\) are used by the gradient descent algorithm to update parameters
\(W\) and \(B\) for the current neuron.

Most of the time a neuron output is linked to multiple neurons.
Therefore during back propagation a neuron receive several \(G_{Y_i}\) gradients.
The gradient used for back propagation is simply the sum of all the incoming
gradients \(G_Y = \sum{G_{Y_i}}\) (see https://en.wikipedia.org/wiki/Chain_rule#Higher_dimensions).

Training process overview

We have all the tools required to train a network. Let’s summarize:

we set up a network by connecting multiple neurons

we prepare training data: input \(X\) and ground truth associated output
\(Y\)

we choose a loss function and add it at the end of the network

we pick up an example and run it through the network and the loss function
(forward propagation)

we compute gradient from the loss function to the first neurons of the network
(backward propagation)

thanks to the weight and bias gradients, we make a tiny update of the neuron’s
weights and bias (gradient descent)

we go back to 4 and loop for many iterations.

]]></description><link>https://elinep.github.io/blog/2017/06/12/neural_networks_training_basics.html</link><guid isPermaLink="true">https://elinep.github.io/blog/2017/06/12/neural_networks_training_basics.html</guid><category><![CDATA[Blog]]></category><category><![CDATA[Neural network]]></category><pubDate>Mon, 12 Jun 2017 00:00:00 GMT</pubDate></item></channel></rss>


text:
{% extends 'layout.html' %}
{% import 'forms.html' as forms %}

{% block body %}
  <form class="form-horizontal" role="form" method="POST">
    {{ form.hidden_tag() }}
    {{ forms.text_field(form.mushroom) }}
    {{ forms.text_field(form.latitude, classes="latitude") }}
    {{ forms.text_field(form.longitude, classes="longitude") }}
    {{ forms.text_field(form.date) }}
    {{ forms.text_field(form.quantity) }}
    {{ forms.submit_button('Submit find') }}
  </form>
{% endblock %}


text:
<!doctype html>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

        <title>Restooking - It's restaurants and booking.</title>
        <meta name="description" content="">
        <meta name="author" content="Ivana Djunisijevic">

        <link rel="stylesheet" href="<?php echo base_url(); ?>css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/isotope.css" media="screen" />
        <link rel="stylesheet" href="<?php echo base_url(); ?>js/fancybox/jquery.fancybox.css" type="text/css" media="screen" />
        <link href="<?php echo base_url(); ?>css/animate.css" rel="stylesheet" media="screen">
        <link href="<?php echo base_url(); ?>flexslider/flexslider.css" rel="stylesheet" />
        <link href="<?php echo base_url(); ?>js/owl-carousel/owl.carousel.css" rel="stylesheet">
        <link rel="stylesheet" href="<?php echo base_url(); ?>css/styles.css" />

        <link href="<?php echo base_url(); ?>font/css/font-awesome.min.css" rel="stylesheet">

                        <button type="button" id="nav-toggle" class="navbar-toggle" data-toggle="collapse" data-target="#main-nav"> Toggle navigation    </button>
                        Restooking

<a href="<?php echo base_url() . 'index.php/OznacavanjeStolaZauzetimCtrl'; ?>" class="">Zauzmi sto

<a href="<?php echo base_url() . 'index.php/PotvrdaIzvrseneRezervacijeCtrl'; ?>" class="">Potvrdi rezervaciju

<a href="<?php echo base_url() . 'index.php/EditovanjeNalogaCtrl/profileWaiter'; ?>" class="scroll-link">Moj profil

<a href="<?php echo base_url() . 'index.php/EditovanjeNalogaCtrl'; ?>" class="scroll-link">Izmeni profil

<a href="<?php echo base_url() . 'index.php/LogoutCtrl'; ?>" class="scroll-link">Izloguj se

                            <img src="<?php echo base_url(); ?>images/slides/1.jpg" alt="Chania">

                            <img src="<?php echo base_url(); ?>images/slides/2.jpg" alt="Chania">

                            <img src="<?php echo base_url(); ?>images/slides/3.jpg" alt="Flower">

                        <form action="<?php echo(base_url()); ?>index.php/EditovanjeNalogaCtrl/confirm" method="POST" role="form">

                                <legend>Izmena naloga</legend>
                                <?php echo form_error('username'); ?>
                                Korisničko ime
                                <input type="text" class="form-control"    name="username" placeholder="Unesite vase korisničko ime ovde" value = "<?php print $user['KIme'] ?>" disabled="">
                                <?php echo form_error('password'); ?>
                                Lozinka
                                <input type="password" class="form-control" name="password" placeholder="Unesite lozinku" value = "<?php print $user['Lozinka']; ?>">
                                <?php echo form_error('name'); ?>
                                Ime
                                <input type="text" class="form-control" name="name" placeholder="Unesite Vaše ime ovde" value = "<?php print $user['Ime']; ?>">
                                <?php echo form_error('lastname'); ?>
                                Prezime
                                <input type="text" class="form-control" name="lastname" placeholder="Unesite Vaše prezime ovde" value = "<?php print $user['Prezime']; ?>">
                                <?php echo form_error('email'); ?>
                                Email
                                <input type="text" class="form-control" name="email" placeholder="Unesite vas email ovde" value = "<?php print $user['Email']; ?>">

                                <button type="submit" class="btn btn-primary">Potvrdi</button>

                        </form>

 Copyright 2016 ETF Belgrade


text:
import React from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';

import { bem, mix } from 'app/libs/bem';

const b = bem('Button');

function Button(props) {
    const {
        className,
        before,
        after,
        children,
        type,
        theme,
        size,
        disabled,
        ...restProps
    } = props;

    return (
        <button
            {...restProps}
            className={mix(b({ before: Boolean(before), after: Boolean(after), size, theme }), className)}
            type={type}
            disabled={disabled}
        >
            {before && {before}}
            {children && {children}}
            {after && {after}}
        </button>
    );
}

Button.propTypes = {
    className: PropTypes.string,
    before: PropTypes.node,
    after: PropTypes.node,
    type: PropTypes.oneOf(['button', 'submit', 'reset']),
    theme: PropTypes.string,
    size: PropTypes.string,
    disabled: PropTypes.bool
};

Button.defaultProps = {
    type: 'button',
    theme: 'default',
    size: 'm',
    disabled: false
};

export default observer(Button);


text:
/**
@module ember
@submodule ember-runtime
*/

var get = Ember.get,
    set = Ember.set,
    slice = Array.prototype.slice,
    getProperties = Ember.getProperties;

/**
  ## Overview

  This mixin provides properties and property observing functionality, core
  features of the Ember object model.

  Properties and observers allow one object to observe changes to a
  property on another object. This is one of the fundamental ways that
  models, controllers and views communicate with each other in an Ember
  application.

  Any object that has this mixin applied can be used in observer
  operations. That includes `Ember.Object` and most objects you will
  interact with as you write your Ember application.

  Note that you will not generally apply this mixin to classes yourself,
  but you will use the features provided by this module frequently, so it
  is important to understand how to use it.

  ## Using `get()` and `set()`

  Because of Ember's support for bindings and observers, you will always
  access properties using the get method, and set properties using the
  set method. This allows the observing objects to be notified and
  computed properties to be handled properly.

  More documentation about `get` and `set` are below.

  ## Observing Property Changes

  You typically observe property changes simply by adding the `observes`
  call to the end of your method declarations in classes that you write.
  For example:

  ```javascript
  Ember.Object.extend({
    valueObserver: function() {
      // Executes whenever the "value" property changes
    }.observes('value')
  });
  ```

  Although this is the most common way to add an observer, this capability
  is actually built into the `Ember.Object` class on top of two methods
  defined in this mixin: `addObserver` and `removeObserver`. You can use
  these two methods to add and remove observers yourself if you need to
  do so at runtime.

  To add an observer for a property, call:

  ```javascript
  object.addObserver('propertyKey', targetObject, targetAction)
  ```

  This will call the `targetAction` method on the `targetObject` whenever
  the value of the `propertyKey` changes.

  Note that if `propertyKey` is a computed property, the observer will be
  called when any of the property dependencies are changed, even if the
  resulting value of the computed property is unchanged. This is necessary
  because computed properties are not computed until `get` is called.

  @class Observable
  @namespace Ember
*/
Ember.Observable = Ember.Mixin.create({

  /**
    Retrieves the value of a property from the object.

    This method is usually similar to using `object[keyName]` or `object.keyName`,
    however it supports both computed properties and the unknownProperty
    handler.

    Because `get` unifies the syntax for accessing all these kinds
    of properties, it can make many refactorings easier, such as replacing a
    simple property with a computed property, or vice versa.

    ### Computed Properties

    Computed properties are methods defined with the `property` modifier
    declared at the end, such as:

    ```javascript
    fullName: function() {
      return this.get('firstName') + ' ' + this.get('lastName');
    }.property('firstName', 'lastName')
    ```

    When you call `get` on a computed property, the function will be
    called and the return value will be returned instead of the function
    itself.

    ### Unknown Properties

    Likewise, if you try to call `get` on a property whose value is
    `undefined`, the `unknownProperty()` method will be called on the object.
    If this method returns any value other than `undefined`, it will be returned
    instead. This allows you to implement "virtual" properties that are
    not defined upfront.

    @method get
    @param {String} keyName The property to retrieve
    @return {Object} The property value or undefined.
  */
  get: function(keyName) {
    return get(this, keyName);
  },

  /**
    To get multiple properties at once, call `getProperties`
    with a list of strings or an array:

    ```javascript
    record.getProperties('firstName', 'lastName', 'zipCode');  // { firstName: 'John', lastName: 'Doe', zipCode: '10011' }
    ```

    is equivalent to:

    ```javascript
    record.getProperties(['firstName', 'lastName', 'zipCode']);  // { firstName: 'John', lastName: 'Doe', zipCode: '10011' }
    ```

    @method getProperties
    @param {String...|Array} list of keys to get
    @return {Hash}
  */
  getProperties: function() {
    return getProperties.apply(null, [this].concat(slice.call(arguments)));
  },

  /**
    Sets the provided key or path to the value.

    This method is generally very similar to calling `object[key] = value` or
    `object.key = value`, except that it provides support for computed
    properties, the `setUnknownProperty()` method and property observers.

    ### Computed Properties

    If you try to set a value on a key that has a computed property handler
    defined (see the `get()` method for an example), then `set()` will call
    that method, passing both the value and key instead of simply changing
    the value itself. This is useful for those times when you need to
    implement a property that is composed of one or more member
    properties.

    ### Unknown Properties

    If you try to set a value on a key that is undefined in the target
    object, then the `setUnknownProperty()` handler will be called instead. This
    gives you an opportunity to implement complex "virtual" properties that
    are not predefined on the object. If `setUnknownProperty()` returns
    undefined, then `set()` will simply set the value on the object.

    ### Property Observers

    In addition to changing the property, `set()` will also register a property
    change with the object. Unless you have placed this call inside of a
    `beginPropertyChanges()` and `endPropertyChanges(),` any "local" observers
    (i.e. observer methods declared on the same object), will be called
    immediately. Any "remote" observers (i.e. observer methods declared on
    another object) will be placed in a queue and called at a later time in a
    coalesced manner.

    ### Chaining

    In addition to property changes, `set()` returns the value of the object
    itself so you can do chaining like this:

    ```javascript
    record.set('firstName', 'Charles').set('lastName', 'Jolley');
    ```

    @method set
    @param {String} keyName The property to set
    @param {Object} value The value to set or `null`.
    @return {Ember.Observable}
  */
  set: function(keyName, value) {
    set(this, keyName, value);
    return this;
  },

  /**
    Sets a list of properties at once. These properties are set inside
    a single `beginPropertyChanges` and `endPropertyChanges` batch, so
    observers will be buffered.

    ```javascript
    record.setProperties({ firstName: 'Charles', lastName: 'Jolley' });
    ```

    @method setProperties
    @param {Hash} hash the hash of keys and values to set
    @return {Ember.Observable}
  */
  setProperties: function(hash) {
    return Ember.setProperties(this, hash);
  },

  /**
    Begins a grouping of property changes.

    You can use this method to group property changes so that notifications
    will not be sent until the changes are finished. If you plan to make a
    large number of changes to an object at one time, you should call this
    method at the beginning of the changes to begin deferring change
    notifications. When you are done making changes, call
    `endPropertyChanges()` to deliver the deferred change notifications and end
    deferring.

    @method beginPropertyChanges
    @return {Ember.Observable}
  */
  beginPropertyChanges: function() {
    Ember.beginPropertyChanges();
    return this;
  },

  /**
    Ends a grouping of property changes.

    You can use this method to group property changes so that notifications
    will not be sent until the changes are finished. If you plan to make a
    large number of changes to an object at one time, you should call
    `beginPropertyChanges()` at the beginning of the changes to defer change
    notifications. When you are done making changes, call this method to
    deliver the deferred change notifications and end deferring.

    @method endPropertyChanges
    @return {Ember.Observable}
  */
  endPropertyChanges: function() {
    Ember.endPropertyChanges();
    return this;
  },

  /**
    Notify the observer system that a property is about to change.

    Sometimes you need to change a value directly or indirectly without
    actually calling `get()` or `set()` on it. In this case, you can use this
    method and `propertyDidChange()` instead. Calling these two methods
    together will notify all observers that the property has potentially
    changed value.

    Note that you must always call `propertyWillChange` and `propertyDidChange`
    as a pair. If you do not, it may get the property change groups out of
    order and cause notifications to be delivered more often than you would
    like.

    @method propertyWillChange
    @param {String} keyName The property key that is about to change.
    @return {Ember.Observable}
  */
  propertyWillChange: function(keyName) {
    Ember.propertyWillChange(this, keyName);
    return this;
  },

  /**
    Notify the observer system that a property has just changed.

    Sometimes you need to change a value directly or indirectly without
    actually calling `get()` or `set()` on it. In this case, you can use this
    method and `propertyWillChange()` instead. Calling these two methods
    together will notify all observers that the property has potentially
    changed value.

    Note that you must always call `propertyWillChange` and `propertyDidChange`
    as a pair. If you do not, it may get the property change groups out of
    order and cause notifications to be delivered more often than you would
    like.

    @method propertyDidChange
    @param {String} keyName The property key that has just changed.
    @return {Ember.Observable}
  */
  propertyDidChange: function(keyName) {
    Ember.propertyDidChange(this, keyName);
    return this;
  },

  /**
    Convenience method to call `propertyWillChange` and `propertyDidChange` in
    succession.

    @method notifyPropertyChange
    @param {String} keyName The property key to be notified about.
    @return {Ember.Observable}
  */
  notifyPropertyChange: function(keyName) {
    this.propertyWillChange(keyName);
    this.propertyDidChange(keyName);
    return this;
  },

  addBeforeObserver: function(key, target, method) {
    Ember.addBeforeObserver(this, key, target, method);
  },

  /**
    Adds an observer on a property.

    This is the core method used to register an observer for a property.

    Once you call this method, any time the key's value is set, your observer
    will be notified. Note that the observers are triggered any time the
    value is set, regardless of whether it has actually changed. Your
    observer should be prepared to handle that.

    You can also pass an optional context parameter to this method. The
    context will be passed to your observer method whenever it is triggered.
    Note that if you add the same target/method pair on a key multiple times
    with different context parameters, your observer will only be called once
    with the last context you passed.

    ### Observer Methods

    Observer methods you pass should generally have the following signature if
    you do not pass a `context` parameter:

    ```javascript
    fooDidChange: function(sender, key, value, rev) { };
    ```

    The sender is the object that changed. The key is the property that
    changes. The value property is currently reserved and unused. The rev
    is the last property revision of the object when it changed, which you can
    use to detect if the key value has really changed or not.

    If you pass a `context` parameter, the context will be passed before the
    revision like so:

    ```javascript
    fooDidChange: function(sender, key, value, context, rev) { };
    ```

    Usually you will not need the value, context or revision parameters at
    the end. In this case, it is common to write observer methods that take
    only a sender and key value as parameters or, if you aren't interested in
    any of these values, to write an observer that has no parameters at all.

    @method addObserver
    @param {String} key The key to observer
    @param {Object} target The target object to invoke
    @param {String|Function} method The method to invoke.
    @return {Ember.Object} self
  */
  addObserver: function(key, target, method) {
    Ember.addObserver(this, key, target, method);
  },

  /**
    Remove an observer you have previously registered on this object. Pass
    the same key, target, and method you passed to `addObserver()` and your
    target will no longer receive notifications.

    @method removeObserver
    @param {String} key The key to observer
    @param {Object} target The target object to invoke
    @param {String|Function} method The method to invoke.
    @return {Ember.Observable} receiver
  */
  removeObserver: function(key, target, method) {
    Ember.removeObserver(this, key, target, method);
  },

  /**
    Returns `true` if the object currently has observers registered for a
    particular key. You can use this method to potentially defer performing
    an expensive action until someone begins observing a particular property
    on the object.

    @method hasObserverFor
    @param {String} key Key to check
    @return {Boolean}
  */
  hasObserverFor: function(key) {
    return Ember.hasListeners(this, key+':change');
  },

  /**
    Retrieves the value of a property, or a default value in the case that the
    property returns `undefined`.

    ```javascript
    person.getWithDefault('lastName', 'Doe');
    ```

    @method getWithDefault
    @param {String} keyName The name of the property to retrieve
    @param {Object} defaultValue The value to return if the property value is undefined
    @return {Object} The property value or the defaultValue.
  */
  getWithDefault: function(keyName, defaultValue) {
    return Ember.getWithDefault(this, keyName, defaultValue);
  },

  /**
    Set the value of a property to the current value plus some amount.

    ```javascript
    person.incrementProperty('age');
    team.incrementProperty('score', 2);
    ```

    @method incrementProperty
    @param {String} keyName The name of the property to increment
    @param {Number} increment The amount to increment by. Defaults to 1
    @return {Number} The new property value
  */
  incrementProperty: function(keyName, increment) {
    if (Ember.isNone(increment)) { increment = 1; }
    Ember.assert("Must pass a numeric value to incrementProperty", (!isNaN(parseFloat(increment)) && isFinite(increment)));
    set(this, keyName, (get(this, keyName) || 0) + increment);
    return get(this, keyName);
  },

  /**
    Set the value of a property to the current value minus some amount.

    ```javascript
    player.decrementProperty('lives');
    orc.decrementProperty('health', 5);
    ```

    @method decrementProperty
    @param {String} keyName The name of the property to decrement
    @param {Number} decrement The amount to decrement by. Defaults to 1
    @return {Number} The new property value
  */
  decrementProperty: function(keyName, decrement) {
    if (Ember.isNone(decrement)) { decrement = 1; }
    Ember.assert("Must pass a numeric value to decrementProperty", (!isNaN(parseFloat(decrement)) && isFinite(decrement)));
    set(this, keyName, (get(this, keyName) || 0) - decrement);
    return get(this, keyName);
  },

  /**
    Set the value of a boolean property to the opposite of it's
    current value.

    ```javascript
    starship.toggleProperty('warpDriveEngaged');
    ```

    @method toggleProperty
    @param {String} keyName The name of the property to toggle
    @return {Object} The new property value
  */
  toggleProperty: function(keyName) {
    set(this, keyName, !get(this, keyName));
    return get(this, keyName);
  },

  /**
    Returns the cached value of a computed property, if it exists.
    This allows you to inspect the value of a computed property
    without accidentally invoking it if it is intended to be
    generated lazily.

    @method cacheFor
    @param {String} keyName
    @return {Object} The cached value of the computed property, if any
  */
  cacheFor: function(keyName) {
    return Ember.cacheFor(this, keyName);
  },

  // intended for debugging purposes
  observersForKey: function(keyName) {
    return Ember.observersFor(this, keyName);
  }
});


text:
<!--
Custom macros can be found in raw file index.md in the src folder.
Some examples are C: "{\\bf{C}}" and Hom: "{\\operatorname{Hom}}"
-->
<!--
Simple commutative diagrams can be made using the AMScd package, but require the command "\require{AMScd}".
For example:
$$
\require{AMScd} \begin{CD}
A @>f>> B \\
@VgVV @VVhV \\
C @>>j> D \\
\end{CD}
$$
-->

Lecture notes for 25 February, 2015.  They could use some cleaning up and buffing up.

### What is a gerbe and where is $G$?

Let $S$ be a site and $X \rightarrow S$ a stack.  X is a gerbe if
- for all $s \in S$, there exists a covering $u \rightarrow s$ such that $X(u) \neq \emptyset$
- for all $s \in S$ and $x, y \in X(s)$, there exists a covering $u \rightarrow s$ such that $x|_{u} \cong y|_{u}$

Consequence: $F(s) = $ isomorphism classes in $X(s)$, $F^s = $ sheaf of singletons

Example: $BG$ stack of $G$-torsors

Question: Can we recover $G$ from BG?

Answer: Yes, but only if we think of $G$ as a *band* (lien).

### What is a band?

How would we try and recover $G$?

$BG(S)$ contains the trivial torsor $G \times S \rightarrow S$ for which $\operatorname{Aut} \cong G^{op}$.

Naïve idea: Recover $G$ in general by searching for objects $x_i \in X(s_i)$ and glue.

Issue: Gluing can have an inner automorphism obstruction.

Upshot: We can associate to any gerbe $X$ a band that is locally made of groups, but inner automorphismims have to be decreed to equal the identity.

The stack of bands on $S$:
- start with stack of groups on $S$: $\operatorname{Grp}_S$
- make new fiber category $PB(S)$
  - objects: groups
  - $\operatorname{Hom}(G,H) = \operatorname{Inn}(H)\backslash\operatorname{Isom}(G,H)/\operatorname{Inn}(G)$
- bands: stackification of $PB$.

There is a map of stacks: $\operatorname{Grp}_S \rightarrow \operatorname{Band}_S$.  This map is not essentially surjective.

Better: The composition $\operatorname{Ab}_S \subseteq \operatorname{Grp}_S \rightarrow \operatorname{Band}_S$ is fully faithful.

Any gerbe $X$ has a canonically associated band: $\exists ! B \in \operatorname{Band}(S)$ and isomorphism $B_{X} \overset{\sim}{\rightarrow}\operatorname{band}(I)$.  Here, $I$ denotes the inertia stack and $B_X = \pi^{-1}B$, where $\pi: X \rightarrow S$.

Given $G \in \operatorname{Grp}$, any inner form of $G$ is canonically isomorphic to $G$ in $\operatorname{Band}_S$.

Inner form examples:
Let $A$ be an Azumaya algebra and let $A^\times$ denote the functor of units: $A^{\times}(T) = \Gamma(T, A_T)^{\times}$.
- $A^\times$ is an inner form of $\operatorname{GL}_n$
- $A_1^\times = \ker(\operatorname{Nrd}:A^\times \rightarrow \bf{G}_m)$ is an inner form of $\operatorname{SL}_n$

Subexample: Let $X$ be a proper, smooth, geometrically connected variety over $k$.  Let $V$ on $X$ be a geometrically simple vector bundle, e.g. a geometrically stable vector bundle:
$\operatorname{Hom}_{{\scr{O}}_X}(V, V) = k$, $A = \operatorname{End}(V,V)$, $A^\times(X) = k^\times$.

###Quasi-coherent sheaves

Quasi-coherent sheaves on the fppf site of a scheme $X$: $(T \overset{f}{\rightarrow} X) \mapsto \Gamma(T, f^*F)$, ${\scr{F}} \in \operatorname{QCoh}(X_{zar})$.

Warning: $\operatorname{QCoh} \rightarrow {\scr{O}}_X-\operatorname{Mod}$ is not exact in the big sites!

Let $X$ be a stack on $S_{fppf}$.  A sheaf $F$ on $X$ is quasi-coherent if for all $T \overset{f}{\rightarrow} X$ (equivalently, for all $f \in X(T)$), $f^{-1}F \in {\scr{O}}_{T_{fppf}}-\operatorname{Mod}$ is quasi-coherent.  Here
$$
\begin{array}{rccc}
f^{-1}F : &  \operatorname{Sch}_T & \rightarrow & \underline{\operatorname{Set}} \\
& U \underset{g}{\rightarrow} T & \mapsto & F(fg) \\
\end{array}
$$

Confusing point: If $U \overset{f}{\rightarrow} T$ and $F \in \operatorname{QCoh}(T_{fppf})$, then
$$
f^{-1}F = f^{*}F
$$
Here, $f^{-1}F$ denotes the restriction in $T_{fppf}$ while $f^*F$ denotes the Zariski pullback.

Look for "Cartesian sheaves" in Laumon & Morret-Bailly (*Champs Algébriques* (?)), Stacks Project, or elsewhere.

Example: $G$ a finite group over $\bf{C}$.  What is $\operatorname{QCoh}(BG)$?

First thought:
$$
\begin{array}{ccc}
\operatorname{Spec}{\bf{C}} & \rightarrow &  BG \\
\\
V & --- & F \\
\mathrm{vector \; space}
\end{array}
$$


text:
package org.apache.hyracks.tests.integration;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

import org.apache.hyracks.api.client.HyracksConnection;
import org.apache.hyracks.api.client.IHyracksClientConnection;
import org.apache.hyracks.api.comm.IFrameTupleAccessor;
import org.apache.hyracks.api.comm.VSizeFrame;
import org.apache.hyracks.api.dataset.IHyracksDataset;
import org.apache.hyracks.api.dataset.IHyracksDatasetReader;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.job.JobFlag;
import org.apache.hyracks.api.job.JobId;
import org.apache.hyracks.api.job.JobSpecification;
import org.apache.hyracks.client.dataset.HyracksDataset;
import org.apache.hyracks.control.cc.ClusterControllerService;
import org.apache.hyracks.control.common.controllers.CCConfig;
import org.apache.hyracks.control.common.controllers.NCConfig;
import org.apache.hyracks.control.nc.NodeControllerService;
import org.apache.hyracks.control.nc.resources.memory.FrameManager;
import org.apache.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor;
import org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream;

public abstract class AbstractMultiNCIntegrationTest {

    private static final Logger LOGGER = Logger.getLogger(AbstractMultiNCIntegrationTest.class.getName());

    public static final String[] ASTERIX_IDS = { "asterix-001", "asterix-002", "asterix-003", "asterix-004",
            "asterix-005", "asterix-006", "asterix-007" };

    private static ClusterControllerService cc;

    private static NodeControllerService[] asterixNCs;

    private static IHyracksClientConnection hcc;

    private final List<File> outputFiles;

    @Rule
    public TemporaryFolder outputFolder = new TemporaryFolder();

    public AbstractMultiNCIntegrationTest() {
        outputFiles = new ArrayList<File>();
        ;
    }

    @BeforeClass
    public static void init() throws Exception {
        CCConfig ccConfig = new CCConfig();
        ccConfig.clientNetIpAddress = "127.0.0.1";
        ccConfig.clientNetPort = 39000;
        ccConfig.clusterNetIpAddress = "127.0.0.1";
        ccConfig.clusterNetPort = 39001;
        ccConfig.profileDumpPeriod = 10000;
        File outDir = new File("target" + File.separator + "ClusterController");
        outDir.mkdirs();
        File ccRoot = File.createTempFile(AbstractMultiNCIntegrationTest.class.getName(), ".data", outDir);
        ccRoot.delete();
        ccRoot.mkdir();
        ccConfig.ccRoot = ccRoot.getAbsolutePath();
        cc = new ClusterControllerService(ccConfig);
        cc.start();

        asterixNCs = new NodeControllerService[ASTERIX_IDS.length];
        for (int i = 0; i < ASTERIX_IDS.length; i++) {
            NCConfig ncConfig = new NCConfig();
            ncConfig.ccHost = "localhost";
            ncConfig.ccPort = 39001;
            ncConfig.clusterNetIPAddress = "127.0.0.1";
            ncConfig.dataIPAddress = "127.0.0.1";
            ncConfig.resultIPAddress = "127.0.0.1";
            ncConfig.nodeId = ASTERIX_IDS[i];
            asterixNCs[i] = new NodeControllerService(ncConfig);
            asterixNCs[i].start();
        }

        hcc = new HyracksConnection(ccConfig.clientNetIpAddress, ccConfig.clientNetPort);
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Starting CC in " + ccRoot.getAbsolutePath());
        }
    }

    @AfterClass
    public static void deinit() throws Exception {
        for (NodeControllerService nc : asterixNCs) {
            nc.stop();
        }
        cc.stop();
    }

    protected void runTest(JobSpecification spec) throws Exception {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info(spec.toJSON().toString(2));
        }
        JobId jobId = hcc.startJob(spec, EnumSet.of(JobFlag.PROFILE_RUNTIME));
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info(jobId.toString());
        }

        int nReaders = 1;

        FrameManager resultDisplayFrameMgr = new FrameManager(spec.getFrameSize());
        VSizeFrame resultFrame = new VSizeFrame(resultDisplayFrameMgr);

        IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor();

        IHyracksDataset hyracksDataset = new HyracksDataset(hcc, spec.getFrameSize(), nReaders);
        IHyracksDatasetReader reader = hyracksDataset.createReader(jobId, spec.getResultSetIds().get(0));

        JSONArray resultRecords = new JSONArray();
        ByteBufferInputStream bbis = new ByteBufferInputStream();

        int readSize = reader.read(resultFrame);

        while (readSize > 0) {

            try {
                frameTupleAccessor.reset(resultFrame.getBuffer());
                for (int tIndex = 0; tIndex < frameTupleAccessor.getTupleCount(); tIndex++) {
                    int start = frameTupleAccessor.getTupleStartOffset(tIndex);
                    int length = frameTupleAccessor.getTupleEndOffset(tIndex) - start;
                    bbis.setByteBuffer(resultFrame.getBuffer(), start);
                    byte[] recordBytes = new byte[length];
                    bbis.read(recordBytes, 0, length);
                    resultRecords.put(new String(recordBytes, 0, length));
                }
            } finally {
                try {
                    bbis.close();
                } catch (IOException e) {
                    throw new HyracksDataException(e);
                }
            }

            readSize = reader.read(resultFrame);
        }

        hcc.waitForCompletion(jobId);
        dumpOutputFiles();
    }

    private void dumpOutputFiles() {
        if (LOGGER.isLoggable(Level.INFO)) {
            for (File f : outputFiles) {
                if (f.exists() && f.isFile()) {
                    try {
                        LOGGER.info("Reading file: " + f.getAbsolutePath() + " in test: " + getClass().getName());
                        String data = FileUtils.readFileToString(f);
                        LOGGER.info(data);
                    } catch (IOException e) {
                        LOGGER.info("Error reading file: " + f.getAbsolutePath());
                        LOGGER.info(e.getMessage());
                    }
                }
            }
        }
    }

    protected File createTempFile() throws IOException {
        File tempFile = File.createTempFile(getClass().getName(), ".tmp", outputFolder.getRoot());
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Output file: " + tempFile.getAbsolutePath());
        }
        outputFiles.add(tempFile);
        return tempFile;
    }

}


text:
import mdsclient
from plugins.contracts import ICartridgeAgentPlugin
import time
import zipfile
import subprocess
from modules.util.log import LogFactory

class TomcatWSO2ISMetadataPublisher(ICartridgeAgentPlugin):

    def run_plugin(self, values):
        log = LogFactory().get_log(__name__)

        log.info("Starting tomcat metadata publisher...")
        # publish callback and issuer id from tomcat for IS to pickup
        publish_data = mdsclient.MDSPutRequest()
        # hostname_entry = {"key": "TOMCAT_HOSTNAME", "values": member_hostname}
        cluster_hostname = values["HOST_NAME"]

        log.info("Reading port mappings...")
        port_mappings_str = values["PORT_MAPPINGS"]
        tomcat_http_port = None

        # port mappings format: """NAME:mgt-console|PROTOCOL:https|PORT:4500|PROXY_PORT:8443;
        #                          NAME:tomcat-http|PROTOCOL:http|PORT:4501|PROXY_PORT:7280;"""

        log.info("Port mappings: %s" % port_mappings_str)
        if port_mappings_str is not None:

            port_mappings_array = port_mappings_str.split(";")
            if port_mappings_array:

                for port_mapping in port_mappings_array:
                    log.debug("port_mapping: %s" % port_mapping)
                    name_value_array = port_mapping.split("|")
                    name = name_value_array[0].split(":")[1]
                    protocol = name_value_array[1].split(":")[1]
                    port = name_value_array[2].split(":")[1]
                    if name == "tomcat-http" and protocol == "http":
                        tomcat_http_port = port

        log.info("Kubernetes service port of tomcat http transport: %s" % tomcat_http_port)

        callback_url = "http://%s:%s/travelocity.com/home.jsp" % (cluster_hostname, tomcat_http_port)

        callback_url_property = {"key": "CALLBACK_URL", "values": [ callback_url ]}
        mdsclient.put(callback_url_property, app=True)
        log.info("Published property to metadata API: CALLBACK_URL: %s" % callback_url)

        issuer_property = {"key": "SSO_ISSUER", "values": [ "travelocity.com" ]}
        mdsclient.put(issuer_property, app=True)
        log.info("Published property to metadata API: SSO_ISSUER: travelocity.com")

        log.info("Tomcat metadata publisher completed")


text:
#include "main.h"
#include "note.h"
#include "beat.h"
#include "event.h"

#define EOF_MAX_UNDO 100
#define EOF_UNDO_TYPE_NONE         0
#define EOF_UNDO_TYPE_NOTE_LENGTH  1
#define EOF_UNDO_TYPE_NOTE_SEL     2	//Perform a generic undo state and deselect all notes
#define EOF_UNDO_TYPE_LYRIC_NOTE   3
#define EOF_UNDO_TYPE_RECORD       4
#define EOF_UNDO_TYPE_SILENCE      5
#define EOF_UNDO_TYPE_TEMPO_ADJUST 6

extern int eof_undo_count;
extern int eof_redo_count;
extern int eof_undo_last_type;
extern char * eof_undo_filename[EOF_MAX_UNDO];
extern int eof_undo_states_initialized;

void eof_undo_reset(void);	//Clears all undo states
int eof_undo_add(int type);	//Adds another undo state, except some cases where the requested undo type is the same as the previous undo (ie. a note addition/deletion)
int eof_undo_apply(void);	//Saves the redo state and applies the next available undo state
void eof_redo_apply(void);	//Applies the redo state
int eof_undo_load_state(const char * fn);	//Applies the specified undo/redo state, or returns 0 upon error (called by eof_undo_apply() and eof_redo_apply())
void eof_destroy_undo(void);	//Frees the memory for all of the filenames in eof_undo_filename[]

#endif