I profiled the sim(net,input) function (part of the neural network toolbox) and noticed it spends a relatively lot of time in the initialization part calling net=obj2struct(net) every time sim is called. Is there any way (beside writing my own ad-hoc sim function) to pass as parameter the already converted struct-type net in order to avoid wasting time converting every time? (convert once, run multiple times)
It would be very nice for NN relatively small (like the one I'm using), whose conversion takes more time than the simulation itself.
Related
Thanks in advance,
I am having a simple Simulink model, that takes in a 32-bit number in the IEEE-754 format and adds the same number, which gives the output again in the 32-bit wide IEEE-754 format. I used MATLAB's HDL CODER add-on and generated the Verilog HDL code for the same. When I wrote a testbench for the same, I found the latency I get from this code is 100ns. But is there a way I can reduce this to even further, say some 10ns.
Below I am attaching the Simulink model I used to generate the Verilog HDL code, along with the generated Verilog files. Also, I am attaching a screenshot of the simulation in case you don't want to waste your time running the scripts
Link to download the files
my point is how to use pipeline settings before conversion
I am assuming that "pipeline settings" is a MATLAB HDL generator parameter.
Basically what you do is "try": use a pipeline setting and synthesize the code. If you have slack you can:
Reduce the number of pipeline stages.
or
Increase the clock frequency.
(For negative slack you use the inverse methods)
Now here is where things get tricky:
Most of the time you can't really speed things up. A certain functionality needs a time to calculate. Some algorithms can be sped up by using more parallel resources but only up tot a limit. An adder is good example: you can have ripple carry, carry look-ahead and more advanced techniques, but you can not speed up infinitely. (Otherwise CPUs these days would be running at Terra Hz)
I suspect in the end you will find that it takes T time to do your IEEE-754 adder. That can be X clock cycles of an A MHz. clock or Y clock cycles of B MHz. But X times A is about the same as Y times B.
What you can do is pump lots of calculations into your pipe so a new one comes out every clock cycle. But the latency will still be there.
I am trying to find a transfer function of bldc motor speed over duty cycle percent. I made two measurements for different duty cycle percentages in order to both estimate transfer function and its validation.
For the first one (%65 duty cycle step input) I got below measurement and its transfer function estimation.
For the second one (%70 duty cycle step input) I got below measurement and it transfer function estimation.
The problem is that my transfer functions are not validating each other as shown below. They do not give the same response for the same input. Can anyone explain the reason?
It looks like the two measurements are very different. One has a maximum of 220, the other has a maximum of 350. This means the data acquisition is at fault, or the motor is itself variable.
Why don't you try measuring 20 times, and see if the raw data look similar?
Otherwise would need more info about your recording setup and the protocol for testing the duty cycles. It doesn't sound like a matlab or programming problem.
-- edit
Transfer functions are usually the output as a function of the input. Not functions of time.
Transfer function estimation assumes that the system is linear and time-invariant.
Most likely the system exhibits a nonlinear response characteristic which causes a very large change in output amplitude when input is increased from 65% to 70%, so a transfer function obtained at one operating point is not valid for the other.
I have a question regarding the Matlab NN toolbox. As a part of research project I decided to create a Matlab script that uses the NN toolbox for some fitting solutions.
I have a data stream that is being loaded to my system. The Input data consists of 5 input channels and 1 output channel. I train my data on on this configurations for a while and try to fit the the output (for a certain period of time) as new data streams in. I retrain my network constantly to keep it updated.
So far everything works fine, but after a certain period of time the results get bad and do not represent the desired output. I really can't explain why this happens, but i could imagine that there must be some kind of memory issue, since as the data set is still small, everything is ok.
Only when it gets bigger the quality of the simulation drops down. Is there something as a memory which gets full, or is the bad sim just a result of the huge data sets? I'm a beginner with this tool and will really appreciate your feedback. Best Regards and thanks in advance!
Please elaborate on your method of retraining with new data. Do you run further iterations? What do you consider as "time"? Do you mean epochs?
At a first glance, assuming time means epochs, I would say that you're overfitting the data. Neural Networks are supposed to be trained for a limited number of epochs with early stopping. You could try regularization, different gradient descent methods (if you're using a GD method), GD momentum. Also depending on the values of your first few training datasets, you may have trained your data using an incorrect normalization range. You should check these issues out if my assumptions are correct.
I am attempting to train a neural network to control a simple entity in a simulated 2D environment, currently by using a genetic algorithm.
Perhaps due to lack of familiarity with the correct terms, my searches have not yielded much information on how to treat fitness and training in cases where all the following conditions hold:
There is no data available on correct outputs for given inputs.
A performance evaluation can only be made after an extended period of interaction with the environment (with continuous controller input/output invocation).
There is randomness inherent in the system.
Currently my approach is as follows:
The NN inputs are instantaneous sensor readings of the entity and environment state.
The outputs are instantaneous activation levels of its effectors, for example, a level of thrust for an actuator.
I generate a performance value by running the simulation for a given NN controller, either for a preset period of simulation time, or until some system state is reached. The performance value is then assigned as appropriate based on observations of behaviour/final state.
To prevent over-fitting, I repeat the above a number of times with different random generator seeds for the system, and assign a fitness using some metric such as average/lowest performance value.
This is done for every individual at every generation. Within a given generation, for fairness each individual will use the same set of random seeds.
I have a couple of questions.
Is this a reasonable, standard approach to take for such a problem? Unsurprisingly it all adds up to a very computationally expensive process. I'm wondering if there are any methods to avoid having to rerun a simulation from scratch every time I produce a fitness value.
As stated, the same set of random seeds is used for the simulations for each individual in a generation. From one generation to the next, should this set remain static, or should it be different? My instinct was to use different seeds each generation to further avoid over-fitting, and that doing so would not have an adverse effect on the selective force. However, from my results, I'm unsure about this.
It is a reasonable approach, but genetic algorithms are not known for being very fast/efficient. Try hillclimbing and see if that is any faster. There are numerous other optimization methods, but nothing is great if you assume the function is a black box that you can only sample from. Reinforcement learning might work.
Using random seeds should prevent overfitting, but may not be necessary depending on how representative a static test is of average, and how easy it is to overfit.
what time units does this simulation stop time use? is it seconds or msec? or is there any method to measure this time as some time I feel 1 unit of this time is not of constant length?
It's seconds. But Simulink does not run in real-time, so one second of simulation time can a lot less than a second of real-time (if your model runs very fast) or a lot more (if your model runs very slow).
If your model runs "too fast", you can use utilities such as Simulink Block for Real Time Execution, Simulink® Real Time Execution, Real-Time Blockset 7.1 for Simulink, Real-Time Pacer for Simulink or RTsync Blockset (there are plenty to choose from) to slow it down to real-time.