go_nets

package module
v0.0.0-...-2721cc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2015 License: GPL-2.0 Imports: 21 Imported by: 0

README

go-nets

Network representation of data & analyses in Go. Includes :

  • A Network "library"
  • A simple xml parser
  • A "dispatcher" that does the link between the two

Documentation

Overview

Super simple implementation of a non-concurrent safe LIFO stack for the wanderer.

Index

Constants

View Source
const TempSuffix = ".tmp"

Variables

View Source
var BatchSize int = 10000

Functions

func Atomize

func Atomize(s string) string

func CcrDetectSubsVertical

func CcrDetectSubsVertical(startNode *Node, maxN int) (map[string]bool, bool)

func DetectSubs

func DetectSubs(startNode *Node, maxN int) (map[*Node]bool, bool)

C. "Stepwise Wide first": potentially slow but no false negatives. Useful because MaxSteps has a meaning.

func DetectSubsLegacy

func DetectSubsLegacy(startNode *Node, maxN int) (map[string]bool, bool)

Old method with string-keyed maps as subnetwork (NEEDS CLEANING!)

func DetectSubsVertical

func DetectSubsVertical(startNode *Node, maxN int) (map[*Node]bool, bool)

----------------------- SECTION 4: SUBNETWORK DETECTION A. "Depth-first": this will not allow a detection of a short wide subnetwork when limited in steps. Could be useful for greedy subnetwork search. The most efficient in term of checks.

func FilingToSaveable

func FilingToSaveable(from <-chan Filing) chan Saveable

func ListenAndSave

func ListenAndSave(c chan Saveable, s Saver)

func ListenAndSaveFilings

func ListenAndSaveFilings(c chan Filing, s *SqlSaver)

func MinInt

func MinInt(x, y int) (r int)

Bloc Subfunctions

Types

type Agent

type Agent struct {
	OrganizationName string         `xml:",omitempty"`
	IndividualName   IndividualName `xml:"IndividualName,omitempty"`
	MailAddress      string
	City             string
	State            string
	PostalCode       string
	// County           string
	Country string
}

func DeleteAgent

func DeleteAgent(agents []Agent, ind int) []Agent

func (*Agent) GetData

func (a *Agent) GetData() AttrGetter

func (*Agent) GetIdentifier

func (a *Agent) GetIdentifier() string

Define the agent as a Noder

func (*Agent) GetKind

func (a *Agent) GetKind() NodeKind

func (*Agent) UpdateData

func (a *Agent) UpdateData(AttrGetter) AttrGetter

type AttrGetter

type AttrGetter interface {
}

type AttrMethodContainer

type AttrMethodContainer struct {
	Attr string `xml:"Method,attr"`
}

type AttrTypeContainer

type AttrTypeContainer struct {
	Attr string `xml:"Type,attr"`
}

type AttrVersionContainer

type AttrVersionContainer struct {
	Attr string `xml:"Version,attr"`
}

type ComObject

type ComObject struct {
	// contains filtered or unexported fields
}

B. "Depth-first", but concurrent. Should be quite efficient. There is no synchronization mechanism (on purpose), so it is not maxN-reproducible.

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter() *Counter

func (*Counter) Add

func (counter *Counter) Add(n *Node)

func (*Counter) Listen

func (passCounter *Counter) Listen(c <-chan *Counter, done <-chan int, nRW int)

Let a counter listen to other sub-counters that will feed him

func (*Counter) Normalize

func (counter *Counter) Normalize() map[*Node]float32

Normalize the counter and give the map output

type Dispatcher

type Dispatcher interface {
	Dispatch(*log.Logger) ([]Noder, []Edger)
}

type Edge

type Edge struct {
	Name     string
	Kind     EdgeKind
	Src      *Node
	Dst      *Node
	LinkData *AttrGetter
}

type EdgeKind

type EdgeKind int
const (
	ER EdgeKind = iota
	EE
	RR
)

func (EdgeKind) String

func (ek EdgeKind) String() string

