Skip to content

Commit

Permalink
Merge pull request #12 from Quafadas/main
Browse files Browse the repository at this point in the history
Start of some docs. Some tests for gamma and log. Design notes tidy
  • Loading branch information
dragonfly-ai authored Sep 18, 2023
2 parents bb9c2be + 26e2e13 commit db4402b
Show file tree
Hide file tree
Showing 57 changed files with 305 additions and 296 deletions.
6 changes: 3 additions & 3 deletions demo/shared/src/main/scala/Demo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ object Demo extends XApp(NativeConsole(style = "padding: 8px; overflow: scroll;"

val allDemos: Array[Demonstration] = Array[Demonstration](
// Math
ai.dragonfly.math.LogDemo,
ai.dragonfly.math.GammaDemo,
ai.dragonfly.math.FactorialDemo,
//ai.dragonfly.math.LogDemo,
//ai.dragonfly.math.GammaDemo,
//ai.dragonfly.math.FactorialDemo,
// TODO: add Interval demo
ai.dragonfly.math.unicode.UnicodeDemo,
// Geometry:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package ai.dragonfly.math
import ai.dragonfly.math
import ai.dragonfly.democrossy.Demonstration

import scala.reflect.ClassTag

object BijectionDemo extends Demonstration {

object H2O {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ai.dragonfly.math

import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.*
import ai.dragonfly.math.Factorial.!
import scala.language.postfixOps

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ai.dragonfly.math.geometry

import ai.dragonfly.math.stats.probability.distributions.Sampleable
import ai.dragonfly.math.interval.*
import Interval.*

import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.vector.*
import Vec.*
import ai.dragonfly.math.geometry.Tetrahedron


object TetrahedronDemo extends Demonstration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ai.dragonfly.math.matrix

import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.matrix.Matrix
import ai.dragonfly.math.matrix.decomposition.*
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import ai.dragonfly.math.matrix.ml.data.StaticSupervisedData
import ai.dragonfly.math.matrix.ml.supervized.regression.{LinearRegressionQR, LinearRegressionSVD, *}
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import ai.dragonfly.math.vector.Vec2.*
import ai.dragonfly.viz.cli.*
import ai.dragonfly.math.interval.*
import scala.compiletime.ops.int.*

object DemoLinearRegression extends Demonstration {

Expand Down Expand Up @@ -60,7 +58,7 @@ object DemoLinearRegression extends Demonstration {
val xSlopeSVD: Double = slrSVD(p + Vec[2](1.0, 0.0)) - yMean
val ySlopeSVD: Double = slrSVD(p + Vec[2](0.0, 1.0)) - yMean

val c = yMean / slrSVD.a.magnitude
yMean / slrSVD.a.magnitude
xPlot.line(Vec[2](p(0), yMean), xSlopeSVD, "SVD (p.x, f'(p))")
yPlot.line(Vec[2](p(1), yMean), ySlopeSVD, "SVD (p.y, f'(p))")

Expand All @@ -73,7 +71,7 @@ object DemoLinearRegression extends Demonstration {
val elrt: EmpiricalRegressionTest[100, 8] = EmpiricalRegressionTest[100, 8](empericalTrainingData, empericalTestData)
val emProbLR: LinearRegressionProblem[100, 8] = LinearRegressionProblem[100, 8](empericalTrainingData)

val size: Double = empericalTrainingData.sampleSize
println(empericalTrainingData.sampleSize)

println("\nTest LinearRegressionQR:\n")
val elrQR = new LinearRegressionQR[100, 8].train(emProbLR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ import ai.dragonfly.math.matrix.ml.data.*
import ai.dragonfly.math.matrix.ml.unsupervised.dimreduction.PCA
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import ai.dragonfly.math.vector.Vec2.*
import ai.dragonfly.math.interval
import ai.dragonfly.viz.cli.CLImg

import Console.*

object DemoPCA extends Demonstration {

import interval.*

def demo(): Unit = {

// 2D shapes represented by centered 2D meshes of exactly 9 points each.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ai.dragonfly.math.matrix

import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.matrix.Matrix
import ai.dragonfly.math.matrix.util.*
import ai.dragonfly.math.matrix.decomposition.*
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import ai.dragonfly.math.vector.Vec2.*
Expand All @@ -15,7 +13,7 @@ object DemoVectorInterop extends Demonstration {
def demo(): Unit = {
val M0: Matrix[2, 3] = Matrix[2, 3](
NArray[NArray[Double]](
NArray[Double](1.0, `𝜑`, `√2`),
NArray[Double](1.0, 1.46557123187676802665, `√2`),
NArray[Double](2.0, π, e),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ package ai.dragonfly.math.stats.kernel
*/

import ai.dragonfly.math.*
import Constant.{`√(2π)`, π}
import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.stats.DenseHistogramOfContinuousDistribution
import ai.dragonfly.math.stats.probability.distributions.Gaussian
import ai.dragonfly.math.vector.*
import narr.*

import scala.collection.mutable

object KernelDemo extends Demonstration {
override def demo():Unit = {
val exclusionRadius:Double = 12.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ai.dragonfly.math.stats.probability.distributions

import ai.dragonfly.math.*
import stats.*
import interval.*
import Interval.*

object BetaDemo {
val demo2param = ProbDistDemo("Beta", Beta(0.5, 5.0), DenseHistogramOfContinuousDistribution(9, 0, 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package ai.dragonfly.math.stats.probability.distributions

import ai.dragonfly.math.*
import stats.*
import ai.dragonfly.math.Factorial.!
import ai.dragonfly.math.interval.*
import Interval.*


import scala.language.postfixOps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ai.dragonfly.math.stats.probability.distributions

import ai.dragonfly.math.*
import stats.*
import ai.dragonfly.math.interval.*
import Interval.*

import scala.language.postfixOps

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package ai.dragonfly.math.stats.probability.distributions

import ai.dragonfly.math.*
import Constant.`√(2π)`
import stats.*
import ai.dragonfly.math.stats.probability.distributions.ProbabilityDistribution
import interval.*



object GaussianDemo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ai.dragonfly.math.stats.probability.distributions

import ai.dragonfly.math.*
import stats.*
import interval.*
import Constant.π

// https://en.wikipedia.org/wiki/Log-normal_distribution#Generation_and_parameters

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package ai.dragonfly.math.stats.probability.distributions


import ai.dragonfly.math.{ProbDistDemo, Random}
import ai.dragonfly.math.{ProbDistDemo}
import ai.dragonfly.math.stats.*
import ai.dragonfly.math.interval.*
import Interval.*
import ai.dragonfly.math.stats.BoundedMean

object PERTDemo {
val demo = ProbDistDemo("PERT", PERT(5.0, 6.0, 11.0), DenseHistogramOfContinuousDistribution(11, 5.0, 11.0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ai.dragonfly.math.stats.probability.distributions

import ai.dragonfly.math.*
import stats.*
import interval.*

object PoissonDemo {
val p15:Poisson = Poisson(15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package ai.dragonfly.math.stats.probability.distributions
import ai.dragonfly.math.*

import stats.*
import ai.dragonfly.math.interval.*
import Interval.*


import scala.language.postfixOps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package ai.dragonfly.math.stats.probability.distributions.stream

import ai.dragonfly.math.stats.probability.distributions
import ai.dragonfly.math.*
import ai.dragonfly.math.interval.*
import Interval.*
import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.stats.BoundedMean


import scala.language.postfixOps
import scala.language.implicitConversions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package ai.dragonfly.math.stats.probability.distributions.stream

import ai.dragonfly.math.*
import ai.dragonfly.math.interval.*
import Interval.*
import ai.dragonfly.math.stats.probability.distributions
import ai.dragonfly.math.stats.PointStatistics


object LogNormalDemo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.*
import ai.dragonfly.math.stats.probability.distributions
import ai.dragonfly.math.stats.probability.distributions.stream
import ai.dragonfly.math.stats.probability.distributions.ProbabilityDistribution
import ai.dragonfly.math.stats.BoundedMean


object PERTDemo extends Demonstration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.*
import ai.dragonfly.math.Random.*
import ai.dragonfly.math.vector.Vec.*
import ai.dragonfly.math.vector.Vec2.*
import narr.*

import scala.language.postfixOps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ai.dragonfly.math.vector

import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.squareInPlace
import narr.*
import Vec.*

Expand Down
12 changes: 12 additions & 0 deletions docs/demo/factorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Factorial

Example

```scala mdoc
import scala.language.postfixOps // don't forget this import
import ai.dragonfly.math.Factorial.!
for (x:Int <- Seq(1, 2, 3, 4, 8, 16, 32, 64, 100)) {
println(s"${x}! = ${x!}")
}

```
22 changes: 22 additions & 0 deletions docs/demo/logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Logarithms

Example

```scala mdoc
import ai.dragonfly.math.*
import ai.dragonfly.math.Constant

log[4](16)

log[10](-1)

log[2.7182818284590452](Constant.e)

println( s"log[2.0](42.0) = ${log[2.0](42.0)}" )
var i: Int = 1; while (i > 0) {
println( s"log[2]($i) = ${log[2](i)}" )
i = i << 1
}


```
Loading

0 comments on commit db4402b

Please sign in to comment.