how to make a ridge regression octave - regression

i have octave 4.2.0 and knew that it dont have this function implemented. I try to make a code, but it dosnt work. Can you please help me to fix it or are there ready codes, which i can use?
My code at the moment:
matrix=xlsread('path'); %predictors
Y=xlsread('path');
[K,J]=size(matrix);
mid=mean(matrix);
standard=std(matrix);
Jn=J-1;
for len= 1:K
for ll=1:J
Z(len,ll)=matrix(len,ll)-mid(ll))/standard(ll);
end
end
I=eye(J,J);
n=1;
for kfact=0:0.0001:0.5
teta(n,:)=inv(matrix'*matrix+kfakt*I)*matrix'*Y;
k(n)=kfakt;
n=n+1;
end
Have someone an idea, because i cant find how to make it?
I try to specify my problem. In the book are the values of the parameters, which are calculate in the dependece of k ver small (e.g. 0.02). I get Values, which are about 20. I dont understand why?
Thanks!

Related

Basic Python - How to run everything inside this function exepct one

Hello, I think my question is fairly simple so I don't have to write in code format here, I just want to know some intermediates coding practice in blender python,
i just want to know how can i run call this function and then leave out and not running just one line?
For example: self.Grobs = False,
I want to keep this true
I sort of guess the function parenthesis can help in this?
def cul_off_all():
thank you in advance!
Cheers!

Linear function with live data

I am an absolute newbie on the programming thing and really desperate. I picked up a high end task to solve as it seems to me...
I know there are tons of explanations for solving y = mx + b with python but they're all for the situation with "solid" data. I am trying to realize it with live data.
So far, i have two data streams, which I successful directed into two lists - please see code below.
for graph in basis_graph:
high_1 = float(graph.high)
low_1 = float(graph.low)
if high_1 > 0:
graph_high.append([high_1])
if low_1 > 0:
graph_low.append([low_1])
Now comes the tricky part and I DON`T GET IT. I need a function that calculates me "m". Something like that:
def function_signal():
if graph_high[-1] < graph_high[-2]:
please, mr. computer, calculate me "m"
I tried something like
def signal():
if graph_low[-1] < graph_low[-2]:
print("a")
ay1 = graph_low[-1]
by1 = graph_low[-2]
m = ay1 - by1
return m
print(m(ay1, ay2))
Two days I tried EVERYTHING from what I know so far but the only thing I earned was a cascade of Tracebacks. From "I can't divide two list objects" to " "m" is not defined" and so on and so on...
In the case above for example NOTHING happens. Sometimes he says "m is not defined"...
Please, if there's someone out there who is willing to help me than I would really appreciate it.
Thanks in advance.

how to fix this easy digital communication excercise using MATLAB

I have a problem in writing in MATLAB a program that modulates data bits, adds noise then demodulates it and calculate the bit error and the symbol error rate. The modulation used first should be QPSK. I have done the following,
N=100;
databits = randi([0 3],N,1);
hModulator = comm.QPSKModulator;
hModulator.PhaseOffset = pi/4;
txsig = step(hModulator, databits);
scatterplot(txsig)
grid on
SNRdB=-10
rxsig = awgn(txsig,SNRdB);
H = comm.QPSKDemodulator
hH.PhaseOffset = pi/4;
symdecoded=step(H,rxsig)
symerr(symdecoded,databits)
biterr(symdecoded, databits)
My first question is I don't think I am doing the bit error rate and symbol error rate correctly, can someone help me spot where the problem is? Where am I missing out?
I am then asked to repeat the same problem but make the changes needed to make it work with 16-QAM and 64-QAM by changing a parameter called CONSTELLATION.
I have tried using demod and ddemodce but these two functions are removed from matlab? Does anyone know how to proceed?
I dont know why you are using SNRdB=-10 dB?
Try for example positive numbers 0 10 20 30, and you may save symerr and biterr as the function proposes [number,ratio] = symerr(x,y)
number= numb of error and ratio = bitsTx/bitsRx
For m-qam better use modem.qammod try the help in matlab
Best regards and good luck

Matlab ode solver using the time in a function for 'value' in events

I've searched extensively, and thought I wouldn't be the only one having this problem, but it seems to look like I am.
I am solving an ode via ode15s (my problem can be stiff) and I use the 'Events' option to find my point of interest.
The problem is: the equation that I use in 'value' is depending (among other things) on the specific time (so value = f(t,y,y'), and I cannot find a way of passing the current time to this function, only the y vector is available.
Anyone has any ideas?
Thanks in advance and all the enjoy the rest of your holidays!
Sorry, made a really stupid error (used , instead of ;)...
You can just use the t argument as long as you set it in your #odefunction(t,y) as well as your #events(t,y).

Matlab Basic Function

I'm trying to read some matlab code, but I'm new to it. How do I figure out what the input parameters are?
function [shortly, longly] = lyapunov(signal,timestep,FreqSamp,segmentapproach, duratsegmen, dodivergence)
//lots of code under here but I couldn't find out where signal, timestep, etc come from.
Read the help for lyapunov. It will tell you that information.