8000 Merge branch 'dev' into feature/batch-matmul · DiffSharp/DiffSharp@3c94672 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 3c94672

Browse files
authored
Merge branch 'dev' into feature/batch-matmul
2 parents b93b754 + 9500d66 commit 3c94672

File tree

4 files changed

+3112
-3091
lines changed

4 files changed

+3112
-3091
lines changed

docs/api-overview.fsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@ API Overview
2525
2626
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
2727
28-
For now, [see the API reference](https://diffsharp.github.io/reference/)
28+
* [The `dsharp.*` API](/reference/diffsharp-dsharp.html)
29+
30+
* [Tensors](/reference/diffsharp-tensor.html)
31+
32+
* [Models](/reference/diffsharp-model.html)
33+
34+
* [Optimizers](/reference/diffsharp-optim.html)
35+
36+
* [Distributions](/reference/diffsharp-distributions.html)
37+
38+
* [Data and Data Loaders](/reference/diffsharp-data.html)
2939
3040
*)
3141

src/DiffSharp.Core/DiffSharp.fs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
namespace DiffSharp
21
namespace DiffSharp
32

43
open DiffSharp.Backends
@@ -473,11 +472,11 @@ type dsharp =
473472
/// <param name="high">The upper-bound of the range to be clamped to.</param>
474473
static member clamp(input:Tensor, ?low:scalar, ?high:scalar) = input.clamp(?low=low, ?high=high)
475474

476-
/// <summary>TBD</summary>
475+
/// <summary>Normalizes a vector so all the values are between zero and one (min-max scaling to 0..1).</summary>
477476
/// <param name="input">The input tensor.</param>
478477
static member normalize(input:Tensor) = input.normalize()
479478

480-
/// <summary>TBD</summary>
479+
/// <summary>Returns the tensor after standardization (z-score normalization)</summary>
481480
/// <param name="input">The input tensor.</param>
482481
static member standardize(input:Tensor) = input.standardize()
483482

@@ -1292,6 +1291,9 @@ type dsharp with
12921291
|] |> Array.rev |> Array.append [|fx|]
12931292

12941293
/// <summary>TBD</summary>
1294+
/// <param name="x">TBD</param>
1295+
/// <param name="v">TBD</param>
1296+
/// <remarks>The <c>x</c> and <c>v</c> tensors should have the same number of elements.</remarks>
12951297
static member fjacobianv f (x:Tensor) (v:Tensor) =
12961298
if x.nelement <> v.nelement then failwithf "x and v must have the same number of elements"
12971299
let fx, d = dsharp.evalForwardDiff f x v
@@ -1302,6 +1304,9 @@ type dsharp with
13021304
static member jacobianv f x v = dsharp.fjacobianv f x v |> snd
13031305

13041306
/// <summary>TBD</summary>
1307+
/// <param name="x">TBD</param>
1308+
/// <param name="v">TBD</param>
1309+
/// <remarks>The <c>x</c> and <c>v</c> tensors should have the same number of elements.</remarks>
13051310
static member fgradv f (x:Tensor) (v:Tensor) =
13061311
if x.nelement <> v.nelement then failwithf "x and v must have the same number of elements"
13071312
let fx, d = dsharp.evalForwardDiff f x v
@@ -1338,14 +1343,20 @@ type dsharp with
13381343
/// <summary>TBD</summary>
13391344
static member diff2 f x = dsharp.diffn 2 f x
13401345

1341-
/// <summary>TBD</summary>
1346+
/// <summary>Original value and transposed Jacobian-vector product of a vector-to-vector function `f`, at point `x`, along vector `v`</summary>
1347+
/// <param name="f">vector-to-vector function</param>
1348+
/// <param name="x">Point at which the function <c>f</c> will be evaluated, it must have a single dimension.</param>
1349+
/// <param name="v">Vector</param>
13421350
static member fjacobianTv f x (v:Tensor) =
13431351
let fx, r = dsharp.evalReverseDiff f x
13441352
if x.dim <> 1 || fx.dim <> 1 then failwithf "f must be a vector-valued function of a vector, encountered f:%A->%A" x.shape fx.shape
13451353
if fx.nelement <> v.nelement then failwithf "(f x) and v must have the same number of elements"
13461354
fx, r v
13471355

1348-
/// <summary>TBD</summary>
1356+
/// <summary>Transposed Jacobian-vector product of a vector-to-vector function `f`, at point `x`, along vector `v`</summary>
1357+
/// <param name="f">vector-to-vector function</param>
1358+
/// <param name="x">Point at which the function <c>f</c> will be evaluated, it must have a single dimension.</param>
1359+
/// <param name="v">Vector</param>
13491360
static member jacobianTv f x v = dsharp.fjacobianTv f x v |> snd
13501361

13511362
/// <summary>TBD</summary>

src/DiffSharp.Core/Distributions.fs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,34 @@ module internal Utils =
2525
[<AbstractClass>]
2626
type Distribution<'T>() =
2727