type EdgeToNode

type EdgeToNode struct {
	*Edge
	ToNode *Node
}

type Edger

type Edger interface {
	GetIdentifier() string
	GetKind() EdgeKind
	GetData() AttrGetter
	GetSrcId() string
	GetDstId() string
}

type Element

type Element struct {
	Node *Node
	Next *Element
}

type Filing

type Filing struct {
	XMLName            xml.Name            `xml:"FileDetail"`
	Method             AttrMethodContainer `xml:"FilingMethod"`
	Amendment          AttrTypeContainer   `xml:"AmendmentType"`
	FilingType         AttrTypeContainer   `xml:"TransType"`
	AltFilingType      AttrTypeContainer   `xml:"AltFilingType"`
	OriginalFileNumber int
	FileNumber         int
	OriginalFileDate   string
	FileDate           string
	Debtors            []Agent `xml:"Debtors>DebtorName>Names"`
	Securers           []Agent `xml:"Secured>Names"`
}

func (*Filing) Dispatch

func (f *Filing) Dispatch(logger *log.Logger) ([]Noder, []Edger)

Define Filing as a Dispatcher

func (Filing) GetInitStatements

func (f Filing) GetInitStatements() []string

func (Filing) GetSavingStatements

func (f Filing) GetSavingStatements() []string

func (*Filing) NewFilingEdger

func (f *Filing) NewFilingEdger(kind EdgeKind, srcId string, dstId string) FilingEdger

type FilingEdger

type FilingEdger struct {
	// contains filtered or unexported fields
}

Create a new Edger from a Filing

func (FilingEdger) GetData

func (fe FilingEdger) GetData() AttrGetter

func (FilingEdger) GetDstId

func (fe FilingEdger) GetDstId() string

func (FilingEdger) GetIdentifier

func (fe FilingEdger) GetIdentifier() string

func (FilingEdger) GetKind

func (fe FilingEdger) GetKind() EdgeKind

func (FilingEdger) GetSrcId

func (fe FilingEdger) GetSrcId() string

type IndividualName

type IndividualName struct {
	FirstName  string `xml:",omitempty"`
	MiddleName string `xml:",omitempty"`
	LastName   string `xml:",omitempty"`
}

func (*IndividualName) String

func (i *IndividualName) String() string

type LIFO

type LIFO interface {
	Push(*Node)
	Pop() *Node
}

type LLifo

type LLifo struct {
	Len int
	Top *Element
}

func (*LLifo) Pop

func (l *LLifo) Pop() *Node

func (*LLifo) Push

func (l *LLifo) Push(n *Node)

type Net

type Net struct {
	NodeMap     map[*Node]int
	SubNetworks map[int]map[*Node]bool
}

D. Crunching the whole Network now.

func NewNet

func NewNet() *Net

func (*Net) AddSub

func (net *Net) AddSub(subN map[*Node]bool)

func (*Net) CrunchNetwork

func (net *Net) CrunchNetwork(n *Network)

func (*Net) Summary

func (net *Net) Summary(w io.Writer)

type Network

type Network struct {
	// Objects of the network
	Name   string
	Edges  map[string]*Edge // Remark: see below
	Nedges int
	Nodes  map[string]*Node // Less efficient with '*' but necessary because we want to share the pointer with the edges and you cannot create apointer to a map element (that can change location)
	Nnodes int
	// EdgeNames []string //AL Needed to iterate over all edges quickly... ?
	// NodeNames []string //AL Needed to iterate over all nodes quickly... ?
	//LinksData []AttrGetter //AL to be fixed / looked into.
	// Parameters of the Network
	Symmetrical bool // TODO let it be assymetrical in the nodes and co.
	// Meta parameters
	Folder         string
	Logger         *log.Logger
	PersistingFile string
	DBDriver       string
}

func NewNetwork

func NewNetwork(name string, logWriter io.Writer, folder string) Network

func (*Network) AddDispatcher

func (n *Network) AddDispatcher(dispatcher Dispatcher)

