Revision | 806452ca6e75ac7d61e76e16f36af28a0e928dcb (tree) |
---|---|
Time | 2010-10-12 00:00:13 |
Author | lorenzo |
Commiter | lorenzo |
I am developing this code which calculates the entropy of a time series, but
I still need to learn how to iterate it on a set of files.
@@ -7,67 +7,31 @@ | ||
7 | 7 | |
8 | 8 | main = do |
9 | 9 | |
10 | - | |
11 | - -- let list = [4,55,66,77,88,99,12,9,77,88,99,12,-99] | |
12 | - let list = [999,99,9] | |
13 | - | |
14 | - -- let list = ["a","b","c","c"] | |
15 | - | |
16 | - | |
17 | - -- let sub_list = [66,77,88] | |
18 | - | |
19 | - -- let i = 9 | |
20 | - | |
21 | - -- let j =2 | |
22 | - | |
10 | + -- let file_list = [1,2,3] | |
23 | 11 | |
24 | 12 | |
25 | - -- let b = iter_find list i | |
26 | - | |
27 | - -- putStrLn "b is, " | |
28 | - -- print b | |
29 | - | |
30 | - | |
31 | - -- let b = iter_find_efficient list i | |
32 | 13 | |
33 | - -- putStrLn "the list of True is, " | |
34 | - -- print b | |
35 | - | |
36 | - -- let b = count_string_length list i | |
37 | 14 | |
38 | - -- putStrLn "the length of the list is, " | |
39 | - -- print b | |
40 | - | |
41 | - let b =list_string_lengths list | |
42 | - | |
43 | - putStrLn "the list of string lengths is, " | |
44 | - print b | |
15 | + list_t <- readFile "tdata.dat" | |
45 | 16 | |
46 | 17 | |
47 | - let b = sum_string_lengths list | |
48 | - | |
49 | - putStrLn "the sum of the lengths of the lists is, " | |
50 | - print b | |
51 | - | |
18 | + let list = lines list_t | |
52 | 19 | |
53 | 20 | let b = entropy_list list |
54 | 21 | |
55 | 22 | putStrLn "the entropy of the list is, " |
56 | 23 | print b |
57 | 24 | |
58 | - | |
59 | - -- putStrLn "length list is, " | |
60 | - -- print (length list) | |
61 | - | |
62 | - -- let c = gen_past_list list i | |
63 | - -- putStrLn "the past of i is, " | |
64 | - -- print (c) | |
65 | - | |
66 | 25 | |
67 | 26 | |
68 | 27 | |
69 | 28 | |
70 | 29 | |
30 | +-- ############################################################## | |
31 | + | |
32 | + | |
33 | + | |
34 | + | |
71 | 35 | is_sublist sublist list = sublist `isInfixOf` list |
72 | 36 | |
73 | 37 |
@@ -91,6 +55,9 @@ | ||
91 | 55 | sum_string_lengths list = sum $ map (count_string_length list) [1..n] |
92 | 56 | where n = length list |
93 | 57 | |
58 | +my_convert list = lines list | |
59 | + | |
60 | + | |
94 | 61 | list_string_lengths list = map (count_string_length list) [1..n] |
95 | 62 | where n = length list |
96 | 63 |
@@ -101,7 +68,8 @@ | ||
101 | 68 | |
102 | 69 | entropy_list list = 1.0/((pref_list list) * fromIntegral (sum_string_lengths list) ) |
103 | 70 | |
104 | - | |
71 | +read_file_and_get_entropy list = entropy_list list_new | |
72 | + where list_new = my_convert list | |
105 | 73 | |
106 | 74 | |
107 | 75 | -- #################################################################################### |
@@ -110,6 +78,11 @@ | ||
110 | 78 | |
111 | 79 | convert x = (map (map read . words) . lines) x |
112 | 80 | |
81 | + | |
82 | +convert_single_col x = concat $ convert x | |
83 | + | |
84 | + | |
85 | + | |
113 | 86 | firstColumn xss = head (transpose xss) |
114 | 87 | |
115 | 88 | nthColumn xss n = (transpose xss) !! n -- my first haskell function! |