28-
/// <summary>TBD</summary>
29-
abstract member sample: unit -> 'T
28+
/// <summary>Samples the distribution</summary>
29+
abstract sample: unit -> 'T
3030

31-
/// <summary>TBD</summary>
32-
abstract member logprob: 'T -> Tensor
31+
/// <summary>Returns the log-probability of the distribution</summary>
32+
abstract logprob: 'T -> Tensor
3333

3434

3535
[<AbstractClass>]
36-
/// <summary>TBD</summary>
36+
/// <summary>Represents a distribution where sampling returns a tensor</summary>
3737
type TensorDistribution() =
3838
inherit Distribution<Tensor>()
3939

40-
/// <summary>TBD</summary>
40+
/// <summary>Samples the distribution mutliple times</summary>
4141
member d.sample(numSamples:int) = Array.init numSamples (fun _ -> d.sample()) |> dsharp.stack
4242

43-
/// <summary>TBD</summary>
44-
abstract member batchShape: Shape
43+
abstract batchShape: Shape
4544

4645
/// <summary>TBD</summary>
47-
abstract member eventShape: Shape
46+
abstract eventShape: Shape
4847

4948
/// <summary>TBD</summary>
50-
abstract member mean: Tensor
49+
abstract mean: Tensor
5150

5251
/// <summary>TBD</summary>
53-
abstract member stddev: Tensor
52+
abstract stddev: Tensor
5453

5554
/// <summary>TBD</summary>
56-
abstract member variance: Tensor
55+
abstract variance: Tensor
5756

5857
default d.stddev = d.variance.sqrt()
5958
default d.variance = d.stddev * d.stddev
@@ -62,7 +61,7 @@ type TensorDistribution() =
6261
member d.prob(value) = d.logprob(value).exp()
6362

6463

65-
/// <summary>TBD</summary>
64+
/// <summary>Represents a normal distribution with the given mean and standard deviation with the mean and standard deviation drawn fom the given tensors.</summary>
6665
type Normal(mean:Tensor, stddev:Tensor) =
6766
inherit TensorDistribution()
6867
do if mean.shape <> stddev.shape then failwithf "Expecting mean and standard deviation with same shape, received %A, %A" mean.shape stddev.shape
@@ -92,7 +91,7 @@ type Normal(mean:Tensor, stddev:Tensor) =
9291
override d.ToString() = sprintf "Normal(mean:%A, stddev:%A)" d.mean d.stddev
9392

9493

95-
/// <summary>TBD</summary>
94+
/// <summary>Represents a uniform distribution with low and high values drawn from the given tensors.</summary>
9695
type Uniform(low:Tensor, high:Tensor) =
9796
inherit TensorDistribution()
9897
do if low.shape <> high.shape then failwithf "Expecting low and high with same shape, received %A, %A" low.shape high.shape
@@ -133,7 +132,7 @@ type Uniform(low:Tensor, high:Tensor) =
133132
override d.ToString() = sprintf "Uniform(low:%A, high:%A)" d.low d.high
134133

135134

136-
/// <summary>TBD</summary>
135+
/// <summary>Represents a Bernoulli distribution.</summary>
137136
type Bernoulli(?probs:Tensor, ?logits:Tensor) =
138137
inherit TensorDistribution()
139138
let _probs, _logits, _dtype =
@@ -174,7 +173,7 @@ type Bernoulli(?probs:Tensor, ?logits:Tensor) =
174173
override d.ToString() = sprintf "Bernoulli(probs:%A)" d.probs
175174

176175

177-
/// <summary>TBD</summary>
176+
/// <summary>Represents a Categorial distribution.</summary>
178177
type Categorical(?probs:Tensor, ?logits:Tensor) =
179178
inherit TensorDistribution()
180179
let _probs, _logits, _dtype =
@@ -217,11 +216,10 @@ type Categorical(?probs:Tensor, ?logits:Tensor) =
217216
let lp = Array.init d.batchShape.[0] (fun i -> _logits.[i, is.[i]]) |> dsharp.stack
218217
lp.cast(_dtype)
219218

220-
/// <summary>TBD</summary>
221219
override d.ToString() = sprintf "Categorical(probs:%A)" d.probs
222220

223221

224-
/// <summary>TBD</summary>
222+
/// <summary>Represents an Empirical distribution.</summary>
225223
type Empirical<'T when 'T:equality>(values:seq<'T>, ?weights:Tensor, ?logWeights:Tensor, ?combineDuplicates:bool) =
226224
inherit Distribution<'T>()
227225
let _categorical, _weighted =
@@ -369,6 +367,5 @@ type Empirical<'T when 'T:equality>(values:seq<'T>, ?weights:Tensor, ?logWeights
369367

370368
/// <summary>TBD</summary>
371369
372-
/// <summary>TBD</summary>
373370
override d.ToString() = sprintf "Empirical(length:%A)" d.length
374371

0 commit comments

Comments
 (0)
0