Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

c# - is there a way to create many input parameters?

        [Parameter("n11", DefaultValue = 0, MinValue = -1, MaxValue = 1, Step = step)]
        public double n11 { get; set; }
        [Parameter("n12", DefaultValue = 0, MinValue = -1, MaxValue = 1, Step = step)]
        public double n12 { get; set; }
        [Parameter("n13", DefaultValue = 0, MinValue = -1, MaxValue = 1, Step = step)]
        public double n13 { get; set; }
        [Parameter("n14", DefaultValue = 0, MinValue = -1, MaxValue = 1, Step = step)]
        public double n14 { get; set; }

I work with cAlgo for ctrader and need many input parameters like those listed above as weights for a neural network. Is there a way to generate as many input parameters as you need?

For example, when i need weights for inbetween 3 hidden layers, in which there are each 8 neurons (which would be 8x8x2 weights needed), i can just tell the programm something like "double[2,8,8]" and it creates those parameters? It would be pretty annoying when i make the neural network bigger and have to write a few thousand input parameters manually.

It would be even better it the weights could directly be stored in a 3dimensional array (between which hidden layers, from which left node, to which right node)

(It is written in c#)

Any help or tips would be appreciated!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just make a struct out of it.

    public void MyAwesomeMethod(MyParamaterSruct s)
    {
        ...
    }

    public struct MyParameterStruct
    { 
        public double n11;
        public double n12;
        public double n13;
        public double n14;
    }

You can also improve performance by not copying the struct (or each value) every time you call the method:

    public void MyAwesomeMethod(in MyParamaterSruct s)
    {
        ...
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...