File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/probability Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1+ package io .github .mandar2812 .dynaml
2+
3+ import scalaxy .streams .optimize
4+ import spire .algebra .InnerProductSpace
5+
6+ /**
7+ * Created by mandar on 11/01/2017.
8+ */
9+ package object probability {
10+
11+ var candidates : Int = 10000
12+
13+ def E [@ specialized(Double ) I ](rv : RandomVariable [I ])(implicit f : InnerProductSpace [I , Double ]): I = optimize {
14+ f.divr(
15+ rv.iid(candidates)
16+ .sample()
17+ .reduce(
18+ (x, y) => f.plus(x,y)
19+ ),
20+ candidates.toDouble)
21+ }
22+
23+
24+ def E (rv : RandomVariable [Double ]): Double = optimize {
25+ rv.iid(candidates).sample().sum/ candidates.toDouble
26+ }
27+
28+
29+ }
Original file line number Diff line number Diff line change 11import io .github .mandar2812 .dynaml .DynaMLPipe ._
22import io .github .mandar2812 .dynaml .analysis .{DifferentiableMap , PushforwardMap }
33import io .github .mandar2812 .dynaml .pipes .DataPipe
4- import io .github .mandar2812 .dynaml .probability .{GaussianRV , RandomVariable }
4+ import io .github .mandar2812 .dynaml .probability .{E , GaussianRV , RandomVariable }
55import spire .implicits ._
66import com .quantifind .charts .Highcharts ._
77import io .github .mandar2812 .dynaml .probability .distributions .SkewGaussian
@@ -34,3 +34,5 @@ spline(x.toIterable)
3434unhold()
3535legend(List (" Log Skew Gaussian" , " Log Gaussian" ))
3636title(" Probability Density Functions" )
37+
38+ println(" E[Q] = " + E (q))
You can’t perform that action at this time.
0 commit comments