-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Impossible to provide arguments to random_normal in scala ? #12140
Comments
Hi @mdespriee Symbol.random_normal(i.output)()(Map("loc" -> mean, ...)) Just put all of your args in the map. You can always check Python API example. BTW, in the future, you can call /**
* <pre>
* Draw random samples from a normal (Gaussian) distribution.
*
* .. note:: The existing alias ``normal`` is deprecated.
*
* Samples are distributed according to a normal distribution parametrized by *loc* (mean) and *scale* (standard deviation).
*
* Example::
*
* normal(loc=0, scale=1, shape=(2,2)) = [[ 1.89171135, -1.16881478],
* [-1.23474145, 1.55807114]]
*
*
* Defined in src/operator/random/sample_op.cc:L85
* </pre>
* @param loc Mean of the distribution.
* @param scale Standard deviation of the distribution.
* @param shape Shape of the output.
* @param ctx Context of output, in format [cpu|gpu|cpu_pinned](n). Only used for imperative calls.
* @param dtype DType of the output in case this can't be inferred. Defaults to float32 if not defined (dtype=None).
* @return org.apache.mxnet.Symbol
*/
@Experimental
def random_normal (loc : Option[org.apache.mxnet.Base.MXFloat] = None, scale : Option[org.apache.mxnet.Base.MXFloat] = None, shape : Option[org.apache.mxnet.Shape] = None, ctx : Option[String] = None, dtype : Option[String] = None, name : String = null, attr : Map[String, String] = null) : org.apache.mxnet.Symbol @mxnet-label-bot can you label this as [scala] ? |
Actually, I tried that as well, and can't make it work either. object NormalTest extends App {
val mean = Symbol.Variable("mean")
val std = Symbol.Variable("std")
val s = Symbol.random_normal("gaussian")()(Map("loc"->mean, "scale"->std, "shape" -> (2,2)))
val exec = s.bind(Context.defaultCtx, Map(
"mean" -> NDArray.array(Array(0f, 10f), Shape(2)),
"std" -> NDArray.array(Array(1f, 2f), Shape(2))
))
exec.forward()
println(s"Result= ${exec.outputs.head.toArray.mkString(",")} ")
}
and:
|
@mdespriee looks like you are using it in a wrong way, are you trying to use it in Symbolic way? val nd = NDArray.random_normal(Map("loc" -> 0, "scale" -> 1, "shape" -> Shape(2, 2)))()
nd.toArray.foreach(println) Output is:
|
@lanking520 Oh wait, I think I understand. To put it differently, I don't have a single value for loc and scale, I have a full batch of them, and I want to draw random numbers for each pair. In a Symbolic computation. As I'm looking for this in Scala, I've probably mixed the differents APIs. it's a bit of a mess. |
@mxnet-label-bot [Scala, Question] |
@mdespriee I got your point. Scala now did not have Random Module, will think of supporting that! |
Actually if you are interested, you can be the contributor to get it out for Scala package. It needs some wrappers similar to python side and expose the following apis:
These can be code-generated from Macro side. Please let me know if you are interested |
@lanking520 yes, I could be interested. I'll have a look after my vacations, though ;-) |
@lanking520 So, I just discovered Symbol.sample_normal which is exactly what it is about ! |
Link this Issue to the PR: #12489 |
@lanking520 @mdespriee I think this can be closed because #13039 was merged |
Close it for now, if you are still facing this problem. Please raise a PR (😄) or reopen this issue |
Description
I'm trying to use random_normal in the Symbol API. In scala.
The docs mentions that loc and scale could be Symbols and have a shape (that's what I'm looking for). Although, when I try to use the symbol:
MXNet complains that arguments are incorrect.
Sounds like a bug to me. Or do I miss something ?
Environment
Full code
The text was updated successfully, but these errors were encountered: