This is my first time building a net from a paper, as I start training until thousands of iterations, the loss doesn't decrease, instead, it fluctuates all the time, no matter how small I change the base_lr into, like 0.0001, or 0.0000001.I suspect that the data doesn't match to the right label, but how to check it out or what is the solution? This net is about crowd density estimation, both data and label are pictures. I first use matlab to generate density map(label) and name them in order,them create lmdb.
Here is how I name my data:
Here is how I name my label:
Here is the solver.
net: "/media/lenovo/KINGSTON/UCF_CC_50/UCF_train_test.prototxt"
test_iter: 1
test_interval: 10
base_lr: 0.00001
momentum: 0.9
weight_decay: 0.004
lr_policy: "inv"
gamma: 0.0001
power: 0.75
display: 100
type:"SGD"
max_iter: 20000
snapshot: 2000
snapshot_prefix: "/media/lenovo/KINGSTON/UCF_CC_50/"
solver_mode: GPU
Related
I am trying to plot the magnitude ratio of a first order system using cftool, I'm aware there are other ways to do that but I need to get to the solution through this method.
I have simulated an RC circuit and, after having applied a sine input at several frequencies, I have measured the output of the system;
Here are the vectors I have created in MATLAB with the data I have measured:
f = [1 10 100 120 130 150 160 170 1000 2000 3000 10000];
Vi = zeros(1,12);
Vi(1,:) = 1; %amplitude
Vo = [0.99 0.99 0.85 0.79 0.77 0.73 0.7 0.68 0.16 0.08 0.05 0.02]; %amplitudes
Vdb = 20*log10(Vo./Vi); %Vo converted to dB
Now, given that an RC circuit is a first order system, I know that the relationship beetween magnitude ratio and frequency can be written as:
M(omega) = 1/(sqrt(1 + (omega * tau)^2))
So, opening cftool in MATLAB, I have set:
X data: f
Y data: Vdb
Custom Equation: 1/sqrt(1 + (2*pi*a*x)^2) %omega = 2*pi*f
Using these settings, however, cftool doesn't plot what I expected to see, so I would like to figure out where my mistakes are.
I believe the Y-data should be V0, not Vdb.
If you want the curvefit for the relationship between the voltage gain in dB and the frequency, then you need to alter the custom equation.
I want to know how quickly some data returns to baseline after an initial peak (here at ca x=5);
The quadratic fit looks about right (from the figures option of matlab, shown below) - but I'm looking for a concise quantification of this curve, therefore I presume the 'decay rate' of the exponential function would be one very straightforward.
Is this assumption correct?
If yes, I looked at the formula on wiki for this, and attempted shamelessly to find a solve for the time constant (but unsuccessfully so). Can someone help me out, or is this actually a not so trivial problem?
edit: I was planning to find the peak using MathWorks' findpeaks() function, and the lowest point of the curve using the 'inverse' findpeaks() (as in: -y)
%approx data values of the curves below
y= [0 0.07 0.08 0.08 0.08 0.06 0.06 0.05 0.04 0.05 0.04 0.02 0.01 0.02 0.01 0.01 0.03 0.02 0.02 0.02 0.03 0.01 0.02 0.01 0.01 0.03 0.02 0.01 0.02 0.01];
x=1:numel(y);
plot(x,y);
These are the two options I was looking for, maybe someone can elaborate / improve this answer about the differences for these approaches - for me this is good enough, thanks for the comments. Before this step, using the data provided in the example of the question, the local maximum and minimum has to be extracted, this can be done easily using findpeaks()
approach 1) requires the curve toolbox from Matlab [Source]
%Fit a Single-Term Exponential Model, copy from Mathworks documentation, all credits go there
x = (0:0.2:5)';
y = 2*exp(-0.2*x) + 0.1*randn(size(x));
f = fit(x,y,'exp1')
f =
General model Exp1:
f(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
a = 2.021 (1.89, 2.151)
b = -0.1812 (-0.2104, -0.152)
plot(f,x,y)
or approach 2) requires the optimizaion toolbox from Matlab [Source]
%copy from Mathworks documentation, all credits go there
rng default % for reproducibility
d = linspace(0,3);
y = exp(-1.3*d) + 0.05*randn(size(d));
fun = #(r)exp(-d*r)-y;
x0 = 4;
x = lsqnonlin(fun,x0)
plot(d,y,'ko',d,exp(-x*d),'b-')
legend('Data','Best fit')
xlabel('t')
ylabel('exp(-tx)')
I am trying to fit a distribution to a discrete dataset.
The possible outcomes are A = [1 3 4 5 9 10] with a respective probability of prob
prob = [0.2 0.15 0.1 0.05 0.35 0.15];
I have used makedist to find the distribution
pd = makedist('Multinomial','probabilities', prob);
I wonder if there is a way to include the outcomes 1 to 10 from A in the distribution, such that I can calculate the mean and the variance of the possible outcomes with var(pd), mean(pd). Up till now the mean is 3.65, but my aim is it to have mean(pd) = 5.95, which is the weighted sum of the possible outcomes . Thanks in advance.
The solution is pretty easy. The possible outcomes of a multinomial distrubution are defined by a sequence of values starting at 1 and ending at numel(prob). From this official documentation page:
Create a multinomial distribution object for a distribution with three
possible outcomes. Outcome 1 has a probability of 1/2, outcome 2 has a
probability of 1/3, and outcome 3 has a probability of 1/6.
pd = makedist('Multinomial','probabilities',[1/2 1/3 1/6])
Basically, your vector of possible outcomes includes a few values associated to a null (signally 0) probability. Thus, define your distribution as follows in order to obtain the expected result:
p = [0.20 0.00 0.15 0.10 0.05 0.00 0.00 0.00 0.35 0.15];
pd = makedist('Multinomial','probabilities',p);
mean(pd) % 5.95
var(pd) % 12.35
I am required to train a single neuron perceptron which classifies two different classes.
I wrote this code on matlab.
function error = train_perc( PercepClassTraining,eta,weights )
%initialization:
xZero=1;
wZero=0.1;
t=1; % round number
x=[];
y=[];
error=[];
epoch_error=[];
c=1;
n=1;
x1=PercepClassTraining(n,1);
x2=PercepClassTraining(n,2);
y(n)=(xZero*wZero)+(x1*weights(1))+(x2*weights(2));
error(n)=PercepClassTraining(n,3)-y(n);
while(error(n)~=0)
weights(1)=weights(1)+(eta*error(n)*x1);
weights(2)=weights(2)+(eta*error(n)*x2);
if(n==2000)
epoch_error(c)=mean(error);
error=[];
c=c+1
n=1;
else
n=n+1;
end
y(n)=(xZero*wZero)+(x1*weights(1))+(x2*weights(2));
error(n)=PercepClassTraining(n,3)-y(n);
end
Where eta is learning rate, and PercepClassTraining is the training set (2000 inputs).
It converges at epoch #58 when I use 0.1 for learning rate and [0.01 0.01] for initial weights, and that doesn't use all the training set.
When I set eta to 0.01 and weights to 0.1, 0.1 it loops forever! Is there anything wrong in the code? How about the stopping criteria?
So if my sampling rate is 8000, and I make a sine wave of frequency 1000 like so:
n = 0:255;
fs = 8000;
fa = 50;
x = sin(2*pi*(fa/fs)*n);
resolution = n * (fs/length(n));
stem(resolution, abs(fft(x)));
Everything is fine, and the plot shows the single peak at 1000Hz.
However, if I set a frequency fa = 50, I get a smoother rise up to the peak, however the peak location is incorrect. It's at 62.5 Hz.
So the obvious solution is reduce the sampling rate, but what if that's not possible, such as in my case?
I think that the above observation/result makes sense given the choice of your sampling rate fs and block size N of 8000 and 256 respectively. Note that
fs/N = 8000/256 = 31.25
The discrete outputs from the FFT N-point transform can only be associated with frequencies that are multiples of the above
m*fs/N = m*31.25 for m=0,1,2,….,255
There does not exist any m such that m*fs/N is equal to 50, so the closest is the 62.5 (2*31.25).
If you cannot change the sampling rate, then how about the block size, N such that 50=fs/N? If N were chosen to be any multiple of 160 (=8000/50) then you should be fine
n = 0:159; % or any multiple of 160 less one
(You mention the smoother rise up to the peak which is just leakage - it causes any input signal whose frequency is not exactly at a FFT bin centre to leak into all of the other FFT output bins.)
Note that everything is fine for the input signal with a 1000 Hz frequency since 1000=32*31.25 when fs=8000 and N=256 (so m=32).
The maximum value of your discrete Fourier transform is at 62.5Hz. However, if you interpolate, you'll find that the maximum value is at 50 Hz. See http://www.dspguru.com/dsp/howtos/how-to-interpolate-fft-peak for details.