I have a multi-dimensional data, but it misses target variable.
I want a model to predict a value for this data that could be passed to my loss function which can be then used as a feedback for updating the weights.
The simulation could look like -
take one data-point, predict a value
pass this value to loss function
use that loss function as feed back
update the weights
In next iteration, take another data-point and predict value on updated weights
again use this value in loss function for feedback.
and the loop continues.
This way, I dont need labelled data for predictions. And I think my use case is more of time series, so can this be implemented with time series?
Related
I have a system, described by a black-box, that takes as input a signal in time (let's say something similar to a sine wave) and returns a single scalar as output.
My goal is to find the optimum signal that maximizes/minimizes the output. As constraints, the time average of the signal must be kept constant and the minimum and maximum value of the signal must be within a specific range.
The parameters to be optimized are all the points describing my signal in time.
I want to use the scipy.optimize library to minimize the output of my black-box system however, everytime the parameters are modified by the optimizer, I need to smooth the input signal in order to avoid discontinuity.
My question is: is it possible to access the input variables after they are modified by the algorithm, smooth them, and substitute them at every iteration of the algorithm?
I am using Simulink for real-time classification using a trained Fine-KNN model. The input data for the model is a 50-point moving average vector [6x1]. I am using the DSP moving average block for this purpose with sliding window technique (window size = 50 and simulating using code generator). When I compare the input and the output of this block for real-time values, I get the following plot:
It is clear from the plot that there is something wrong with the output as there is quite a discrepancy between the input and the output. What could possibly be the problem or am I doing something wrong?
Edit (after Cris's comment):
Here are some screenshots to showcase some modeling parameters within Simulink:
Screenshot showing probes for measuring actual input and moving average output along with the Moving Average block parameters
Probes
Other block parameters that might be affecting the performance of the model:
a. OPC Config real-time block parameters
b. OPC Read block parameters
PS: One issue that I can think of is that the actual input is fed to the Moving Average in real-time at 10ms time-step and I am not sure if the moving average block has a buffer to store up to the "Window Length" data as it keeps coming in. What I mean by this is, the moving average block might not have access to 50 values of the input signals for quite some time and I am not sure how it deals with that kind of a situation.
I can reproduce this with the following minimal example:
So a constant input of [1; 2; 3] gives a moving average of roughly 2 (the average of the input elements) in all elements, when you would expect an output of [1; 2; 3] since each element is constant.
In your example, the inputs average approximately 0.62, which you are seeing in the output from the moving average.
Using a demux to split your vector up gives the desired output
The docs say that the moving average block should be able to handle this though
The Moving Average block computes the moving average of the input signal along each channel independently over time.
It turns out that a channel in this case is a column of your vector. Since you have a column vector, the columns in each iteration are getting stacked and averaged. Unfortunately the underlying code is sealed so we can't check this theory other than by trying it out.
Reshape your input to be a row array using the reshape block.
Then you get the expected output
I have a Matlab function (created by me) that must be evaluated only at a given rate. I would like to sample the value of a signal, give to this function (discrete values) and then, the calculated output must be hold until the next value is available. Is there a way in simulink to do this? All answers I have found use quantizer + ZOH but in this case I still get "a continuum" (or almost it) of points to be evaluated by thsi function which is really slow. Changing the rate of simulink's solver is also not an option as the result of this function will be given for a continuous time system.
Any help will be highly appreciatted!
Thank you
Assuming by Matlab function you mean a MATLAB Function block, then it sounds as if all you need to do is make the block discrete. Do that by right-clicking on the block, going down to Block Properties and then in the resulting dialog enter your required sample time.
The block will then sample its input and generate an output (which is held between sample times) at each sample time.
I wish to use online logistic regression training in Matlab in which I train the model by presenting the first sample, evaluate the model, next add the second sample, evaluate etc. etc.
I could do this by first creating a model on the first sample, evaluating it, throw this model away; next create a model on sample one and two, evaluate it etc. etc but this is very ineffecient. Is there a way I could do 'real' online training of the logistic regression model in Matlab?
Short answer: No Matlab does not support it (at least not that i'm aware of). Therefore you need to create a whole new model every time you get new input data. Depending on the size of the task this might still be the best choice.
Workaround: You can implement it yourself, by creating a loss function which updates every time. Take a look at this paper if you decide to go this way (it about many kinds of loss function but you are interested in the logistic one):
http://arxiv.org/abs/1011.1576
Or you could go Bayesan and update your priors any time a new point comes in.
I have a relatively basic Simulink block Model in which there is a Gaussian Noise Generator & an Error rate calculator. I want to get data on how changing the "variance" property of the Gaussian noise generator affects the result from the error rate calculator.
The most obvious way to do this is to manually run the simulation, record the results, change the variance of the Gaussian Noise Generator, rerun etc.
However, is there a way of getting the Simulink model to run the model, increase the Gaussian Noise variance by an amount, and rerun automatically for x number of iterations, and then to store the results in a list or array?
I am damn sure there is, but being new to Matlab & Simulink I have no idea of how to go about doing it? Somehow I imagine it would involve setting the "variance" as an input, and collecting the figure from the error rate calculator as an output - but again, I don't really know.
You want to use a for loop, and within the loop use the functions set_param and sim.
Look at the doc for more on how to use those functions.
There are also a couple of examples of using set_param here and using sim here.