Documentation
¶
Index ¶
- Constants
- Variables
- func AbbadingoDataset(dfa DFA, sparsityPercentage float64, testingRatio float64) (Dataset, Dataset)
- func AbbadingoDatasetExact(dfa DFA, trainingSetSize int, testingSetSize int) (Dataset, Dataset)
- func AbbadingoInstance(numberOfStates int, exact bool, sparsityPercentage float64, ...) (DFA, Dataset, Dataset)
- func AbbadingoInstanceExact(numberOfStates int, exact bool, trainingSetSize int, testingSetSize int) (DFA, Dataset, Dataset)
- func BlueFringeEDSM(APTA DFA) (DFA, MergeData)
- func BlueFringeEDSMFromDataset(dataset Dataset) (DFA, MergeData)
- func BlueFringeSearchUsingScoringFunction(statePartition StatePartition, scoringFunction ScoringFunction) (StatePartition, MergeData)
- func DefaultStaminaDataset(dfa DFA, sparsityPercentage float64) (Dataset, Dataset)
- func DefaultStaminaInstance(alphabetSize, targetDFASize int, sparsityPercentage float64) (DFA, Dataset, Dataset)
- func ExhaustiveEDSM(APTA DFA) (DFA, MergeData)
- func ExhaustiveEDSMFromDataset(dataset Dataset) (DFA, MergeData)
- func ExhaustiveSearchUsingScoringFunction(statePartition StatePartition, scoringFunction ScoringFunction) (StatePartition, MergeData)
- func GRBM(statePartition StatePartition) (StatePartition, MergeData)
- func GeneralizedRedBlueMerging(APTA DFA) (DFA, MergeData)
- func GeneralizedRedBlueMergingFromDataset(dataset Dataset) (DFA, MergeData)
- func GenerateBlueSetFromRedSetWithShuffle(statePartition *StatePartition, redSet map[int]util.Void) []int
- func GenerateOrderedBlueSetFromRedSet(statePartition *StatePartition, redSet map[int]util.Void) []int
- func RPNI(APTA DFA) (DFA, MergeData)
- func RPNIFromDataset(dataset Dataset) (DFA, MergeData)
- func RPNISearch(statePartition StatePartition) (StatePartition, MergeData)
- func StaminaDataset(dfa DFA, sparsityPercentage float64, ...) (Dataset, Dataset)
- func StaminaInstance(alphabetSize, targetDFASize int, sparsityPercentage float64, ...) (DFA, Dataset, Dataset)
- func UpdateOrderedRedBlueSets(statePartition *StatePartition, redStates []int) ([]int, []int)
- func UpdateRedBlueSets(statePartition *StatePartition, redStates *[]int) []int
- func UpdateRedBlueSetsWithShuffle(statePartition *StatePartition, redStates *[]int) []int
- func UpdateWindow(window []int, statePartition StatePartition) []int
- func WindowedEDSM(APTA DFA, windowSize int, windowGrow float64) (DFA, MergeData)
- func WindowedEDSMFromDataset(dataset Dataset, windowSize int, windowGrow float64) (DFA, MergeData)
- func WindowedSearchUsingScoringFunction(statePartition StatePartition, windowSize int, windowGrow float64, ...) (StatePartition, MergeData)
- type Block
- type DFA
- func (dfa DFA) AcceptingStates() []int
- func (dfa DFA) AcceptingStatesCount() int
- func (dfa DFA) Accuracy(dataset Dataset) float64
- func (dfa *DFA) AddSinkState() int
- func (dfa *DFA) AddState(stateLabel StateLabel) int
- func (dfa *DFA) AddSymbol()
- func (dfa *DFA) AddTransition(symbol int, fromStateID int, toStateID int)
- func (dfa DFA) AllStates() []int
- func (dfa *DFA) CalculateDepthAndOrder()
- func (dfa *DFA) ChangeRejectingStatesToUnlabelled()
- func (dfa DFA) Clone() DFA
- func (dfa *DFA) Depth() int
- func (dfa DFA) Describe(detail bool)
- func (dfa DFA) Equal(dfa2 DFA) bool
- func (dfa *DFA) IndistinguishableStatePairs() []StateIDPair
- func (dfa DFA) IsComplete() bool
- func (dfa DFA) IsTree() bool
- func (dfa DFA) IsValidPanic()
- func (dfa DFA) IsValidSafe() bool
- func (dfa DFA) LabelledStates() []int
- func (dfa DFA) LabelledStatesCount() int
- func (dfa DFA) LeavesCount() int
- func (dfa DFA) LoopsCount() int
- func (dfa DFA) Minimise() DFA
- func (dfa *DFA) OrderedStates() []int
- func (dfa DFA) RejectingStates() []int
- func (dfa DFA) RejectingStatesCount() int
- func (dfa *DFA) RemoveNonAcceptingLeaves()
- func (dfa *DFA) RemoveState(stateID int)
- func (dfa *DFA) RemoveTransition(symbol int, fromStateID int)
- func (dfa *DFA) RemoveUnreachableStates()
- func (dfa DFA) SameAs(dfa2 DFA) bool
- func (dfa *DFA) SetOrderAsID() DFA
- func (dfa DFA) StartingState() *State
- func (dfa DFA) StructurallyComplete(dataset Dataset) bool
- func (dfa DFA) SymmetricallyStructurallyComplete(dataset Dataset) bool
- func (dfa *DFA) ToDOT(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool)
- func (dfa DFA) ToJPG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (dfa DFA) ToJSON(filePath string) bool
- func (dfa DFA) ToPDF(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (dfa DFA) ToPNG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (dfa DFA) ToSVG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (dfa DFA) ToStaminaFile(filePath string)
- func (dfa DFA) ToStatePartition() StatePartition
- func (dfa DFA) TransitionsCount() int
- func (dfa DFA) TransitionsCountForSymbol(symbol int) int
- func (dfa DFA) UnknownStates() []int
- func (dfa DFA) UnknownStatesCount() int
- func (dfa DFA) UnreachableStates() []int
- type Dataset
- func (dataset Dataset) AcceptingStringInstances() Dataset
- func (dataset Dataset) AcceptingStringInstancesCount() int
- func (dataset Dataset) AcceptingStringInstancesRatio() float64
- func (dataset Dataset) Accuracy(dfa DFA) float64
- func (dataset Dataset) ConsistentWithDFA(dfa DFA) bool
- func (dataset Dataset) ConsistentWithStatePartition(statePartition StatePartition) bool
- func (dataset Dataset) Count() int
- func (dataset Dataset) GetPTA(APTA bool) DFA
- func (dataset Dataset) RejectingStringInstances() Dataset
- func (dataset Dataset) RejectingStringInstancesCount() int
- func (dataset Dataset) RejectingStringInstancesRatio() float64
- func (dataset Dataset) SameAs(dataset2 Dataset) bool
- func (dataset Dataset) SortDatasetByLength() Dataset
- func (dataset Dataset) StructurallyComplete(dfa DFA) bool
- func (dataset Dataset) SymmetricallyStructurallyComplete(dfa DFA) bool
- func (dataset Dataset) ToAbbadingoFile(filePath string)
- func (dataset Dataset) ToJSON(filePath string) bool
- func (dataset Dataset) ToStaminaFile(filePath string)
- type MergeData
- type ScoringFunction
- type State
- func (state State) AllTransitionsExist() bool
- func (state State) Clone() State
- func (state State) DFA() *DFA
- func (state *State) Depth() int
- func (state State) InDegree(stateID int) int
- func (state State) IsAccepting() bool
- func (state State) IsLeaf() bool
- func (state State) IsRejecting() bool
- func (state State) IsUnknown() bool
- func (state *State) Order() int
- func (state State) OutDegree() int
- func (state State) TransitionExists(stateID int) bool
- func (state State) TransitionsCount(stateID int) int
- func (state State) ValidTransitions() []int
- type StateIDPair
- type StateLabel
- type StatePairScore
- type StatePartition
- func (statePartition *StatePartition) ChangedBlock(blockID int)
- func (statePartition StatePartition) Clone() StatePartition
- func (statePartition StatePartition) Copy() StatePartition
- func (statePartition *StatePartition) CopyChangesFrom(copiedStatePartition *StatePartition)
- func (statePartition *StatePartition) DepthOfBlocks() map[int]int
- func (statePartition *StatePartition) Find(stateID int) int
- func (statePartition *StatePartition) MergeStates(state1 int, state2 int) bool
- func (statePartition StatePartition) NumberOfLabelledBlocks() int
- func (statePartition *StatePartition) OrderOfBlocks() map[int]int
- func (statePartition *StatePartition) OrderedBlocks() []int
- func (statePartition StatePartition) ReturnSet(blockID int) []int
- func (statePartition *StatePartition) RollbackChangesFrom(originalStatePartition StatePartition)
- func (statePartition StatePartition) RootBlocks() []int
- func (statePartition *StatePartition) StartingBlock() int
- func (statePartition StatePartition) ToDOT(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool)
- func (statePartition StatePartition) ToJPG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (statePartition StatePartition) ToJSON(filePath string) bool
- func (statePartition StatePartition) ToPDF(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (statePartition StatePartition) ToPNG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (statePartition *StatePartition) ToQuotientDFA() DFA
- func (statePartition *StatePartition) ToQuotientDFAWithMapping() (DFA, map[int]int)
- func (statePartition StatePartition) ToSVG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
- func (statePartition *StatePartition) Union(blockID1 int, blockID2 int)
- func (statePartition *StatePartition) WithinSameBlock(stateID1 int, stateID2 int) bool
- type StringInstance
- func (stringInstance StringInstance) ConsistentWithDFA(dfa DFA) bool
- func (stringInstance StringInstance) ConsistentWithStatePartition(statePartition StatePartition) bool
- func (stringInstance StringInstance) Length() int
- func (stringInstance StringInstance) ParseToState(dfa DFA) (bool, int)
- func (stringInstance StringInstance) ParseToStateLabel(dfa DFA) StateLabel
- func (stringInstance StringInstance) WithinDataset(dataset Dataset) bool
- type TeamOfAutomata
- func (teamOfAutomata TeamOfAutomata) Accuracy(dataset Dataset, ...) float64
- func (teamOfAutomata TeamOfAutomata) AverageNumberOfStates() int
- func (teamOfAutomata TeamOfAutomata) BetterHalfWeightedVoteAccuracy(dataset Dataset) float64
- func (teamOfAutomata TeamOfAutomata) FairVoteAccuracy(dataset Dataset) float64
- func (teamOfAutomata TeamOfAutomata) WeightedVoteAccuracy(dataset Dataset) float64
- type TeamOfAutomataClassifierFunction
- type Transition
Constants ¶
const ( REJECTING = iota // 0 ACCEPTING // 1 UNLABELLED // 2 )
Constants which represent the 3 possible state labels.
Variables ¶
var SymbolAlphabetMappingAbbadingo = map[int]string{0: "a", 1: "b"}
SymbolAlphabetMappingAbbadingo represents the symbol-alphabet mapping for the Abbadingo competition standard (using only a's and b's / 0s and 1s).
Functions ¶
func AbbadingoDataset ¶
AbbadingoDataset returns a training and testing Dataset using the Abbadingo protocol given a DFA, a sparsity percentage and a training:testing ratio.
func AbbadingoDatasetExact ¶
AbbadingoDatasetExact returns a training and testing Dataset using the Abbadingo protocol given a DFA and a set size for each.
func AbbadingoInstance ¶
func AbbadingoInstance(numberOfStates int, exact bool, sparsityPercentage float64, testingRatio float64) (DFA, Dataset, Dataset)
AbbadingoInstance returns a random DFA using the Abbadingo protocol given a number of states while returning a training and testing dataset built on the generated DFA given a sparsity percentage and a training:testing ratio. If exact is set to true, the resultant DFA will have the required depth as per Abbadingo protocol.
func AbbadingoInstanceExact ¶
func AbbadingoInstanceExact(numberOfStates int, exact bool, trainingSetSize int, testingSetSize int) (DFA, Dataset, Dataset)
AbbadingoInstanceExact returns a random DFA using the Abbadingo protocol given a number of states while returning a training and testing dataset built on the generated DFA given a set size for each. If exact is set to true, the resultant DFA will have the required depth as per Abbadingo protocol.
func BlueFringeEDSM ¶
BlueFringeEDSM is a Blue Fringe version of Evidence Driven State-Merging. It takes a DFA (APTA) as an argument which is used within the blue-fringe search.
func BlueFringeEDSMFromDataset ¶
BlueFringeEDSMFromDataset is a Blue Fringe version of Evidence Driven State-Merging. It takes a dataset as an argument which is used to generate an APTA.
func BlueFringeSearchUsingScoringFunction ¶
func BlueFringeSearchUsingScoringFunction(statePartition StatePartition, scoringFunction ScoringFunction) (StatePartition, MergeData)
BlueFringeSearchUsingScoringFunction deterministically merges possible state pairs within red-blue sets. The state pair to be merged is chosen using a scoring function passed as a parameter. Returns the resultant state partition and merge data when no more valid merges are possible.
func DefaultStaminaDataset ¶
DefaultStaminaDataset returns a training and testing Dataset using the Stamina protocol given a DFA and a sparsity percentage. The default values for the initial strings generated (20000) and the maximum testing string instances (1500) which were used within the Stamina competition are used within this function.
func DefaultStaminaInstance ¶
func DefaultStaminaInstance(alphabetSize, targetDFASize int, sparsityPercentage float64) (DFA, Dataset, Dataset)
DefaultStaminaInstance returns a random DFA using the Stamina protocol given a target size while returning a training and testing dataset built on the generated DFA given a sparsity percentage. The default values for the initial strings generated (20000) and the maximum testing string instances (1500) which were used within the Stamina competition are used within this function.
func ExhaustiveEDSM ¶
ExhaustiveEDSM is a greedy version of Evidence Driven State-Merging. It takes a DFA (APTA) as an argument which is used within the greedy search.
func ExhaustiveEDSMFromDataset ¶
ExhaustiveEDSMFromDataset is a greedy version of Evidence Driven State-Merging. It takes a dataset as an argument which is used to generate an APTA.
func ExhaustiveSearchUsingScoringFunction ¶
func ExhaustiveSearchUsingScoringFunction(statePartition StatePartition, scoringFunction ScoringFunction) (StatePartition, MergeData)
ExhaustiveSearchUsingScoringFunction deterministically merges all possible state pairs. The state pair to be merged is chosen using a scoring function passed as a parameter. Returns the resultant state partition and merge data when no more valid merges are possible.
func GRBM ¶
func GRBM(statePartition StatePartition) (StatePartition, MergeData)
GRBM deterministically merges possible state pairs within red-blue sets. The state pair to be merged is chosen using a scoring function passed as a parameter. Returns the resultant state partition and merge data when no more valid merges are possible.
func GeneralizedRedBlueMerging ¶
GeneralizedRedBlueMerging is a. It takes a DFA (APTA) as an argument which is used within the greedy search.
func GeneralizedRedBlueMergingFromDataset ¶
GeneralizedRedBlueMergingFromDataset is a. It takes a dataset as an argument which is used to generate an APTA.
func GenerateBlueSetFromRedSetWithShuffle ¶
func GenerateBlueSetFromRedSetWithShuffle(statePartition *StatePartition, redSet map[int]util.Void) []int
GenerateBlueSetFromRedSetWithShuffle generates the blue set given the state partition and the red set within the Red-Blue framework such as the GeneralizedRedBlueMerging function. It generates and returns the blue set in arbitrary order.
func GenerateOrderedBlueSetFromRedSet ¶
func GenerateOrderedBlueSetFromRedSet(statePartition *StatePartition, redSet map[int]util.Void) []int
GenerateOrderedBlueSetFromRedSet generates the blue set given the state partition and the red set within the Red-Blue framework such as the BlueFringeSearchUsingScoringFunction function. It generates and returns the blue set in canonical order.
func RPNI ¶
RPNI returns a DFA and merge data generated by the regular positive and negative inference (RPNI) algorithm. It takes an APTA as a parameter which is passed to the RPNISearch function.
func RPNIFromDataset ¶
RPNIFromDataset returns a DFA and merge data generated by the regular positive and negative inference (RPNI) algorithm. It takes a dataset as a parameter which is used to generate an APTA while passing it to the RPNI function.
func RPNISearch ¶
func RPNISearch(statePartition StatePartition) (StatePartition, MergeData)
RPNISearch deterministically merges all possible state pairs within red-blue framework. The first valid merge with respect to the rejecting examples is chosen. Returns the resultant state partition and merge data when no more valid merges are possible. Used by the regular positive and negative inference (RPNI) algorithm.
func StaminaDataset ¶
func StaminaDataset(dfa DFA, sparsityPercentage float64, initialStringsGenerated, maximumTestingStringInstances int) (Dataset, Dataset)
StaminaDataset returns a training and testing Dataset using the Stamina protocol given a DFA and a sparsity percentage. This process is described in http://stamina.chefbe.net/samples and in Walkinshaw, N., Lambeau, B., Damas, C., Bogdanov, K., & Dupont, P. (2012). STAMINA: a competition to encourage the development and assessment of software model inference techniques. Empirical Software Engineering, 18(4), 791–824. doi:10.1007/s10664-012-9210-3
func StaminaInstance ¶
func StaminaInstance(alphabetSize, targetDFASize int, sparsityPercentage float64, initialStringsGenerated, maximumTestingStringInstances int) (DFA, Dataset, Dataset)
StaminaInstance returns a random DFA using the Stamina protocol given a target size while returning a training and testing dataset built on the generated DFA given a sparsity percentage, an initial string generated value, and a maximum testing string instances value.
func UpdateOrderedRedBlueSets ¶
func UpdateOrderedRedBlueSets(statePartition *StatePartition, redStates []int) ([]int, []int)
UpdateOrderedRedBlueSets updates the red and blue sets given the state partition and the red set within the Red-Blue framework such as the BlueFringeSearchUsingScoringFunction function. It returns the red and blue sets in canonical order. This is used when the state partition is changed or when new states have been added to the red set.
func UpdateRedBlueSets ¶
func UpdateRedBlueSets(statePartition *StatePartition, redStates *[]int) []int
UpdateRedBlueSets updates the red and blue sets given the state partition and the red set within the Red-Blue framework such as the GeneralizedRedBlueMerging function. It returns the blue set and modifies the red set via its pointer. This is used when the state partition is changed or when new states have been added to the red set.
func UpdateRedBlueSetsWithShuffle ¶
func UpdateRedBlueSetsWithShuffle(statePartition *StatePartition, redStates *[]int) []int
UpdateRedBlueSetsWithShuffle updates the red and blue sets given the state partition and the red set within the Red-Blue framework such as the GeneralizedRedBlueMerging function. It returns the blue set and modifies the red set via its pointer. Both sets are shuffled . This is used when the state partition is changed or when new states have been added to the red set.
func UpdateWindow ¶
func UpdateWindow(window []int, statePartition StatePartition) []int
UpdateWindow updates a window given the state partition within a Windowed framework such as the WindowedSearchUsingScoringFunction function. It returns the new window as a slice of integers. This works by gathering the root of each block within the previous window and assigns it to the position of the first index of any block which is part of that block. This is used to avoid attempting merges more than once within a windowed search.
func WindowedEDSM ¶
WindowedEDSM is a windowed version of Evidence Driven State-Merging. It takes a DFA (APTA) as an argument which is used within the windowed search.
func WindowedEDSMFromDataset ¶
WindowedEDSMFromDataset is a windowed version of Evidence Driven State-Merging. It takes a dataset as an argument which is used to generate an APTA.
func WindowedSearchUsingScoringFunction ¶
func WindowedSearchUsingScoringFunction(statePartition StatePartition, windowSize int, windowGrow float64, scoringFunction ScoringFunction) (StatePartition, MergeData)
WindowedSearchUsingScoringFunction deterministically merges state pairs within a given window. The state pair to be merged is chosen using a scoring function passed as a parameter. Returns the resultant state partition and merge data when no more valid merges are possible.
Types ¶
type Block ¶
type Block struct { Root int // Parent block of state. Size int // Size (score) of block. Link int // Index of next state within the block. Label StateLabel // Label of block. Changed bool // Whether block has been changed. Transitions []int // Transition Table where each element corresponds to a transition for each symbol. }
Block struct which represents a block within a partition.
type DFA ¶
type DFA struct { States []State // Slice of states within the DFA where the index is the State ID. Alphabet []int // Alphabet within DFA. StartingStateID int // The ID of the starting state of the DFA. // contains filtered or unexported fields }
DFA struct which represents a DFA.
func AbbadingoDFA ¶
AbbadingoDFA returns a random DFA using the Abbadingo protocol given a number of states. If exact is set to true, the resultant DFA will have the required depth as per Abbadingo protocol.
func DFAFromJSON ¶
DFAFromJSON returns a DFA read from a JSON file given a file path. The boolean value returned is set to true if DFA was read successfully.
func GetDFAFromStaminaFile ¶
GetDFAFromStaminaFile returns a DFA from a Stamina-Format File (adl).
func StaminaDFA ¶
StaminaDFA returns a random DFA using the Stamina protocol given a number of states. This process is described in http://stamina.chefbe.net/machines and in Walkinshaw, N., Lambeau, B., Damas, C., Bogdanov, K., & Dupont, P. (2012). STAMINA: a competition to encourage the development and assessment of software model inference techniques. Empirical Software Engineering, 18(4), 791–824. doi:10.1007/s10664-012-9210-3
func (DFA) AcceptingStates ¶
AcceptingStates returns state IDs of accepting states within DFA.
func (DFA) AcceptingStatesCount ¶
AcceptingStatesCount returns the number of accepting states within DFA.
func (*DFA) AddSinkState ¶
AddSinkState adds a sink state within DFA. This is used to convert a non-complete DFA to a complete DFA by adding a sink state.
func (*DFA) AddState ¶
func (dfa *DFA) AddState(stateLabel StateLabel) int
AddState adds a new state to the DFA with the corresponding State Label. Returns the new state's ID (index).
func (*DFA) AddTransition ¶
AddTransition adds a new transition for a given symbol from one state to another.
func (*DFA) CalculateDepthAndOrder ¶
func (dfa *DFA) CalculateDepthAndOrder()
CalculateDepthAndOrder computes the depth and Order for each state within DFA. This is done by traversing the DFA in a breadth-first order.
func (*DFA) ChangeRejectingStatesToUnlabelled ¶
func (dfa *DFA) ChangeRejectingStatesToUnlabelled()
ChangeRejectingStatesToUnlabelled changes all rejecting states within the DFA to unlabelled.
func (*DFA) Depth ¶
Depth returns the DFA's depth which is defined as the maximum over all nodes x of the length of the shortest path from the root to x.
func (DFA) Describe ¶
Describe prints the details of the DFA. If detail is set to true, each state and each transition will also be printed.
func (DFA) Equal ¶
Equal checks whether DFA is equal to the given DFA. This function makes use of DeepEqual and if it returns false, it does not necessarily mean that the DFAs are not equal. Use SameAs() for equivalence.
func (*DFA) IndistinguishableStatePairs ¶
func (dfa *DFA) IndistinguishableStatePairs() []StateIDPair
IndistinguishableStatePairs returns a slice of indistinguishable state pairs within DFA. P. Linz, An Introduction to Formal Languages and Automata. Jones & Bartlett Publishers, 2011.
func (DFA) IsComplete ¶
IsComplete returns true if DFA is complete, false is returned otherwise.
func (DFA) IsValidPanic ¶
func (dfa DFA) IsValidPanic()
IsValidPanic checks whether DFA is valid. Panics if not valid. Used for error checking.
func (DFA) IsValidSafe ¶
IsValidSafe checks whether DFA is valid. Returns false if not valid.
func (DFA) LabelledStates ¶
LabelledStates returns state IDs of labelled states within DFA.
func (DFA) LabelledStatesCount ¶
LabelledStatesCount returns the number of labelled states (accepting or rejecting) within DFA.
func (DFA) LeavesCount ¶
LeavesCount returns the number of leaves within DFA.
func (DFA) LoopsCount ¶
LoopsCount returns the number of loops within DFA.
func (DFA) Minimise ¶
Minimise returns a minimised version of the DFA. P. Linz, An Introduction to Formal Languages and Automata. Jones & Bartlett Publishers, 2011.
func (*DFA) OrderedStates ¶
OrderedStates returns the state IDs in order.
func (DFA) RejectingStates ¶
RejectingStates returns state IDs of rejecting states within DFA.
func (DFA) RejectingStatesCount ¶
RejectingStatesCount returns the number of rejecting states within DFA.
func (*DFA) RemoveNonAcceptingLeaves ¶
func (dfa *DFA) RemoveNonAcceptingLeaves()
RemoveNonAcceptingLeaves removes all states which are leaves within DFA and are not accepting states.
func (*DFA) RemoveState ¶
RemoveState removes a state from DFA with the corresponding State ID.
func (*DFA) RemoveTransition ¶
RemoveTransition removes a transition for a given symbol from one state to another.
func (*DFA) RemoveUnreachableStates ¶
func (dfa *DFA) RemoveUnreachableStates()
RemoveUnreachableStates removes unreachable states from DFA.
func (*DFA) SetOrderAsID ¶
SetOrderAsID returns a new DFA where the State IDs are the order of the states within the original DFA.
func (DFA) StartingState ¶
StartingState returns a pointer to the starting state within the DFA.
func (DFA) StructurallyComplete ¶
StructurallyComplete checks if DFA is structurally complete with respect to a Dataset.
func (DFA) SymmetricallyStructurallyComplete ¶
SymmetricallyStructurallyComplete checks if DFA is symmetrically structurally complete with respect to a Dataset.
func (*DFA) ToDOT ¶
ToDOT creates a .dot file using the DOT language. This DOT file contains a representation for the given DFA which can then be used to generate a visual representation of the DFA. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within DFA. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. This function is also called from all of the functions below.
func (DFA) ToJPG ¶
func (dfa DFA) ToJPG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToJPG creates and saves a .jpg image which represents the DFA to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within DFA. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (DFA) ToPDF ¶
func (dfa DFA) ToPDF(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToPDF creates and saves a .pdf file which represents the DFA to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within DFA. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (DFA) ToPNG ¶
func (dfa DFA) ToPNG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToPNG creates and saves a .png image which represents the DFA to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within DFA. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (DFA) ToSVG ¶
func (dfa DFA) ToSVG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToSVG creates and saves a .svg file which represents the DFA to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within DFA. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (DFA) ToStaminaFile ¶
ToStaminaFile writes a given DFA to file in Stamina-Format (adl).
func (DFA) ToStatePartition ¶
func (dfa DFA) ToStatePartition() StatePartition
ToStatePartition converts a DFA to a State Partition.
func (DFA) TransitionsCount ¶
TransitionsCount returns the number of transitions within DFA.
func (DFA) TransitionsCountForSymbol ¶
TransitionsCountForSymbol returns the number of transitions for a given symbol within DFA.
func (DFA) UnknownStates ¶
UnknownStates returns state IDs of unknown states within DFA.
func (DFA) UnknownStatesCount ¶
UnknownStatesCount returns the number of unknown states within DFA.
func (DFA) UnreachableStates ¶
UnreachableStates returns the state IDs of unreachable states. Extracted from: P. Linz, An Introduction to Formal Languages and Automata. Jones & Bartlett Publishers, 2011.
type Dataset ¶
type Dataset []StringInstance
Dataset which is a slice of string instances.
func DatasetFromJSON ¶
DatasetFromJSON returns a dataset read from a JSON file given a file path. The boolean value returned is set to true if Dataset was read successfully.
func GetDatasetFromAbbadingoFile ¶
GetDatasetFromAbbadingoFile returns a Dataset from an Abbadingo-Format File.
func GetDatasetFromStaminaFile ¶
GetDatasetFromStaminaFile returns a Dataset from a Stamina-Format File.
func (Dataset) AcceptingStringInstances ¶
AcceptingStringInstances returns the accepting string instances.
func (Dataset) AcceptingStringInstancesCount ¶
AcceptingStringInstancesCount returns the number of accepting string instances within dataset.
func (Dataset) AcceptingStringInstancesRatio ¶
AcceptingStringInstancesRatio returns the ratio of accepting string instances to the rejecting string instances within dataset.
func (Dataset) ConsistentWithDFA ¶
ConsistentWithDFA checks whether dataset is consistent with a given DFA.
func (Dataset) ConsistentWithStatePartition ¶
func (dataset Dataset) ConsistentWithStatePartition(statePartition StatePartition) bool
ConsistentWithStatePartition checks whether dataset is consistent with a given StatePartition.
func (Dataset) GetPTA ¶
GetPTA returns an APTA/PTA (DFA) given a dataset. If APTA is set to true, an APTA is returned.
func (Dataset) RejectingStringInstances ¶
RejectingStringInstances returns the rejecting string instances.
func (Dataset) RejectingStringInstancesCount ¶
RejectingStringInstancesCount returns the number of accepting string instances within dataset.
func (Dataset) RejectingStringInstancesRatio ¶
RejectingStringInstancesRatio returns the ratio of rejecting string instances to the accepting string instances within dataset.
func (Dataset) SameAs ¶
SameAs checks whether Dataset is the same as the given Dataset. Both datasets are sorted before checking with DeepEqual.
func (Dataset) SortDatasetByLength ¶
SortDatasetByLength sorts the given dataset by length and returns it.
func (Dataset) StructurallyComplete ¶
StructurallyComplete checks if Dataset is structurally complete with respect to a DFA.
func (Dataset) SymmetricallyStructurallyComplete ¶
SymmetricallyStructurallyComplete checks if Dataset is symmetrically structurally complete with respect to a DFA.
func (Dataset) ToAbbadingoFile ¶
ToAbbadingoFile writes a given Dataset to file in Abbadingo-Format.
func (Dataset) ToStaminaFile ¶
ToStaminaFile writes a given Dataset to file in Stamina-Format.
type MergeData ¶
type MergeData struct { Merges []StatePairScore // Slice of state pairs and scores of merges done. AttemptedMergesCount int // The number of attempted merges. ValidMergesCount int // The number of valid attempted merges. Duration time.Duration // The duration for the search function to finish. }
MergeData struct to store merge merge data.
func (MergeData) AttemptedMergesPerSecond ¶
AttemptedMergesPerSecond returns the number of attempted merges per second. Used for performance evaluation.
func (MergeData) MergesCount ¶
MergesCount returns the number of merges done before reaching the final StatePartition.
type ScoringFunction ¶
type ScoringFunction func(stateID1, stateID2 int, partitionBefore, partitionAfter StatePartition) float64
ScoringFunction takes two stateIDs and two state partitions as input and returns a score as a float.
type State ¶
type State struct { Label StateLabel // State Label (Rejecting, Accepting, or Unknown). Transitions []int // Transition Table where each element corresponds to a transition for each symbol. // contains filtered or unexported fields }
State struct which represents a State within a DFA.
func (State) AllTransitionsExist ¶
AllTransitionsExist checks whether all transitions from a given state exist (not -1). In other words, whether the state has a transition for each of the symbols within the alphabet.
func (State) IsAccepting ¶
IsAccepting returns true if state label is accepting, otherwise returns false.
func (State) IsLeaf ¶
IsLeaf checks whether given state is a leaf within DFA. In other words, whether the state has any valid transitions.
func (State) IsRejecting ¶
IsRejecting returns true if state label is rejecting, otherwise returns false.
func (State) TransitionExists ¶
TransitionExists checks whether a transition exists from a given state to another state, regardless of the symbol.
func (State) TransitionsCount ¶
TransitionsCount returns the number of transitions to given state ID.
func (State) ValidTransitions ¶
ValidTransitions returns all transitions from a given state that are valid (not -1). The symbolIDs of the corresponding valid transitions are returned in a slice of integers.
type StateIDPair ¶
type StateIDPair struct {
// contains filtered or unexported fields
}
StateIDPair which represents a pair of states.
type StatePairScore ¶
type StatePairScore struct { State1 int // StateID for first state. State2 int // StateID for second state. Score float64 // Score of merge for given states. }
StatePairScore struct to store state pairs and their merge score.
type StatePartition ¶
type StatePartition struct { Blocks []Block // Slice of blocks. BlocksCount int // Number of blocks within partition. AcceptingBlocksCount int // Number of accepting blocks within partition. RejectingBlocksCount int // Number of rejecting blocks within partition. AlphabetSize int // Size of alphabet. StartingStateID int // The ID of the starting state. IsCopy bool // Whether state partition is a copy (for reverting merges). ChangedBlocks []int // Slice of changed blocks. ChangedBlocksCount int // Number of changed blocks within partition. }
StatePartition struct which represents a State Partition.
func NewStatePartition ¶
func NewStatePartition(referenceDFA DFA) StatePartition
NewStatePartition returns an initialized State Partition.
func StatePartitionFromJSON ¶
func StatePartitionFromJSON(filePath string) (StatePartition, bool)
StatePartitionFromJSON returns a StatePartition read from a JSON file given a file path. The boolean value returned is set to true if DFA was read successfully.
func (*StatePartition) ChangedBlock ¶
func (statePartition *StatePartition) ChangedBlock(blockID int)
ChangedBlock updates the required fields to mark block as changed.
func (StatePartition) Clone ¶
func (statePartition StatePartition) Clone() StatePartition
Clone returns a clone of the state partition.
func (StatePartition) Copy ¶
func (statePartition StatePartition) Copy() StatePartition
Copy returns a copy of the state partition in 'copy' (undo) mode.
func (*StatePartition) CopyChangesFrom ¶
func (statePartition *StatePartition) CopyChangesFrom(copiedStatePartition *StatePartition)
CopyChangesFrom copies the changes from one state partition to another and resets the changed values within the copied state partition.
func (*StatePartition) DepthOfBlocks ¶
func (statePartition *StatePartition) DepthOfBlocks() map[int]int
DepthOfBlocks returns the depth of each block.
func (*StatePartition) Find ¶
func (statePartition *StatePartition) Find(stateID int) int
Find traverses each root element while compressing the levels to find the root element of the stateID.
func (*StatePartition) MergeStates ¶
func (statePartition *StatePartition) MergeStates(state1 int, state2 int) bool
MergeStates recursively merges states to merge state1 and state2. Returns false if merge results in a non-deterministic automaton. Returns true if merge was successful.
func (StatePartition) NumberOfLabelledBlocks ¶
func (statePartition StatePartition) NumberOfLabelledBlocks() int
NumberOfLabelledBlocks returns the number of labelled blocks (states) within state partition.
func (*StatePartition) OrderOfBlocks ¶
func (statePartition *StatePartition) OrderOfBlocks() map[int]int
OrderOfBlocks returns the order of each block.
func (*StatePartition) OrderedBlocks ¶
func (statePartition *StatePartition) OrderedBlocks() []int
OrderedBlocks returns the IDs of root blocks in order as a slice of integers.
func (StatePartition) ReturnSet ¶
func (statePartition StatePartition) ReturnSet(blockID int) []int
ReturnSet returns the state IDs within given block.
func (*StatePartition) RollbackChangesFrom ¶
func (statePartition *StatePartition) RollbackChangesFrom(originalStatePartition StatePartition)
RollbackChangesFrom reverts any changes made within state partition given the original state partition.
func (StatePartition) RootBlocks ¶
func (statePartition StatePartition) RootBlocks() []int
RootBlocks returns the IDs of root blocks as a slice of integers.
func (*StatePartition) StartingBlock ¶
func (statePartition *StatePartition) StartingBlock() int
StartingBlock returns the ID of the block which contains the starting state.
func (StatePartition) ToDOT ¶
func (statePartition StatePartition) ToDOT(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool)
ToDOT creates a .dot file using the DOT language. This DOT file contains a representation for the given StatePartition which can then be used to generate a visual representation of the DFA represented by the State Partition. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within partition. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. This function is also called from all of the functions below.
func (StatePartition) ToJPG ¶
func (statePartition StatePartition) ToJPG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToJPG creates and saves a .jpg image which represents the state partition to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within partition. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (StatePartition) ToJSON ¶
func (statePartition StatePartition) ToJSON(filePath string) bool
ToJSON saves the StatePartition to a JSON file given a file path.
func (StatePartition) ToPDF ¶
func (statePartition StatePartition) ToPDF(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToPDF creates and saves a .pdf file which represents the state partition to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within partition. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (StatePartition) ToPNG ¶
func (statePartition StatePartition) ToPNG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToPNG creates and saves a .png image which represents the state partition to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within partition. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (*StatePartition) ToQuotientDFA ¶
func (statePartition *StatePartition) ToQuotientDFA() DFA
ToQuotientDFA converts a State Partition to a quotient DFA and returns it.
func (*StatePartition) ToQuotientDFAWithMapping ¶
func (statePartition *StatePartition) ToQuotientDFAWithMapping() (DFA, map[int]int)
ToQuotientDFAWithMapping converts a State Partition to a quotient DFA and returns it. This function also returns the state partition's blocks to state mapping.
func (StatePartition) ToSVG ¶
func (statePartition StatePartition) ToSVG(filePath string, symbolMapping map[int]string, showOrder bool, topDown bool) bool
ToSVG creates and saves a .svg file which represents the state partition to the given file path. Please note that GraphViz must be downloaded and installed before hand from https://graphviz.org/download/. The symbolMapping parameter is a map which maps each symbol within the alphabet to a string. This can be set to nil, which will map each symbol with a number starting from 0. If showOrder is set to true, the canonical order of the states is shown inside the node within partition. If topDown is set to true, the visual representation will be top down. A left to right representation is used otherwise. Returns true if successful or false if an error occurs.
func (*StatePartition) Union ¶
func (statePartition *StatePartition) Union(blockID1 int, blockID2 int)
Union connects two blocks by comparing their respective size (score) values to keep the tree flat.
func (*StatePartition) WithinSameBlock ¶
func (statePartition *StatePartition) WithinSameBlock(stateID1 int, stateID2 int) bool
WithinSameBlock checks whether two states are within the same block.
type StringInstance ¶
type StringInstance struct { Value []int // Slice of integers which represents the symbol values. Accepting bool // Accepting label flag for StringInstance. }
StringInstance struct which represents a string instance within a dataset.
func BinaryStringToStringInstance ¶
func BinaryStringToStringInstance(dfa DFA, binaryString string) StringInstance
BinaryStringToStringInstance returns a StringInstances from a binary string.
func NewStringInstanceFromAbbadingoFile ¶
func NewStringInstanceFromAbbadingoFile(text string, delimiter string) StringInstance
NewStringInstanceFromAbbadingoFile returns a StringInstance from a line within an Abbadingo-Format File.
func NewStringInstanceFromStaminaFile ¶
func NewStringInstanceFromStaminaFile(text string, delimiter string) StringInstance
NewStringInstanceFromStaminaFile returns a StringInstance from a line within a Stamina-Format File.
func (StringInstance) ConsistentWithDFA ¶
func (stringInstance StringInstance) ConsistentWithDFA(dfa DFA) bool
ConsistentWithDFA returns whether a string instance is consistent within a given DFA.
func (StringInstance) ConsistentWithStatePartition ¶
func (stringInstance StringInstance) ConsistentWithStatePartition(statePartition StatePartition) bool
ConsistentWithStatePartition returns whether a string instance is consistent within a given StatePartition.
func (StringInstance) Length ¶
func (stringInstance StringInstance) Length() int
Length returns the length of the string.
func (StringInstance) ParseToState ¶
func (stringInstance StringInstance) ParseToState(dfa DFA) (bool, int)
ParseToState returns the State ID of a given string instance within a given DFA. A boolean is also returned which returns false if string instance does not correspond to any state within DFA.
func (StringInstance) ParseToStateLabel ¶
func (stringInstance StringInstance) ParseToStateLabel(dfa DFA) StateLabel
ParseToStateLabel returns the State Label of a given string instance within a given DFA. If state does not exist, REJECTING is returned.
func (StringInstance) WithinDataset ¶
func (stringInstance StringInstance) WithinDataset(dataset Dataset) bool
WithinDataset checks whether a StringInstance is within given Dataset.
type TeamOfAutomata ¶
TeamOfAutomata represents a team of automata within the AutomataTeams algorithm.
func AutomataTeams ¶
func AutomataTeams(APTA DFA, teamSize int) TeamOfAutomata
AutomataTeams creates a team of automata of size teamSize. This creates a TeamOfAutomata instance which can then be used to classify testing examples.
func AutomataTeamsFromDataset ¶
func AutomataTeamsFromDataset(dataset Dataset, teamSize int) TeamOfAutomata
AutomataTeamsFromDataset creates a team of automata of size teamSize. This creates a TeamOfAutomata instance which can then be used to classify testing examples. It takes a dataset as an argument which is used to generate an APTA.
func (TeamOfAutomata) Accuracy ¶
func (teamOfAutomata TeamOfAutomata) Accuracy(dataset Dataset, teamOfAutomataClassifierFunction TeamOfAutomataClassifierFunction) float64
Accuracy returns the TeamOfAutomata's Accuracy with respect to a dataset.
func (TeamOfAutomata) AverageNumberOfStates ¶
func (teamOfAutomata TeamOfAutomata) AverageNumberOfStates() int
AverageNumberOfStates returns the average number of states of DFAs within team.
func (TeamOfAutomata) BetterHalfWeightedVoteAccuracy ¶
func (teamOfAutomata TeamOfAutomata) BetterHalfWeightedVoteAccuracy(dataset Dataset) float64
BetterHalfWeightedVoteAccuracy returns the TeamOfAutomata's Accuracy with respect to a dataset using the better half weighted vote scoring heuristic.
func (TeamOfAutomata) FairVoteAccuracy ¶
func (teamOfAutomata TeamOfAutomata) FairVoteAccuracy(dataset Dataset) float64
FairVoteAccuracy returns the TeamOfAutomata's Accuracy with respect to a dataset using the fair vote scoring heuristic.
func (TeamOfAutomata) WeightedVoteAccuracy ¶
func (teamOfAutomata TeamOfAutomata) WeightedVoteAccuracy(dataset Dataset) float64
WeightedVoteAccuracy returns the TeamOfAutomata's Accuracy with respect to a dataset using the weighted vote scoring heuristic.
type TeamOfAutomataClassifierFunction ¶
type TeamOfAutomataClassifierFunction func(stringInstance StringInstance) StateLabel
TeamOfAutomataClassifierFunction takes a string instance as input and returns a state label. An example of how this function type should be used can be seen in BetterHalfWeightedVoteAccuracy.
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
Transition struct which represents a transition. Used in SymmetricallyStructurallyComplete and StructurallyComplete functions.