/// <summary> /// Constructor /// </summary> /// <param name="rate">rate = 1 / scale of the distribution (often referred to as 'β')</param> /// <param name="generator">An optional random number generator object.</param> public Exponential(Tensor rate, torch.Generator generator = null) : base(generator) { var locScale = torch.broadcast_tensors(rate); this.batch_shape = rate.size(); this.rate = locScale[0]; }
/// <summary> /// Constructor /// </summary> /// <param name="probs">The probability of sampling '1'. Must be in range (0, 1]</param> /// <param name="logits">The log-odds of sampling '1'</param> /// <param name="generator">An optional random number generator object.</param> public Geometric(Tensor probs = null, Tensor logits = null, torch.Generator generator = null) : base(generator) { this.batch_shape = probs is null?logits.size() : probs.size(); this._probs = probs; this._logits = logits; }
/// <summary> /// Constructor /// </summary> /// <param name="low">Lower bound (inclusive)</param> /// <param name="high">Upper bound (exclusive)</param> /// <param name="generator">An optional random number generator object.</param> public Uniform(Tensor low, Tensor high, torch.Generator generator = null) : base(generator, low.size()) { var lowHigh = torch.broadcast_tensors(low, high); this.low = lowHigh[0]; this.high = lowHigh[1]; }
/// <summary> /// Constructor /// </summary> /// <param name="loc">Mode or median of the distribution.</param> /// <param name="scale">Half width at half maximum.</param> /// <param name="generator">An optional random number generator object.</param> public Cauchy(Tensor loc, Tensor scale, torch.Generator generator = null) : base(generator) { this.batch_shape = loc.size(); var locScale = torch.broadcast_tensors(loc, scale); this.loc = locScale[0]; this.scale = locScale[1]; }
/// <summary> /// Constructor /// </summary> /// <param name="concentration">Shape parameter of the distribution (often referred to as 'α')</param> /// <param name="rate">rate = 1 / scale of the distribution (often referred to as 'β')</param> /// <param name="generator">An optional random number generator object.</param> public Gamma(Tensor concentration, Tensor rate, torch.Generator generator = null) : base(generator) { var locScale = torch.broadcast_tensors(concentration, rate); this.concentration = locScale[0]; this.rate = locScale[1]; this.batch_shape = this.concentration.size(); }
/// <summary> /// Constructor /// </summary> /// <param name="concentration">Shape parameter of the distribution (often referred to as 'α')</param> /// <param name="generator">An optional random number generator object.</param> public Dirichlet(Tensor concentration, torch.Generator generator = null) : base(generator) { var cshape = concentration.shape; this.batch_shape = cshape.Take(cshape.Length - 1).ToArray(); this.event_shape = new long[] { cshape[cshape.Length - 1] }; this.concentration = concentration; }
/// <summary> /// Constructor /// </summary> /// <param name="probs">Event probabilities</param> /// <param name="logits">Even log-odds</param> /// <param name="generator">An optional random number generator object.</param> public Categorical(Tensor probs = null, Tensor logits = null, torch.Generator generator = null) : base(generator) { var param = probs is null ? logits : probs; this._probs = (probs is not null) ? probs / probs.sum(-1, keepdim: true) : null; this._logits = (logits is not null) ? (logits - logits.logsumexp(-1, keepdim: true)) : null; this.num_events = param.size(-1); this.batch_shape = param.ndim > 1 ? param.shape.Take(param.shape.Length - 1).ToArray() : new long[0]; }
private Multinomial(int total_count, Categorical categorical, torch.Generator generator = null) : base(generator) { this.total_count = total_count; this.categorical = categorical; this.batch_shape = categorical.batch_shape; var ps = categorical.param_shape; this.event_shape = new long[] { ps[ps.Length - 1] }; }
// Note that the order of the arguments is not a mistake -- the original source has them // ordered this way. public Beta(Tensor concentration1, Tensor concentration0, torch.Generator generator = null) : base(generator) { var bcast = torch.broadcast_tensors(concentration1, concentration0); this.concentration1 = bcast[0]; this.concentration0 = bcast[1]; this.dirichlet = new Dirichlet(torch.stack(bcast, -1), generator); this.batch_shape = this.dirichlet.batch_shape; }
/// <summary> /// Constructor /// </summary> /// <param name="df1">Degrees of freedom parameter 1</param> /// <param name="df2">Degrees of freedom parameter 2</param> /// <param name="generator">An optional random number generator object.</param> public FisherSnedecor(Tensor df1, Tensor df2, torch.Generator generator = null) : base(generator) { var bcast = torch.broadcast_tensors(df1, df2); this.df1 = bcast[0]; this.df2 = bcast[1]; this.gamma1 = new Gamma(this.df1 * 0.5, this.df1, generator); this.gamma2 = new Gamma(this.df2 * 0.5, this.df2, generator); this.batch_shape = this.df1.size(); }
/// <summary> /// Constructor /// </summary> /// <param name="p"></param> /// <param name="l"></param> /// <param name="generator"></param> public Bernoulli(Tensor p = null, Tensor l = null, torch.Generator generator = null) : base(generator) { if ((p is null && logits is null) || (p is not null && l is not null)) { throw new ArgumentException("One and only one of 'probs' and logits should be provided."); } this.batch_shape = p is null?l.size() : p.size(); this._probs = p; this._logits = l; }
public Binomial(Tensor total_count, Tensor p = null, Tensor l = null, torch.Generator generator = null) : base(generator) { this.batch_shape = p is null?l.size() : p.size(); this._probs = p; this._logits = l; this.generator = generator; var broadcast = (p is null) ? torch.broadcast_tensors(total_count, l) : torch.broadcast_tensors(total_count, p); this.total_count = broadcast[0].type_as(p ?? l); }
/// <summary> /// Constructor /// </summary> /// <param name="total_count">Number of Bernoulli trials</param> /// <param name="probs">The probability of sampling '1'</param> /// <param name="logits">The log-odds of sampling '1'</param> /// <param name="generator">An optional random number generator object.</param> public Multinomial(int total_count, Tensor probs = null, Tensor logits = null, torch.Generator generator = null) : base(generator) { this.total_count = total_count; this.categorical = new Categorical(probs, logits); this.batch_shape = this.categorical.batch_shape; var ps = this.categorical.param_shape; this.event_shape = new long[] { ps[ps.Length - 1] }; }
/// <summary> /// Constructor /// </summary> /// <param name="df">Shape parameter of the distribution</param> /// <param name="generator">An optional random number generator object.</param> public Chi2(Tensor df, torch.Generator generator = null) : base(df * 0.5, torch.tensor(0.5), generator) { }