add octave 03 and 04
This commit is contained in:
parent
8fecab6dcf
commit
389e4c7dbd
8 changed files with 125 additions and 0 deletions
4
1sem/octave/04/alph_entropy.m
Normal file
4
1sem/octave/04/alph_entropy.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
function [h] = alph_entropy(P);
|
||||
P = P(P ~= 0);
|
||||
h = -sum(P.*log2(P));
|
||||
endfunction;
|
||||
5
1sem/octave/04/alph_redundancy.m
Normal file
5
1sem/octave/04/alph_redundancy.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function [r] = alph_redundancy(P);
|
||||
ent = alph_entropy(P);
|
||||
mx_ent = log2(length(P))
|
||||
r = 1 - ent/mx_ent;
|
||||
endfunction;
|
||||
23
1sem/octave/04/main.m
Normal file
23
1sem/octave/04/main.m
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# stage 1
|
||||
V=33
|
||||
rand("state", V)
|
||||
|
||||
#stage 4
|
||||
c = rand(1, 10);
|
||||
ralph = c./sum(c);
|
||||
save -ascii "ralph.txt" ralph;
|
||||
|
||||
#stage 5
|
||||
load -ascii "coin.txt" coin;
|
||||
load -ascii "crime.txt" crime;
|
||||
load -ascii "unfair.txt" unfair;
|
||||
load -ascii "ventsel.txt" ventsel;
|
||||
|
||||
results = [
|
||||
alph_entropy(coin), alph_redundancy(coin);
|
||||
alph_entropy(crime), alph_redundancy(crime);
|
||||
alph_entropy(unfair), alph_redundancy(unfair);
|
||||
alph_entropy(ventsel), alph_redundancy(ventsel);
|
||||
alph_entropy(ralph), alph_redundancy(ralph);
|
||||
]
|
||||
save -ascii "results.txt" results;
|
||||
Loading…
Add table
Add a link
Reference in a new issue