jubatus 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,4 @@
1
- #
2
- # Copyright (c) 2012 Preferred Infrastructure, inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- # SOFTWARE.
21
- #
22
- # This file is auto-generated from ./jubatus/jubatus.github/src/server//stat.idl
1
+ # This file is auto-generated from jubatus-generate/src/server/stat.idl
23
2
  # *** DO NOT EDIT ***
24
3
 
25
4
  require 'rubygems'
@@ -27,20 +6,18 @@ require 'msgpack/rpc'
27
6
  require File.join(File.dirname(__FILE__), 'types')
28
7
 
29
8
  module Jubatus
9
+ module Stat
30
10
  module Client
31
11
 
32
12
  class Stat
33
13
  def initialize(host, port)
34
14
  @cli = MessagePack::RPC::Client.new(host, port)
35
15
  end
36
- def set_config(name, c)
37
- @cli.call(:set_config, name, c)
38
- end
39
16
  def get_config(name)
40
- Config_data.from_tuple(@cli.call(:get_config, name))
17
+ @cli.call(:get_config, name)
41
18
  end
42
- def push(name, key, val)
43
- @cli.call(:push, name, key, val)
19
+ def push(name, key, value)
20
+ @cli.call(:push, name, key, value)
44
21
  end
45
22
  def sum(name, key)
46
23
  @cli.call(:sum, name, key)
@@ -57,8 +34,8 @@ class Stat
57
34
  def entropy(name, key)
58
35
  @cli.call(:entropy, name, key)
59
36
  end
60
- def moment(name, key, n, c)
61
- @cli.call(:moment, name, key, n, c)
37
+ def moment(name, key, degree, center)
38
+ @cli.call(:moment, name, key, degree, center)
62
39
  end
63
40
  def save(name, id)
64
41
  @cli.call(:save, name, id)
@@ -73,3 +50,4 @@ end
73
50
 
74
51
  end
75
52
  end
53
+ end
@@ -1,48 +1,11 @@
1
- #
2
- # Copyright (c) 2012 Preferred Infrastructure, inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- # SOFTWARE.
21
- #
22
- # This file is auto-generated from ./jubatus/jubatus.github/src/server//stat.idl
1
+ # This file is auto-generated from jubatus-generate/src/server/stat.idl
23
2
  # *** DO NOT EDIT ***
24
3
 
25
4
  require 'rubygems'
26
5
  require 'msgpack/rpc'
27
6
  module Jubatus
7
+ module Stat
28
8
 
29
- class Config_data
30
- def initialize(window_size)
31
- @window_size = window_size
32
- end
33
- def to_tuple
34
- [@window_size]
35
- end
36
- def to_msgpack(out = '')
37
- to_tuple.to_msgpack(out)
38
- end
39
- def Config_data.from_tuple(tuple)
40
- Config_data.new(
41
- tuple[0]
42
- )
43
- end
44
- attr_accessor :window_size
45
9
  end
46
-
47
10
  end
