|
| 1 | +using System.Collections.Generic; |
| 2 | + |
1 | 3 | namespace Tensorflow |
2 | 4 | { |
3 | 5 | class Normal : Distribution |
4 | 6 | { |
5 | | - public Normal (Tensor loc, Tensor scale, bool validate_args=false, bool allow_nan_stats=true, string name="Normal") |
| 7 | + public Tensor _loc { get; set; } |
| 8 | + public Tensor _scale { get; set; } |
| 9 | + |
| 10 | + Dictionary<string, object> parameters = new Dictionary<string, object>(); |
| 11 | + /// <summary> |
| 12 | + /// The Normal distribution with location `loc` and `scale` parameters. |
| 13 | + /// Mathematical details |
| 14 | + /// The probability density function(pdf) is, |
| 15 | + /// ''' |
| 16 | + /// pdf(x; mu, sigma) = exp(-0.5 (x - mu)**2 / sigma**2) / Z |
| 17 | + /// Z = (2 pi sigma**2)**0.5 |
| 18 | + /// ''' |
| 19 | + /// where `loc = mu` is the mean, `scale = sigma` is the std.deviation, and, `Z` |
| 20 | + /// is the normalization constant. |
| 21 | + /// </summary> |
| 22 | + /// <param name="loc"></param> |
| 23 | + /// <param name="scale"></param> |
| 24 | + /// <param name="validate_args"></param> |
| 25 | + /// <param name="allow_nan_stats"></param> |
| 26 | + /// <param name="name"></param> |
| 27 | + public Normal (Tensor loc, Tensor scale, bool validate_args=false, bool allow_nan_stats=true, string name="Normal") |
| 28 | + { |
| 29 | + parameters.Add("name", name); |
| 30 | + parameters.Add("loc", loc); |
| 31 | + parameters.Add("scale", scale); |
| 32 | + parameters.Add("validate_args", validate_args); |
| 33 | + parameters.Add("allow_nan_stats", allow_nan_stats); |
| 34 | + |
| 35 | + with(new ops.name_scope(name, "", new { loc, scale }), scope => |
| 36 | + { |
| 37 | + with(ops.control_dependencies(validate_args ? new Operation[] { scale.op} : new Operation[] { }), cd => |
| 38 | + { |
| 39 | + this._loc = array_ops.identity(loc, name); |
| 40 | + this._scale = array_ops.identity(scale, name); |
| 41 | + base._dtype = this._scale.dtype; |
| 42 | + base._reparameterization_type = new ReparameterizationType("FULLY_REPARAMETERIZED"); |
| 43 | + base._validate_args = validate_args; |
| 44 | + base._allow_nan_stats = allow_nan_stats; |
| 45 | + base._parameters = parameters; |
| 46 | + base._graph_parents = new List<Tensor>(new Tensor[] { this._loc, this._scale }); |
| 47 | + base._name = name; |
| 48 | + }); |
| 49 | + |
| 50 | + }); |
| 51 | + |
| 52 | + } |
| 53 | + /// <summary> |
| 54 | + /// Distribution parameter for the mean. |
| 55 | + /// </summary> |
| 56 | + /// <returns></returns> |
| 57 | + public Tensor loc() |
| 58 | + { |
| 59 | + return this._loc; |
| 60 | + } |
| 61 | + /// <summary> |
| 62 | + /// Distribution parameter for standard deviation." |
| 63 | + /// </summary> |
| 64 | + /// <returns></returns> |
| 65 | + public Tensor scale() |
| 66 | + { |
| 67 | + return this._scale; |
| 68 | + } |
| 69 | + |
| 70 | + public Tensor _batch_shape_tensor() |
| 71 | + { |
| 72 | + return array_ops.broadcast_dynamic_shape(array_ops.shape(this._loc), array_ops.shape(this._scale)); |
| 73 | + } |
| 74 | + |
| 75 | + public Tensor _batch_shape() |
6 | 76 | { |
7 | | - |
| 77 | + return array_ops.broadcast_static_shape(new Tensor(this._loc.shape), new Tensor(this._scale.shape)); |
8 | 78 | } |
9 | 79 |
|
10 | 80 | } |
|
0 commit comments