func (*Network) AddEdge

func (n *Network) AddEdge(edger Edger)

func (*Network) AddNode

func (n *Network) AddNode(noder Noder)

func (*Network) CheckSubNetwork

func (n *Network) CheckSubNetwork(subNetwork map[string]bool) bool

Checking subnetworks

func (*Network) CheckSubNetworkNodes

func (n *Network) CheckSubNetworkNodes(subNetwork map[*Node]bool) bool

func (*Network) Compare

func (n *Network) Compare(ns ...Network)

func (*Network) GetAMatrix

func (nn *Network) GetAMatrix() (*mat64.Dense, Nlut)

GetAMatrix returns the adjacency matrix of the network.

func (*Network) GetDMatrix

func (nn *Network) GetDMatrix() (*mat64.Dense, Nlut)

func (*Network) GetLUT

func (nn *Network) GetLUT() Nlut

GetLUT() create a two ways look-up table for indexing the graph

func (*Network) GetSortedLUT

func (nn *Network) GetSortedLUT() Nlut

func (*Network) Load

func (n *Network) Load()

func (*Network) LoadEdges

func (n *Network) LoadEdges(fp string)

func (*Network) LoadFrom

func (n *Network) LoadFrom(filePath string)

func (*Network) LoadNodes

func (n *Network) LoadNodes(fp string)

func (*Network) PageRankMatrix

func (nn *Network) PageRankMatrix() map[*Node]float32

PageRankMatrix uses matrix computation to efficiently compute the pi ditribution. Can be used only for small networks.

func (*Network) PageRankRW

func (nn *Network) PageRankRW(nRW, nSteps int, seeds []*Node) map[*Node]float32

Pagerank function defined on random walkers (Larry Page way) Applicable in case of large networks if non regular OR for personalization (seeds as a subset)

func (*Network) PageRankSymmetric

func (n *Network) PageRankSymmetric() map[*Node]float32

Simple PageRank implementation based on node degree information. Applicable only for symetric networks. Everything compiles but the missing property Edge.Weight

func (*Network) PageRankSymmetricRegular

func (n *Network) PageRankSymmetricRegular() map[*Node]float32

Simple PageRank implementation based on node degree information. Applicable only for regular symetric networks. No Edge strengh is checked. (mainly because the lack of implementation so far)

func (*Network) Save

func (n *Network) Save()

func (*Network) SaveAs

func (n *Network) SaveAs(fp string)

func (*Network) SaveEdges

func (n *Network) SaveEdges(fp string, ch chan string)

func (*Network) SaveNodes

func (n *Network) SaveNodes(fp string, ch chan string)

func (*Network) Search

func (n *Network) Search(namePattern string, mode string)

----------------------- SECTION 3: NON-COMPLEX NETWORK OPERATIONS

func (*Network) SearchEdges

func (n *Network) SearchEdges(namePattern string) []*Edge

func (*Network) SearchNodes

func (n *Network) SearchNodes(namePattern string) []*Node

func (*Network) Summary

func (n *Network) Summary(w io.Writer)

type Nlut

type Nlut struct {
	// contains filtered or unexported fields
}

Look up table type for network nodes

type Node

type Node struct {
	Name     string
	Kind     NodeKind
	Edges    []*EdgeToNode //map[string]*Edge
	NodeData AttrGetter
}

type NodeKind

type NodeKind int
const (
	Emitter NodeKind = iota
	Receiver
)

func (NodeKind) String

func (nk NodeKind) String() string

type Noder

type Noder interface {
	GetIdentifier() string
	GetKind() NodeKind
	GetData() AttrGetter
	UpdateData(AttrGetter) AttrGetter
}

type OnOffWriter

type OnOffWriter struct {
	Writing bool
	// contains filtered or unexported fields
}

func (OnOffWriter) Write

func (w OnOffWriter) Write(p []byte) (n int, err error)

type Order

type Order int
const (
	Done Order = iota
	Continue
	Break
	Merge
)

