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

Entropy monitor #11

Merged
merged 5 commits into from
Jul 31, 2023
Merged
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
3 changes: 2 additions & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-XX:+UseG1GC
-XX:+UseStringDeduplication
-Xmx8G
-Xms8g
-Xmx28g
-Xss4M
28 changes: 15 additions & 13 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
version = 2.7.5

version = 3.5.9
maxColumn = 120

align.arrowEnumeratorGenerator = true
align.openParenCallSite = true
align.preset=more
continuationIndent.defnSite = 4
style = defaultWithAlign
danglingParentheses.preset = true
includeCurlyBraceInSelectChains = false
newlines.alwaysBeforeTopLevelStatements = true
newlines.penalizeSingleSelectMultiArgList = false
indentOperator.preset = "spray"
align.arrowEnumeratorGenerator = true
align.openParenCallSite = false
align.openParenDefnSite = false
align.tokens = [{code = "="}, {code = "<-"}, {code = ":="}, {code = "->"}, {code = "%"}, {code = "%%"}]
continuationIndent.callSite = 2
continuationIndent.defnSite = 2
optIn.breakChainOnFirstMethodDot = true
optIn.configStyleArguments = true

spaces {
inImportCurlyBraces = true
}

project.git = true
rewrite.rules = [ RedundantBraces, RedundantParens, PreferCurlyFors]
runner.optimizer.forceConfigStyleOnOffset = 120
runner.optimizer.forceConfigStyleMinArgCount = 3
runner.dialect = scala213
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A few aspects differentiate Thylacine from other Bayesian inference frameworks:
* Framework and design largely de-coupled from Bayesian graphical representations of the problem (more details in the FAQ below)
* Designed to be multi-threaded from the ground up using a high-performance Software Transactional Memory (STM) implementation to facilitate efficient concurrency across the differing computational profiles for sampling, integration, visualisation, etc.
* Analytic gradient calculations can be specified on a component level that enables automatic differentiation to be used in gradient calculations. This is essential if aiming to perform high-dimension inference using gradient information.
* A growing list of advanced algorithms/concepts have already been implementated:
* A growing list of advanced algorithms/concepts have already been implemented:
* Gaussian analytic posteriors
* Optimisation
* Hooke & Jeeves
Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
ThisBuild / baseVersion := "0.5.0"
ThisBuild / baseVersion := "0.6.0"

ThisBuild / organization := "ai.entrolution"
ThisBuild / organizationName := "Greg von Nessi"
ThisBuild / organization := "ai.entrolution"
ThisBuild / organizationName := "Greg von Nessi"
ThisBuild / publishGithubUser := "gvonness"
ThisBuild / publishFullName := "Greg von Nessi"
ThisBuild / publishFullName := "Greg von Nessi"

ThisBuild / homepage := Some(url("https://github.com/gvonness/thylacine"))
ThisBuild / scmInfo := Some(
ScmInfo(url("https://github.com/gvonness/thylacine"), "git@github.com:gvonness/thylacine.git")
)

ThisBuild / startYear := Some(2020)
ThisBuild / endYear := Some(2022)
ThisBuild / endYear := Some(2022)

ThisBuild / spiewakCiReleaseSnapshots := false
ThisBuild / spiewakMainBranches := Seq("main")
ThisBuild / spiewakMainBranches := Seq("main")

ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local"
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local"

scalaVersion := DependencyVersions.scala2p13Version
scalaVersion := DependencyVersions.scala2p13Version
ThisBuild / crossScalaVersions := Seq(DependencyVersions.scala2p13Version)

Global / idePackagePrefix := Some("ai.entrolution")
Expand Down
6 changes: 3 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sbt._
import sbt.*

