Skip to content

Commit

Permalink
Merging legacy Develop into legacy Master to create release 0.4.1
Browse files Browse the repository at this point in the history
Merging legacy Develop into legacy Master to create release 0.4.1
  • Loading branch information
miratepuffin authored Mar 29, 2022
2 parents a0c0bb3 + 81295af commit 63a9d2b
Show file tree
Hide file tree
Showing 38 changed files with 976 additions and 436 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ logs
/src/main/scala/com/raphtory/dev/algorithms/test.scala

testupdates.txt

# local files
src/main/scala/com/raphtory/lotr
/src/main/scala/com/raphtory/dev/lotr/lotr2.csv
/src/main/scala/com/raphtory/dev/networkx/networkxGraphBuilder.scala
/src/main/scala/com/raphtory/dev/networkx/networkxSpout.scala
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![test and build](https://github.com/Raphtory/Raphtory/actions/workflows/test_and_build.yml/badge.svg?event=schedule)](https://github.com/Raphtory/Raphtory/actions/workflows/test_and_build.yml?query=event%3Aschedule++)
[![Latest Tag](https://img.shields.io/github/v/tag/Raphtory/Raphtory?include_prereleases&sort=semver&color=brightgreen)](https://github.com/Raphtory/Raphtory/tags)
[![Latest Release](https://img.shields.io/github/v/release/Raphtory/Raphtory?color=brightgreen&include_prereleases&sort=semver)](https://github.com/Raphtory/Raphtory/releases)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

Raphtory is an open-source platform for distributed real-time temporal graph analytics, allowing you to load and process large dynamic datsets across time. If you would like a brief summary of what its used for before fully diving into the getting started guide please check out this [article](https://www.turing.ac.uk/blog/just-add-time-dizzying-potential-dynamic-graphs) from the Alan Turing Institute first!

Expand Down Expand Up @@ -50,6 +51,25 @@ If you want to see how Raphtory runs without reading a mountain of documentation

**Note:** Raphtory is built with Scala. We recommend using IntelliJ IDE for your code. They have a community version which is free. Follow their [guide](https://www.jetbrains.com/idea/download/#section=windows) for installation.

### Conventional Commits
Raphtory is now **commitizen friendly** which means our commit history is now be dictated by [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/) conventions. To add and enforce this convention in our development workflow we are using npm tool called [commitizen](https://github.com/commitizen/cz-cli). In practise, what it means is that we need to have `commitizen` installed on our dev machines as external dev dependency before we could start making contributions.

1. Install nodejs (refer [documentation](https://nodejs.org/en/download/))
2. Install [commitizen](https://github.com/commitizen/cz-cli)
```
$ npm install -g commitizen
```
3. Install [commitizen adapter](https://github.com/commitizen/cz-cli#adapters)
```
$ npm install -g cz-conventional-changelog
$ echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
```
4. Run `sbt`. This will copy necessary custom hooks from `git-hooks` to `.git/hooks`

You're good to start making contributions. `git commit` should present you now with a serious of questions, answers to which will result in conventional commit.

[![Conventional Commits](https://i.postimg.cc/fRxN5BR2/cc.png)](https://postimg.cc/zyX6GwWK)


## Community and Changelog

Expand Down
10 changes: 10 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,13 @@ lazy val raphtory = project
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % Test,
Compile / PB.targets := Seq(scalapb.gen() -> (Compile / sourceManaged).value / "scalapb")
)

// Write custom git hooks to .git/hooks on sbt load
lazy val startupTransition: State => State = { s: State =>
"writeHooks" :: s
}

onLoad in Global := {
val old = (onLoad in Global).value
startupTransition compose old
}
2 changes: 2 additions & 0 deletions git-hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec < /dev/tty && git cz --hook || true
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.1")
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.5")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
addSbtPlugin("uk.co.randomcoding" % "sbt-git-hooks" % "0.2.0")
51 changes: 27 additions & 24 deletions src/main/scala/com/raphtory/algorithms/GraphState.scala
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package com.raphtory.algorithms

import com.raphtory.core.model.algorithm.{GraphAlgorithm, GraphPerspective, Row}
import com.raphtory.core.model.algorithm.{GraphAlgorithm, GraphPerspective, Row, Table}

class GraphState(path:String) extends GraphAlgorithm{
override def algorithm(graph: GraphPerspective): Unit = {
graph.select(vertex=> {
val inDeg = vertex.getInEdges().size
val outDeg = vertex.getOutEdges().size
val deg = inDeg + outDeg
val vdeletions = vertex.history().count(f => !f.event)
val vcreations = vertex.history().count(f =>f.event)
val outedgedeletions =vertex.getOutEdges().map(f=>f.history().count(f => !f.event)).sum
val outedgecreations =vertex.getOutEdges().map(f=>f.history().count(f => f.event)).sum

val inedgedeletions =vertex.getInEdges().map(f=>f.history().count(f => !f.event)).sum
val inedgecreations =vertex.getInEdges().map(f=>f.history().count(f => f.event)).sum

val properties = vertex.getPropertySet().size
val propertyhistory = vertex.getPropertySet().toArray.map(x=> vertex.getPropertyHistory(x).size).sum
val outedgeProperties = vertex.getOutEdges().map(edge => edge.getPropertySet().size).sum
val outedgePropertyHistory = vertex.getOutEdges().map(edge => edge.getPropertySet().toArray.map(x=> edge.getPropertyHistory(x).size).sum).sum

val inedgeProperties = vertex.getInEdges().map(edge => edge.getPropertySet().size).sum
val inedgePropertyHistory = vertex.getInEdges().map(edge => edge.getPropertySet().toArray.map(x=> edge.getPropertyHistory(x).size).sum).sum

Row(vertex.ID(),inDeg, outDeg,deg, vdeletions,vcreations,outedgedeletions,outedgecreations,inedgedeletions,inedgecreations,properties,propertyhistory,outedgeProperties,outedgePropertyHistory,inedgeProperties,inedgePropertyHistory)
override def tabularise(graph: GraphPerspective): Table = {
graph.select(vertex => {
val inDeg = vertex.getInEdges().size
val outDeg = vertex.getOutEdges().size
val deg = inDeg + outDeg
val vdeletions = vertex.history().count(f => !f.event)
val vcreations = vertex.history().count(f => f.event)
val outedgedeletions = vertex.getOutEdges().map(f => f.history().count(f => !f.event)).sum
val outedgecreations = vertex.getOutEdges().map(f => f.history().count(f => f.event)).sum

val inedgedeletions = vertex.getInEdges().map(f => f.history().count(f => !f.event)).sum
val inedgecreations = vertex.getInEdges().map(f => f.history().count(f => f.event)).sum

val properties = vertex.getPropertySet().size
val propertyhistory = vertex.getPropertySet().toArray.map(x => vertex.getPropertyHistory(x).size).sum
val outedgeProperties = vertex.getOutEdges().map(edge => edge.getPropertySet().size).sum
val outedgePropertyHistory = vertex.getOutEdges().map(edge => edge.getPropertySet().toArray.map(x => edge.getPropertyHistory(x).size).sum).sum

val inedgeProperties = vertex.getInEdges().map(edge => edge.getPropertySet().size).sum
val inedgePropertyHistory = vertex.getInEdges().map(edge => edge.getPropertySet().toArray.map(x => edge.getPropertyHistory(x).size).sum).sum

Row(vertex.ID(), inDeg, outDeg, deg, vdeletions, vcreations, outedgedeletions, outedgecreations, inedgedeletions, inedgecreations, properties, propertyhistory, outedgeProperties, outedgePropertyHistory, inedgeProperties, inedgePropertyHistory)
})
.writeTo(path)
}

override def write(table: Table): Unit = {
table.writeTo(path)
}
}

Expand Down
74 changes: 0 additions & 74 deletions src/main/scala/com/raphtory/algorithms/LPA.scala

This file was deleted.

42 changes: 0 additions & 42 deletions src/main/scala/com/raphtory/algorithms/MotifAlpha.scala

This file was deleted.

This file was deleted.

64 changes: 64 additions & 0 deletions src/main/scala/com/raphtory/algorithms/generic/CBOD.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.raphtory.algorithms.generic

import com.raphtory.core.model.algorithm._

/**
Description
Returns outliers detected based on the community structure of the Graph.
The algorithm assumes that the state of each vertex contains a community label (e.g., set by running LPA on the graph, initially)
and then defines an outlier score based on a node's
community membership and how it compares to its neighbors community memberships.
Parameters
label (String) - Identifier for community label
cutoff (Double) - Outlier score threshold (default: 0.0). Identifies the outliers with an outlier score > cutoff.
labeler (GraphAlgorithm) - Community algorithm to run to get labels (does nothing by default, i.e., labels should
be already set on the input graph, either via chaining or defined as properties of the data)
**/
class CBOD(label: String = "label", cutoff: Double = 0.0, output: String = "/tmp/CBOD", labeler:GraphAlgorithm = Identity())
extends GraphAlgorithm {
/**
Run CBOD algorithm and sets "outlierscore" state
**/
override def apply(graph: GraphPerspective): GraphPerspective = {
labeler.apply(graph)
.step { vertex => //Get neighbors' labels
val vlabel = vertex.getState[Long](key = label, includeProperties = true)
vertex.messageAllNeighbours(vlabel)
}
.step { v => // Get outlier score
val vlabel = v.getState[Long](key = label, includeProperties = true)
val neighborLabels = v.messageQueue[Long]
val outlierScore = 1 - (neighborLabels.count(_ == vlabel) / neighborLabels.length.toDouble)
v.setState("outlierscore", outlierScore)
}
}

/**
* extract vertex ID and outlier score for vertices with outlierscore >= threshold
**/
override def tabularise(graph: GraphPerspective): Table = {
graph.select { vertex =>
Row(
vertex.name(),
vertex.getStateOrElse[Double]("outlierscore", 10.0)
)
}
.filter(_.get(1).asInstanceOf[Double] >= cutoff)
}

override def write(table: Table): Unit = {
table.writeTo(output)
}
}

object CBOD {
def apply(
label: String = "label",
cutoff: Double = 0.0,
output: String = "/tmp/CBOD",
labeler: GraphAlgorithm = Identity()
) =
new CBOD(label, cutoff, output, labeler)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.raphtory.algorithms
package com.raphtory.algorithms.generic

import com.raphtory.core.model.algorithm.{GraphAlgorithm, GraphPerspective, Row}
import com.raphtory.core.model.algorithm.{GraphAlgorithm, GraphPerspective, Row, Table}


/**
Expand All @@ -23,7 +23,7 @@ Notes
**/
class ConnectedComponents(path:String) extends GraphAlgorithm{
override def algorithm(graph: GraphPerspective): Unit = {
override def apply(graph: GraphPerspective): GraphPerspective = {
graph
.step({
vertex =>
Expand All @@ -40,8 +40,14 @@ class ConnectedComponents(path:String) extends GraphAlgorithm{
else
vertex.voteToHalt()
}, iterations = 100, executeMessagedOnly = true)
.select(vertex => Row(vertex.ID(),vertex.getState[Long]("cclabel")))
.writeTo(path)
}

override def tabularise(graph: GraphPerspective): Table = {
graph.select(vertex => Row(vertex.name(), vertex.getState[Long]("cclabel")))
}

override def write(table: Table): Unit = {
table.writeTo(path)
}
}

Expand Down
Loading

0 comments on commit 63a9d2b

Please sign in to comment.