type RandomWalker

type RandomWalker struct {
	// contains filtered or unexported fields
}

func (*RandomWalker) Next

func (rw *RandomWalker) Next() *Node

Advance the walker to the next node

func (*RandomWalker) Walk

func (rw *RandomWalker) Walk(nStep int, c chan<- *Counter, done chan<- int)

Walk for nStep steps.

type SLifo

type SLifo []*Node

func (*SLifo) Pop

func (l *SLifo) Pop() *Node

func (*SLifo) Push

func (l *SLifo) Push(n *Node)

type Saveable

type Saveable interface {
	GetInitStatements() []string
	GetSavingStatements() []string
}

type Saver

type Saver interface {
	SaveBatch([]Saveable) // TODO add error handling
	InitPersistance(Saveable) chan string
}

type SimpleEdger

type SimpleEdger struct {
	Name         string
	Kind         EdgeKind
	SrcId, DstId string
}

func (*SimpleEdger) GetData

func (s *SimpleEdger) GetData() AttrGetter

func (*SimpleEdger) GetDstId

func (s *SimpleEdger) GetDstId() string

func (*SimpleEdger) GetIdentifier

func (s *SimpleEdger) GetIdentifier() string

func (*SimpleEdger) GetKind

func (s *SimpleEdger) GetKind() EdgeKind

func (*SimpleEdger) GetSrcId

func (s *SimpleEdger) GetSrcId() string

type SimpleNoder

type SimpleNoder struct {
	Name string
	Kind NodeKind
}

func (*SimpleNoder) GetData

func (s *SimpleNoder) GetData() AttrGetter

func (*SimpleNoder) GetIdentifier

func (s *SimpleNoder) GetIdentifier() string

func (*SimpleNoder) GetKind

func (s *SimpleNoder) GetKind() NodeKind

func (*SimpleNoder) UpdateData

func (s *SimpleNoder) UpdateData(AttrGetter) AttrGetter

type SimpleWanderer

type SimpleWanderer struct {
	Moignons   *SLifo
	SubNetwork map[*Node]bool
}

E. "Wanderer", is a non recursive re-writing of the DetectSubVertical to make it concurrent in the bigger picture.

func NewSimpleWanderer

func NewSimpleWanderer() *SimpleWanderer

func (*SimpleWanderer) DetectSubs

func (sw *SimpleWanderer) DetectSubs(startNode *Node, maxN int) (map[string]bool, bool)

func (*SimpleWanderer) Merge

func (sw *SimpleWanderer) Merge(sw2 *SimpleWanderer)

func (*SimpleWanderer) Wander

func (sw *SimpleWanderer) Wander(startNode *Node, maxN int) (map[*Node]bool, bool)

Wandering function, similar to the DetectSub above, but with embedded duplicity to enable lightweight communication

func (*SimpleWanderer) WanderStep

func (sw *SimpleWanderer) WanderStep(startNode *Node, stepSize int, com WandererCom)

type SqlSaver

type SqlSaver struct {
	DbPath, DbName string
	DBDriver       string
	// contains filtered or unexported fields
}

//////// Implement a sql saver

func (*SqlSaver) InitPersistance

func (ss *SqlSaver) InitPersistance(so Saveable) chan string

func (*SqlSaver) SaveBatch

func (s *SqlSaver) SaveBatch(ss []Saveable)

func (*SqlSaver) SaveFilingBatch

func (ss *SqlSaver) SaveFilingBatch(batch []Filing)

type WandererCom

type WandererCom struct {
	// contains filtered or unexported fields
}

func NewWandererCom

func NewWandererCom() *WandererCom

type XmlParser

type XmlParser struct {
	FileDir  string
	FileName string
	Encoding encoding.Encoding
}

func (*XmlParser) Parse

func (p *XmlParser) Parse(c chan Filing, logDst io.Writer)

func (*XmlParser) ParseVerbose

func (p *XmlParser) ParseVerbose(c chan Filing, logDst io.Writer)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL