Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define probability monad by using simulacrum. #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Dependencies._

scalacOptions += "-Ypartial-unification"
scalacOptions ++= Seq("-Ypartial-unification", "-Ymacro-annotations")

lazy val commonSettings = Seq(
organization := "com.github.sdual",
Expand All @@ -9,6 +9,9 @@ lazy val commonSettings = Seq(
)

lazy val root = (project in file("."))
.settings(
name := "stanz"
)
.aggregate(
prototype,
example
Expand All @@ -17,8 +20,8 @@ lazy val root = (project in file("."))
lazy val core = (project in file("core"))
.settings(
commonSettings,
name := "stanz",
libraryDependencies ++= stanzCommonDependencies,
name := "core",
libraryDependencies ++= stanzCoreDependencies,
)

lazy val prototype = (project in file("prototype"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.sdual.stanz.distribution

import simulacrum.typeclass

import scala.util.Random

@typeclass trait Distribution[A] {
//def sample(dist: Distribution[A])(random: Random): A
}

object Distribution {
case class Point[P](value: P) extends Distribution[P]
case class FlatMap[P0, P1](dist: Distribution[P0], f: P0 => Distribution[P1]) extends Distribution[P1]
case class Primitive[P](fa: PrimitiveDistribution[P]) extends Distribution[P]
case class Conditional[P](dist: Distribution[P], likelihood: P => Probability) extends Distribution[P]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.sdual.stanz.distribution

trait PrimitiveDistribution[P] {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.sdual.stanz

package object distribution {
type Probability = Double
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.sdual.stanz.typeclass

import simulacrum.typeclass

@typeclass trait Applicative[F[_]] extends Functor[F] {
def pure[A](a: => A): F[A]
def ap[A, B](fa: => F[A])(f: => F[A => B]): F[B]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.sdual.stanz.typeclass

import simulacrum.typeclass

@typeclass trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.sdual.stanz.typeclass

import simulacrum.typeclass

@typeclass trait Monad[F[_]] extends Applicative[F] {
def point[A](a: => A): F[A] = pure(a)
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.sdual.stanz.typeclass

import simulacrum.typeclass

import scala.util.Random

@typeclass trait Sampleable[F[_]] {
def sample[A](fa: F[A])(random: Random): A
}
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Dependencies {
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
val scalaMock = "org.scalamock" %% "scalamock" % "4.1.0"
val apacheCommonsMath = "org.apache.commons" % "commons-math3" % "3.6.1"
val cats = "org.typelevel" %% "cats-core" % "2.0.0"
val simulacrum = "org.typelevel" %% "simulacrum" % "1.0.0"

val stanzCommonDependencies = Seq(
apacheCommonsMath,
Expand All @@ -14,7 +14,7 @@ object Dependencies {
)

val stanzCoreDependencies = Seq(
cats
simulacrum
) ++ stanzCommonDependencies

}