48
11
 
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'json'
6
+
7
+ require 'jubatus/anomaly/client'
8
+ require 'jubatus/anomaly/types'
9
+ require 'jubatus_test/test_util'
10
+
11
+ class AnomalyTest < Test::Unit::TestCase
12
+ HOST = "127.0.0.1"
13
+ PORT = 23006
14
+ TIMEOUT = 10
15
+
16
+ def setup
17
+ @config = {
18
+ "method" => "lof",
19
+ "converter" => {
20
+ "string_filter_types" => {},
21
+ "string_filter_rules" => [],
22
+ "num_filter_types" => {},
23
+ "num_filter_rules" => [],
24
+ "string_types" => {},
25
+ "string_rules" => [{"key" => "*", "type" => "str", "sample_weight" => "bin", "global_weight" => "bin"}],
26
+ "num_types" => {},
27
+ "num_rules" => [{"key" => "*", "type" => "num"}]
28
+ },
29
+ "parameter" => {
30
+ "nearest_neighbor_num" => 10,
31
+ "reverse_nearest_neighbor_num" => 30,
32
+ "method" => "euclid_lsh",
33
+ "parameter" => {
34
+ "lsh_num" => 8,
35
+ "table_num" => 16,
36
+ "probe_num" => 64,
37
+ "bin_width" => 10.0,
38
+ "seed" => 1091,
39
+ "retain_projection" => false
40
+ }
41
+ }
42
+ }
43
+
44
+ TestUtil.write_file("config_anomaly.json", @config.to_json)
45
+ @srv = TestUtil.fork_process("anomaly", PORT, "config_anomaly.json")
46
+ @cli = Jubatus::Anomaly::Client::Anomaly.new(HOST, PORT)
47
+ end
48
+
49
+ def teardown
50
+ TestUtil.kill_process(@srv)
51
+ end
52
+
53
+ def test_clear_row
54
+ d = Jubatus::Anomaly::Datum.new([], [])
55
+ (row_id, score) = @cli.add("name", d)
56
+ assert_equal(true, @cli.clear_row("name", row_id))
57
+ end
58
+
59
+ def test_add
60
+ d = Jubatus::Anomaly::Datum.new([], [])
61
+ (row_id, score) = @cli.add("name", d)
62
+ end
63
+
64
+ def test_update
65
+ d = Jubatus::Anomaly::Datum.new([], [])
66
+ (row_id, score) = @cli.add("name", d)
67
+ d = Jubatus::Anomaly::Datum.new([], [['val', 3.1]])
68
+ score = @cli.update("name", row_id, d)
69
+ end
70
+
71
+ def test_clear
72
+ assert_equal(true, @cli.clear("name"))
73
+ end
74
+
75
+ def test_calc_score
76
+ d = Jubatus::Anomaly::Datum.new([], [['val', 1.1]])
77
+ (row_id, score) = @cli.add("name", d)
78
+ d = Jubatus::Anomaly::Datum.new([], [['val', 3.1]])
79
+ score = @cli.calc_score("name", d)
80
+ end
81
+
82
+ def test_get_all_rows
83
+ @cli.get_all_rows("name")
84
+ end
85
+
86
+ def test_get_config
87
+ config = @cli.get_config("name")
88
+ assert_equal(JSON.parse(config).to_json, @config.to_json)
89
+ end
90
+
91
+ def test_save
92
+ assert_equal(true, @cli.save("name", "anomaly.save_test.model"))
93
+ end
94
+
95
+
96
+ def test_load
97
+ model_name = "anomaly.load_test.model"
98
+ @cli.save("name", model_name)
99
+ assert_equal(true, @cli.load("name", model_name))
100
+ end
101
+
102
+ def test_get_status
103
+ @cli.get_status("name")
104
+ end
105
+
106
+ end
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'json'
6
+
7
+ require 'jubatus/classifier/client'
8
+ require 'jubatus/classifier/types'
9
+ require 'jubatus_test/test_util'
10
+
11
+ class ClassifierTest < Test::Unit::TestCase
12
+ HOST = "127.0.0.1"
13
+ PORT = 23001
14
+ TIMEOUT = 10
15
+
16
+ def setup
17
+ @config = {
18
+ "method" => "AROW",
19
+ "converter" => {
20
+ "string_filter_types" => {},
21
+ "string_filter_rules" => [],
22
+ "num_filter_types" => {},
23
+ "num_filter_rules" => [],
24
+ "string_types" => {},
25
+ "string_rules" => [{"key" => "*", "type" => "str", "sample_weight" => "bin", "global_weight" => "bin"}],
26
+ "num_types" => {},
27
+ "num_rules" => [{"key" => "*", "type" => "num"}]
28
+ },
29
+ "parameter" => {
30
+ "regularization_weight" => 1.001
31
+ }
32
+ }
33
+
34
+ TestUtil.write_file("config_classifier.json", @config.to_json)
35
+ @srv = TestUtil.fork_process("classifier", PORT, "config_classifier.json")
36
+ @cli = Jubatus::Classifier::Client::Classifier.new(HOST, PORT)
37
+ end
38
+
39
+ def teardown
40
+ TestUtil.kill_process(@srv)
41
+ end
42
+
43
+ def test_get_config
44
+ config = @cli.get_config("name")
45
+ assert_equal(@config.to_json, JSON.parse(config).to_json)
46
+
47
+ end
48
+
49
+
50
+ def test_train
51
+ string_values = [["key1", "val1"], ["key2", "val2"]]
52
+ num_values = [["key1", 1.0], ["key2", 2.0]]
53
+ d = Jubatus::Classifier::Datum.new(string_values, num_values)
54
+ data = [["label", d]]
55
+ assert_equal(@cli.train("name", data), 1)
56
+
57
+ end
58
+
59
+
60
+ def test_classify
61
+ string_values = [["key1", "val1"], ["key2", "val2"]]
62
+ num_values = [["key1", 1.0], ["key2", 2.0]]
63
+ d = Jubatus::Classifier::Datum.new(string_values, num_values)
64
+ data = [d]
65
+ result = @cli.classify("name", data)
66
+
67
+ end
68
+
69
+
70
+ def test_save
71
+ assert_equal(@cli.save("name", "classifier.save_test.model"), true)
72
+
73
+ end
74
+
75
+
76
+ def test_load
77
+ model_name = "classifier.load_test.model"
78
+ @cli.save("name", model_name)
79
+ assert_equal(@cli.load("name", model_name), true)
80
+
81
+ end
82
+
83
+
84
+ def test_get_status
85
+ @cli.get_status("name")
86
+
87
+ end
88
+
89
+
90
+ end
91
+
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'jubatus_test/test_util'
5
+
6
+ require 'json'
7
+
8
+ require 'jubatus/graph/client'
9
+ require 'jubatus/graph/types'
10
+
11
+ class GraphTest < Test::Unit::TestCase
12
+ HOST = "127.0.0.1"
13
+ PORT = 23005
14
+ TIMEOUT = 10
15
+
16
+ def setup
17
+ @config = {
18
+ "method" => "graph_wo_index",
19
+ "parameter" => {
20
+ "damping_factor" => 0.9,
21
+ "landmark_num" => 5
22
+ }
23
+ }
24
+
25
+ TestUtil.write_file("config_graph.json", @config.to_json)
26
+ @srv = TestUtil.fork_process("graph", PORT, "config_graph.json")
27
+ @cli = Jubatus::Graph::Client::Graph.new(HOST, PORT)
28
+ end
29
+
30
+ def teardown
31
+ TestUtil.kill_process(@srv)
32
+ end
33
+
34
+ def test_node_info
35
+ edge_query = [["a", "b"], ["c", "d"], ["e", "f"]]
36
+ node_query = [["0", "1"], ["2", "3"]]
37
+ p = Jubatus::Graph::Preset_query.new(edge_query, node_query)
38
+ in_edges = [0, 0]
39
+ out_edges = [0, 0]
40
+ Jubatus::Graph::Node.new(p, in_edges, out_edges)
41
+ end
42
+
43
+
44
+ def test_create_node
45
+ name = "name"
46
+ @cli.clear(name)
47
+ nid = @cli.create_node("sample_node")
48
+ assert_equal(nid.to_i.to_s, nid)
49
+ end
50
+
51
+ def test_remove_node
52
+ name = "name"
53
+ @cli.clear(name)
54
+ nid = @cli.create_node(name)
55
+ assert_equal(@cli.remove_node(name, nid), true)
56
+
57
+ end
58
+
59
+
60
+ def test_update_node
61
+ name = "name"
62
+ @cli.clear(name)
63
+ nid = @cli.create_node(name)
64
+ prop = {"key1" => "val1", "key2" => "val2"}
65
+ assert_equal(@cli.update_node(name, nid, prop), true)
66
+ end
67
+
68
+
69
+ def test_create_edge
70
+ name = "name"
71
+ @cli.clear(name)
72
+ src = @cli.create_node(name)
73
+ tgt = @cli.create_node(name)
74
+ prop = {"key1" => "val1", "key2" => "val2"}
75
+ ei = Jubatus::Graph::Edge.new(prop, src, tgt)
76
+ eid = @cli.create_edge("name", tgt, ei)
77
+ end
78
+
79
+
80
+ def test_create_edge
81
+ name = "name"
82
+ @cli.clear(name)
83
+ src = @cli.create_node(name)
84
+ tgt = @cli.create_node(name)
85
+ prop = {"key1" => "val1", "key2" => "val2"}
86
+ ei = Jubatus::Graph::Edge.new(prop, src, tgt)
87
+ eid = @cli.create_edge(src, tgt, ei)
88
+ end
89
+ end
90
+
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'json'
6
+
7
+ require 'jubatus/recommender/client'
8
+ require 'jubatus/recommender/types'
9
+ require 'jubatus_test/test_util'
10
+
11
+ class RecommenderTest < Test::Unit::TestCase
12
+ HOST = "127.0.0.1"
13
+ PORT = 23003
14
+ TIMEOUT = 10
15
+
16
+ def setup
17
+ @config = {
18
+ "method" => "inverted_index",
19
+ "converter" => {
20
+ "string_filter_types" => {},
21
+ "string_filter_rules" => [],
22
+ "num_filter_types" => {},
23
+ "num_filter_rules" => [],
24
+ "string_types" => {},
25
+ "string_rules" => [{"key" => "*", "type" => "str", "sample_weight" => "bin", "global_weight" => "bin"}],
26
+ "num_types" => {},
27
+ "num_rules" => [{"key" => "*", "type" => "num"}]
28
+ }
29
+ }
30
+
31
+ TestUtil.write_file("config_recommender.json", @config.to_json)
32
+ @srv = TestUtil.fork_process("recommender", PORT, "config_recommender.json")
33
+ @cli = Jubatus::Recommender::Client::Recommender.new(HOST, PORT)
34
+ end
35
+
36
+ def teardown
37
+ TestUtil.kill_process(@srv)
38
+ end
39
+
40
+ def test_get_config
41
+ config = @cli.get_config("name")
42
+ assert_equal(@config.to_json, JSON.parse(config).to_json)
43
+
44
+ end
45
+
46
+
47
+ def test_complete_row
48
+ @cli.clear_row("name", "complete_row")
49
+ string_values = [["key1", "val1"], ["key2", "val2"]]
50
+ num_values = [["key1", 1.0], ["key2", 2.0]]
51
+ d = Jubatus::Recommender::Datum.new(string_values, num_values)
52
+ @cli.update_row("name", "complete_row", d)
53
+ d1 = @cli.complete_row_from_id("name", "complete_row")
54
+ d2 = @cli.complete_row_from_datum("name", d)
55
+
56
+ end
57
+
58
+
59
+ def test_get_similar_row
60
+ @cli.clear_row("name", "similar_row")
61
+ string_values = [["key1", "val1"], ["key2", "val2"]]
62
+ num_values = [["key1", 1.0], ["key2", 2.0]]
63
+ d = Jubatus::Recommender::Datum.new(string_values, num_values)
64
+ @cli.update_row("name", "similar_row", d)
65
+ s1 = @cli.similar_row_from_id("name", "similar_row", 10)
66
+ s2 = @cli.similar_row_from_datum("name", d, 10)
67
+
68
+ end
69
+
70
+
71
+ def test_decode_row
72
+ @cli.clear_row("name", "decode_row")
73
+ string_values = [["key1", "val1"], ["key2", "val2"]]
74
+ num_values = [["key1", 1.0], ["key2", 2.0]]
75
+ d = Jubatus::Recommender::Datum.new(string_values, num_values)
76
+ @cli.update_row("name", "decode_row", d)
77
+ decoded_row = @cli.decode_row("name", "decode_row")
78
+ assert_equal(d.string_values, decoded_row.string_values)
79
+ assert_equal(d.num_values, decoded_row.num_values)
80
+ end
81
+
82
+
83
+ def test_get_row
84
+ @cli.clear("name")
85
+ string_values = [["key1", "val1"], ["key2", "val2"]]
86
+ num_values = [["key1", 1.0], ["key2", 2.0]]
87
+ d = Jubatus::Recommender::Datum.new(string_values, num_values)
88
+ @cli.update_row("name", "get_row", d)
89
+ row_names = @cli.get_all_rows("name")
90
+ assert_equal(row_names, ["get_row"])
91
+
92
+ end
93
+
94
+
95
+ def test_clear
96
+ @cli.clear("name")
97
+
98
+ end
99
+
100
+
101
+ def test_calcs
102
+ string_values = [["key1", "val1"], ["key2", "val2"]]
103
+ num_values = [["key1", 1.0], ["key2", 2.0]]
104
+ d = Jubatus::Recommender::Datum.new(string_values, num_values)
105
+ assert_in_delta(@cli.calc_similarity("name", d, d), 1, 0.000001)
106
+ assert_in_delta(@cli.calc_l2norm("name", d), Math.sqrt(1*1 + 1*1+ 1*1 + 2*2), 0.000001)
107
+
108
+ end
109
+
110
+
111
+ def test_clear
112
+ @cli.clear("name")
113
+
114
+ end
115
+
116
+
117
+ def test_save
118
+ assert_equal(@cli.save("name", "recommender.save_test.model"), true)
119
+
120
+ end
121
+
122
+
123
+ def test_load
124
+ model_name = "recommender.load_test.model"
125
+ @cli.save("name", model_name)
126
+ assert_equal(@cli.load("name", model_name), true)
127
+
128
+ end
129
+
130
+
131
+ def test_get_status
132
+ @cli.get_status("name")
133
+
134
+ end
135
+
136
+
137
+ end
138
+