public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Categorical)) { throw new ArgumentException("expand(): 'instance' must be a Categorical distribution"); } var param_shape = new List <long>(); param_shape.AddRange(batch_shape); param_shape.Add(num_events); var shape = param_shape.ToArray(); var p = _probs?.expand(shape); var l = _logits?.expand(shape); var newDistribution = ((instance == null) ? new Categorical(p, l) : instance) as Categorical; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.num_events = this.num_events; newDistribution._probs = p; newDistribution._logits = l; } return(newDistribution); }
public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Gamma)) { throw new ArgumentException("expand(): 'instance' must be a Chi2 distribution"); } if (instance == null) { instance = new Chi2(concentration); } return(base.expand(batch_shape, instance)); }
/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Cauchy)) { throw new ArgumentException("expand(): 'instance' must be a Cauchy distribution"); } var newDistribution = ((instance == null) ? new Cauchy(loc.expand(batch_shape), scale.expand(batch_shape)) : instance) as Cauchy; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.loc = loc.expand(batch_shape); newDistribution.scale = scale.expand(batch_shape); } return(newDistribution); }
public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Poisson)) { throw new ArgumentException("expand(): 'instance' must be a Poisson distribution"); } var r = rate.expand(batch_shape); var newDistribution = ((instance == null) ? new Poisson(r) : instance) as Poisson; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.rate = r; } return(newDistribution); }
public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Geometric)) { throw new ArgumentException("expand(): 'instance' must be a Geometric distribution"); } var newDistribution = ((instance == null) ? new Geometric(p: _probs?.expand(batch_shape), l: logits?.expand(batch_shape)) : instance) as Geometric; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution._probs = _probs?.expand(batch_shape); newDistribution._logits = _logits?.expand(batch_shape); } return(newDistribution); }
public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Uniform)) { throw new ArgumentException("expand(): 'instance' must be a Uniform distribution"); } var newDistribution = ((instance == null) ? new Uniform(low.expand(batch_shape), high.expand(batch_shape)) : instance) as Uniform; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.low = low.expand(batch_shape); newDistribution.high = high.expand(batch_shape); } return(newDistribution); }
public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Binomial)) { throw new ArgumentException("expand(): 'instance' must be a Binomial distribution"); } var newDistribution = ((instance == null) ? new Binomial(total_count.expand(batch_shape), p: _probs?.expand(batch_shape), l: logits?.expand(batch_shape)) : instance) as Binomial; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.total_count = total_count.expand(batch_shape); newDistribution._probs = _probs?.expand(batch_shape); newDistribution._logits = _logits?.expand(batch_shape); } return(newDistribution); }
/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Gamma)) { throw new ArgumentException("expand(): 'instance' must be a Gamma distribution"); } var c = concentration.expand(batch_shape); var r = rate.expand(batch_shape); var newDistribution = ((instance == null) ? new Gamma(c, r) : instance) as Gamma; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.concentration = c; newDistribution.rate = r; } return(newDistribution); }
/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> /// <returns></returns> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Bernoulli)) { throw new ArgumentException("expand(): 'instance' must be a Bernoulli distribution"); } var p = _probs?.expand(batch_shape); var l = _logits?.expand(batch_shape); var newDistribution = ((instance == null) ? new Bernoulli(p, l) : instance) as Bernoulli; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution._probs = p; newDistribution._logits = l; } return(newDistribution); }
public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Beta)) { throw new ArgumentException("expand(): 'instance' must be a Beta distribution"); } var c0 = concentration0.expand(batch_shape); var c1 = concentration1.expand(batch_shape); var newDistribution = ((instance == null) ? new Beta(c1, c0) : instance) as Beta; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.dirichlet = new Dirichlet(torch.stack(new Tensor[] { c1, c0 }, -1)); newDistribution.concentration1 = c1; newDistribution.concentration0 = c0; } return(newDistribution); }
/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Multinomial)) { throw new ArgumentException("expand(): 'instance' must be a Multinomial distribution"); } var newDistribution = ((instance == null) ? new Multinomial(total_count, categorical.expand(batch_shape) as Categorical) : instance) as Multinomial; if (newDistribution == instance) { newDistribution.total_count = total_count; newDistribution.categorical = categorical.expand(batch_shape) as Categorical; newDistribution.batch_shape = newDistribution.categorical.batch_shape; var ps = newDistribution.categorical.param_shape; newDistribution.event_shape = new long[] { ps[ps.Length - 1] }; } return(newDistribution); }
/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is FisherSnedecor)) { throw new ArgumentException("expand(): 'instance' must be a FisherSnedecor distribution"); } var df1 = this.df1.expand(batch_shape); var df2 = this.df2.expand(batch_shape); var newDistribution = ((instance == null) ? new FisherSnedecor(df1, df2) : instance) as FisherSnedecor; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.df1 = df1; newDistribution.df2 = df2; newDistribution.gamma1 = this.gamma1.expand(batch_shape) as Gamma; newDistribution.gamma2 = this.gamma2.expand(batch_shape) as Gamma; } return(newDistribution); }
/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> /// <returns></returns> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Dirichlet)) { throw new ArgumentException("expand(): 'instance' must be a Dirichlet distribution"); } var shape = new List <long>(); shape.AddRange(batch_shape); shape.AddRange(event_shape); var c = concentration.expand(shape.ToArray()); var newDistribution = ((instance == null) ? new Dirichlet(c) : instance) as Dirichlet; newDistribution.batch_shape = batch_shape; if (newDistribution == instance) { newDistribution.concentration = c; } return(newDistribution); }