You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ok...@apache.org on 2018/06/26 18:31:11 UTC
[2/5] madlib git commit: Madpack: Add dev-check and a compact
install-check.
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/lda/test/lda.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/lda/test/lda.ic.sql_in b/src/ports/postgres/modules/lda/test/lda.ic.sql_in
new file mode 100644
index 0000000..5931ba7
--- /dev/null
+++ b/src/ports/postgres/modules/lda/test/lda.ic.sql_in
@@ -0,0 +1,95 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+---------------------------------------------------------------------------
+-- Rules:
+-- ------
+-- 1) Any DB objects should be created w/o schema prefix,
+-- since this file is executed in a separate schema context.
+-- 2) There should be no DROP statements in this script, since
+-- all objects created in the default schema will be cleaned-up outside.
+---------------------------------------------------------------------------
+
+m4_include(`SQLCommon.m4')
+
+---------------------------------------------------------------------------
+-- Build vocabulary:
+---------------------------------------------------------------------------
+CREATE TABLE lda_vocab(wordid INT4, word TEXT);
+
+INSERT INTO lda_vocab VALUES
+(0, 'code'), (1, 'data'), (2, 'graph'), (3, 'image'), (4, 'input'), (5,
+'layer'), (6, 'learner'), (7, 'loss'), (8, 'model'), (9, 'network'), (10,
+'neuron'), (11, 'ob'), (13, 'rate'), (14, 'set'), (15,
+'signal'), (16, 'sparse'), (17, 'spatiaject'), (12, 'outputl'), (18, 'system'), (19, 'training');
+
+---------------------------------------------------------------------------
+-- Build training dataset:
+---------------------------------------------------------------------------
+CREATE TABLE lda_training
+(
+ docid INT4,
+ wordid INT4,
+ count INT4
+);
+
+INSERT INTO lda_training VALUES
+(0, 0, 2),(0, 3, 2),(0, 5, 1),(0, 7, 1),(0, 8, 1),(0, 9, 1),(0, 11, 1),(0, 13,
+1), (1, 0, 1),(1, 3, 1),(1, 4, 1),(1, 5, 1),(1, 6, 1),(1, 7, 1),(1, 10, 1),(1,
+14, 1),(1, 17, 1),(1, 18, 1), (2, 4, 2),(2, 5, 1),(2, 6, 2),(2, 12, 1),(2, 13,
+1),(2, 15, 1),(2, 18, 2), (3, 0, 1),(3, 1, 2),(3, 12, 3),(3, 16, 1),(3, 17,
+2),(3, 19, 1), (4, 1, 1),(4, 2, 1),(4, 3, 1),(4, 5, 1),(4, 6, 1),(4, 10, 1),(4,
+11, 1),(4, 14, 1),(4, 18, 1),(4, 19, 1), (5, 0, 1),(5, 2, 1),(5, 5, 1),(5, 7,
+1),(5, 10, 1),(5, 12, 1),(5, 16, 1),(5, 18, 1),(5, 19, 2), (6, 1, 1),(6, 3,
+1),(6, 12, 2),(6, 13, 1),(6, 14, 2),(6, 15, 1),(6, 16, 1),(6, 17, 1), (7, 0,
+1),(7, 2, 1),(7, 4, 1),(7, 5, 1),(7, 7, 2),(7, 8, 1),(7, 11, 1),(7, 14, 1),(7,
+16, 1), (8, 2, 1),(8, 4, 4),(8, 6, 2),(8, 11, 1),(8, 15, 1),(8, 18, 1),
+(9, 0, 1),(9, 1, 1),(9, 4, 1),(9, 9, 2),(9, 12, 2),(9, 15, 1),(9, 18, 1),(9,
+19, 1);
+
+
+CREATE TABLE lda_testing
+(
+ docid INT4,
+ wordid INT4,
+ count INT4
+);
+
+INSERT INTO lda_testing VALUES
+(0, 0, 2),(0, 8, 1),(0, 9, 1),(0, 10, 1),(0, 12, 1),(0, 15, 2),(0, 18, 1),(0,
+19, 1), (1, 0, 1),(1, 2, 1),(1, 5, 1),(1, 7, 1),(1, 12, 2),(1, 13, 1),(1, 16,
+1),(1, 17, 1),(1, 18, 1), (2, 0, 1),(2, 1, 1),(2, 2, 1),(2, 3, 1),(2, 4, 1),(2,
+5, 1),(2, 6, 1),(2, 12, 1),(2, 14, 1),(2, 18, 1), (3, 2, 2),(3, 6, 2),(3, 7,
+1),(3, 9, 1),(3, 11, 2),(3, 14, 1),(3, 15, 1), (4, 1, 1),(4, 2, 2),(4, 3,
+1),(4, 5, 2),(4, 6, 1),(4, 11, 1),(4, 18, 2);
+
+---------------------------------------------------------------------------
+-- Test
+---------------------------------------------------------------------------
+SELECT lda_train(
+ 'lda_training',
+ 'lda_model',
+ 'lda_output_data',
+ 20, 5, 2, 10, 0.01);
+
+
+SELECT lda_parse_model(model, voc_size, topic_num) AS parsed_model
+FROM lda_model;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/linalg/test/linalg.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linalg/test/linalg.ic.sql_in b/src/ports/postgres/modules/linalg/test/linalg.ic.sql_in
new file mode 100644
index 0000000..2c1c579
--- /dev/null
+++ b/src/ports/postgres/modules/linalg/test/linalg.ic.sql_in
@@ -0,0 +1,125 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test linear-algebra operations.
+ * -------------------------------------------------------------------------- */
+
+\set p 3
+
+SELECT
+ closest_columns(
+ ARRAY[
+ ARRAY[0,0],
+ ARRAY[0,1],
+ ARRAY[1,0],
+ ARRAY[0,1]
+ ]::DOUBLE PRECISION[][],
+ ARRAY[.5,.5]::DOUBLE PRECISION[],
+ 2::INTEGER
+ );
+
+CREATE TABLE some_vectors (
+ id SERIAL,
+ x FLOAT8[]
+);
+
+INSERT INTO some_vectors(x) VALUES
+(ARRAY[1,0,0,0]),
+(ARRAY[0,1,0,0]),
+(ARRAY[0,0,1,0]),
+(ARRAY[0,0,0,2]);
+
+
+SELECT matrix_column(matrix, 0), matrix_column(matrix, 1)
+FROM (
+ SELECT ARRAY[ARRAY[1,2],ARRAY[3,4]]::DOUBLE PRECISION[][] AS matrix
+) ignored;
+
+SELECT index_2d_array(ARRAY[ARRAY[1,2],ARRAY[3,4]]::float8[], 2);
+---------------------------------------------------------------------------
+SELECT * FROM deconstruct_2d_array(array[[1,2],[5,6]]) as k(id int, a float8, b float8);
+
+---------------------------------------------------------------------------
+-- user doc examples
+---------------------------------------------------------------------------
+CREATE TABLE two_vectors(
+ id integer,
+ a float8[],
+ b float8[]);
+INSERT INTO two_vectors VALUES
+(1, '{3,4}', '{4,5}'),
+(2, '{1,1,0,-4,5,3,4,106,14}', '{1,1,0,6,-3,1,2,92,2}');
+
+SELECT
+ id,
+ norm1(a),
+ norm2(a)
+FROM two_vectors
+WHERE id = 2;
+
+SELECT
+ id,
+ dist_norm1(a, b),
+ dist_norm2(a, b),
+ dist_pnorm(a, b, 5),
+ dist_inf_norm(a, b),
+ squared_dist_norm2(a, b),
+ dist_angle(a, b),
+ dist_tanimoto(a, b)
+FROM two_vectors
+WHERE id = 2;
+
+---------------------------------------------------------------------------
+CREATE TABLE matrix(
+ id integer,
+ m float8[]);
+INSERT INTO matrix VALUES
+(1, '{{4,5},{3,5},{9,0}}');
+
+SELECT
+ get_row(m, 1) AS row_1,
+ get_row(m, 2) AS row_2,
+ get_row(m, 3) AS row_3,
+ get_col(m, 1) AS col_1,
+ get_col(m, 2) AS col_2
+FROM matrix;
+
+---------------------------------------------------------------------------
+CREATE TABLE vector(
+ id integer,
+ v float8[]);
+INSERT INTO vector VALUES
+(1, '{4,3}'),
+(2, '{8,6}'),
+(3, '{12,9}');
+
+SELECT
+ avg(v),
+ normalized_avg(v),
+ matrix_agg(v)
+FROM vector;
+-------------------------------------------------------------------------
+
+-- adding 1.0 on left and right to avoid division by zero
+SELECT dist_jaccard(ARRAY['a', 'b', 'c']::TEXT[], ARRAY['a', 'b', 'c']::TEXT[]);
+
+-------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/linalg/test/matrix_ops.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linalg/test/matrix_ops.ic.sql_in b/src/ports/postgres/modules/linalg/test/matrix_ops.ic.sql_in
new file mode 100644
index 0000000..3736e53
--- /dev/null
+++ b/src/ports/postgres/modules/linalg/test/matrix_ops.ic.sql_in
@@ -0,0 +1,121 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+m4_include(`SQLCommon.m4')
+
+CREATE TABLE s(
+ row_id INT8,
+ col_id INT8,
+ val INT4
+)
+m4_ifdef(`__GREENPLUM__',
+`WITH (APPENDONLY=TRUE) DISTRIBUTED BY (row_id)');
+
+INSERT INTO s VALUES(1, 1, 1) , (1, 2, 3) , (2, 1, 4) , (2, 2, 5) , (3, 1, 7) ,
+ (3, 2, 8), (3, 3, 0);
+
+DROP TABLE IF EXISTS s_t;
+SELECT matrix_trans('s', 'row=row_id, col=col_id, val=val', 's_t', 'row=row_num, col=col_num, val=val');
+
+DROP TABLE IF EXISTS d;
+SELECT matrix_densify('s', 'row=row_id, col=col_id, val=val', 'd');
+
+DROP TABLE IF EXISTS s;
+SELECT matrix_sparsify('d', 'row=row_id', 's', 'row=row_id, col=col_id, val=val');
+
+DROP TABLE IF EXISTS s2;
+SELECT matrix_mult('s', 'row=row_id, col=col_id, val=val, trans=false',
+ 's_t', 'row=row_num, col=col_num, val=val, trans=false', 's2');
+
+DROP TABLE IF EXISTS dd;
+SELECT matrix_max('d', 'row=row_id', 1, 'dd', true);
+
+DROP TABLE IF EXISTS dd;
+SELECT matrix_min('d', 'row=row_id', 2, 'dd', true);
+
+SELECT matrix_extract_col('d', 'row=row_id', 3);
+SELECT matrix_extract_row('s', 'row=row_id, col=col_id, val=val', 1);
+
+DROP TABLE IF EXISTS d_d;
+SELECT matrix_square('d', 'row=row_id', 'd_d');
+
+DROP TABLE IF EXISTS s3;
+SELECT matrix_add('s', 'row=row_id, col=col_id, val=val',
+ 's', 'row=row_id, col=col_id, val=val',
+ 's3');
+
+DROP TABLE IF EXISTS s3;
+SELECT matrix_sub('s', 'row=row_id, col=col_id, val=val',
+ 's', 'row=row_id, col=col_id, val=val',
+ 's3');
+
+DROP TABLE IF EXISTS s3;
+SELECT matrix_elem_mult('s', 'row=row_id, col=col_id, val=val',
+ 's', 'row=row_id, col=col_id, val=val',
+ 's3');
+
+CREATE TABLE b(
+ row_id INT4,
+ col_id INT4,
+ block INT4[]
+)
+m4_ifdef(`__GREENPLUM__',
+`WITH (APPENDONLY=TRUE) DISTRIBUTED BY (row_id)');
+
+INSERT INTO b VALUES(1, 1, array[[1,2], [3,4]]);
+INSERT INTO b VALUES(2, 1, array[[5,6], [7,8]]);
+INSERT INTO b VALUES(3, 1, array[[9,10]]);
+
+
+SELECT matrix_mem_trans(array[[1,2,3], [4,5,6]]);
+SELECT matrix_mem_mult(array[[1,2,3], [4,5,6]], array[[1,4],[2,5],[3,6]]);
+
+DROP TABLE if exists b_t;
+SELECT matrix_block_trans('b', 'row=row_id, col=col_id, val=block', 'b_t', NULL);
+
+DROP TABLE if exists b2;
+SELECT matrix_block_square('b', 'row=row_id, col=col_id, val=block', 'b2', NULL);
+
+DROP TABLE if exists b2;
+SELECT matrix_block_mult('b', 'row=row_id, col=col_id, val=block',
+ 'b_t', 'row=row_id, col=col_id, val=block',
+ 'b2', NULL);
+
+DROP TABLE if exists d_b;
+SELECT matrix_blockize('d', 'row=row_id', 2, 2, 'd_b');
+
+DROP TABLE if exists d_r;
+SELECT matrix_unblockize('d_b', 'row=row_id', 'd_r', NULL);
+
+
+
+CREATE TABLE random_matrix(row_id INTEGER, row_vec DOUBLE PRECISION[]);
+INSERT INTO random_matrix VALUES
+ (1, array[2, 2, 0]), (2, array[15, 2, 0]), (3, array[0, 5, 2]);
+
+SELECT array_to_1d(__matrix_dense_inverse(3, row_id - 1, row_vec)) as result
+FROM random_matrix;
+
+CREATE TABLE random_sparse_matrix(row_id INTEGER, col_id INTEGER, val DOUBLE PRECISION);
+INSERT INTO random_sparse_matrix VALUES
+ (1, 1, 2), (1, 2, 2), (2, 1, 15), (2, 2, 2), (3, 2, 5), (3, 3, 2);
+SELECT array_to_1d(__matrix_sparse_inverse(3, 3, row_id - 1, col_id - 1, val)) as result
+FROM random_sparse_matrix
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/linalg/test/svd.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linalg/test/svd.ic.sql_in b/src/ports/postgres/modules/linalg/test/svd.ic.sql_in
new file mode 100644
index 0000000..e13aee8
--- /dev/null
+++ b/src/ports/postgres/modules/linalg/test/svd.ic.sql_in
@@ -0,0 +1,47 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* ------------------------------------------------------------------------
+ * Dense cases
+ * ----------------------------------------------------------------------*/
+drop table if exists mat;
+CREATE TABLE mat (
+ row_id integer,
+ row_vec double precision[]
+);
+
+-- COPY mat (row_id, row_vec) FROM stdin delimiter '|';
+-- 1|{396,840,353,446}
+-- 2|{691,58,899,163}
+-- 3|{293,742,298,75}
+-- 4|{462,532,787,265}
+-- \.
+
+COPY mat (row_id, row_vec) FROM stdin delimiter '|';
+1|{396}
+\.
+
+drop table if exists svd_u;
+drop table if exists svd_v;
+drop table if exists svd_s;
+drop table if exists svd_summary;
+select svd('mat', 'svd', 'row_id', 1, NULL, 'svd_summary');
+
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/linear_systems/test/dense_linear_sytems.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linear_systems/test/dense_linear_sytems.ic.sql_in b/src/ports/postgres/modules/linear_systems/test/dense_linear_sytems.ic.sql_in
new file mode 100644
index 0000000..74fbb80
--- /dev/null
+++ b/src/ports/postgres/modules/linear_systems/test/dense_linear_sytems.ic.sql_in
@@ -0,0 +1,50 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Dense Linear Systems
+ * -------------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS linear_system_test_data;
+CREATE TABLE "Linear_systems_test_data" (
+ id INTEGER NOT NULL,
+ "A" DOUBLE PRECISION[],
+ b DOUBLE PRECISION
+);
+
+INSERT INTO "Linear_systems_test_data"(id, "A", b) VALUES
+(0, ARRAY[1,0,0], 20),
+(1, ARRAY[0,1,0], 15),
+(2, ARRAY[0,0,1], 20);
+
+drop table if exists result_table;
+select linear_solver_dense(
+ '"Linear_systems_test_data"',
+ 'result_table',
+ 'id',
+ '"A"',
+ 'b',
+ NULL,
+ 'direct',
+ 'algorithm=llt'
+ );
+
+drop table if exists result_table;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/linear_systems/test/sparse_linear_sytems.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linear_systems/test/sparse_linear_sytems.ic.sql_in b/src/ports/postgres/modules/linear_systems/test/sparse_linear_sytems.ic.sql_in
new file mode 100644
index 0000000..87ced14
--- /dev/null
+++ b/src/ports/postgres/modules/linear_systems/test/sparse_linear_sytems.ic.sql_in
@@ -0,0 +1,64 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test sparse Linear Systems
+ * -------------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS "Sparse_linear_systems_lhs";
+CREATE TABLE "Sparse_linear_systems_lhs" (
+ "Rid" INTEGER NOT NULL,
+ cid INTEGER,
+ val DOUBLE PRECISION
+);
+
+DROP TABLE IF EXISTS "Sparse_linear_systems_rhs";
+CREATE TABLE "Sparse_linear_systems_rhs" (
+ "Rid" INTEGER NOT NULL,
+ val DOUBLE PRECISION
+);
+
+
+INSERT INTO "Sparse_linear_systems_lhs"("Rid", cid, val) VALUES
+(0, 0, 1),
+(1, 1, 1),
+(2, 2, 1),
+(3, 3, 1);
+
+INSERT INTO "Sparse_linear_systems_rhs"("Rid", val) VALUES
+(0, 1),
+(1, 1),
+(2, 1);
+
+drop table if exists result_table;
+select linear_solver_sparse(
+ '"Sparse_linear_systems_lhs"',
+ '"Sparse_linear_systems_rhs"',
+ 'result_table',
+ '"Rid"',
+ 'cid',
+ 'val',
+ '"Rid"',
+ 'val',
+ 4,
+ NULL,
+ 'direct',
+ 'algorithm=ldlt');
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/pca/test/pca.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/pca/test/pca.ic.sql_in b/src/ports/postgres/modules/pca/test/pca.ic.sql_in
new file mode 100644
index 0000000..1a64ba3
--- /dev/null
+++ b/src/ports/postgres/modules/pca/test/pca.ic.sql_in
@@ -0,0 +1,52 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * PCA Install Check.
+ * -------------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS mat;
+CREATE TABLE mat (
+ row_id integer,
+ row_vec double precision[]
+);
+
+COPY mat (row_id, row_vec) FROM stdin delimiter '|';
+1|{396,84,1}
+2|{691,58,1}
+3|{293,1,1}
+\.
+
+drop table if exists result_table_214712398172490837;
+drop table if exists result_table_214712398172490837_mean;
+drop table if exists result_table_214712398172490838;
+select pca_train('mat', 'result_table_214712398172490837', 'row_id', 3,
+NULL, 3, FALSE, 'result_table_214712398172490838');
+select * from result_table_214712398172490837;
+select * from result_table_214712398172490838;
+
+drop table if exists result_table_214712398172490837;
+drop table if exists result_table_214712398172490837_mean;
+drop table if exists result_table_214712398172490838;
+select pca_train('mat', 'result_table_214712398172490837', 'row_id', 0.8,
+NULL, 3, FALSE, 'result_table_214712398172490838');
+select * from result_table_214712398172490837;
+select * from result_table_214712398172490838;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/pca/test/pca_project.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/pca/test/pca_project.ic.sql_in b/src/ports/postgres/modules/pca/test/pca_project.ic.sql_in
new file mode 100644
index 0000000..19a4bab
--- /dev/null
+++ b/src/ports/postgres/modules/pca/test/pca_project.ic.sql_in
@@ -0,0 +1,79 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * pca Install Check.
+ * -------------------------------------------------------------------------- */
+
+-----------------------------------------------------------------------------
+-- DENSE pca Project : Make sure all possible default calls for dense pca work
+-- Test data (Indentical to SVD). See the SVD module for details
+-- on how the data was generated
+-----------------------------------------------------------------------------
+DROP TABLE IF EXISTS mat;
+CREATE TABLE mat (
+ row_id integer,
+ row_vec double precision[]
+);
+
+COPY mat (row_id, row_vec) FROM stdin delimiter '|';
+1|{396,1}
+2|{691,58}
+3|{293,1}
+4|{462,532}
+5|{304,151}
+\.
+
+DROP TABLE IF EXISTS result;
+CREATE TABLE result (
+ row_id integer,
+ principal_components double precision[],
+ std_dev double precision,
+ proportion double precision
+);
+
+DROP TABLE IF EXISTS result_mean;
+CREATE TABLE result_mean (
+ column_mean double precision[]
+);
+
+--To reduce runtime, we are inserting the component data instead of calling pca_train
+TRUNCATE TABLE result, result_mean;
+
+COPY result (row_id, principal_components, std_dev, proportion) FROM stdin delimiter '|';
+1|{0.16526842327063,-0.366421389980424}|505.194492329765|0.315197084359835
+2|{0.291457976390416,-0.152774780364566}|388.886052223584|0.18677111487815
+\.
+
+COPY result_mean (column_mean) FROM stdin delimiter '|';
+{559.1875,479.6875}
+\.
+
+
+drop table if exists out_table;
+drop table if exists residual_table;
+drop table if exists result_summary_table;
+select pca_project( 'mat',
+ 'result',
+ 'out_table',
+ 'row_id',
+ 'residual_table',
+ 'result_summary_table');
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/prob/test/prob.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/prob/test/prob.ic.sql_in b/src/ports/postgres/modules/prob/test/prob.ic.sql_in
new file mode 100644
index 0000000..4d80629
--- /dev/null
+++ b/src/ports/postgres/modules/prob/test/prob.ic.sql_in
@@ -0,0 +1,44 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test probability functions.
+ * -------------------------------------------------------------------------- */
+
+SELECT
+ bernoulli_cdf(0, 0.3),
+ beta_cdf(-1, 1, 1) ,
+ binomial_cdf(11, 11, 0.4),
+ cauchy_cdf('-Inf', 1, 2),
+ chi_squared_cdf(-1, 1) ,
+ exponential_cdf(-1, 1),
+ extreme_value_cdf(3, 1, 2),
+ fisher_f_cdf(0, 1, 1),
+ gamma_cdf(0, 0.5, 2) ,
+ geometric_cdf(0, 0.3) ,
+ hypergeometric_cdf(-1 ,50, 30, 500),
+ inverse_gamma_cdf(-1, 1, 2),
+ laplace_pdf('-Inf', 1, 1),
+ logistic_quantile(0.7310586, 1, 2),
+ normal_quantile(NULL, 0, 1),
+ poisson_cdf(NULL, 1),
+ uniform_pdf(-1, 0, 1)
+;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/recursive_partitioning/test/decision_tree.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/recursive_partitioning/test/decision_tree.ic.sql_in b/src/ports/postgres/modules/recursive_partitioning/test/decision_tree.ic.sql_in
new file mode 100644
index 0000000..c4bfbf9
--- /dev/null
+++ b/src/ports/postgres/modules/recursive_partitioning/test/decision_tree.ic.sql_in
@@ -0,0 +1,70 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+--------------------------------------------------------------------------------
+-- Validate tree train function ------------------------------------------------
+DROP TABLE IF EXISTS dt_golf CASCADE;
+CREATE TABLE dt_golf (
+ id integer NOT NULL,
+ id_2 integer,
+ "OUTLOOK" text,
+ temperature double precision,
+ humidity double precision,
+ "Cont_features" double precision[],
+ cat_features text[],
+ windy boolean,
+ class text
+) ;
+
+INSERT INTO dt_golf (id,"OUTLOOK",temperature,humidity,"Cont_features",cat_features, windy,class) VALUES
+(1, 'sunny', 85, 85,ARRAY[85, 85], ARRAY['a', 'b'], false, 'Don''t Play'),
+(2, 'sunny', 80, 90, ARRAY[80, 90], ARRAY['a', 'b'], true, 'Don''t Play'),
+(3, 'overcast', 83, 78, ARRAY[83, 78], ARRAY['a', 'b'], false, 'Play'),
+(4, 'rain', 70, NULL, ARRAY[70, 96], ARRAY['a', 'b'], false, 'Play'),
+(5, 'rain', 68, 80, ARRAY[68, 80], ARRAY['a', 'b'], false, 'Play'),
+(6, 'rain', NULL, 70, ARRAY[65, 70], ARRAY['a', 'b'], true, 'Don''t Play'),
+(7, 'overcast', 64, 65, ARRAY[64, 65], ARRAY['c', 'b'], NULL , 'Play'),
+(8, 'sunny', 72, 95, ARRAY[72, 95], ARRAY['a', 'b'], false, 'Don''t Play');
+
+update dt_golf set id_2 = id % 2;
+-------------------------------------------------------------------------
+
+-- no grouping, with cross_validation
+DROP TABLE IF EXISTS train_output, train_output_summary, train_output_cv;
+SELECT tree_train('dt_golf'::text, -- source table
+ 'train_output'::text, -- output model table
+ 'id'::text, -- id column
+ 'temperature::double precision'::text, -- response
+ 'humidity, windy'::text, -- features
+ NULL::text, -- exclude columns
+ 'gini'::text, -- split criterion
+ NULL::text, -- no grouping
+ NULL::text, -- no weights
+ 1::integer, -- max depth
+ 2::integer, -- min split
+ 2::integer, -- min bucket
+ 2::integer, -- number of bins per continuous variable
+ 'cp=0.01' -- cost-complexity pruning parameter
+ );
+
+SELECT _print_decision_tree(tree) from train_output;
+SELECT tree_display('train_output', False);
+-------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/recursive_partitioning/test/random_forest.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/recursive_partitioning/test/random_forest.ic.sql_in b/src/ports/postgres/modules/recursive_partitioning/test/random_forest.ic.sql_in
new file mode 100644
index 0000000..1a5ab2a
--- /dev/null
+++ b/src/ports/postgres/modules/recursive_partitioning/test/random_forest.ic.sql_in
@@ -0,0 +1,66 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS dt_golf CASCADE;
+CREATE TABLE dt_golf (
+ id integer NOT NULL,
+ "OUTLOOK" text,
+ temperature double precision,
+ humidity double precision,
+ "Cont_features" double precision[],
+ cat_features text[],
+ windy boolean,
+ class text
+) ;
+
+INSERT INTO dt_golf (id,"OUTLOOK",temperature,humidity,"Cont_features",cat_features, windy,class) VALUES
+(1, 'sunny', 85, 85,ARRAY[85, 85], ARRAY['a', 'b'], false, 'Don''t Play'),
+(2, 'sunny', 80, 90, ARRAY[80, 90], ARRAY['a', 'b'], true, 'Don''t Play'),
+(3, 'overcast', 83, 78, ARRAY[83, 78], ARRAY['a', 'b'], false, 'Play'),
+(4, 'rain', 70, NULL, ARRAY[70, 96], ARRAY['a', 'b'], false, 'Play'),
+(5, 'rain', 68, 80, ARRAY[68, 80], ARRAY['a', 'b'], false, 'Play'),
+(6, 'rain', NULL, 70, ARRAY[65, 70], ARRAY['a', 'b'], true, 'Don''t Play'),
+(7, 'overcast', 64, 65, ARRAY[64, 65], ARRAY['c', 'b'], NULL , 'Play'),
+(8, 'sunny', 72, 95, ARRAY[72, 95], ARRAY['a', 'b'], false, 'Don''t Play');
+
+-------------------------------------------------------------------------
+-- classification without grouping
+DROP TABLE IF EXISTS train_output, train_output_summary, train_output_group;
+SELECT forest_train(
+ 'dt_golf', -- source table
+ 'train_output', -- output model table
+ 'id' , -- id column
+ 'class', -- response
+ 'windy, "Cont_features"[1]', -- features
+ NULL, -- exclude columns
+ NULL, -- no grouping
+ 2, -- num of trees
+ NULL, -- num of random features
+ TRUE, -- importance
+ 1, -- num_permutations
+ 1, -- max depth
+ 1, -- min split
+ 1, -- min bucket
+ 2, -- number of bins per continuous variable
+ 'max_surrogates=0',
+ FALSE
+ );
+
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/regress/test/clustered.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/test/clustered.ic.sql_in b/src/ports/postgres/modules/regress/test/clustered.ic.sql_in
new file mode 100644
index 0000000..e2abc20
--- /dev/null
+++ b/src/ports/postgres/modules/regress/test/clustered.ic.sql_in
@@ -0,0 +1,48 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+-- Test clustered standard errors
+
+DROP TABLE IF EXISTS abalone1;
+
+CREATE TABLE abalone1 (
+ id integer,
+ sex text,
+ length double precision,
+ diameter double precision,
+ height double precision,
+ whole double precision,
+ shucked double precision,
+ viscera double precision,
+ shell double precision,
+ rings integer
+);
+
+INSERT INTO abalone1 VALUES
+(1, 'M', 0.45500000000000002, 0.36499999999999999, 0.095000000000000001, 0.51400000000000001, 0.22450000000000001, 0.10100000000000001, 0.14999999999999999, 15),
+(4, 'M', 0.44, 0.36499999999999999, 0.125, 0.51600000000000001, 0.2155, 0.114, 0.155, 10),
+(3, 'F', 0.53000000000000003, 0.41999999999999998, 0.13500000000000001, 0.67700000000000005, 0.25650000000000001, 0.14149999999999999, 0.20999999999999999, 9),
+(2, 'M', 0.34999999999999998, 0.26500000000000001, 0.089999999999999997, 0.22550000000000001, 0.099500000000000005, 0.048500000000000001, 0.070000000000000007, 7),
+(5, 'I', 0.33000000000000002, 0.255, 0.080000000000000002, 0.20499999999999999, 0.089499999999999996, 0.0395, 0.055, 7);
+
+drop table if exists temp_out;
+drop table if exists temp_out_summary;
+select clustered_variance_linregr('abalone1', 'temp_out', 'rings', 'array[1, length]', 'sex');
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/regress/test/linear.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/test/linear.ic.sql_in b/src/ports/postgres/modules/regress/test/linear.ic.sql_in
new file mode 100644
index 0000000..4fb5398
--- /dev/null
+++ b/src/ports/postgres/modules/regress/test/linear.ic.sql_in
@@ -0,0 +1,56 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+
+/* -----------------------------------------------------------------------------
+ * Test Linear Regression.
+ * -------------------------------------------------------------------------- */
+
+/*
+ * The following example is taken from:
+ * http://www.weibull.com/DOEWeb/estimating_regression_models_using_least_squares.htm#Example%205.1
+ * http://www.weibull.com/DOEWeb/hypothesis_tests_in_multiple_linear_regression.htm#Example%205.3
+ */
+DROP TABLE IF EXISTS weibull;
+CREATE TABLE weibull (
+ id INTEGER NOT NULL,
+ x1 DOUBLE PRECISION,
+ x2 DOUBLE PRECISION,
+ y DOUBLE PRECISION
+ , CONSTRAINT pk_weibull PRIMARY KEY (id)
+);
+
+/*
+ * We materialize the table here because on MPP systems we want to distribute
+ * the data to the segments (and not do the calculations in memory).
+ */
+INSERT INTO weibull(id, x1, x2, y) VALUES
+( 1, 41.9, 29.1, 251.3),
+( 2, 43.4, 29.3, 251.3),
+( 3, 43.9, 29.5, 248.3),
+( 4, 44.5, 29.7, 267.5),
+( 5, 47.3, 29.9, 273.0);
+
+SELECT (linregr(y, ARRAY[1, x1, x2])).*
+FROM weibull;
+
+
+
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/regress/test/logistic.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/test/logistic.ic.sql_in b/src/ports/postgres/modules/regress/test/logistic.ic.sql_in
new file mode 100644
index 0000000..bd7ed3a
--- /dev/null
+++ b/src/ports/postgres/modules/regress/test/logistic.ic.sql_in
@@ -0,0 +1,59 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+
+/* -----------------------------------------------------------------------------
+ * Test Logistic Regression.
+ * -------------------------------------------------------------------------- */
+
+/*
+ * The following example is taken from:
+ * http://luna.cas.usf.edu/~mbrannic/files/regression/Logistic.html
+ * Predicting heart attack
+ */
+DROP TABLE IF EXISTS patients;
+CREATE TABLE patients (
+ id INTEGER NOT NULL,
+ second_attack INTEGER,
+ treatment INTEGER,
+ trait_anxiety INTEGER
+ , CONSTRAINT pk_patient PRIMARY key (id)
+);
+
+INSERT INTO patients(ID, second_attack, treatment, trait_anxiety) VALUES
+( 0, NULL, 1, 70),
+( 1, 1, 1, 70),
+( 2, 1, 1, 80),
+( 3, 1, 1, 50),
+( 4, 1, 0, 60),
+( 5, 1, 0, 40);
+
+drop table if exists temp_result;
+drop table if exists temp_result_summary;
+select logregr_train(
+ 'patients',
+ 'temp_result',
+ 'second_attack',
+ 'ARRAY[1, treatment]',
+ Null,
+ 2,
+ 'irls'
+);
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/regress/test/marginal.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/test/marginal.ic.sql_in b/src/ports/postgres/modules/regress/test/marginal.ic.sql_in
new file mode 100644
index 0000000..0279650
--- /dev/null
+++ b/src/ports/postgres/modules/regress/test/marginal.ic.sql_in
@@ -0,0 +1,69 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Logistic Regression.
+ * -------------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS patients;
+CREATE TABLE patients (
+ id INTEGER NOT NULL,
+ second_attack INTEGER,
+ treatment INTEGER,
+ trait_anxiety INTEGER
+ , CONSTRAINT pk_patient PRIMARY key (id)
+);
+INSERT INTO patients(ID, second_attack, treatment, trait_anxiety) VALUES
+( 1, 1, 1, 70),
+( 2, 1, 1, 80),
+( 3, 0, 1, 50),
+( 4, 0, 0, 60);
+
+-- CHECK : Make sure all possible default values work
+drop table if exists result_table;
+drop table if exists result_table_summary;
+select margins_logregr(
+ 'patients',
+ 'result_table',
+ 'second_attack',
+ 'ARRAY[1, treatment]',
+ NULL,
+ NULL,
+ 2,
+ 'irls',
+ 1e-5
+ );
+/* -----------------------------------------------------------------------------
+ * Test Multinomial Logistic Regression.
+ * -------------------------------------------------------------------------- */
+
+-- CHECK : Make sure cherry picking marginal values work
+drop table if exists result_table;
+drop table if exists result_table_summary;
+select margins_mlogregr(
+ 'patients',
+ 'result_table',
+ 'second_attack',
+ 'ARRAY[1, treatment]',
+ 0,
+ NULL,
+ ARRAY[1, 2],
+ 'max_iter=2, optimizer=newton, tolerance=0.01');
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/regress/test/multilogistic.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/test/multilogistic.ic.sql_in b/src/ports/postgres/modules/regress/test/multilogistic.ic.sql_in
new file mode 100644
index 0000000..0c5a759
--- /dev/null
+++ b/src/ports/postgres/modules/regress/test/multilogistic.ic.sql_in
@@ -0,0 +1,61 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Multinomial Logistic Regression.
+ * -------------------------------------------------------------------------- */
+
+/*
+ * The following example is taken from:
+ * http://luna.cas.usf.edu/~mbrannic/files/regression/Logistic.html
+ * Predicting heart attack. This example is the same as the (binomial) logistic
+ * regression example.
+ */
+DROP TABLE IF EXISTS patients;
+CREATE TABLE patients (
+ id INTEGER NOT NULL,
+ "SECOND_ATTACK" INTEGER,
+ treatment INTEGER,
+ trait_anxiety INTEGER
+ ,CONSTRAINT pk_patient PRIMARY key (id)
+);
+
+INSERT INTO patients(id, "SECOND_ATTACK", treatment, trait_anxiety) VALUES
+( 1, 1, 1, 70),
+( 2, 1, 1, 80),
+( 3, 0, 1, 50),
+( 4, 0, 0, 60);
+
+DROP TABLE IF EXISTS temp_result;
+DROP TABLE IF EXISTS temp_result_summary;
+SELECT mlogregr_train(
+ 'patients',
+ 'temp_result',
+ '"SECOND_ATTACK"',
+ 'ARRAY[1, treatment]');
+
+DROP TABLE IF EXISTS predict_result;
+SELECT mlogregr_predict(
+ 'temp_result',
+ 'patients',
+ 'id',
+ 'predict_result'
+ );
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/regress/test/robust.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/test/robust.ic.sql_in b/src/ports/postgres/modules/regress/test/robust.ic.sql_in
new file mode 100644
index 0000000..54a26ff
--- /dev/null
+++ b/src/ports/postgres/modules/regress/test/robust.ic.sql_in
@@ -0,0 +1,62 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Linear Regression.
+ * -------------------------------------------------------------------------- */
+
+/*
+ * The following example is taken from:
+ * http://www.weibull.com/DOEWeb/estimating_regression_models_using_least_squares.htm#Example%205.1
+ * http://www.weibull.com/DOEWeb/hypothesis_tests_in_multiple_linear_regression.htm#Example%205.3
+ */
+DROP TABLE IF EXISTS weibull;
+CREATE TABLE weibull (
+ id INTEGER NOT NULL,
+ x1 DOUBLE PRECISION,
+ x2 DOUBLE PRECISION,
+ y DOUBLE PRECISION
+ , CONSTRAINT pk_weibull PRIMARY KEY (id)
+);
+
+/*
+ * We materialize the table here because on MPP systems we want to distribute
+ * the data to the segments (and not do the calculations in memory).
+ */
+INSERT INTO weibull(id, x1, x2, y) VALUES
+( 1, 41.9, 29.1, 251.3),
+( 2, 43.4, 29.3, 251.3),
+( 3, 43.9, 29.5, 248.3),
+( 4, 44.5, 29.7, 267.5);
+
+
+--------------------- Robust linear regression install checks -----------
+
+SELECT (robust_linregr(y, ARRAY[1, x1, x2], coef)).*
+FROM
+( SELECT (linregr(y, ARRAY[1, x1, x2])).coef
+ FROM weibull
+) as mle_coef,
+weibull as src;
+DROP TABLE IF EXISTS result_weibull_3;
+DROP TABLE IF EXISTS result_weibull_3_summary;
+select robust_variance_linregr('weibull', 'result_weibull_3', 'y', 'ARRAY[1, x1, x2]');
+-- End of robust linear regression
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/sample/test/balance_sample.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/sample/test/balance_sample.ic.sql_in b/src/ports/postgres/modules/sample/test/balance_sample.ic.sql_in
new file mode 100644
index 0000000..597db9b
--- /dev/null
+++ b/src/ports/postgres/modules/sample/test/balance_sample.ic.sql_in
@@ -0,0 +1,43 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS "TEST_s" CASCADE;
+
+CREATE TABLE "TEST_s"(
+ id1 INTEGER,
+ id2 INTEGER,
+ gr1 INTEGER,
+ gr2 INTEGER,
+ gr3 TEXT
+);
+
+INSERT INTO "TEST_s" VALUES
+(1,0,1,1,'a'),
+(1,0,1,1,'b'),
+(1,0,1,2,'b'),
+(30,30,6,6,'d'),
+(40,40,6,6,'d'),
+(700,70,NULL,2,'e');
+
+-- --- Test for random undersampling with replacement
+DROP TABLE IF EXISTS out_sr2;
+SELECT balance_sample('"TEST_s"', 'out_sr2', 'gr1', 'undersample ', NULL, NULL, TRUE, TRUE);
+
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/sample/test/sample.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/sample/test/sample.ic.sql_in b/src/ports/postgres/modules/sample/test/sample.ic.sql_in
new file mode 100644
index 0000000..8d00c29
--- /dev/null
+++ b/src/ports/postgres/modules/sample/test/sample.ic.sql_in
@@ -0,0 +1,33 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test random sampling.
+ * -------------------------------------------------------------------------- */
+
+SELECT weighted_sample(i, i) AS value
+FROM generate_series(1,10) AS i;
+
+SELECT *, poisson_random(1.0)
+FROM generate_series(1,5);
+
+SELECT *, gamma_random(5)
+FROM generate_series(1,5);
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/sample/test/stratified_sample.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/sample/test/stratified_sample.ic.sql_in b/src/ports/postgres/modules/sample/test/stratified_sample.ic.sql_in
new file mode 100644
index 0000000..9bad19f
--- /dev/null
+++ b/src/ports/postgres/modules/sample/test/stratified_sample.ic.sql_in
@@ -0,0 +1,42 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS "TEST";
+
+CREATE TABLE "TEST"(
+ id1 INTEGER,
+ "ID2" INTEGER,
+ gr1 INTEGER,
+ gr2 INTEGER
+);
+
+INSERT INTO "TEST" VALUES
+(1,0,1,1),
+(9,0,1,1),
+(0,2,1,2),
+(0,3,1,2),
+(30,30,2,2),
+(70,70,2,2)
+;
+
+DROP TABLE IF EXISTS out;
+SELECT stratified_sample('"TEST"', 'out', 0.5, NULL, 'id1,"ID2",gr1,gr2', FALSE);
+
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/sample/test/train_test_split.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/sample/test/train_test_split.ic.sql_in b/src/ports/postgres/modules/sample/test/train_test_split.ic.sql_in
new file mode 100644
index 0000000..1270c07
--- /dev/null
+++ b/src/ports/postgres/modules/sample/test/train_test_split.ic.sql_in
@@ -0,0 +1,43 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS test;
+
+CREATE TABLE test(
+ id1 INTEGER,
+ id2 INTEGER,
+ gr1 INTEGER,
+ gr2 INTEGER
+);
+
+INSERT INTO test VALUES
+(1,0,1,1),
+(9,0,1,1),
+(0,2,1,2),
+(0,3,1,2),
+(30,30,2,2),
+(70,70,2,2)
+;
+
+SELECT setseed(0);
+
+DROP TABLE IF EXISTS out_train,out_test,out;
+SELECT train_test_split('test', 'out', 0.1, 0.2, NULL, 'id1,id2,gr1,gr2', FALSE, TRUE);
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/anova_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/anova_test.ic.sql_in b/src/ports/postgres/modules/stats/test/anova_test.ic.sql_in
new file mode 100644
index 0000000..f119a65
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/anova_test.ic.sql_in
@@ -0,0 +1,49 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test ANOVA.
+ *
+ * Example taken from:
+ * http://www.itl.nist.gov/div898/handbook/prc/section4/prc433.htm
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE nist_anova_test (
+ id SERIAL,
+ resistance FLOAT8[]
+);
+
+COPY nist_anova_test(resistance) FROM stdin;
+{6.9,8.3,8.0}
+{5.4,6.8,10.5}
+{5.8,7.8,8.1}
+{4.6,9.2,6.9}
+{4.0,6.5,9.3}
+\.
+
+CREATE TABLE one_way_anova_nist AS
+SELECT (one_way_anova(level, value)).* FROM (
+ SELECT level, resistance[level] AS value
+ FROM
+ nist_anova_test, (
+ SELECT * FROM generate_series(1,3) level
+ ) q
+) q;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/chi2_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/chi2_test.ic.sql_in b/src/ports/postgres/modules/stats/test/chi2_test.ic.sql_in
new file mode 100644
index 0000000..4a01b7d
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/chi2_test.ic.sql_in
@@ -0,0 +1,42 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Chi-squared goodness-of-fit test.
+ *
+ * Example taken from:
+ * http://www.statsdirect.com/help/chi_square_tests/chi_good.htm
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE chi2_test_blood_group (
+ id SERIAL,
+ blood_group VARCHAR,
+ observed BIGINT,
+ expected DOUBLE PRECISION
+);
+
+INSERT INTO chi2_test_blood_group(blood_group, observed, expected) VALUES
+ ('O', 67, 82.28),
+ ('A', 83, 84.15),
+ ('B', 29, 14.96),
+ ('AB', 8, 5.61);
+
+SELECT chi2_gof_test(observed, expected) FROM chi2_test_blood_group;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/correlation.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/correlation.ic.sql_in b/src/ports/postgres/modules/stats/test/correlation.ic.sql_in
new file mode 100644
index 0000000..042fc6d
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/correlation.ic.sql_in
@@ -0,0 +1,35 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+CREATE TABLE rand_numeric (a int2, b int4, c int8, d float4, e float8, f real);
+INSERT INTO rand_numeric
+SELECT
+ random() * 1000,
+ random() * 1000,
+ random() * 1000,
+ random() * 1000,
+ random() * 1000,
+ random() * 1000
+FROM
+ generate_series(1, 5);
+
+DROP TABLE IF EXISTS corr_output, corr_output_summary;
+SELECT * FROM correlation('rand_numeric', 'corr_output', 'a, c, e');
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/cox_prop_hazards.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/cox_prop_hazards.ic.sql_in b/src/ports/postgres/modules/stats/test/cox_prop_hazards.ic.sql_in
new file mode 100644
index 0000000..30854ee
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/cox_prop_hazards.ic.sql_in
@@ -0,0 +1,51 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Cox proportional hazard survival regression
+ *
+ * Both Example taken from:
+ * http://www.sph.emory.edu/~cdckms/CoxPH/prophaz2.html
+ * -------------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS leukemia;
+CREATE TABLE leukemia (
+ id INTEGER NOT NULL,
+ grp DOUBLE PRECISION,
+ wbc DOUBLE PRECISION,
+ timedeath INTEGER,
+ status BOOLEAN
+ ,CONSTRAINT pk_leukemia PRIMARY key (id)
+);
+
+
+INSERT INTO leukemia(id, grp, wbc, timedeath,status) VALUES
+(0,0,1.45,35,TRUE),
+(1,0,1.47,34,TRUE),
+(3,0,2.2,32,TRUE),
+(22,1,4.01,3,TRUE),
+(23,1,4.91,2,TRUE),
+(24,1,5,1,TRUE),
+(25,NULL,4.01,3,TRUE);
+
+drop table if exists coxph_out;
+drop table if exists coxph_out_summary;
+select coxph_train('leukemia', 'coxph_out', 'timedeath', 'ARRAY[grp, wbc]', 'status', NULL, NULL);
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/f_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/f_test.ic.sql_in b/src/ports/postgres/modules/stats/test/f_test.ic.sql_in
new file mode 100644
index 0000000..0f4de01
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/f_test.ic.sql_in
@@ -0,0 +1,82 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test F-test.
+ *
+ * Example ("JAHANMI2.DAT") taken from:
+ * http://www.itl.nist.gov/div898/handbook/eda/section3/eda359.htm
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE jahanmi2 (
+ Run INTEGER,
+ Lab INTEGER,
+ Batch INTEGER,
+ Y FLOAT8,
+ X1 FLOAT8,
+ X2 FLOAT8,
+ X3 FLOAT8
+);
+
+COPY jahanmi2 FROM stdin;
+1 1 1 608.781 -1 -1 -1
+2 1 2 569.670 -1 -1 -1
+62 1 2 587.695 -1 1 1
+90 1 2 592.845 -1 1 1
+151 2 1 753.333 1 1 1
+179 2 1 635.079 1 1 1
+180 2 2 534.236 1 1 1
+181 2 1 716.926 1 -1 -1
+182 2 2 606.188 1 -1 -1
+299 3 1 701.716 1 -1 1
+300 3 2 627.516 1 -1 1
+301 3 1 382.133 1 1 -1
+302 3 2 574.522 1 1 -1
+303 3 1 719.744 1 1 -1
+389 4 1 775.272 -1 -1 1
+390 4 2 579.167 -1 -1 1
+421 4 1 708.885 -1 1 -1
+450 4 2 703.980 -1 1 -1
+541 5 1 715.224 -1 -1 -1
+569 5 1 776.197 -1 -1 -1
+570 5 2 345.294 -1 -1 -1
+571 5 1 547.099 1 -1 1
+572 5 2 570.999 1 -1 1
+573 5 1 619.942 1 -1 1
+629 6 1 684.523 1 1 1
+630 6 2 552.304 1 1 1
+631 6 1 717.159 -1 1 -1
+632 6 2 545.303 -1 1 -1
+633 6 1 721.343 -1 1 -1
+749 7 1 690.826 1 1 -1
+750 7 2 472.463 1 1 -1
+811 7 1 666.893 -1 1 1
+812 7 2 645.932 -1 1 1
+813 7 1 759.860 -1 1 1
+929 8 1 682.500 -1 -1 1
+930 8 2 684.167 -1 -1 1
+931 8 1 658.116 1 -1 -1
+932 8 2 672.153 1 -1 -1
+933 8 1 738.213 1 -1 -1
+\.
+
+CREATE TABLE f_test AS
+SELECT (f_test((2 - batch)::BOOLEAN, y)).* FROM jahanmi2;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/ks_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/ks_test.ic.sql_in b/src/ports/postgres/modules/stats/test/ks_test.ic.sql_in
new file mode 100644
index 0000000..150c1f8
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/ks_test.ic.sql_in
@@ -0,0 +1,43 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Kolmogorov-Smirnov test.
+ *
+ * Example taken from:
+ * http://www.physics.csbsju.edu/stats/KS-test.html
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE ks_sample_1 AS
+SELECT
+ TRUE AS first,
+ unnest(ARRAY[0.22, -0.87, -2.39, -1.79, 0.37, -1.54, 1.28, -0.31, -0.74, 1.72, 0.38, -0.17, -0.62, -1.10, 0.30, 0.15, 2.30, 0.19, -0.50, -0.09]) AS value
+UNION ALL
+SELECT
+ FALSE,
+ unnest(ARRAY[-5.13, -2.19, -2.43, -3.83, 0.50, -3.25, 4.32, 1.63, 5.18, -0.43, 7.11, 4.87, -3.10, -5.81, 3.76, 6.31, 2.58, 0.07, 5.76, 3.50]);
+
+CREATE TABLE ks_test_1 AS
+SELECT (ks_test(first, value,
+ (SELECT count(value) FROM ks_sample_1 WHERE first),
+ (SELECT count(value) FROM ks_sample_1 WHERE NOT first)
+ ORDER BY value)).*
+FROM ks_sample_1;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/mw_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/mw_test.ic.sql_in b/src/ports/postgres/modules/stats/test/mw_test.ic.sql_in
new file mode 100644
index 0000000..47d143e
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/mw_test.ic.sql_in
@@ -0,0 +1,54 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Mann-Whitney-test.
+ *
+ * Example taken from:
+ * http://www.itl.nist.gov/div898/handbook/prc/section3/prc35.htm
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE nist_mw_example (
+ id SERIAL,
+ group_a FLOAT8,
+ rank_a FLOAT8,
+ group_b FLOAT8,
+ rank_b FLOAT8
+);
+
+COPY nist_mw_example(group_a, rank_a, group_b, rank_b) FROM stdin;
+.55 8 .49 5
+.67 15.5 .68 17
+.53 7 .77 22
+.44 2 .62 12
+.65 13.5 .48 3.5
+.75 20.5 .59 9.5
+\.
+
+CREATE TABLE mw_test AS
+SELECT (mw_test(from_first, value ORDER BY value)).*
+FROM (
+ SELECT TRUE AS from_first, group_a AS value
+ FROM nist_mw_example
+ UNION ALL
+ SELECT FALSE, group_b
+ FROM nist_mw_example
+) q;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/pred_metrics.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/pred_metrics.ic.sql_in b/src/ports/postgres/modules/stats/test/pred_metrics.ic.sql_in
new file mode 100644
index 0000000..5bb3a3a
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/pred_metrics.ic.sql_in
@@ -0,0 +1,56 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * @file pred_metrics.sql_in
+ *
+ * @brief A collection of summary statistics to gauge model
+ * accuracy based on predicted values vs. ground-truth values.
+ * @date April 2016
+ *
+ *
+ *//* ----------------------------------------------------------------------- */
+
+CREATE TABLE test_set(
+ pred FLOAT8,
+ obs FLOAT8
+ );
+
+INSERT INTO test_set VALUES
+ (37.5,53.1), (12.3,34.2);
+
+DROP TABLE IF EXISTS table_out;
+SELECT mean_squared_error( 'test_set', 'table_out', 'pred', 'obs');
+DROP TABLE IF EXISTS table_out;
+SELECT adjusted_r2_score( 'test_set', 'table_out', 'pred', 'obs', 3, 100);
+DROP TABLE IF EXISTS table_out;
+SELECT confusion_matrix( 'test_set', 'table_out', 'pred', 'obs');
+DROP TABLE IF EXISTS table_out;
+
+CREATE TABLE test_binary(
+ pred FLOAT8,
+ obs FLOAT8
+ );
+
+INSERT INTO test_binary VALUES
+ (0.5,0), (0.2,1.0);
+SELECT binary_classifier( 'test_binary', 'table_out', 'pred', 'obs');
+DROP TABLE IF EXISTS table_out;
+
+SELECT area_under_roc( 'test_binary', 'table_out', 'pred', 'obs');
+DROP TABLE IF EXISTS table_out;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/robust_and_clustered_variance_coxph.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/robust_and_clustered_variance_coxph.ic.sql_in b/src/ports/postgres/modules/stats/test/robust_and_clustered_variance_coxph.ic.sql_in
new file mode 100644
index 0000000..d34b96a
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/robust_and_clustered_variance_coxph.ic.sql_in
@@ -0,0 +1,57 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Robust variance for Cox proportional hazard survival regression
+ * -------------------------------------------------------------------------- */
+
+DROP TABLE IF EXISTS bladder;
+CREATE TABLE bladder(
+ id INTEGER,
+ rx INTEGER,
+ num INTEGER,
+ sz INTEGER,
+ stop INTEGER,
+ event INTEGER,
+ enum INTEGER);
+
+COPY bladder FROM STDIN;
+1 1 1 3 1 0 1
+1 1 1 3 1 0 2
+1 1 2 3 1 1 3
+6 1 1 1 14 0 4
+85 2 2 3 59 0 1
+85 2 1 2 59 1 2
+85 2 2 3 59 1 3
+85 2 1 3 59 0 4
+\.
+
+drop table if exists bladder_coxph_out;
+drop table if exists bladder_coxph_out_summary;
+select coxph_train('bladder', 'bladder_coxph_out', 'stop', 'ARRAY[rx, sz, num]', 'event=1', NULL, NULL);
+
+-- robust variance
+drop table if exists bladder_rv_coxph_out;
+select robust_variance_coxph('bladder_coxph_out', 'bladder_rv_coxph_out');
+
+-- cluster variance (id)
+drop table if exists bladder_cv_coxph_out;
+select clustered_variance_coxph('bladder_coxph_out', 'bladder_cv_coxph_out', 'id');
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/t_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/t_test.ic.sql_in b/src/ports/postgres/modules/stats/test/t_test.ic.sql_in
new file mode 100644
index 0000000..bcff2c3
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/t_test.ic.sql_in
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test one-sample t-test.
+ *
+ * Example ("ZARR13.DAT") taken from:
+ * http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE ZARR13 (
+ id SERIAL,
+ value FLOAT8
+);
+
+COPY ZARR13(value) FROM stdin;
+9.206343
+9.299992
+9.277895
+9.288454
+9.216746
+9.274107
+9.273776
+\.
+
+CREATE TABLE t_test_one AS
+SELECT (t_test_one(value - 5.0)).* FROM zarr13;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/stats/test/wsr_test.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/stats/test/wsr_test.ic.sql_in b/src/ports/postgres/modules/stats/test/wsr_test.ic.sql_in
new file mode 100644
index 0000000..a873ceb
--- /dev/null
+++ b/src/ports/postgres/modules/stats/test/wsr_test.ic.sql_in
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Wilcoxon signed-rank test.
+ *
+ * Example taken from:
+ * http://www-stat.stanford.edu/~susan/courses/s141/hononpara.pdf
+ * -------------------------------------------------------------------------- */
+
+CREATE TABLE test_wsr (
+ x DOUBLE PRECISION,
+ y DOUBLE PRECISION
+);
+
+INSERT INTO test_wsr VALUES (0.32,0.39);
+INSERT INTO test_wsr VALUES (0.4,0.47);
+INSERT INTO test_wsr VALUES (0.11,0.11);
+INSERT INTO test_wsr VALUES (0.48,0.4);
+
+CREATE TABLE wsr_test AS
+SELECT (wsr_test(
+ x - y,
+ 2 * 2^(-52) * greatest(x,y)
+ ORDER BY abs(x - y)
+)).*
+FROM test_wsr;
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/summary/test/summary.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/summary/test/summary.ic.sql_in b/src/ports/postgres/modules/summary/test/summary.ic.sql_in
new file mode 100644
index 0000000..99b6a95
--- /dev/null
+++ b/src/ports/postgres/modules/summary/test/summary.ic.sql_in
@@ -0,0 +1,34 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+-- table with data types that cannot be casted into text
+CREATE TABLE bit_data (
+ a bit(3),
+ b bit varying(5)
+);
+
+COPY bit_data (a, b) FROM stdin;
+101 00
+\.
+
+DROP TABLE IF EXISTS bit_data_summary;
+SELECT summary('bit_data', 'bit_data_summary', NULL, 'a');
+
http://git-wip-us.apache.org/repos/asf/madlib/blob/4ed8b35e/src/ports/postgres/modules/svm/test/svm.ic.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/svm/test/svm.ic.sql_in b/src/ports/postgres/modules/svm/test/svm.ic.sql_in
new file mode 100644
index 0000000..606873e
--- /dev/null
+++ b/src/ports/postgres/modules/svm/test/svm.ic.sql_in
@@ -0,0 +1,46 @@
+/* ----------------------------------------------------------------------- *//**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *//* ----------------------------------------------------------------------- */
+
+CREATE TABLE abalone_train_small (
+ sex TEXT,
+ id SERIAL NOT NULL,
+ length DOUBLE PRECISION,
+ diameter DOUBLE PRECISION,
+ rings INTEGER);
+
+INSERT INTO abalone_train_small(id,sex,length,diameter,rings) VALUES
+(1040,'F',0.66,0.475,6),
+(177,'I',0.315,0.21,5),
+(3359,'M',0.285,0.215,5);
+
+-- verify gaussian kernel with grouping
+-- verify partial string support in kernel specification
+SELECT svm_regression(
+ 'abalone_train_small',
+ 'svr_mdl_m',
+ 'rings',
+ 'ARRAY[1,diameter]',
+ 'gau',
+ 'n_components=3',
+ 'sex',
+ 'max_iter=1, init_stepsize=1, decay_factor=0.9, tolerance=1e-16, epsilon = 0.05',
+ false);
+SELECT svm_predict('svr_mdl_m','abalone_train_small', 'id', 'svm_test_mdl_m');