object DependencyVersions {
val scala2p13Version = "2.13.11"

val bengalStmVersion = "0.9.2"
val bengalStmVersion = "0.9.3"
val bigMathVersion = "2.3.0"
val breezeVersion = "2.1.0"
val catsEffectVersion = "3.4.8"
Expand All @@ -13,7 +13,7 @@ object DependencyVersions {
}

object Dependencies {
import DependencyVersions._
import DependencyVersions.*

private val bengalStm: ModuleID =
"ai.entrolution" %% "bengal-stm" % bengalStmVersion
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.1
sbt.version=1.9.2
8 changes: 4 additions & 4 deletions src/main/scala/thylacine/config/ConjugateGradientConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package ai.entrolution
package thylacine.config

case class ConjugateGradientConfig(
convergenceThreshold: Double,
goldenSectionTolerance: Double,
lineProbeExpansionFactor: Double,
numberOfResultsToRetain: Int
convergenceThreshold: Double,
goldenSectionTolerance: Double,
lineProbeExpansionFactor: Double,
numberOfResultsToRetain: Int
)
8 changes: 4 additions & 4 deletions src/main/scala/thylacine/config/CoordinateSlideConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package ai.entrolution
package thylacine.config

case class CoordinateSlideConfig(
convergenceThreshold: Double,
goldenSectionTolerance: Double,
lineProbeExpansionFactor: Double,
numberOfPriorSamplesToSetScale: Option[Int]
convergenceThreshold: Double,
goldenSectionTolerance: Double,
lineProbeExpansionFactor: Double,
numberOfPriorSamplesToSetScale: Option[Int]
)
10 changes: 5 additions & 5 deletions src/main/scala/thylacine/config/HmcmcConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package ai.entrolution
package thylacine.config

case class HmcmcConfig(
stepsBetweenSamples: Int,
stepsInDynamicsSimulation: Int,
warmupStepCount: Int,
dynamicsSimulationStepSize: Double,
sampleParallelism: Option[Int]
stepsBetweenSamples: Int,
stepsInDynamicsSimulation: Int,
warmupStepCount: Int,
dynamicsSimulationStepSize: Double,
sampleParallelism: Option[Int]
)
4 changes: 2 additions & 2 deletions src/main/scala/thylacine/config/HookeAndJeevesConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package ai.entrolution
package thylacine.config

case class HookeAndJeevesConfig(
convergenceThreshold: Double,
numberOfPriorSamplesToSetScale: Option[Int]
convergenceThreshold: Double,
numberOfPriorSamplesToSetScale: Option[Int]
)
6 changes: 3 additions & 3 deletions src/main/scala/thylacine/config/LeapfrogMcmcConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package ai.entrolution
package thylacine.config

case class LeapfrogMcmcConfig(
stepsBetweenSamples: Int,
warmupStepCount: Int,
samplePoolSize: Int
stepsBetweenSamples: Int,
warmupStepCount: Int,
samplePoolSize: Int
)
8 changes: 4 additions & 4 deletions src/main/scala/thylacine/config/MdsConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package ai.entrolution
package thylacine.config

case class MdsConfig(
convergenceThreshold: Double,
expansionMultiplier: Double,
contractionMultiplier: Double,
numberOfPriorSamplesToSetStartingPoint: Option[Int]
convergenceThreshold: Double,
expansionMultiplier: Double,
contractionMultiplier: Double,
numberOfPriorSamplesToSetStartingPoint: Option[Int]
)
14 changes: 7 additions & 7 deletions src/main/scala/thylacine/config/SlqConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package ai.entrolution
package thylacine.config

case class SlqConfig(
poolSize: Int,
abscissaNumber: Int,
domainScalingIncrement: Double,
targetAcceptanceProbability: Double,
sampleParallelism: Int,
maxIterationCount: Int,
minIterationCount: Int
poolSize: Int,
abscissaNumber: Int,
domainScalingIncrement: Double,
targetAcceptanceProbability: Double,
sampleParallelism: Int,
maxIterationCount: Int,
minIterationCount: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private[thylacine] trait ForwardModel[F[_]] extends GenericMapping with CanValid
// Note that input validation should be done within
// the surrounding likelihood
private[thylacine] def evalAt(
input: IndexedVectorCollection
input: IndexedVectorCollection
): F[VectorContainer]

private[thylacine] final def evalAt(input: Map[String, Vector[Double]]): F[Vector[Double]] =
Expand All @@ -37,7 +37,7 @@ private[thylacine] trait ForwardModel[F[_]] extends GenericMapping with CanValid
// Note that input validation should be done within
// the surrounding likelihood
private[thylacine] def jacobianAt(
input: IndexedVectorCollection
input: IndexedVectorCollection
): F[IndexedMatrixCollection]

private[thylacine] final def jacobianAt(input: Map[String, Vector[Double]]): F[Map[String, Vector[Vector[Double]]]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package thylacine.model.components.forwardmodel
import thylacine.model.core.StmImplicits
import thylacine.model.core.computation.CachedComputation
import thylacine.model.core.values.IndexedVectorCollection.ModelParameterCollection
import thylacine.model.core.values.{IndexedMatrixCollection, VectorContainer}
import thylacine.model.core.values.{ IndexedMatrixCollection, VectorContainer }

private[thylacine] trait InMemoryMemoizedForwardModel[F[_]] extends ForwardModel[F] {
this: StmImplicits[F] =>
Expand All @@ -29,12 +29,12 @@ private[thylacine] trait InMemoryMemoizedForwardModel[F[_]] extends ForwardModel
protected val jacobianCache: CachedComputation[F, IndexedMatrixCollection]

private[thylacine] override final def evalAt(
input: ModelParameterCollection
input: ModelParameterCollection
): F[VectorContainer] =
evalCache.performComputation(input)

private[thylacine] override def jacobianAt(
input: ModelParameterCollection
input: ModelParameterCollection
): F[IndexedMatrixCollection] =
jacobianCache.performComputation(input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import thylacine.model.core.computation.CachedComputation
import thylacine.model.core.values._
import thylacine.model.core.values.modelparameters.ModelParameterContext

import breeze.linalg.{DenseMatrix, DenseVector}
import breeze.linalg.{ DenseMatrix, DenseVector }
import cats.effect.kernel.Async
import cats.syntax.all._

Expand All @@ -33,13 +33,13 @@ import scala.annotation.unused
// A linear forward model may work across more than
// one model parameter generator
case class LinearForwardModel[F[_]: STM: Async](
protected override val evalCache: CachedComputation[F, VectorContainer],
protected override val jacobianCache: CachedComputation[F, IndexedMatrixCollection],
private[thylacine] val transform: IndexedMatrixCollection,
private[thylacine] val vectorOffset: Option[VectorContainer],
override val domainDimension: Int,
override val rangeDimension: Int,
private[thylacine] override val validated: Boolean = false
protected override val evalCache: CachedComputation[F, VectorContainer],
protected override val jacobianCache: CachedComputation[F, IndexedMatrixCollection],
private[thylacine] val transform: IndexedMatrixCollection,
private[thylacine] val vectorOffset: Option[VectorContainer],
override val domainDimension: Int,
override val rangeDimension: Int,
private[thylacine] override val validated: Boolean = false
) extends StmImplicits[F]
with InMemoryMemoizedForwardModel[F] {
if (!validated) {
Expand All @@ -54,9 +54,9 @@ case class LinearForwardModel[F[_]: STM: Async](
this
} else {
this.copy(
transform = transform.getValidated,
transform = transform.getValidated,
vectorOffset = vectorOffset.map(_.getValidated),
validated = true
validated = true
)
}

Expand All @@ -66,17 +66,17 @@ case class LinearForwardModel[F[_]: STM: Async](
transform

private[thylacine] override def jacobianAt(
input: IndexedVectorCollection
input: IndexedVectorCollection
): F[IndexedMatrixCollection] =
Async[F].pure(getJacobian)
}

object LinearForwardModel {

def of[F[_]: STM: Async](
transform: IndexedMatrixCollection,
vectorOffset: Option[VectorContainer],
evalCacheDepth: Option[Int]
transform: IndexedMatrixCollection,
vectorOffset: Option[VectorContainer],
evalCacheDepth: Option[Int]
): F[LinearForwardModel[F]] = {
val rangeDimension: Int =
transform.index.head._2.rowTotalNumber
Expand Down Expand Up @@ -109,7 +109,7 @@ object LinearForwardModel {
}

def transformedEval(
input: IndexedVectorCollection
input: IndexedVectorCollection
): VectorContainer =
VectorContainer(applyOffset(rawMatrixTransform * rawMappings.modelParameterCollectionToRawVector(input)))

Expand All @@ -125,37 +125,37 @@ object LinearForwardModel {

@unused
private[thylacine] def of[F[_]: STM: Async](
identifier: ModelParameterIdentifier,
values: Vector[Vector[Double]],
evalCacheDepth: Option[Int]
identifier: ModelParameterIdentifier,
values: Vector[Vector[Double]],
evalCacheDepth: Option[Int]
): F[LinearForwardModel[F]] =
of[F](
transform = IndexedMatrixCollection(identifier, values),
vectorOffset = None,
transform = IndexedMatrixCollection(identifier, values),
vectorOffset = None,
evalCacheDepth = evalCacheDepth
)

def of[F[_]: STM: Async](
label: String,
values: Vector[Vector[Double]],
evalCacheDepth: Option[Int]
label: String,
values: Vector[Vector[Double]],
evalCacheDepth: Option[Int]
): F[LinearForwardModel[F]] =
of[F](
transform = IndexedMatrixCollection(ModelParameterIdentifier(label), values),
vectorOffset = None,
transform = IndexedMatrixCollection(ModelParameterIdentifier(label), values),
vectorOffset = None,
evalCacheDepth = evalCacheDepth
)

@unused
def identityOf[F[_]: STM: Async](
label: String,
dimension: Int,
evalCacheDepth: Option[Int]
label: String,
dimension: Int,
evalCacheDepth: Option[Int]
): F[LinearForwardModel[F]] =
of[F](
transform = IndexedMatrixCollection
.squareIdentity(ModelParameterIdentifier(label), dimension),
vectorOffset = None,
vectorOffset = None,
evalCacheDepth = evalCacheDepth
)
}
Loading
Loading