Full Code of b-k/apophenia for AI

master e3ef8e3bd9f3 cached
162 files
1.6 MB
489.7k tokens
914 symbols
1 requests
Download .txt
Showing preview only (1,700K chars total). Download the full file or copy to clipboard to get everything.
Repository: b-k/apophenia
Branch: master
Commit: e3ef8e3bd9f3
Files: 162
Total size: 1.6 MB

Directory structure:
gitextract_f7cy6ezx/

├── ChangeLog
├── README
├── apop.m4.h
├── apop_arms.c
├── apop_asst.m4.c
├── apop_bootstrap.m4.c
├── apop_conversions.m4.c
├── apop_data.m4.c
├── apop_db.m4.c
├── apop_db_mysql.c
├── apop_db_sqlite.c
├── apop_fexact.c
├── apop_hist.m4.c
├── apop_internal.h
├── apop_linear_algebra.m4.c
├── apop_linear_constraint.m4.c
├── apop_mapply.m4.c
├── apop_mcmc.m4.c
├── apop_missing_data.m4.c
├── apop_mle.m4.c
├── apop_model.m4.c
├── apop_name.m4.c
├── apop_output.m4.c
├── apop_rake.m4.c
├── apop_regression.m4.c
├── apop_settings.c
├── apop_sort.m4.c
├── apop_stats.m4.c
├── apop_tests.m4.c
├── apop_update.m4.c
├── apop_vtables.c
├── asprintf.c
├── cmd/
│   ├── Makefile.am
│   ├── apop_db_to_crosstab.c
│   ├── apop_plot_query.c
│   └── apop_text_to_db.c
├── configure
├── docs/
│   ├── Makefile.am
│   ├── adjust
│   ├── apop_data_fig.html
│   ├── apop_data_fig.tex
│   ├── documentation.h
│   ├── doxygen.conf.in
│   ├── edit_globals.sed
│   ├── edit_group.sed
│   ├── edit_outline.sed
│   ├── edit_width.sed
│   ├── foot.html
│   ├── head.html
│   ├── make_model_doc.awk
│   ├── model.dot
│   ├── structs.dot
│   ├── tree.js
│   ├── triangle.c
│   └── typical.css
├── eg/
│   ├── Makefile.am
│   ├── apop_map_row.c
│   ├── banana.c
│   ├── binning.c
│   ├── boot_clt.c
│   ├── cross_models.c
│   ├── data_fill.c
│   ├── db_fns.c
│   ├── dconstrain.c
│   ├── dot_products.c
│   ├── draw_some_normals.c
│   ├── draw_to_db.c
│   ├── entropy_model.c
│   ├── entropy_vector.c
│   ├── f_test.c
│   ├── faithful.c
│   ├── fake_logit.c
│   ├── fix_params.c
│   ├── hills2.c
│   ├── iv.c
│   ├── jack.c
│   ├── jacobian.c
│   ├── kernel.c
│   ├── ks_tests.c
│   ├── logit.c
│   ├── ls_tables.c
│   ├── ml_imputation.c
│   ├── normalization_demo.c
│   ├── ols.c
│   ├── ols2.c
│   ├── ols_oneliner.c
│   ├── parameterization.c
│   ├── pmf_test.c
│   ├── simple_subsets.c
│   ├── some_cdfs.c
│   ├── sql_to_html.c
│   ├── t_test_by_rows.c
│   ├── test_distances.c
│   ├── test_fisher.c
│   ├── test_harmonic.c
│   ├── test_kl_divergence.c
│   ├── test_pruning.c
│   ├── test_ranks.c
│   ├── test_regex.c
│   ├── test_updating.c
│   ├── text_demo.c
│   └── transform.c
├── install/
│   ├── COPYING
│   ├── Makefile.am
│   ├── Readme-pkg
│   ├── Readme-pkg-debian
│   ├── acinclude.m4
│   ├── apophenia.pc.in
│   ├── configure.ac
│   ├── prep_variadics.m4
│   ├── push_pkg
│   └── rpm.spec
├── model/
│   ├── Makefile.am
│   ├── apop_bernoulli.c
│   ├── apop_beta.c
│   ├── apop_dirichlet.c
│   ├── apop_exponential.c
│   ├── apop_gamma.c
│   ├── apop_kerneld.c
│   ├── apop_loess.c
│   ├── apop_multinomial.c
│   ├── apop_multivariate_normal.c
│   ├── apop_normal.c
│   ├── apop_ols.c
│   ├── apop_pmf.c
│   ├── apop_poisson.c
│   ├── apop_probit.c
│   ├── apop_t.c
│   ├── apop_uniform.c
│   ├── apop_wishart.c
│   ├── apop_yule.c
│   └── apop_zipf.c
├── tests/
│   ├── Makefile.am
│   ├── Readme
│   ├── amash_vote_analysis.csv
│   ├── data
│   ├── data-mixed
│   ├── db_tests.c
│   ├── distribution_tests.c
│   ├── error_test.c
│   ├── factors.c
│   ├── faith.data
│   ├── lognormal_test.c
│   ├── nist_tests.c
│   ├── printing_sample
│   ├── rake_test.c
│   ├── sort_example.c
│   ├── sort_tests.c
│   ├── test_apop.c
│   ├── test_data
│   ├── test_data2
│   ├── test_data_fixed_width
│   ├── test_data_nans
│   ├── test_kernel_ll.c
│   ├── update_via_rng.c
│   └── utilities_test.in
└── transform/
    ├── Makefile.am
    ├── apop_coordinate_transform.c
    ├── apop_cross.c
    ├── apop_dconstrain.c
    ├── apop_fix_params.c
    └── apop_mixture.c

================================================
FILE CONTENTS
================================================

================================================
FILE: ChangeLog
================================================
Since April 2014, this changelog includes only those changes that break existing code or are especially notable. For a full list of changes, see the Git history at 
https://github.com/b-k/Apophenia/commits/master


[Key, pre-March 2014: 
--Addition or improvement
**Change that could require recoding existing code.
!!Big.
]

    October 2014
** apop_model_stack --> apop_model_cross

    August 2014
** default for apop_data_pack is .all_pages='y' (was 'n').
** remove apop_plot_lattice, apop_plot_triangle, apop_plot_line_and_scatter, apop_plot_qq.
Find them at https://github.com/b-k/apophenia/wiki/gnuplot_snippets .

	March 2014
--Command-line tools print help should a user add a --help option.

	February 2014
!!OpenMP for threading. All calls to apop_map and friends, apop_model_draws, and others auto-thread.
!!apop_rng_get_thread to get a thread-specific RNG, so you can thread random processes.

	January 2014
**View macro reform:
	Apop_cols       Apop_rows       A contiguous set of columns or rows as an apop_data set (with names)
	Apop_col	    Apop_row        One column or row as an apop_data set
	Apop_col_t      Apop_row_t      One column or row as an apop_data set, retrieved by row/col name
	Apop_col_v      Apop_row_v      One column or row as a gsl_vector
	Apop_col_tv     Apop_row_tv     One column or row as a gsl_vector, retrieved by row/col name
	Apop_matrix_col Apop_matrix_row One column or row as a gsl_matrix
**MLE methods are now strings instead of all-caps enums.
**All blank elements of a data->text grid point to the same NUL string.
--Add apop_model_metropolis; revise apop_update accordingly.
--apop_draw uses metropolis to draw from any model with a log likelihood/p and where data size>1.
**Replace all instances of output_file with output_name (GNU sed -i 's/output_file/output_name/g' *c)
--Consolidated headers
**apop.h no longer #includes time.h or unistd.h
**apop_draw returns zero on success; nonzero on failure.
**Removed the BIC-by-cells from estimation output. Added AIC_c. OLS now reports the ICs along with R^2.

	December 2013
--append and replace options for apop_text_to_db
--apop_probit bug fix
**apop_plot_histograms now uses gnuplot's impulses, not boxes by default---handles missing zero bins better.
**MLE path trace lists the probs/loglikelihoods in the vector of the apop_data set it produces. path is apop_data**, from apop_data*.
**apop_data_transpose has an .inplace option, which is 'y' by default. Add .inplace='n' to existing uses.
--siman checks constraints for the starting point.
--Mixture models overhauled.
--cleaned up the command-line utilities
**removed apop_lookup.

	November 2013
--rewrite apop_data_sort to allow sorting by multiple columns or text or names
--apop_pmf now has a CDF method.
--fixed up K-S tests.
--removed the Swig Python wrapper from this package.
**replaced char apop_opts.db_nan[101] with char *apop_opts.nan_string. More descriptive, easier to use.
**apop_name_find does plain case-insensitive search; no regexes.

	October 2013
**all built-in models (apop_ols, apop_dirichlet, ...) are now apop_model* (ptr-to-struct), from apop_model (plain struct).
**apop_estimate and apop_copy take in an apop_model* instead of plain apop_model.
**printing no longer part of the apop_model struct; uses a vtable.

	September 2013
**change vbase, m1base, m2base ==> vsize, msize1, msize2
**Estimate returns void (was apop_model*)
--vtable mechanism improvements
**Remove score, predict, and parameter_model from the apop_model object; use the vtable mechanism.
**Upgrade model p, ll, cdf, constraint to return long double (was double)
**consolidate vector_var and vector_weighted_var. same with cov, mean, weighted_skew, and weighted_pop. Users just have to replace apop_vector_weighted_var with apop_vector_var.
**removed deprecated.h entirely.
--apop_data_add_named_elmts puts new data in the vector, not the matrix, because it is intended for a list of scalars (==a vector). If you use apop_data_get(infodata, .rowname="statistic name") then you'll be able to retrieve the element either way.
**removed apop_line_to_data and apop_line_to_matrix. Use apop_data_fill and apop_data_falloc.

	August 2013
--apop_map(_sum) properly threads data-row mappings. .inplace='v' to return NULL.
**Remove apop_settings_alloc, apop_settings_group_alloc
**Change Apop_row to return an apop_data set, not a vector (for which use Apop_matrix_row).
**Apop_settings_set sets model->error='s' on error, instead of returning.
**Add a .want_path='y' setting to your apop_mle_settings group, and I'll put a list of the points tried by the optimizer in an apop_data set named path (in the settings group); see documentation for details. Remove the former trace_path mechanism.
**removed apop_(vector|matrix)_increment. Use, e.g., *gsl_vector_ptr(v, 7) += 3; or (*gsl_vector_ptr(v, 7))++.
**Some mu and sigmas => μ and σ
**Removed apop_settings_alloc, apop_settings_group_alloc
**Change Apop_row to return an apop_data set, not a vector (for which use Apop_matrix_row).

	June 2013
--replaced makefile in base directory with ./configure.
--version number now equals build date.
**name->title is a ptr; name->column => name->col
**removed apop_strip_dots; it's up to the user to give reasonable names for the db.

	May 2013
--jacobian transformations
--Apop_model_copy_set to copy a model and add a settings group at once
--mixture models
--data-data composition
--added apop_model_draws
!!vtables, allowing for more functions with special cases for certain model(s) outside of the model object itself.

	April 2013
--plugged some memory leaks
--default tolerance for MLE is much finer (1e-5).
--Added apop_text_fill
**Finally removed support for gsl_histograms, including the apop_histogram model. This cut has been promised for about four years now. Use the apop_pmf instead.
**apop_data_to_bins no longer modifies the input data in place. It now makes a copy and modifies the copy.
**Removed apop_crosstab_to_pmf. There's a version at https://github.com/b-k/Apophenia/wiki/Crosstab-to-PMF for matrices.
**Removed apop_vector_to_array. If your array has stride 1, use your_array->data; else write a for loop to copy out the data.
**Removed apop_array_to_matrix.

	March 2013
**apop_text_paste now prints the pasted string at verbosity level 3 (formerly 2).

	February 2013
--Starting_point in Bayesian updating no longer does anything, but it was never significant to begin with. Added some verbosity options to apop_update.

	January 2013
--Logit regression much smarter about picking a starting point.
--Defaults for simulated annealing try 1600x fewer points. Prior settings were overkill.
--configure.ac checks for native asprintf and uses it if it is present
**Removed apop_db_merge and apop_db_merge_table. Get them from http://modelingwithdata.org/arch/00000141.html .
**Removed apop_matrix_fill; use apop_data_fill
**Removed apop_array_to_data.
**Removed apop_matrix_correlation; use apop_data_correlation
**Deprecated apop_rank_compress; use apop_data_to_dummies(..., .keep_first='y').
--apop_model_stack

	December 2012
--Added an apop_pmf_settings group, eliminating a couple of hacks (e.g., see October 2012).
--faster read-in of text files
--Exponential model uses data in both the vector and matrix parts of the apop_data input
--transformation to generate mixtures (i.e., linear combinations) of models.
**apop_data_transpose now transposes the text element as well as the matrix (by default).
	Use apop_data_transpose(your_matrix,  .transpose_text='n') to replicate the previous behavior.
--removed Autoconf pkg-config macros, because Autoconf no longer needs the help.
--writing apop_data to DB uses prepared queries where possible => much faster.
**It is now up to you to put apop_query("begin"); / apop_query("commit"); wrappers around
	writing of tables to the database.

	November 2012
--apop_vector_unique_elements, apop_data_to_dummies, and apop_data_to_factors handle NaNs
	better; put them at the end of the sort order.
!!Finally added an .error element to apop_data and apop_model structs, thus simplifying
	error-checking.
--Apop_stopif macro, rendering the Apop_assert family largely obsolete (so if you're using
	them in your own work, consider them deprecated...).
--Where the assert macros used to abort() on errors, they now send signal(SIGTRAP), making
	debugging a little easier. Most host systems force an abort on SIGTRAP anyway.

	October 2012
**Removed apop_strcmp. If you still need it, this macro is basically equivalent:
    #define apop_strcmp(a, b) (((a)&&(b) && !strcmp((a), (b))) || (!(a) && !(b)))
--clean up of parameter-fixing model transformation.
--split off multiple imputation variance code.
**Removed apop_vector_grid_distance. Use apop_vector_distance(v1, v2, .metric='M');
--If apop_pmf.dsize==0, apop_pmf.draw returns a row number, not the data in that row. This will change shortly.
--Logit draw function, akin to apop_ols.draw. Both will change shortly.
--apop_data_to_factors now auto-allocates a matrix if need be (because it always auto-allocated a vector). 

	September 2012
--\0 in text files counts as white space
--fixed counting bug for text files with ,<end-of-line> sequences.

	July 2012
--some MLE cleanup
--fixes to apop_rake
--apop_logit.score fixed

	June 2012
--The sample kurtosis calculation is still more precise.

	May 2012
--Autotools improvements. Use the standard 'make check' instead of the ad hoc 'make test'.
!!Set apop_opts.stop_on_warning='n' to never abort() on any type of error. E.g., GUIs that
	should never halt will use this. Default is still to halt on errors, because that's
	most useful for interactively developing numeric analyses.
--Use apop_opts.log_file=fopen("yourlog", "w") to divert the warnings/errors from stderr into yourlog.
--Some formerly void functions now return an int, to return an error code. E.g.,
	apop_opts.stop_on_warning='n';
	if (apop_data_set(data, row, col)) printf("Error! Nothing was set.\n");
--Fixed a memory leak in simulated annealing.
--Apop_data_row and apop_data_set_row handle row names

	March 2012
--bug fix in apop_text_to_data when input file has no names.
--probit dlog likelihood isn't implemented for N>2; now acknowledging this.
--added apop_data_get_factor_names
--apop_(vector|matrix)_(map|apply) now accepts NULL input.

	January 2012
**Removed apop_matrix_var_m, which nobody was using.
--bug fix in apop_vector_distance for Ln norms where n is odd.
--reading data from text files rewritten; much more robust. 
   **A space is no long a default delimiter.  Use apop_opts.input_delimiters="| ,\t" to restore old default.
   **apop_opts.db_nan is no longer a regex; I just do a case-insensitive comparison.

	December 2011
--apop_model.textsize is now a size_t instead of an int.
--apop_update accepts likelihoods with no pre-set parameters 

	November 2011
--moved to Github; some changes to structure and documentation to accommodate. 
**apop_ols.predict didn't do the OLS shuffle if the input has no vector; this was anomalous.

	October 2011
--apop_text_paste added.
**apop_multinomial and apop_binomial overhauled. No longer accepting Bernoulli draws as input.
--standardization: make docs => make doc

	September 2011
--`query turned up a blank table' warning turns up when apop_opts.verbose >=2. (used to be >=1)
--apop_t_test and apop_paired_t_test are quieter---no intermediate results until apop_opts.verbose >=2.
**apop_opts.db_name_column now has a blank default (instead of the SQL-specific and potentially surprise-inducing "rowname").

	August 2011
--Bootstrap/Jackknife are better with text
**apop_data_memcpy used to reallocate memory for the text and names elements; use apop_data_copy if you want allocation done for you.

	July 2011
--Apop_data_rm_rows now accepts a test function as well as a fixed list of rows to drop.

	June 2011
--apop_crosstab_to_db handles missing labels and NaNs better.
**apop_matrix_to_db removed (as promised a few years ago). Use apop_matrix_print(yourdata, "tabname", .output_type='d').
**F-test defaults now match ANOVA tradition.
--documentation script doesn't use GNU extensions to awk; should now be POSIX-standard.

	May 2011
**apop_map returns a data set with an allocated/filled vector when not called with .inplace='y'.  Before, it had been making a full copy, which is idiosyncratic.
--apop_rake accepts a weights column.
--apop_anova uses variadic arguments for a marginally nicer interface (and better argument checking).
**apop_data_to_dummies tries to give nicer labels. You may have to recode things if you relied on the old labels.

	March 2011
--Header files have been merged. A few long files is as easy to grep as a multitude of
	nearly one-line files. If you #include <apop.h> instead of the individual headers,
	then this shouldn't affect you. Due to redundancy, compilation with gcc takes 3% longer.

	0.99 February 2011
!!The apop_PMF model has more support:
	--New supporting functions: apop_data_pmf_compress, apop_model_to_pmf
	--functions that took apop_histogram models now take apop_pmfs as well:
		apop_test_chi_squared_goodness_of_fit, apop_test_kolmogorov
	--Consider the apop_histogram to be deprecated. Only two associated functions were removed; see below.
	**apop_histogram_plot is removed. Replace with:
	    fprintf(apop_opts.output_pipe, "plot '-' using 1:3 with boxes\n");
		apop_model_print(hist);
		fprintf(apop_opts.output_pipe, "e\n");
	**apop_histogram_print was a bad idea to begin with, because it basically replicates
	    gsl_histogram_fprintf. Use apop_model_print(your_histogram), which calls gsl_histogram_fprintf, 
		or call that function directly. The only difference: the GSL function prints 
		[start of bin] [end of bin] [value]
		and apop_histogram print showed
		[start of bin] [value]

	December 2010
**apop_maximum_likelihood no longer calls apop_prep. If you want that, use apop_estimate.
--apop_text_to_db lets users specify types and keys.
--deleted some obsolete/deprecated items: apop_error, apop_multinomial_settings
--apop_data_split retains text when splitting by rows; still ignores it when splitting by columns.

	November 2010
--apop_listwise_delete uses apop_opts.db_nan to check for missing data in the text part of the input data.
--apop_data_split handles names

    September 2010
**Multinomial distribution sets N to be the length of the row (a single observation)
    rather than the size of the full data set. Added apop_multinomial.parameter_model method
    for testing purposes.

    August 2010
** What was apop_assert => apop_assert_c; what was apop_assert_s => apop_assert. Their
    arguments are slightly different, and the thing that was asserted no longer prints along
    with the message you chose.
--verbosity defaults to 1. Queries print at verbosity >=2.
--apop_data_to_db writes the weights.
--Iterative proportional fitting, aka raking. 

**apop_text_add now frees the contents of cell in the text grid that you are about to
    overwrite, thus preventing memory leaks without effort from the user. If your existing
    code has other pointers to the string in that text cell, you'll have to replace the now
    string-freeing apop_text_add with asprintf(&(your_dataset->text[row][col]), "your string").

    July 2010
** apop_regex now gets all matches when you pull substrings. Each row of the text grid
    is a match, and if you have multiple substrings, each match's substrings will be
    along the columns.  May require recoding because the substrings used to be along
    the rows; just switch the indices.

    June 2010
** Removed the apop_rank settings group, and thus all the code related to it. It was just
    the wrong place to do this. Added apop_data_rank_expand to convert rank data to
    what the various models typically expect. This is another step for some users and
    could be a problem if the counts get into the billions, but it still makes more sense
    than rewriting every model twice.

    May 2010
**apop_data_prune_columns_base now takes in a list of strings terminated by a NULL, not by
a zero-length string.
--apop_data_get_row lets you pull a view from a data set. [this was briefly the apop_data_row]
    ==>apop_data_set_rows, apop_data_rm_rows
        ==> apop_data_listwise_delete is fifty lines shorter.
--apop_parts_wanted_settings: fixes some infinite loops (est needs parameter models ->
    p.m. bootstraps for variances -> bootstrap runs estimate -> repeat) and allows
    just-the-parameters estimation when you want it.
--cleaned up build system, including an added RPM spec file

    April 2010
--apop_t_distribution now has three parameters: mean, std dev, df. That is, it is based on un-normalized data.
**apop_random_int and apop_random_double removed for not being particularly useful.

    March 2010
**The apop_predict special case for when all data is non-missing was a bit too special,
    and has been eliminated---you now have to specify the first column as NaN yourself.
    E.g., Apop_col(data, -1, to_nan); gsl_vector_set_all(to_nan, GSL_NAN);
    This will make things more predictable, and save you if(!has_nans)... else... kind of statements.
**Removed the prepared element of the apop_model.
**apop_model_prep ==> apop_prep for consistency with other apop_model dispatch functions. apop_model_prep left for now as an alias in deprecated.h
!!apop_parameter_model: a method for getting the distribution of a parameter.
    **Moved OLS-family test stats (pval, qval, whatever) to a page of your_estimate->info. It won't be there for long either.
--settings macros let you use lowercase, thus entirely ignoring that they're macros.
    **apop_settings_rm_group function, which you were probably not using, changed to apop_settings_remove_group; apop_settings_get_group function => apop_settings_get_grp. Having a macro and a function that differed by a question of case was a bad idea to begin with.

    February 2010
!!Overhauling the output from estimations; pardon our dust. 
--Added CDF method to the apop_model, including apop_cdf dispatch method and default via random draws.
**Defininitvely removed the residual, covariance, and llikelihood elements from the
    apop_model struct. The first two will be pages appended to the data and parameters,
    respectively, and the last will be in the Info page appended to the parameters.
**Renamed apop_ls_settings (least square) to apop_lm_settings (linear model) "s/apop_ls/apop_lm/g" should work.
**Sundry lists of scalars, like the R^2 table and the estimation routine's info table put the data in column zero, not column -1. In the next bullet point you'll see how this simplifies retrieval.
**Added an info element to the apop_model--> more shuffling of auxiliary info. 
    --Find results like the log likelihood or AIC via, e.g., apop_data_get(your_model->info, .rowname="log likelihood");
  **Find the predicted/residuals via apop_data_get_page(your_model->info, "Predicted");
        This means that the input data set is read-only again. 
    --Find the parameter covariances via apop_data_get_page(your_model->parameters, "Covariance");
    **apop_estimate_coefficient_of_determination takes in the model again. Just replace est->parameters in your argument with est. apop_ols calls this fn automatically now [apop_data_get(your_model->info, .rowname="R sq")], so you probably aren't even calling it anymore.
**apop_data_add_named_elmt now writes to the zeroth element of the matrix, not the vector.
So instead of apop_data_get(data, .rowname="R squared", -1), just go with apop_data_get(data, .rowname="R squared"). This affects many of the elements of the info-type matrices.
--apop_data_pack, apop_data_unpack, apop_ml_impute, apop_map offer an option to use all pages. 

    0.23 January 2010
**expected_value element of the model renamed predict; made coherent across models.
!!apop_data set now has a ->more pointer to an additional apop_data set, e.g., for data + covariances or predictions + confidence intervals.
--apop_ml_imputation renamed to apop_ml_impute. "#define apop_ml_imputation apop_ml_impute" retains noun-form name, but consider it deprecated.
!!apop_estimate now copies, preps, then estimates. Estimate method of apop_model struct can thus assume the copy/prep step has been done;
probably should not do these itself. As a side-effect, apop_maximum_likelihood's second argument is now a apop_model* (used to be apop_model).
--apop_regex and apop_strcmp, for easier searching through your info pages.
--minor rewording of COPYING2.
**Because the Predicted table is now part of the parameter set, not the model,
    apop_estimate_coefficient_of_determination now takes in the parameter set, not the model. Just replace est in your argument with est->parameters.
**apop_multinomial_probit folded into apop_probit, where it should've been all along.
    Regex for the fix: "s/apop_multinomial_probit/apop_probit/g"

    December 2009
--apop_strcmp
--apop_loess model: 3,500 lines of code from the netlib archive, lovingly restored.

    November 2009
--apop_rm_columns bug fixed by Birger Baksaas.
--apop_text_to_db attaches numeric affinity to sqlite3 columns, making numeric comparisons easier.
--apop_histogram_model_reset's first argument is now "base" instead of "template", as a concession to C++ users.

	September 2009
--Many minor changes, mostly regarding adding optional arguments.
--Dirichlet model
--Output functions now take a consistent set of specs regarding to where they will write. You no longer have to use the global apop_opts settings if you don't want to.

	August 2009
--apop_map and apop_map_sum. Reworks the apop_(map|apply) system to be more flexible but a little more complex.
-apop_(data|matrix|vector)_fill is now more robust---no more int vs float issues.
**Removed apop_count_cols
--Default univariate RNG, if you don't have one: Adaptive rejection markov chain sampling
**.use_covar and other such settings now take 'y' or 'n', not 0 or 1.
--new macro Apop_settings_set = Apop_settings_add, but makes more human sense
--numeric covariance, formerly maligned, now works.

	July 2009
--multivariate gamma, log-gamma.
--t, F, chi^2, Wishart distributions, for description [and Bayesian
updating]
--apop_matrix_to_positive_semidefinite and apop_matrix_is_positive_semidefinite 
--bug fixes
--Apop_model_add_group replaces Apop_settings_add_group, and is much more easy to work with.

	June 2009
--More variadicized functions
	--notably, apop_estimate is much more useful
--apop_opts.version.
--apop_(vector|matrix|data)_stack have an inplace option, making stacking inside a for loop easier.
--apop_test convenience function
--more autoconf macros ==> some compilation hacks now done right

	May 2009
--mysql functions slightly cleaned up
--apop_opts.db_user and apop_opts.db_pass for mysql.
!!Functions that take lots of basically optional inputs, like apop_text_to_db, now use some designated initializer magic to let the user rearrange or omit inputs.
**apop_dot also now allows designated initializers, which breaks
(only) calls of the form apop_dot(a_vector, a_matrix, 't'). Replace with
apop_dot(a_vector, a_matrix, 0, 't') or apop_dot(a_vector, a_matrix,
.form2='t')
--With optional inputs, some functions now handle RNGs for the lazy user ==>added apop_opts.rng_seed
--apop_vector_distance is much more versatile
**Removed apop_matrix_summarize. Too much like apop_data_summarize. Just
replace every instance of apop_matrix_summarize(m) with apop_data_summarize(apop_matrix_to_data(m)).


    April 2009
--sample moments are now mega-accurate---possibly the most unbiased estimators in code today.
!!Python interface via swig

	March 2009
--apop_matrix_realloc, apop_vector_realloc
--sqlite queries no longer rely on a temp table ==> faster
--fixed bugs in apop_table_exists making queries fail in Cygwin.

	Jan/Feb 2009
--Added more tests; some cleanup in test.c
--Binomial distribution looks in both the data set's vector and matrix

	December 2008
--When writing x=infinity to a db table, I now write 'inf' to the db, instead of breaking.  SQLite has no standard here.

	October 2008
--bug fixes to new apop_data_show
--bug fixes to apop_bernoulli.p
--apop_update tweaks

	September 2008
--Documentation overhaul
--apop_data_show is much more screen-friendly. Keep using
apop_data_print for more machine-readable and less fixed-width output.
**apop_plot_histogram now takes in a vector, bin count, and name of output. This is what it did in the first half of the year.
  The current version of apop_plot_histogram, which acts on a histogram model, is renamed to apop_histogram_plot.

	August 2008
--Constraints in ML work better.
**Overhaul of some discrete choice models
	--Added tests for the probit and logit.
	--fixed a bug revealed by the tests
	**the first choice has a fixed value of zero.
	**You'll probably need to call Apop_category_settings_add before estimating 
		your model, unless the outcome choice variable is the 0th column of the matrix.
	--more to come, e.g., multinomial probit will be merged with ordered probit.
-Adding a settings group of a given type when that group already exists used to induce an error; now the old type is replaced with a clean default.
--bug fix for apop_test_fisher_exact on non-square matrices
--apop_settings_add and company do more work in functions and less in macros.
--removed the settings_ct element of the apop_model; using a sentinel at the end of the array instead.
--Slightly improved reading of text files.
--Bootstrap/jackknife act on models with parameters in both matrix and vector form.


    July 2008
--Guts of apop_plot_histogram now use the apop_histogram model. 
**  Also, it no longer normalizes the histogram to integrate to one by
  default. You need to explicitly request this via
  apop_histogram_normalize
--apop_plot finally deleted.
--apop_histogram_plot deleted; use apop_plot_histogram.
--Added apop_vector_skew_sample, apop_vector_kurtosis_sample.


	May 2008
--apop_settings_rm_group added.
--mysql interface has the beginnings of support for multiple
	semicolon-separated queries in one call.
--apop_histogram_refill_with_model ==> apop_histogram_model_reset;
	apop_histogram_refill_with_vector ==> apop_histogram_vector_reset.

	April 2008
--apop_dot handles names.
--apop_t_test now behaves correctly when one vector is of length 1.
--some improvements/fixes when dealing with mySQL.
--apop_sv_decomp renamed to apop_matrix_pca. Minor changes so that it correctly works as such.
--apop_text_to_(db|data) handles column names like it used to, which
   works better. Also a few other fixes for odd situations.

	March 2008
--Various improvements in reading in from text.
	-- a, "b, c", d will now correctly read in as three elements: a; then "b, c"; then d
	-- a,,b,c reads as a, NAN, b, c.

	February 2008
--Some of the header references didn't work for a fresh install.
--bug fixes, esp. with apop_test_kolmogorov
--added convenience fn apop_data_transpose

	January 2008
--Apop_assert, which streamlines the use of apop_error (thus shrinking the code base by 2%).
--apop_OLS now has a log likelihood (also shuffled some of the code around)
--bug fix in apop_binomial.p.
**More name reform: apop_correlation_matrix --> apop_matrix_correlation; apop_data_correlation_matrix --> apop_data_correlation; apop_covariance_matrix --> apop_matrix_covariance; apop_data_covariance_matrix --> apop_data_covariance.
--apop_count_(rows|cols)_in_text are now static functions and removed from the documentation.
--Removed apop_random_beta, which had been set as deprecated earlier.  Use apop_beta_from_mean_var.
**Removed apop_vector_isnan---just use apop_vector_map_sum(your_vector, isnan)
**Removed apop_vector_finite---just use apop_vector_bounded(your_vector, INFINITY)
--For your convenience, added Apop_settings_alloc() macro.
	**apop_histogram_params ==> apop_histogram_settings
	**apop_kernel_density_params ==> apop_kernel_density_settings
	[The settings/params distinction is in some ways arbitrary anyway.]
--bug fix in apop_mle.c: wasn't copying output parameters to the estimated model in some cases.
--As part of name reform, all function names are being switched to
lower-case throughout, so apop_ANOVA ==> apop_anova. Am keeping the old
forms via macros. Notice also the non-yelling macro capitalizations above, such as Apop_assert.
!!**Revised the settings for the apop_model. model_settings and
method_settings are out, replaced by a much more organized single list
of settings.
--added the apop_lookup command-line program.
**Renamed the apop_multinomial_logit model the apop_logit, because the
binary logit is a special case that requires no special handling.
**Reversed the signs on the probit coefficients, to better conform to
the norm.


	December 2007
--added apop_vector_moving_average
--apop_model now has prep and print methods.
**apop_p, apop_log_likelihood, apop_score now take a pointer to an apop_model, not the model itself.
--apop_multinomial_probit model
--When a data set has matrix and vector, apop_dot accepts a 'v' to use the vector.
--apop_plot_lattice produces a more attractive (and standard-form) plot.
--apop_data_print works much better now.
**apop_model no longer requires your data input to be const. It probably
will be const, but it's not the interface's place to dictate that.
**apop_data_unpack no longer allocates a new data set, but writes to an input data set assumed to be of the right size.
--added apop_ANOVA to produce one- or two-way ANOVA tables from the database.
**apop_test_ANOVA renamed to apop_test_ANOVA_independence to create a little more cognitive distance.
--apop_data_text_to_factors
--APOP_COL_T and APOP_ROW_T macros, to pull a column or row by name
--apop_beta_from_mean_var produces a beta-distributed model with the right (alpha, beta) parameters. 
**Thus, apop_random_beta is now marked as deprecated.
**apop_x_prime_sigma_x removed, on grounds of being silly. If you want it back, see model/apop_multivariate_normal.c, where it is now a static function.
**apop_qq_plot --> apop_plot_qq
--Multinomial logit model (and the probit now has names).
**Revised the bin-syncing methods. apop_vectors_to_histogram and apop_model_to_histogram are now out; apop_histogram_refill_with_vector and apop_histogram_refill_with_model are in. 
**Also removed apop_model_test_goodness_of_fit as redundant. Just produce a histogram, use the above refill functions, and send your two histograms to apop_histograms_test_goodness_of_fit. If you do this often, you can write a convenience function to do that as quickly as I could.
**apop_vector_replace and apop_matrix_replace are redundant---just use apop_(vector|matrix)_apply.
--The covariance matrix is now produced via the derivative of the score function at the parameter. I follow Efron and Hinkley in using the estimated information matrix---the value of the information matrix at the estimated value of the score---not the expected information matrix that is the integral over all possible data.

	November 2007
--added apop_model_copy_set_string to get a copy of a model whose
model_settings is just a string.
**Thanks to this, folded all of the _rank versions of models into their
base models. Set model_settings to "r" to use the rank version.
--The default MLE method is now the Nelder-Mead Simplex algorithm,
instead of the Fletcher-Reeves conjugate gradient. This is more
conservative.
--apop_(vector|matrix|matrix_all)_map_sum to get the sum of a function
applied to a vector. E.g., find count of NaNs with apop_vector_map_sum(v, isnan);
--apop_logit bug fix.

	October 2007

--apop_estimate now defaults to using MLEs, meaning you don't have to explicitly specify an estimate method for MLE models. 
--apop_crosstab_to_db reads both the matrix and text elements of the input apop_data set. 
--apop_system convenience function, to make C feel more like a scripting language. 
--Added some SQLite functions for mySQL compatibility: var_samp, var_pop, stddev_samp, stddev_pop, std. 
--Probit patched to not NaN for very unlikely parameter/data combinations. 
**apop_estimate_restart takes two models, rather than one model and some haphazard settings. 
--apop_plot_query no longer forces you to use the -d and -q switches to specify the database and query. 
**The two places that use regular expressions: apop_opts.db_nan and the search for a name via apop_data_get/set... use case-insensitive EREs. Before I'd been using BREs, which nobody likes. 
--<ctrl-c> stops the MLE searches, prints output, and continues the program. Especially useful for simulated annealing. [GDB tip: use the command: signal SIGINT ] 
--apop_mle_fix_params debugging: gradients work now. 
--apop_test_ANOVA added, to test the null hypothesis that all cells of a crosstab are equally likely. 
**apop_multivariate_normal_prob removed. Use the apop_multivariate_normal model and its .log_likelihood, .p, .draw, et cetera. 
**sed -i -e "s/apop_OLS_params/apop_ls_settings/g" -e "s/apop_mle_params/apop_mle_settings/g" *.c *.h

	September 2007
--The optimization methods now have an enumerated type.
**apop_opts.mle_trace_path is now the trace_path element of the apop_mle_params struct. Also, it works much better.
--apop_histogram_normalize function 
--improvements to apop_kernel_density and apop_histogram_print

	August 2007
--removed apop_model_template. Just copy one of the existing models. 
--apop_data_ptr_ti, apop_data_ptr_ii, apop_data_ptr_it 
--And you can never have too many bug fixes

	July 2007
--apop_binomial model takes two types of input now: a two-column form with hit count and miss count, and a list of binary hits or misses. 
--apop_lognormal model 
--bug fixes on Information matrix calculation.

	June 2007
[subversion ate this part; sorry.]

	May 2007
--apop_query_to_mixed_data
**apop_produce_dummies now makes dummy variables from both data and
text. This means that there's another parameter you need to set to 'd'
or 't' to indicate what you want dummified.
!!**Merged the apop_params and apop_model structures, leaving everything
in just one struct. That's about all the merging left.
--apop_text_alloc and apop_text_add to make text manipulation a little
easier.
--apop_matrix_apply_all and apop_matrix_map_all operate on all items in
a matrix.
**small tweak to apop_vector_normalize interface.
--apop_matrix_inverse and apop_matrix_determinant, because the
apop_det_and_inv interface is sort of ugly.
--APOP_SUBMATRIX macro
--MLEs put the expected score in the ->more element of the returned
apop_model. If people find this useful, we can maybe put a
proper expected_score element in the model.
--More consts in function headers. You can decide whether this
is actually useful.

	0.19 April 2007
!!**Eliminated the apop_estimate and apop_ep structures, replacing them
with the apop_params structure. The apop_params + apop_model pair form a
closure representing a parametrized model. Expect the uses element to go
away soon; after that, things should be stable. Parameters for individual
methods now have their own space; try apop_ml_params_alloc and
apop_OLS_params_alloc, for example.
If you are just doing things like
apop_estimate_show(apop_OLS.estimate(data,NULL));
then don't worry, but if you are doing a lot with the input parameters,
then have a look at Chapter 6 of _Modeling with Data_.
--apop_histogram model
**Gradually rewriting the histogram functions from before to make use of
that model. E.g., eliminated apop_vector_to_cmf.
**apop_line_to_data fixed to use both vector and matrix terms. Now
requires arguments: (indata, vsize, m1size, m2size).
--MLE now approximates the Information matrix using data gathered during
the MLE search. This is wrong but cheap; right but expensive procedures
forthcoming. [Hint: Simulated annealing gathers more info.]
--apop_(data|matrix|vector)_fill functions, which are a touch fragile,
but very useful when used with care.
**apop_data_(get|set)_(tn|nt) changed to (ti|it), because n could stand
for name or number, while i stands for index, and is often used for integers.
--apop_names now have a title element, so you can give your data
structures a title.
**apop_params_alloc takes an apop_model, not an &apop_model. It's more
natural that way.
**Finally erradicated every last vestige of inventories: apop_params no
longer has a .uses element. Instead, apop_specific_model_params may have
a want_cov, want_expected_value, want_whatever element if the element is
optional. And really, the parameters themselves should never be
optional. What was I thinking.
**apop_model_fix_params now sets up and returns an apop_mle_params object,
thus resolving the problem that the MLE params needs a model input,
and the model_fix_params model needed an MLE params input.

	0.18 March 2007
**apop_text_to_db now assumes column names unless you specify -nc.
--If you set parameter_ct==0 in your model definition, the MLEs will
assign parameter_ct == the number of columns in your data set.
--Missing data functions: apop_listwise_delete and apop_ml_imputation
**The constraint element of the apop_model now takes a void* parameter,
like it should have all this time.
**apop_jackknife (1) renamed to apop_jackknife_cov and (2) now actually
works.
**Entirely eliminated the apop_inventory structure. Its sole utility is
inside the apop_ep struct.
**Changed the RNG interface for the sake of allowing multidimensional
draws. [Not that I have any functions that do that right now.]
--Bayes-oriented MCMC algorithm: apop_mcmc_update
!!Bayesian model generator: apop_update
**apop_model paramters is now an apop_model. See the documentation of
the model for all the changes.
**apop_data_alloc now takes three arguments: vsize, msize1, msize2. To
update, just put a 0, at the head of the arg list.
!!An absolutely fabulous apop_linear_constraint function.
--Produce a model with some parameters fixed via apop_model_fix_params.
--apop_beta model

	February 2007

**Apop_sv_decomposition has a slightly nicer interface.
**data->categories was too much to type, and too specific. The apop_data
struct now has a data->text element, and textsize[0] and [1]. The
categories element is linked to this, but is now deprecated.

	January 2007
**Root finding hooked into the max likelihood fns.

0.17	December 2006
**Apop_model struct has lost the fdf object, which was annoying, and now
has the p function.
--mySQL support.
**apop_query_to_chars now returns an apop_data structure, so you don't
have to go back and gather column names and dimensions.
**apop_name_get (and the apop_get_tt family) now use regular expressions
instead of SQL's LIKE operator. This is _much_ faster.
--the apop_distribution model.

		November 2006
--The preeminently useful APOP_COL and APOP_ROW
--apop_data_calloc
--apop_vector_(apply|map) debugged.
**apop_estimation_params is just too darn long; reduced to apop_ep.


		October 2006
--apop_text_to_db now reads from STDIN.
**deleted apop_query_db; use apop_query.
--Kolmogorov-Smirnov test.
--apop_t_test returns GSL_NAN when given a one-element vector instead of
hanging.
--no more soft links in the tgz file==>may work better on Windows machines.
--apop_(vector|matrix)_(map|apply) will apply a function to every
row of a matrix or every element of a vector. The map functions return a
gsl_vector.
--bug fix in apop_test_goodness_of_fit.

		September 2006

**Removed apop command-line server thing. It was interesting, but that's
the best that could be said of it.
--Added functions for weighted data: weighted least squares, weighted moments.
--apop_vector_percentiles now allows for averaging instead of rounding.

		August 2006
**apop_log_likelihood and friends now demand that data be apop_data*,
rather than void*. Too many things broke when users gave non-apop_data
data.
--bug fixes

		July 2006
--Many more checks for NULL ==> more robust code and easier debugging.
--Bug fixes.
**apop_data_split, and apop_data_stack has been revised to handle the
idea that a vector is the -1st element of the matrix. I.e., check your
code if you're trying to merge matrices without merging the vectors.
--Lattice plots.
--Convenience t-tests from inside model estimations are fixed.
--apop_query_to_vector. 
--apop_opts.output_type == 'p' to print to apop_opts.output_pipe
**apop_..._print and apop_..._show now work out whether elements are
integers (if (val == (int) val)...), and print accordingly. This means
that apop_..._print_int and apop_..._show_int are basically obsolete,
and have been removed.
--Apop_OLS now allows weights.
--Test library now includes a few NIST certified tests.

		June 2006
--added preprocessor cruft to let the library work for C++
--Jackknife revised

		May 2006
**The apop_model no longer includes an inventory. I leave it to the
estimate function to do its own allocation.

		April 2006
**apop_matrix_normalize and apop_vector_normalize had different
numbers for the same normalizations. Was that ever dumb. Also, I've
switched to chars instead of ints to signify this stuff, for better
mnemonics without resorting to the
APOP_ENUM_YOU_HAVE_TO_LOOK_UP_EVERY_TIME_BECAUSE_ITS_SO_LONG sort of
thing. If you were using apop_matrix_normalize(data, 0) before, you
need to change that to using apop_matrix_normalize(data, 'm'). Thus,
apop_vector_normalize now has one more normalization, for a total of
four for both.

--Added apop_rng_alloc convenience fn.

--Added apop_strip_dots to keep inputs to the database healthy.

--apop_name_find uses LIKE instead of strcmp.

--a fn to calculate the generalized harmonic.

--A whole section on histograms and goodness-of-fit tests.

--apop_data_set fns to go with the apop_data_get fns.

--apop_data now includes a vector type
	--apop_estimate.parameters is now an apop_data type.
	--apop_estimate.names is thus obsolete.

		March 2006
**apop_inventory is now a subset of apop_estimation_params. Implications:
	--added apop_estimation_params_alloc() to ensure that inventory is set right.
	--the model.estimate(data, inv, params) method is now model.estimate(data, params)
	  model.estimate(data, NULL) still does what the user expects it to.
  This makes structural sense, but will lightly break any existing code.
  fix: change 
   apop_inventory *inv = apop_inventory_set(1);
   model.estimate(data, inv, NULL);

   to
   apop_estimation_params *ep = apop_estimation_params_alloc();
   model.estimate(data, ep);

   and in any apop_estimates, change any use of est->uses to
   est.estimation_params.uses.

**Next apop_estimate reform: y_values and residuals combined into one
apop_data table with actual, predicted, residual columns.
	--obviated the need for a 'dependent' element in apop_names; removed that.
	If you need the name, it's now your_est->dependent->names->colnames[0].

**your_estimate->covariance is now an apop_data set instead of a gsl_matrix.

**the data element of the apop_matrix structure is now named matrix. So
instead of data_set->data, use data_set->matrix, and instead of
estimate->data->data->data, you can use estimate->data->matrix->data.

--The command-line utility has been revisited, and can do a few more
things, like OLS.

--Simulated annealing
	--added convenience fns apop_vector_distance(pt1,pt2) and
		apop_vector_grid_distance(pt1,pt2)

**Apop_data_memcpy no longer malloc()s for you, for comparability with
the world's other memcpy fns. If you want mallocing, use apop_data_copy.

--apop_test_fisher_exact(). Cut 'n' pasted from R, who cut 'n' pasted it
from somebody else. Despite being the same code, it runs fifty (50)
times faster from Apophenia.

		February 2006
--sort-of-adaptive MLE: use apop_estimate_restart to execute a new MLE
search beginning where the last one ended, perhaps using a new method or
rescaled parameters.
	--This needed convenience functions to check for divergence, thus
		added apop_vector_finite, apop_vector_bounded, apop_vector_isnan.
**apop_db_to_crosstab now returns an apop_data set instead of a gsl_matrix.
Also, it finally works with column headers that aren't numeric.
**stats like apop_mean are now apop_vector_mean, following the proper
	pkg-noun-verb naming scheme. 
--Textbook is much improved.
--apop_vector_to_pdf convenience fn.

--Some of the fns that used to be of the form
	apop_get_something(input, &output);
are now of the more natural
	out	= apop_get_something(input);
This includes apop_array_to_vector and apop_array_to_matrix

--bootstrapping works, and works with with apop_models.
--apop_poisson model

0.15	January 2006
Added an apop_opts structure for options. Alowed the following changes:
	--apop_verbose  is now apop_opts.verbose. Try this on your existing code:
		perl -pi.bak -e 's/apop_verbose/apop_opts.verbose/g' *.c *.h
	--the output functions now output into three formats: on screen, to file, to db;
		see chapter five of the manual.
		
--F tests 
--R squared.

0.14	December 2005

The apop_data structure, which is just a shell for a gsl_matrix and an
apop_name. Was just sick of sending names following around my tables. 
Lets us keep both numerical and categorical data in one place; kind of
like R's data frame.

--Added linear model objects: OLS, GLS. This means that what had been
the apop_OLS function is now the apop_estimate_OLS function, and where it
used to take in a gsl_matrix and an apop_name, now it takes an apop_data
structure and a NULL. So you'll have to modify your code accordingly.

--A function to generate dummy variables, useful in conjunction with
--Functions to stack matrices and apop_data sets. Even a
apop_partitioned_OLS function, that will only practically work for small data sets.

--pow(.,.) in the database. I can't believe I dealt with SQL this long w/o it.

0.13	December 2005

--The apop_model object. This was a big deal that deserves more than
just one line; see the manuals.

0.12 	mid November 2005

--Bar charts (assuming you've got Gnuplot > 4.1)
--percentiles (in case you haven't got it)
**redid MLE system so you can pick among the many options now available.  As a part of this:
	--better handling of constraints.
	--numerical gradients.
	--numerical Hessians.

0.12 	early November 2005, post-hiatus

--You now have three maximum likelihood estimators to choose from: the
GSL's no-gradient, the GSL's with-gradient, and Mr. WN's autocalculated
gradient. 

--If you haven't seen it before, the apop_distribution structure is
increasingly well-supported. It allows the user to specify the features
of the Max. Likeihood model in a consistent manner which facilitates
things like comparing two models.

--I'd still suggest taking the Waring and Yule distributions with care;
everything else seems to check out.


0.12 	September 2005
**The distributions are now objects, which just provides a neat way
of grouping together the half-dozen functions which are associated with
any one distribution.

0.11	September 2005
--command-line server is much improved. I actually do work with it.
--Documentation is now via doxygen.
--asst bug fixes.
--Have started to take plotting (via gnuplot) seriously
--a limited test suite. Try: make test .

0.10	August 2005
--This version includes a server to park itself in memory and receive data
processing requests. The intent is that one can then do analysis from
the command line or a Perl/Python/Whatever script. The client/server
works in the sense of handling a handful of requests without
segfaulting, but remains in proof-of-concept stage. 
--Added apop_merge_db for joining databases, both via C and command line 
--Run t tests from the cmd line or the database.

0.09	July 2005
--Flattened the relatively complex vasprintf subsystem from GNU, so if
you've been having trouble compiling on non-GNU systems, try again.
Added two little command-line programs. Also, added more little
functions which aren't very interesting, like t-tests; maybe you'll
stumble upon them.

0.08	May 2005
--OLS/GLS/MLE now properly support the apop_estimate structure 
--Column names

0.07	April 2005
--uses the apop_estimate structure to return heaps of data from regressions & MLEs
--uses the apop_model structure

0.06
--var(x), skew(x), kurtosis(x) added to SQL understood by Apophenia.

0.05
--added a little crosstab utility
--queries now accept printf-type arguments. 
	==>GNU vasprintf was added.
		==>updated to work with autoconf 1.7


================================================
FILE: README
================================================
Apophenia is an open statistical library for working with data sets and statistical or simulation models. It provides functions on the same level as those of the typical stats package (such as OLS, probit, or singular value decomposition) but gives the user more flexibility to be creative in model-building. Being in C, it is often an order of magnitude faster when searching for optima or running MCMC chains. The core functions are written in C, but experience has shown them to be easy to bind to Python/Julia/Perl/Ruby/&c.

http://apophenia.info/gentle.html provides an overview of the basics of using the library. If you want to know more about the package, see the web site, http://apophenia.info, or have a look at the textbook from Princeton University Press that coevolved with Apophenia, downloadable from http://modelingwithdata.org .


The quick summary for installation:

∙ The library depends on the GNU Scientific Library and SQLite3. If you are using a system with a package manager of some sort, there is certainly a package for them. Be sure to include both the main package and the lib-, -dev, or -devel package. Sample package manager calls:

    sudo apt-get install make gcc libgsl0-dev libsqlite3-dev 
or 
    sudo yum install make gcc gsl-devel libsqlite3x-devel
or 
    sudo pacman -S make gcc gsl sqlite 

∙ The prebuilt package, that has only basic prerequisites (no Autotools or m4) can be downloaded from another Git branch:

    #Download the zip file, via wget or your preferred downloading method:
    wget https://github.com/b-k/Apophenia/archive/pkg.zip

    #unzip and build
    unzip pkg.zip
    cd Apophenia-pkg
    ./configure
    make
    sudo make install

Or check out the branch via git:

    git clone https://github.com/b-k/Apophenia.git
    cd Apophenia
    git checkout pkg
    ./configure
    make
    sudo make install

∙ This master branch of the git repository requires Autotools, so it can build the
package. Try (apt-get || yum install) autoconf automake libtool. If you have Autotools installed, then from this branch you can run:

    ./configure
    cd apophenia-1.0
    make 
    sudo make install

∙ Find detailed setup instructions and some troubleshooting notes at
http://apophenia.info/setup.html .


Thanks for your interest. I do hope that Apophenia helps you learn more from your data.

--BK

PS: Lawyers, please note that a file named COPYING in the install/ directory describes how this package is licensed under GPLv2.


================================================
FILE: apop.m4.h
================================================
/** \file  */
/* Copyright (c) 2005--2014 by Ben Klemens.  Licensed under the GPLv2; see COPYING. */

/* Here are the headers for all of apophenia's functions, typedefs, static variables and
macros. All of these begin with the apop_ (or Apop_ or APOP_) prefix.

There used to be a series of sub-headers, but they never provided any serious
benefit. Please use your text editor's word-search feature to find any elements you
may be looking for. About a third of the file is comments and doxygen documentation,
so syntax highlighting that distinguishes code from comments will also help to make
this more navigable.*/

/** \defgroup all_public Public functions, structs, and types
\addtogroup all_public
@{
*/

#pragma once
#ifdef	__cplusplus
extern "C" {
#endif

/** \cond doxy_ignore */
#ifndef _GNU_SOURCE
#define  _GNU_SOURCE //for asprintf
#endif

#include <assert.h>
#include <signal.h> //raise(SIGTRAP)
#include <string.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_matrix.h>


            //////Optional arguments

/* A means of providing more script-like means of sending arguments to a function.

These macros are intended as internal. If you are interested in using this mechanism
in out-of-Apophenia work, grep docs/documentation.h for optionaldetails to find notes
on how these are used (Doxygen doesn't use that page),
*/
#define apop_varad_head(type, name) type variadic_##name(variadic_type_##name varad_in)

#define apop_varad_declare(type, name, ...) \
    typedef struct {                        \
                __VA_ARGS__ ;               \
            } variadic_type_##name;         \
    apop_varad_head(type, name);

#define apop_varad_var(name, value) name = varad_in.name ? varad_in.name : (value);
#define apop_varad_link(name,...) variadic_##name((variadic_type_##name) {__VA_ARGS__})

/** \endcond */ //End of Doxygen ignore.


            //////The types and functions that act on them

/** This structure holds the names of the components of the \ref apop_data set. You may never have to worry about it directly, because most operations on \ref apop_data sets will take care of the names for you.
*/
typedef struct{
    char *title;
	char * vector;
	char ** col;
	char ** row;
	char ** text;
	int colct, rowct, textct;
    unsigned long *colhash, *rowhash, *texthash;
} apop_name;

/** The \ref apop_data structure represents a data set. See \ref dataoverview.*/
typedef struct apop_data{
    gsl_vector  *vector;
    gsl_matrix  *matrix;
    apop_name   *names;
    char        ***text;
    size_t      textsize[2];
    gsl_vector  *weights;
    struct apop_data   *more;
    char        error;
} apop_data;

/* Settings groups. For internal use only; see apop_settings.c and 
   settings.h for related machinery. */
typedef struct {
    char name[101];
    unsigned long name_hash;
    void *setting_group;
    void *copy;
    void *free;
} apop_settings_type;

/** A statistical model. See \ref modelsec for details. */
typedef struct apop_model apop_model;

/** The elements of the \ref apop_model type, representing a statistical model. See \ref
 modelsec and \ref modeldetails for use and details.  */
struct apop_model{
    char name[101]; 
    int vsize, msize1, msize2, dsize;
    apop_data *data;
    apop_data *parameters;
    apop_data *info;
    void (*estimate)(apop_data * data, apop_model *params); 
    long double (*p)(apop_data *d, apop_model *params);
    long double (*log_likelihood)(apop_data *d, apop_model *params);
    long double (*cdf)(apop_data *d, apop_model *params);
    long double (*constraint)(apop_data *data, apop_model *params);
    int (*draw)(double *out, gsl_rng* r, apop_model *params);
    void (*prep)(apop_data *data, apop_model *params);
    apop_settings_type *settings;
    void *more;
    size_t more_size;
    char error;
};

/** The global options. */
typedef struct{
    int verbose; /**< Set this to zero for silent mode, one for errors and warnings. default = 0. */
    char stop_on_warning; /**< See \ref debugging . */
    char output_delimiter[100]; /**< The separator between elements of output tables. The default is "\t", but 
                                for LaTeX, use "&\t", or use "|" to get pipe-delimited output. */
    char input_delimiters[100]; /**< Deprecated. Please use per-function inputs to \ref apop_text_to_db and \ref apop_text_to_data. Default = "|,\t" */
    char *db_name_column; /**< If not NULL or <tt>""</tt>, the name of the column in your tables that holds row names.*/
    char *nan_string; /**< The string used to indicate NaN. Default: <tt>"NaN</tt>. Comparisons are case-insensitive.*/
    char db_engine; /**< If this is 'm', use mySQL, else use SQLite. */
    char db_user[101]; /**< Username for database login. Max 100 chars.  */
    char db_pass[101]; /**< Password for database login. Max 100 chars.  */
    FILE *log_file;  /**< The file handle for the log. Defaults to \c stderr, but change it with, e.g.,
                           <tt>apop_opts.log_file = fopen("outlog", "w");</tt> */

#define Autoconf_no_atomics @Autoconf_no_atomics@

    #if __STDC_VERSION__ > 201100L && !defined(__STDC_NO_ATOMICS__) && Autoconf_no_atomics==0
        _Atomic(int) rng_seed;
    #else
        int rng_seed;
    #endif
    float version;
} apop_opts_type;

extern apop_opts_type apop_opts;

apop_name * apop_name_alloc(void);
int apop_name_add(apop_name * n, char const *add_me, char type);
void  apop_name_free(apop_name * free_me);
void  apop_name_print(apop_name * n);
Apop_var_declare( void  apop_name_stack(apop_name * n1, apop_name *nadd, char type1, char typeadd) )
apop_name * apop_name_copy(apop_name *in);
int  apop_name_find(const apop_name *n, const char *findme, const char type);

void apop_data_add_names_base(apop_data *d, const char type, char const ** names);

/** Add a list of names to a data set.

\li Use this with a list of names that you type in yourself, like
\code
apop_data_add_names(mydata, 'c', "age", "sex", "height");
\endcode
Notice the lack of curly braces around the list.

\li You may have an array of names, probably autogenerated, that you would like to
add. In this case, make certain that the last element of the array is \c NULL, and
call the base function:
\code
char **[] colnames = {"age", "sex", "height", NULL};
apop_data_add_names_base(mydata, 'c', colnames);
\endcode
But if you forget the \c NULL marker, this has good odds of segfaulting. You may prefer to use a \c for loop that inserts each name in turn using \ref apop_name_add.

\see \ref apop_name_add, although \ref apop_data_add_names will be more useful in most cases. 
*/
#define apop_data_add_names(dataset, type, ...) apop_data_add_names_base((dataset), (type), (char const*[]) {__VA_ARGS__, NULL}) 


/** Free an \ref apop_data structure.
 
\li As with \c free(), it is safe to send in a \c NULL pointer (in which case the function does nothing).
\li If the \c more pointer is not \c NULL, I will free the pointed-to data set first.
If you don't want to free data sets down the chain, set <tt>more=NULL</tt> before calling this.
\li This is actually a macro (that calls \ref apop_data_free_base). It
sets \c freeme to \c NULL when it's done, because there's nothing safe you can do with the
freed location, and you can later safely test conditions like <tt>if (data) ...</tt>.
*/
#define apop_data_free(freeme) (apop_data_free_base(freeme) ? 0 : ((freeme)= NULL))

char        apop_data_free_base(apop_data *freeme);
Apop_var_declare( apop_data * apop_data_alloc(const size_t size1, const size_t size2, const int size3) )
Apop_var_declare( apop_data * apop_data_calloc(const size_t size1, const size_t size2, const int size3) )
Apop_var_declare( apop_data * apop_data_stack(apop_data *m1, apop_data * m2, char posn, char inplace) )
apop_data ** apop_data_split(apop_data *in, int splitpoint, char r_or_c);
apop_data * apop_data_copy(const apop_data *in);
void        apop_data_rm_columns(apop_data *d, int *drop);
void apop_data_memcpy(apop_data *out, const apop_data *in);
Apop_var_declare( double * apop_data_ptr(apop_data *data, int row, int col, const char *rowname, const char *colname, const char *page) )
Apop_var_declare( double apop_data_get(const apop_data *data, size_t row, int  col, const char *rowname, const char *colname, const char *page) )
Apop_var_declare( int apop_data_set(apop_data *data, size_t row, int col, const double val, const char *rowname, const char * colname, const char *page) )
void apop_data_add_named_elmt(apop_data *d, char *name, double val);
int apop_text_set(apop_data *in, const size_t row, const size_t col, const char *fmt, ...);
apop_data * apop_text_alloc(apop_data *in, const size_t row, const size_t col);
void apop_text_free(char ***freeme, int rows, int cols);
Apop_var_declare( apop_data * apop_data_transpose(apop_data *in, char transpose_text, char inplace) )
gsl_matrix * apop_matrix_realloc(gsl_matrix *m, size_t newheight, size_t newwidth);
gsl_vector * apop_vector_realloc(gsl_vector *v, size_t newheight);

#define apop_data_prune_columns(in, ...) apop_data_prune_columns_base((in), (char *[]) {__VA_ARGS__, NULL})
apop_data* apop_data_prune_columns_base(apop_data *d, char **colnames);

Apop_var_declare( apop_data * apop_data_get_page(const apop_data * data, const char * title, const char match) )
apop_data * apop_data_add_page(apop_data * dataset, apop_data *newpage,const char *title);
Apop_var_declare( apop_data* apop_data_rm_page(apop_data * data, const char *title, const char free_p) )
Apop_var_declare( apop_data * apop_data_rm_rows(apop_data *in, int *drop, int (*do_drop)(apop_data* ! void*), void* drop_parameter) )

//in apop_asst.c:
Apop_var_declare( apop_data * apop_model_draws(apop_model *model, int count, apop_data *draws) )


/* Convenience functions to convert among vectors (gsl_vector), matrices (gsl_matrix), 
  arrays (double **), and database tables */

//From vector
gsl_vector *apop_vector_copy(const gsl_vector *in);
Apop_var_declare( gsl_matrix * apop_vector_to_matrix(const gsl_vector *in, char row_col) )

//From matrix
gsl_matrix *apop_matrix_copy(const gsl_matrix *in);
Apop_var_declare( apop_data *apop_db_to_crosstab(char const*tabname, char const*row, char const*col, char const*data, char is_aggregate) )

//From array
Apop_var_declare( gsl_vector * apop_array_to_vector(double *in, int size) )
/** \cond doxy_ignore */   //Deprecated
#define apop_text_add apop_text_set
#define apop_line_to_vector apop_array_to_vector
/** \endcond */

//From text
Apop_var_declare( apop_data * apop_text_to_data(char const *text_file, int has_row_names, int has_col_names, int const *field_ends, char const *delimiters) )
Apop_var_declare( int apop_text_to_db(char const *text_file, char *tabname, int has_row_names, int has_col_names, char **field_names, int const *field_ends, apop_data *field_params, char *table_params, char const *delimiters, char if_table_exists) )

//rank data
apop_data *apop_data_rank_expand (apop_data *in);
Apop_var_declare( apop_data *apop_data_rank_compress (apop_data *in, int min_bins) )

//From crosstabs
void apop_crosstab_to_db(apop_data *in, char *tabname, char *row_col_name, 
						char *col_col_name, char *data_col_name);

//packing data into a vector
Apop_var_declare( gsl_vector * apop_data_pack(const apop_data *in, gsl_vector *out, char more_pages, char use_info_pages) )
Apop_var_declare( void apop_data_unpack(const gsl_vector *in, apop_data *d, char use_info_pages) )

#define apop_vector_fill(avfin, ...) apop_vector_fill_base((avfin), (double []) {__VA_ARGS__})
#define apop_data_fill(adfin, ...) apop_data_fill_base((adfin), (double []) {__VA_ARGS__})
#define apop_text_fill(dataset, ...)   apop_text_fill_base((dataset), (char* []) {__VA_ARGS__, NULL})
#define apop_data_falloc(sizes, ...) apop_data_fill(apop_data_alloc sizes, __VA_ARGS__)
    
apop_data *apop_data_fill_base(apop_data *in, double []);
gsl_vector *apop_vector_fill_base(gsl_vector *in, double []);
apop_data *apop_text_fill_base(apop_data *data, char* text[]);

            //// Models and model support functions

extern apop_model *apop_beta;
extern apop_model *apop_bernoulli;
extern apop_model *apop_binomial;
extern apop_model *apop_chi_squared;
extern apop_model *apop_dirichlet;
extern apop_model *apop_exponential;
extern apop_model *apop_f_distribution;
extern apop_model *apop_gamma;
extern apop_model *apop_improper_uniform;
extern apop_model *apop_iv;
extern apop_model *apop_kernel_density;
extern apop_model *apop_loess;
extern apop_model *apop_logit;
extern apop_model *apop_lognormal;
extern apop_model *apop_multinomial;
extern apop_model *apop_multivariate_normal;
extern apop_model *apop_normal;
extern apop_model *apop_ols;
extern apop_model *apop_pmf;
extern apop_model *apop_poisson;
extern apop_model *apop_probit;
extern apop_model *apop_t_distribution;
extern apop_model *apop_uniform;
//extern apop_model *apop_wishart;
extern apop_model *apop_wls;
extern apop_model *apop_yule;
extern apop_model *apop_zipf;

//model transformations
extern apop_model *apop_coordinate_transform;
extern apop_model *apop_composition;
extern apop_model *apop_dconstrain;
extern apop_model *apop_mixture;
extern apop_model *apop_cross;

/** Alias for the \ref apop_normal distribution, qv. */
#define apop_gaussian apop_normal
#define apop_OLS apop_ols
#define apop_PMF apop_pmf
#define apop_F_distribution apop_f_distribution
#define apop_IV apop_iv


void apop_model_free (apop_model * free_me);
Apop_var_declare( void apop_model_print (apop_model * model, FILE *output_pipe) )
void apop_model_show (apop_model * print_me); //deprecated
apop_model * apop_model_copy(apop_model *in); //in apop_model.c
apop_model * apop_model_clear(apop_data * data, apop_model *model);

apop_model * apop_estimate(apop_data *d, apop_model *m);
void apop_score(apop_data *d, gsl_vector *out, apop_model *m);
double apop_log_likelihood(apop_data *d, apop_model *m);
double apop_p(apop_data *d, apop_model *m);
double apop_cdf(apop_data *d, apop_model *m);
int apop_draw(double *out, gsl_rng *r, apop_model *m);
void apop_prep(apop_data *d, apop_model *m);
apop_model *apop_parameter_model(apop_data *d, apop_model *m);
apop_data * apop_predict(apop_data *d, apop_model *m);

apop_model *apop_beta_from_mean_var(double m, double v); //in apop_beta.c

#define apop_model_set_parameters(in, ...) apop_model_set_parameters_base((in), (double []) {__VA_ARGS__})
apop_model *apop_model_set_parameters_base(apop_model *in, double ap[]);

//apop_mixture.c
/** Produce a model as a linear combination of other models. See the documentation for the \ref apop_mixture model. 

\param ... A list of models, either all parameterized or all unparameterized. See
examples in the \ref apop_mixture documentation.
*/
#define apop_model_mixture(...) apop_model_mixture_base((apop_model *[]){__VA_ARGS__, NULL})
apop_model *apop_model_mixture_base(apop_model **inlist);

//transform/apop_cross.c.

/** Generate a model consisting of the cross product of several independent models. The output \ref apop_model
is a copy of \ref apop_cross; see that model's documentation for details.

\li If you input only one model, return a copy of that model; print a warning iff <tt>apop_opts.verbose >= 2</tt>.

\exception error=='n' First model input is \c NULL.

Examples:

\include cross_models.c
*/
#define apop_model_cross(...) apop_model_cross_base((apop_model *[]){__VA_ARGS__, NULL})
apop_model *apop_model_cross_base(apop_model *mlist[]);

        ////More functions

    //The variadic versions, with lots of options to input extra parameters to the
    //function being mapped/applied
Apop_var_declare( apop_data * apop_map(apop_data *in, double (*fn_d)(double), double (*fn_v)(gsl_vector*),
                double (*fn_r)(apop_data *), double (*fn_dp)(double! void *), double (*fn_vp)(gsl_vector*! void *),
                double (*fn_rp)(apop_data *! void *), double (*fn_dpi)(double! void *! int),
                double (*fn_vpi)(gsl_vector*! void *! int), double (*fn_rpi)(apop_data*! void *! int),
                double (*fn_di)(double! int), double (*fn_vi)(gsl_vector*! int), double (*fn_ri)(apop_data*! int),
                void *param, int inplace, char part, int all_pages) )
Apop_var_declare( double apop_map_sum(apop_data *in, double (*fn_d)(double), double (*fn_v)(gsl_vector*),
                double (*fn_r)(apop_data *), double (*fn_dp)(double! void *), double (*fn_vp)(gsl_vector*! void *),
                double (*fn_rp)(apop_data *! void *), double (*fn_dpi)(double! void *! int),
                double (*fn_vpi)(gsl_vector*! void *! int), double (*fn_rpi)(apop_data*! void *! int),
                double (*fn_di)(double! int), double (*fn_vi)(gsl_vector*! int), double (*fn_ri)(apop_data*! int),
                void *param, char part, int all_pages) )

    //the specific-to-a-type versions, quicker and easier when appropriate.
gsl_vector *apop_matrix_map(const gsl_matrix *m, double (*fn)(gsl_vector*));
gsl_vector *apop_vector_map(const gsl_vector *v, double (*fn)(double));
void apop_matrix_apply(gsl_matrix *m, void (*fn)(gsl_vector*));
void apop_vector_apply(gsl_vector *v, void (*fn)(double*));
gsl_matrix * apop_matrix_map_all(const gsl_matrix *in, double (*fn)(double));
void apop_matrix_apply_all(gsl_matrix *in, void (*fn)(double *));

double apop_vector_map_sum(const gsl_vector *in, double(*fn)(double));
double apop_matrix_map_sum(const gsl_matrix *in, double (*fn)(gsl_vector*));
double apop_matrix_map_all_sum(const gsl_matrix *in, double (*fn)(double));


        // Some output routines
Apop_var_declare( void apop_matrix_print(const gsl_matrix *data, char const *output_name, FILE *output_pipe, char output_type, char output_append) )
Apop_var_declare( void apop_vector_print(gsl_vector *data, char const *output_name, FILE *output_pipe, char output_type, char output_append) )
Apop_var_declare( void apop_data_print(const apop_data *data, char const *output_name, FILE *output_pipe, char output_type, char output_append) )

void apop_matrix_show(const gsl_matrix *data);
void apop_vector_show(const gsl_vector *data);
void apop_data_show(const apop_data *data);


        //statistics
Apop_var_declare( double apop_vector_mean(gsl_vector const *v, gsl_vector const *weights))
Apop_var_declare( double apop_vector_var(gsl_vector const *v, gsl_vector const *weights))
Apop_var_declare( double apop_vector_skew_pop(gsl_vector const *v, gsl_vector const *weights))
Apop_var_declare( double apop_vector_kurtosis_pop(gsl_vector const *v, gsl_vector const *weights))
Apop_var_declare( double apop_vector_cov(gsl_vector const *v1, gsl_vector const *v2,
                                         gsl_vector const *weights))

Apop_var_declare( double apop_vector_distance(const gsl_vector *ina, const gsl_vector *inb, const char metric, const double norm) )

Apop_var_declare( void apop_vector_normalize(gsl_vector *in, gsl_vector **out, const char normalization_type) )

apop_data * apop_data_covariance(const apop_data *in);
apop_data * apop_data_correlation(const apop_data *in);
long double apop_vector_entropy(gsl_vector *in);
long double apop_matrix_sum(const gsl_matrix *m);
double apop_matrix_mean(const gsl_matrix *data);
void apop_matrix_mean_and_var(const gsl_matrix *data, double *mean, double *var);
apop_data * apop_data_summarize(apop_data *data);
Apop_var_declare( double * apop_vector_percentiles(gsl_vector *data, char rounding)  )

apop_data *apop_test_fisher_exact(apop_data *intab); //in apop_fisher.c

//from apop_t_f_chi.c:
Apop_var_declare( int apop_matrix_is_positive_semidefinite(gsl_matrix *m, char semi) )
double apop_matrix_to_positive_semidefinite(gsl_matrix *m);
long double apop_multivariate_gamma(double a, int p);
long double apop_multivariate_lngamma(double a, int p);

//apop_tests.c
apop_data *	apop_t_test(gsl_vector *a, gsl_vector *b);
apop_data *	apop_paired_t_test(gsl_vector *a, gsl_vector *b);
Apop_var_declare( apop_data* apop_anova(char *table, char *data, char *grouping1, char *grouping2) )
#define apop_ANOVA apop_anova
Apop_var_declare( apop_data * apop_f_test (apop_model *est, apop_data *contrast) )
#define apop_F_test apop_f_test

//from the regression code:
#define apop_estimate_r_squared(in) apop_estimate_coefficient_of_determination(in)

apop_data * apop_text_unique_elements(const apop_data *d, size_t col);
gsl_vector * apop_vector_unique_elements(const gsl_vector *v);
Apop_var_declare( apop_data * apop_data_to_factors(apop_data *data, char intype, int incol, int outcol) )
Apop_var_declare( apop_data * apop_data_get_factor_names(apop_data *data, int col, char type) )

Apop_var_declare( apop_data * apop_data_to_dummies(apop_data *d, int col, char type, int keep_first, char append, char remove) )

Apop_var_declare( long double apop_model_entropy(apop_model *in, int draws) )
Apop_var_declare( long double apop_kl_divergence(apop_model *from, apop_model *to, int draw_ct, gsl_rng *rng) )

apop_data *apop_estimate_coefficient_of_determination (apop_model *);
void apop_estimate_parameter_tests (apop_model *est);

//Bootstrapping & RNG
apop_data * apop_jackknife_cov(apop_data *data, apop_model *model);
Apop_var_declare( apop_data * apop_bootstrap_cov(apop_data *data, apop_model *model, gsl_rng* rng, int iterations, char keep_boots, char ignore_nans, apop_data **boot_store) )
gsl_rng *apop_rng_alloc(int seed);
double apop_rng_GHgB3(gsl_rng * r, double* a); //in apop_asst.c

#define apop_rng_get_thread(thread_in) apop_rng_get_thread_base(#thread_in[0]=='\0' ? -1: (thread_in+0))
gsl_rng *apop_rng_get_thread_base(int thread);

int apop_arms_draw (double *out, gsl_rng *r, apop_model *m);


    // maximum likelihod estimation related functions

Apop_var_declare( gsl_vector * apop_numerical_gradient(apop_data * data, apop_model* model, double delta) )
Apop_var_declare( apop_data * apop_model_hessian(apop_data * data, apop_model *model, double delta) )
Apop_var_declare( apop_data * apop_model_numerical_covariance(apop_data * data, apop_model *model, double delta) )

void apop_maximum_likelihood(apop_data * data, apop_model *dist);

Apop_var_declare( apop_model * apop_estimate_restart (apop_model *e, apop_model *copy, char * starting_pt, double boundary) )

//in apop_linear_constraint.c
Apop_var_declare( long double  apop_linear_constraint(gsl_vector *beta, apop_data * constraint, double margin) )

//in apop_model_fix_params.c
apop_model * apop_model_fix_params(apop_model *model_in);
apop_model * apop_model_fix_params_get_base(apop_model *model_in);



            //////vtables
/** \cond doxy_ignore */

/* This declares the vtable macros for each procedure that uses the mechanism.

--We want to have type-checking on the functions put into the vtables. Type checking
happens only with functions, not macros, so we need a type_check function for every
vtable.

--Only once in your codebase, you'll need to #define Declare_type_checking_fns to
actually define the type checking function. Everywhere else, the function is merely
declared.

--All other uses point to having a macro, such as using __VA_ARGS__ to allow any sort
of inputs to the hash.

--We want to have such a macro for every vtable. That means that we need a macro
to write macros. We can't do that with C macros, so this file uses m4 macros to
generate C macros.

--After the m4 definition of make_vtab_fns, each new vtable requires a typedef, a hash
definition, and a call to make_vtab_fns to do the rest.
*/
m4_define(make_vtab_fns, <|m4_dnl
#ifdef Declare_type_checking_fns
void $1_type_check($1_type in){ };
#else
void $1_type_check($1_type in);
#endif
#define $1_vtable_add(fn, ...) $1_type_check(fn), apop_vtable_add("$1", fn, $1_hash(__VA_ARGS__))
#define $1_vtable_get(...) apop_vtable_get("$1", $1_hash(__VA_ARGS__))
#define $1_vtable_drop(...) apop_vtable_drop("$1", $1_hash(__VA_ARGS__))m4_dnl
|>)

int apop_vtable_add(char const *tabname, void *fn_in, unsigned long hash);
void *apop_vtable_get(char const *tabname, unsigned long hash);
int apop_vtable_drop(char const *tabname, unsigned long hash);

typedef apop_model *(*apop_update_type)(apop_data *, apop_model* , apop_model*);
#define apop_update_hash(m1, m2) (          \
           ((m1)->log_likelihood ? (size_t)(m1)->log_likelihood : \
            (m1)->p              ? (size_t)(m1)->p*33 : \
            (m1)->draw           ? (size_t)(m1)->draw*33*27 \
                                 : 33*27*19) \
          +((m2)->log_likelihood ? (size_t)(m2)->log_likelihood : \
            (m2)->p              ? (size_t)(m2)->p*33 : \
            (m2)->draw           ? (size_t)(m2)->draw*33*27 \
                                 : 33*27*19 \
           ) * 37)
make_vtab_fns(apop_update)

typedef long double (*apop_entropy_type)(apop_model *model);
#define apop_entropy_hash(m1) ((size_t)(m1)->log_likelihood + 33 * (size_t)((m1)->p) + 27*(size_t)((m1)->draw))
make_vtab_fns(apop_entropy)

typedef void (*apop_score_type)(apop_data *d, gsl_vector *gradient, apop_model *params);
#define apop_score_hash(m1) ((size_t)((m1)->log_likelihood ? (m1)->log_likelihood : (m1)->p))
make_vtab_fns(apop_score)

typedef apop_model* (*apop_parameter_model_type)(apop_data *, apop_model *);
#define apop_parameter_model_hash(m1) ((size_t)((m1)->log_likelihood ? (m1)->log_likelihood : (m1)->p)*33 + (m1)->estimate ? (size_t)(m1)->estimate: 27)
make_vtab_fns(apop_parameter_model)

typedef apop_data * (*apop_predict_type)(apop_data *d, apop_model *params);
#define apop_predict_hash(m1) ((size_t)((m1)->log_likelihood ? (m1)->log_likelihood : (m1)->p)*33 + (m1)->estimate ? (size_t)(m1)->estimate: 27)
make_vtab_fns(apop_predict)

typedef void (*apop_model_print_type)(apop_model *params, FILE *out);
#define apop_model_print_hash(m1) ((m1)->log_likelihood ? (size_t)(m1)->log_likelihood : \
            (m1)->p ? (size_t)(m1)->p*33 : \
            (m1)->estimate ? (size_t)(m1)->estimate*33*33 : \
            (m1)->draw ? (size_t)(m1)->draw*33*27  : \
            (m1)->cdf ? (size_t)(m1)->cdf*27*27  \
            : 27)
make_vtab_fns(apop_model_print)

/** \endcond */ //End of Doxygen ignore.


        //////Asst

long double apop_generalized_harmonic(int N, double s) __attribute__ ((__pure__));

apop_data * apop_test_anova_independence(apop_data *d);
#define apop_test_ANOVA_independence(d) apop_test_anova_independence(d)

Apop_var_declare( int apop_regex(const char *string, const char* regex, apop_data **substrings, const char use_case) )

int apop_system(const char *fmt, ...) __attribute__ ((format (printf,1,2)));

//Histograms and PMFs
gsl_vector * apop_vector_moving_average(gsl_vector *, size_t);
apop_data * apop_histograms_test_goodness_of_fit(apop_model *h0, apop_model *h1);
apop_data * apop_test_kolmogorov(apop_model *m1, apop_model *m2);
apop_data *apop_data_pmf_compress(apop_data *in);
Apop_var_declare( apop_data * apop_data_to_bins(apop_data const *indata, apop_data const *binspec, int bin_count, char close_top_bin) )
Apop_var_declare( apop_model * apop_model_to_pmf(apop_model *model, apop_data *binspec, long int draws, int bin_count) )

//text conveniences
Apop_var_declare( char* apop_text_paste(apop_data const*strings, char *between, char *before, char *after, char *between_cols, int (*prune)(apop_data* ! int ! int ! void*), void* prune_parameter) )
/** Notify the user of errors, warning, or debug info. 

writes to \ref apop_opts.log_file, which is a \c FILE handle. The default is \c stderr,
but use \c fopen to attach to a file.

 \param verbosity   At what verbosity level should the user be warned? E.g., if level==2, then print iff apop_opts.verbosity >= 2.
 \param ... The message to write to the log (presuming the verbosity level is high
enough). This can be a printf-style format with following arguments, 
e.g., <tt>apop_notify(0, "Beta is currently %g", beta)</tt>.
*/
#define Apop_notify(verbosity, ...) {\
    if (apop_opts.verbose != -1 && apop_opts.verbose >= verbosity) {  \
        if (!apop_opts.log_file) apop_opts.log_file = stderr; \
        fprintf(apop_opts.log_file, "%s: ", __func__); fprintf(apop_opts.log_file, __VA_ARGS__); fprintf(apop_opts.log_file, "\n");   \
        fflush(apop_opts.log_file); \
} }

/** \cond doxy_ignore */
#define Apop_maybe_abort(level) \
            {if ((apop_opts.verbose >= level && apop_opts.stop_on_warning == 'v') \
                 || (apop_opts.stop_on_warning=='w') ) \
                raise(SIGTRAP);}
/** \endcond */

/** Execute an action and print a message to the current \c FILE handle held by <tt>apop_opts.log_file</tt> (default: \c stderr).
 
\param test The expression that, if true, triggers the action.
\param onfail If the assertion fails, do this. E.g., <tt>out->error='x'; return GSL_NAN</tt>. Notice that it is OK to include several lines of semicolon-separated code here, but if you have a lot to do, the most readable option may be <tt>goto outro</tt>, plus an appropriately-labeled section at the end of your function.
\param level Print the warning message only if \ref apop_opts_type "apop_opts.verbose" is greater than or equal to this. Zero usually works, but for minor infractions use one, or for more verbose debugging output use 2.
\param ... The error message in printf form, plus any arguments to be inserted into the printf string. I'll provide the function name and a carriage return.

Some examples:

\code
//the typical case, stopping function execution:
Apop_stopif(isnan(x), return NAN, 0, "x is NAN; failing");

//Mark a flag, go to a cleanup step
Apop_stopif(x < 0, needs_cleanup=1; goto cleanup, 0, "x is %g; cleaning up and exiting.", x);

//Print a diagnostic iff <tt>apop_opts.verbose>=1</tt> and continue
Apop_stopif(x < 0,  , 1, "warning: x is %g.", x);
\endcode

\li If \c apop_opts.stop_on_warning is nonzero and not <tt>'v'</tt>, then a failed test halts via \c abort(), even if the <tt>apop_opts.verbose</tt> level is set so that the warning message doesn't print to screen. Use this when running via debugger.
\li If \c apop_opts.stop_on_warning is <tt>'v'</tt>, then a failed test halts via \c abort() iff the verbosity level is high enough to print the error.
*/
#define Apop_stopif(test, onfail, level, ...) do {\
     if (test) {  \
        Apop_notify(level,  __VA_ARGS__);   \
        Apop_maybe_abort(level)  \
        onfail;  \
    } } while(0)

#define apop_errorlevel -5

/** \cond doxy_ignore */
//For use in stopif, to return a blank apop_data set with an error attached.
#define apop_return_data_error(E) {apop_data *out=apop_data_alloc(); out->error='E'; return out;}

/* The Apop_stopif macro is currently favored, but there's a long history of prior
   error-handling setups. Consider all of the Assert... macros below to be deprecated.
*/
#define Apop_assert_c(test, returnval, level, ...) \
    Apop_stopif(!(test), return returnval, level, __VA_ARGS__)

#define Apop_assert(test, ...) Apop_assert_c((test), 0, apop_errorlevel, __VA_ARGS__)

//For things that return void. Transitional and deprecated at birth.
#define Apop_assert_n(test, ...) Apop_assert_c((test),  , apop_errorlevel, __VA_ARGS__)
#define Apop_assert_negone(test, ...) Apop_assert_c((test), -1, apop_errorlevel, __VA_ARGS__)
/** \endcond */ //End of Doxygen ignore.

//Missing data
Apop_var_declare( apop_data * apop_data_listwise_delete(apop_data *d, char inplace) )
apop_model * apop_ml_impute(apop_data *d, apop_model* meanvar);

Apop_var_declare(apop_model *apop_model_metropolis(apop_data *d, gsl_rng* rng, apop_model *m))
Apop_var_declare( apop_model * apop_update(apop_data *data, apop_model *prior, apop_model *likelihood, gsl_rng *rng) )

Apop_var_declare( double apop_test(double statistic, char *distribution, double p1, double p2, char tail) )

//apop_sort.c
Apop_var_declare( apop_data *apop_data_sort(apop_data *data, apop_data *sort_order, char asc, char inplace, double *col_order))

//raking
Apop_var_declare( apop_data * apop_rake(char const *margin_table, char * const*var_list, 
                    int var_ct, char * const *contrasts, int contrast_ct, 
                    char const *structural_zeros, int max_iterations, double tolerance, 
                    char const *count_col, char const *init_table, 
                    char const *init_count_col, double nudge) )


#include <gsl/gsl_cdf.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_sf_log.h>
#include <gsl/gsl_sf_exp.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_sf_psi.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_statistics_double.h>


    //Some linear algebra utilities

double apop_det_and_inv(const gsl_matrix *in, gsl_matrix **out, int calc_det, int calc_inv);
Apop_var_declare( apop_data * apop_dot(const apop_data *d1, const apop_data *d2, char form1, char form2) )
Apop_var_declare( int         apop_vector_bounded(const gsl_vector *in, long double max) )
gsl_matrix * apop_matrix_inverse(const gsl_matrix *in) ;
double      apop_matrix_determinant(const gsl_matrix *in) ;
//apop_data*  apop_sv_decomposition(gsl_matrix *data, int dimensions_we_want);
Apop_var_declare( apop_data *  apop_matrix_pca(gsl_matrix *data, int const dimensions_we_want) )
Apop_var_declare( gsl_vector * apop_vector_stack(gsl_vector *v1, gsl_vector const * v2, char inplace) )
Apop_var_declare( gsl_matrix * apop_matrix_stack(gsl_matrix *m1, gsl_matrix const * m2, char posn, char inplace) )

void apop_vector_log(gsl_vector *v);
void apop_vector_log10(gsl_vector *v);
void apop_vector_exp(gsl_vector *v);

                ////Subsetting macros

/** \cond doxy_ignore */
/** These are all deprecated.*/
#define APOP_SUBMATRIX(m, srow, scol, nrows, ncols, o) gsl_matrix apop_mm_##o = gsl_matrix_submatrix((m), (srow), (scol), (nrows),(ncols)).matrix;\
gsl_matrix * o = &( apop_mm_##o );                                                  // Use \ref Apop_subm. 
#define Apop_submatrix APOP_SUBMATRIX

#define Apop_col_v(m, col, v) gsl_vector apop_vv_##v = ((col) == -1) ? (gsl_vector){} : gsl_matrix_column((m)->matrix, (col)).vector;\
gsl_vector * v = ((col)==-1) ? (m)->vector : &( apop_vv_##v );                      // Use \ref Apop_cv.

#define Apop_row_v(m, row, v) Apop_matrix_row((m)->matrix, row, v)                  // Use \ref Apop_rv.
#define Apop_rows(d, rownum, len, outd) apop_data *outd = Apop_rs(d, rownum, len)   // Use \ref Apop_rs.
#define Apop_row(d, row, outd) Apop_rows(d, row, 1, outd)                           // Use \ref Apop_r.
#define Apop_cols(d, colnum, len, outd) apop_data *outd =  Apop_cs(d, colnum, len); // Use \ref Apop_cs.
/** \endcond */ //End of Doxygen ignore.

/** \def Apop_row_tv(m, row_name, v)
 After this call, \c v will hold a \c gsl_vector view of an \ref apop_data set \c m. The view will consist only of the row with name \c row_name.
 Unlike \ref Apop_rv, the second argument is a row name, that I'll look up using \ref apop_name_find, and the third is the name of the view to be generated.
\see Apop_rs, Apop_r, Apop_rv, Apop_row_t, Apop_mrv
*/
#define Apop_row_tv(m, row, v) gsl_vector apop_vv_##v = gsl_matrix_row((m)->matrix, apop_name_find((m)->names, row, 'r')).vector;\
gsl_vector * v = &( apop_vv_##v );

/** \def Apop_col_tv(m, col_name, v)
After this call, \c v will hold a \c gsl_vector view of the \ref apop_data set \c m.
The view will consist only of the column with name \c col_name.
Unlike \ref Apop_cv, the second argument is a column name, that I'll look up using \ref apop_name_find, and the third is the name of the view to be generated.
\see Apop_cs, Apop_c, Apop_cv, Apop_col_t, Apop_mcv
*/
#define Apop_col_tv(m, col, v) gsl_vector apop_vv_##v = gsl_matrix_column((m)->matrix, apop_name_find((m)->names, col, 'c')).vector;\
gsl_vector * v = &( apop_vv_##v );

/** \def Apop_row_t(m, row_name, v)
 After this call, \c v will hold an \ref apop_data view of an \ref apop_data set \c m. The view will consist only of the row with name \c row_name.
 Unlike \ref Apop_r, the second argument is a row name, that I'll look up using \ref apop_name_find, and the third is the name of the view to be generated.
\see Apop_rs, Apop_r, Apop_rv, Apop_row_tv, Apop_mrv
*/
#define Apop_row_t(d, rowname, outd) int apop_row_##outd = apop_name_find((d)->names, rowname, 'r'); Apop_rows(d, apop_row_##outd, 1, outd)

/** \def Apop_col_t(m, col_name, v)
 After this call, \c v will hold a view of the \ref apop_data set \c m. The view will consist only of a \c gsl_vector view of the column of the \ref apop_data set \c m with name \c col_name.
 Unlike \ref Apop_c, the second argument is a column name, that I'll look up using \ref apop_name_find, and the third is the name of the view to be generated.
\see Apop_cs, Apop_c, Apop_cv, Apop_col_tv, Apop_mcv
*/
#define Apop_col_t(d, colname, outd) int apop_col_##outd = apop_name_find((d)->names, colname, 'c'); Apop_cols(d, apop_col_##outd, 1, outd)

// The above versions relied on gsl_views, which stick to C as of 1989 CE.
// Better to just create the views via designated initializers.


/** \def Apop_subm(data_to_view, srow, scol, nrows, ncols)
Generate a view of a submatrix within a \c gsl_matrix. Like \ref Apop_r, et al., the view is an automatically-allocated variable that is lost once the program flow leaves the scope in which it is declared.

\param data_to_view The root matrix
\param srow the first row (in the root matrix) of the top of the submatrix
\param scol the first column (in the root matrix) of the left edge of the submatrix
\param nrows number of rows in the submatrix
\param ncols number of columns in the submatrix
\return An automatically-allocated view of type \c gsl_matrix.
*/
#define Apop_subm(matrix_to_view, srow, scol, nrows, ncols)(                  \
        (!(matrix_to_view)                                                   \
            || (matrix_to_view)->size1 < (srow)+(nrows) || (srow) < 0        \
            || (matrix_to_view)->size2 < (scol)+(ncols) || (scol) < 0) ? NULL \
        : &(gsl_matrix){.size1=(nrows), .size2=(ncols),                         \
             .tda=(matrix_to_view)->tda,                                  \
             .data=gsl_matrix_ptr((matrix_to_view), (srow), (scol))}      \
        )

/** Get a vector view of a single row of a \ref gsl_matrix.

\param matrix_to_vew A \ref gsl_matrix.
\param row An integer giving the row to be viewed.
\return A \c gsl_vector view of the given row. The view is automatically allocated,
  and disappears as soon as the program leaves the scope in which it is declared.

See \ref apop_vector_correlation for an example of use.
\see Apop_r, Apop_rv
*/
#define Apop_mrv(matrix_to_view, row) Apop_rv(&(apop_data){.matrix=matrix_to_view}, row)

/** Get a vector view of a single column of a \ref gsl_matrix.

\param matrix_to_vew A \ref gsl_matrix.
\param row An integer giving the column to be viewed.
\return A \c gsl_vector view of the given column. The view is automatically allocated,
  and disappears as soon as the program leaves the scope in which it is declared.

\code 
gsl_matrix *m = apop_query_to_data("select col1, col2, col3 from data")->matrix;
printf("The correlation coefficient between columns two "
       "and three is %g.\n", apop_vector_correlation(Apop_mcv(m, 2), Apop_mcv(m, 3)));
\endcode 

\see Apop_r, Apop_cv
*/
#define Apop_mcv(matrix_to_view, col) Apop_cv(&(apop_data){.matrix=matrix_to_view}, col)

/** \def Apop_rv(d, row)
A macro to generate a temporary one-row view of the matrix in an \ref apop_data set \c d, pulling out only
row \c row. The view is a \c gsl_vector set.

\code
gsl_vector *v = Apop_rv(your_data, i);

for (int i=0; i< your_data->matrix->size1; i++)
    printf("Σ_%i = %g\n", i, apop_vector_sum(Apop_r(your_data, i)));
\endcode

The view is automatically allocated, and disappears as soon as the program leaves the scope in which it is declared.
\see Apop_r, Apop_rv, Apop_row_tv, Apop_row_t, Apop_mrv
*/
#define Apop_rv(data_to_view, row) (                                            \
        ((data_to_view) == NULL || (data_to_view)->matrix == NULL               \
            || (data_to_view)->matrix->size1 <= (row) || (row) < 0) ? NULL        \
        : &(gsl_vector){.size=(data_to_view)->matrix->size2,                    \
             .stride=1, .data=gsl_matrix_ptr((data_to_view)->matrix, (row), 0)} \
        )

/** \def Apop_cv(d, col)
A macro to generate a temporary one-column view of the matrix in an \ref apop_data
set \c d, pulling out only column \c col. The view is a \c gsl_vector set.

As usual, column -1 is the vector element of the \ref apop_data set.

\code
gsl_vector *v = Apop_cv(your_data, i);

for (int i=0; i< your_data->matrix->size2; i++)
    printf("Σ_%i = %g\n", i, apop_vector_sum(Apop_c(your_data, i)));
\endcode

The view is automatically allocated, and disappears as soon as the program leaves the
scope in which it is declared.

\see Apop_cs, Apop_c, Apop_col_tv, Apop_col_t, Apop_mcv
*/
#define Apop_cv(data_to_view, col) (                                           \
          !(data_to_view) ? NULL                                               \
        : (col)==-1       ? (data_to_view)->vector                             \
        : (!(data_to_view)->matrix                                             \
            || (data_to_view)->matrix->size2 <= (col) || ((int)(col)) < -1) ? NULL    \
        : &(gsl_vector){.size=(data_to_view)->matrix->size1,                   \
             .stride=(data_to_view)->matrix->tda, .data=gsl_matrix_ptr((data_to_view)->matrix, 0, (col))} \
        )

/** \cond doxy_ignore */
/* Not (yet) for public use. */
#define Apop_subvector(v, start, len) (                                          \
        ((v) == NULL || (v)->size < ((start)+(len)) || (start) < 0) ? NULL      \
        : &(gsl_vector){.size=(len), .stride=(v)->stride, .data=(v)->data+(start*(v)->stride)})
/** \endcond */

/** \def Apop_rs(d, row, len)
A macro to generate a temporary view of \ref apop_data set \c d pulling only certain rows, beginning at row \c row
and having height \c len. 

The view is automatically allocated, and disappears as soon as the program leaves the scope in which it is declared.
\see Apop_r, Apop_rv, Apop_row_tv, Apop_row_t, Apop_mrv
*/
#define Apop_rs(d, rownum, len)(                                                 \
        (!(d) || (rownum) < 0) ? NULL                                            \
        : &(apop_data){                                                          \
         .names= ( !((d)->names) ? NULL :                                        \
            &(apop_name){                                                        \
                .title = (d)->names->title,                                      \
                .vector = (d)->names->vector,                                    \
                .col = (d)->names->col,                                          \
                .row = ((d)->names->row && (d)->names->rowct > (rownum)) ? &((d)->names->row[rownum]) : NULL,  \
                .texthash = (d)->names->texthash,                                \
                .rowhash = ((d)->names->rowhash && (d)->names->rowct > (rownum)) ? &((d)->names->rowhash[rownum]) : NULL,  \
                .colhash = (d)->names->colhash,                                  \
                .text = (d)->names->text,                                        \
                .colct = (d)->names->colct,                                      \
                .rowct = (d)->names->row ? (GSL_MIN(1, GSL_MAX((d)->names->rowct - (int)(rownum), 0)))      \
                                          : 0,                                   \
                .textct = (d)->names->textct }),                                 \
        .vector= Apop_subvector((d->vector), (rownum), (len)),                   \
        .matrix = Apop_subm(((d)->matrix), (rownum), 0,  (len), (d)->matrix?(d)->matrix->size2:0),    \
        .weights =  Apop_subvector(((d)->weights), (rownum), (len)),             \
        .textsize[0]=(d)->textsize[0]> (rownum)+(len)-1 ? (len) : 0,                                   \
        .textsize[1]=(d)->textsize[1],                                           \
        .text = (d)->text ? &((d)->text[rownum]) : NULL,                         \
        })


/** \def Apop_cs(d, col, len)
A macro to generate a temporary view of \ref apop_data set \c d including only certain columns, beginning at column \c col and having length \c len. 

The view is automatically allocated, and disappears as soon as the program leaves the scope in which it is declared.
\see Apop_c, Apop_cv, Apop_col_tv, Apop_col_t, Apop_mcv
*/
#define Apop_cs(d, colnum, len) ( \
            (!(d)||!(d)->matrix || (d)->matrix->size2 <= (colnum)+(len)-1)       \
             ? NULL                                                              \
             : &(apop_data){                                                     \
                .vector= NULL,                                                   \
                .weights= (d)->weights,                                          \
                .matrix = Apop_subm((d)->matrix, 0, colnum, (d)->matrix->size1, (len)),\
                .textsize[0] = 0,                                                \
                .textsize[1] = 0,                                                \
                .text = NULL,                                                    \
                .names= (d)->names ? &(apop_name){                                                         \
                    .title = (d)->names->title,                                      \
                    .vector = NULL,                                                  \
                    .row = (d)->names->row,                                          \
                    .col = ((d)->names->col && (d)->names->colct > colnum) ? &((d)->names->col[colnum]) : NULL,  \
                    .text = NULL,                                                    \
                    .texthash = NULL,                                                \
                    .rowhash = (d)->names->rowhash,                                  \
                    .colhash = ((d)->names->colhash && (d)->names->colct > (colnum)) ? &((d)->names->colhash[colnum]) : NULL,  \
                    .rowct = (d)->names->rowct,                                      \
                    .colct = (d)->names->col ? (GSL_MIN(len, GSL_MAX((d)->names->colct - colnum, 0)))      \
                                              : 0,                                   \
                    .textct = (d)->names->textct } : NULL \
            })

/** \def Apop_r(d, row)
A macro to generate a temporary one-row view of \ref apop_data set \c d, pulling out only
row \c row. The view is also an \ref apop_data set, with names and other decorations.
\code
//pull a single row
apop_data *v = Apop_r(your_data, 7);

//or loop through a sequence of one-row data sets.
apop_model *std = apop_model_set_parameters(apop_normal, 0, 1);
for (int i=0; i< your_data->matrix->size1; i++)
    printf("Std Normal CDF up to observation %i is %g\n",
                       i, apop_cdf(Apop_r(your_data, i), std));
\endcode

The view is automatically allocated, and disappears as soon as the program leaves the
scope in which it is declared.
\see Apop_rs, Apop_row_v, Apop_row_tv, Apop_row_t, Apop_mrv
*/
#define Apop_r(d, rownum) Apop_rs(d, rownum, 1)

/** \def Apop_c(d, col)
A macro to generate a temporary one-column view of \ref apop_data set \c d, pulling out only
column \c col. 
After this call, \c outd will be a pointer to this temporary
view, that you can use as you would any \ref apop_data set.
\see Apop_cs, Apop_cv, Apop_col_tv, Apop_col_t, Apop_mcv
*/
#define Apop_c(d, col) Apop_cs(d, col, 1)

/** \cond doxy_ignore */
#define APOP_COL Apop_col
#define apop_col Apop_col
#define APOP_COL_T Apop_col_t
#define apop_col_t Apop_col_t
#define APOP_COL_TV Apop_col_tv
#define apop_col_tv Apop_col_tv

#define APOP_ROW Apop_row
#define apop_row Apop_row
#define APOP_COLS Apop_cols
#define apop_cols Apop_cols
#define APOP_COL_V Apop_col_v
#define apop_col_v Apop_col_v
#define APOP_ROW_V Apop_row_v
#define apop_row_v Apop_row_v
#define APOP_ROWS Apop_rows
#define apop_rows Apop_rows
#define Apop_data_row Apop_row   #deprecated
#define APOP_ROW_T Apop_row_t
#define apop_row_t Apop_row_t
#define APOP_ROW_TV Apop_row_tv
#define apop_row_tv Apop_row_tv

/** Deprecated. Use Apop_mrv */
#define Apop_matrix_row(m, row, v) gsl_vector apop_vv_##v = gsl_matrix_row((m), (row)).vector;\
gsl_vector * v = &( apop_vv_##v );

/* Deprecated. Use Apop_mcv */
#define Apop_matrix_col(m, col, v) gsl_vector apop_vv_##v = gsl_matrix_column((m), (col)).vector;\
gsl_vector * v = &( apop_vv_##v );

#define APOP_MATRIX_ROW Apop_matrix_row 
#define apop_matrix_row Apop_matrix_row 
#define APOP_MATRIX_COL Apop_matrix_col 
#define apop_matrix_col Apop_matrix_col 
/** \endcond */


long double apop_vector_sum(const gsl_vector *in);
double apop_vector_var_m(const gsl_vector *in, const double mean);
Apop_var_declare( double apop_vector_correlation(const gsl_vector *ina, const gsl_vector *inb, const gsl_vector *weights) )
double apop_vector_kurtosis(const gsl_vector *in);
double apop_vector_skew(const gsl_vector *in);

#define apop_sum apop_vector_sum
#define apop_var apop_vector_var
#define apop_mean apop_vector_mean

        //////database utilities

Apop_var_declare( int apop_table_exists(char const *name, char remove) )

int apop_db_open(char const *filename);
Apop_var_declare( int apop_db_close(char vacuum) )

int apop_query(const char *q, ...) __attribute__ ((format (printf,1,2)));
apop_data * apop_query_to_text(const char * fmt, ...) __attribute__ ((format (printf,1,2)));
apop_data * apop_query_to_data(const char * fmt, ...) __attribute__ ((format (printf,1,2)));
apop_data * apop_query_to_mixed_data(const char *typelist, const char * fmt, ...) __attribute__ ((format (printf,2,3)));
gsl_vector * apop_query_to_vector(const char * fmt, ...) __attribute__ ((format (printf,1,2)));
double apop_query_to_float(const char * fmt, ...) __attribute__ ((format (printf,1,2)));

int apop_data_to_db(const apop_data *set, const char *tabname, char);


        //////Settings groups

    //Part I: macros and fns for getting/setting settings groups and elements

/** \cond doxy_ignore */
void * apop_settings_get_grp(apop_model *m, char *type, char fail);
void apop_settings_remove_group(apop_model *m, char *delme);
void apop_settings_copy_group(apop_model *outm, apop_model *inm, char *copyme);
void *apop_settings_group_alloc(apop_model *model, char *type, void *free_fn, void *copy_fn, void *the_group);
apop_model *apop_settings_group_alloc_wm(apop_model *model, char *type, void *free_fn, void *copy_fn, void *the_group);
/** \endcond */ //End of Doxygen ignore.

/** Retrieves a settings group from a model.  See \ref Apop_settings_get
to just pull a single item from within the settings group.

This macro returns NULL if a group of type \c type_settings isn't found attached
to model \c m, so you can easily put it in a conditional like
  \code 
  if (!apop_settings_get_group(m, "apop_ols")) ...
  \endcode

\param m An \ref apop_model
\param type A string giving the type of the settings group you are retrieving. E.g., for an \ref apop_mle_settings group, use only \c apop_mle.
\return A void pointer to the desired struct (or \c NULL if not found).
*/
#define Apop_settings_get_group(m, type) apop_settings_get_grp(m, #type, 'c')

/** Removes a settings group from a model's list. 
 
\li  If the so-named group is not found, do nothing.
*/
#define Apop_settings_rm_group(m, type) apop_settings_remove_group(m, #type)

/** Add a settings group. The first two arguments (the model you are
attaching to and the settings group name) are mandatory, and then you
can use the \ref designated syntax to specify default values (if any).
\return A pointer to the newly-prepped group.

See \ref modelsettings, \ref maxipage, or \ref Apop_settting_set for examples.

\li If a settings group of the given type is already attached to the model, 
the previous version is removed. Use \ref Apop_settings_get to check whether a group
of the given type is already attached to a model, and \ref Apop_settings_set to modify
an existing group.
*/
#define Apop_settings_add_group(model, type, ...)  \
    apop_settings_group_alloc(model, #type, type ## _settings_free, type ## _settings_copy, type ##_settings_init ((type ## _settings) {__VA_ARGS__}))

/** Copy a model and add a settings group. Useful for models that require a settings group to function. See \ref Apop_settings_add_group.

\return A pointer to the newly-prepped model.
*/
#define apop_model_copy_set(model, type, ...)  \
    apop_settings_group_alloc_wm(apop_model_copy(model), #type, type ## _settings_free, type ## _settings_copy, type ##_settings_init ((type ## _settings) {__VA_ARGS__}))


/** This is the complement to \ref apop_model_set_parameters, for those models that are
 set up by adding settings group, rather than filling in a list of parameters.

For example, the \ref apop_kernel_density model is built by adding a \ref apop_kernel_density_settings group. From the example on the \ref apop_kernel_density page:

\code
apop_model *k2 = apop_model_set_settings(apop_kernel_density,
                    .base_data=d,
                    .set_fn = set_uniform_edges,
                    .kernel = apop_uniform);
\endcode

The name of the model and the settings group to be built must match, which is the case
for many model transformations, including \ref apop_dconstrain and \ref apop_cross. If the names do not match, use \ref apop_model_copy_set.
*/
#define Apop_model_set_settings(model, ...)  \
    apop_settings_group_alloc_wm(apop_model_copy(model), #model, model ## _settings_free, model ## _settings_copy, model ##_settings_init ((model ## _settings) {__VA_ARGS__}))

#define apop_model_set_settings Apop_model_set_settings

/** Retrieves a setting from a model.  See \ref Apop_settings_get_group to pull the entire group.

\param model An \ref apop_model.
\param type A string giving the type of the settings group you are retrieving, without the \c _settings ending. E.g., for an \ref apop_mle_settings group, use \c apop_mle.
\param setting The struct element you want to retrieve.
*/
#define Apop_settings_get(model, type, setting)  \
    (((type ## _settings *) apop_settings_get_grp(model, #type, 'f'))->setting)

/** Modifies a single element of a settings group to the given value. 

For example,
\code
//set up a mixture of two Normals. This function initializes an apop_mixture_settings group
apop_model *mix = apop_model_mixture(apop_model_copy(apop_normal), apop_model_copy(apop_normal));

//Add an apop_mle_settings group to specify the search strategy
Apop_settings_add_group(mix, apop_mle, .starting_pt=(double[]){.5, .5, 50, 5, 80, 5},
                                           .step_size=3, .tolerance=1e-6);

//The mix model now has apop_mle and apop_mixture settings groups attached. Modify them:
Apop_settings_set(mix, apop_mixture, find_weights, 'y');  //Search for optimal mixture weights
Apop_settings_set(mix, apop_mle, method, "NM simplex");   //Nelder-Mead simplex algorithm
apop_model *optimal_mix = apop_estimate(input_data, mix); //Everything is set up, so do the search.
\endcode

\li If <tt>model==NULL</tt>, fails silently. 
\li If <tt>model!=NULL</tt> but the given settings group is not found attached to the model, set <tt>model->error='s'</tt>.
*/
#define Apop_settings_set(model, type, setting, data)   \
    do {                                                \
        if (!(model)) continue; /* silent fail. */      \
        type ## _settings *apop_tmp_settings = apop_settings_get_grp(model, #type, 'c');  \
        Apop_stopif(!apop_tmp_settings, (model)->error='s', 0, "You're trying to modify a setting in " \
                        #model "'s setting group of type " #type " but that model doesn't have such a group."); \
    apop_tmp_settings->setting = (data);                \
    } while (0);

/** \cond doxy_ignore */
#define Apop_settings_add Apop_settings_set
#define APOP_SETTINGS_ADD Apop_settings_set
#define apop_settings_set Apop_settings_set
#define APOP_SETTINGS_GET Apop_settings_get
#define apop_settings_get Apop_settings_get
#define APOP_SETTINGS_ADD_GROUP Apop_settings_add_group
#define apop_settings_add_group Apop_settings_add_group
#define APOP_SETTINGS_GET_GROUP Apop_settings_get_group
#define apop_settings_get_group Apop_settings_get_group
#define APOP_SETTINGS_RM_GROUP Apop_settings_rm_group
#define apop_settings_rm_group Apop_settings_rm_group
#define Apop_model_copy_set apop_model_copy_set

//deprecated:
#define Apop_model_add_group Apop_settings_add_group

/** \endcond */ //End of Doxygen ignore.

/** Put this in your header file to declare the init, copy, and
free functions for ysg_settings. Of course, these functions will also have to be defined
in a .c file using \ref Apop_settings_init, \ref Apop_settings_copy, and \ref Apop_settings_free. */
#define Apop_settings_declarations(ysg) \
   ysg##_settings * ysg##_settings_init(ysg##_settings); \
   void * ysg##_settings_copy(ysg##_settings *); \
   void ysg##_settings_free(ysg##_settings *);

/** A convenience macro for declaring the initialization function for a new settings group.
See \ref settingswriting for details and an example.
*/
#define Apop_settings_init(name, ...)   \
    name##_settings *name##_settings_init(name##_settings in) {       \
        name##_settings *out = malloc(sizeof(name##_settings));     \
        *out = in; \
        __VA_ARGS__;            \
        return out; \
    }

/** \cond doxy_ignore */
#define Apop_varad_set(var, value) (out)->var = (in).var ? (in).var : (value);
/** \endcond */

/** A convenience macro for declaring the copy function for a new settings group.
See \ref settingswriting for details and an example.
*/
#define Apop_settings_copy(name, ...) \
    void * name##_settings_copy(name##_settings *in) {\
        name##_settings *out = malloc(sizeof(name##_settings)); \
        *out = *in; \
        __VA_ARGS__;    \
        return out;     \
    }

/** A convenience macro for declaring the delete function for a new settings group.
See \ref settingswriting for details and an example.
*/
#define Apop_settings_free(name, ...) \
    void name##_settings_free(name##_settings *in) {\
        __VA_ARGS__;    \
        free(in);  \
    }

        //Part II: the details of extant settings groups.


/** The settings for maximum likelihood estimation (including simulated annealing). */
typedef struct{
    double      *starting_pt;   /**< An array of doubles (e.g., <tt>(double*){2,4,6,8}</tt>) suggesting a starting point. 
                                  If NULL, use an all-ones vector.  If \c startv is a \c gsl_vector
                                  and is not a view of a matrix, use <tt>.starting_pt=startv->data</tt>.*/
    char *method; /**< The method to be used for the optimization. All strings are case-insensitive.

        <table>
<tr>
<td> String <td></td> Name  <td></td>  Notes
</td> </tr>
                                     
<tr><td> "NM simplex" </td><td> Nelder-Mead simplex </td><td> Does not use gradients at all. Can sometimes get stuck.</td></tr>

<tr><td> "FR cg"  </td><td> Conjugate gradient (Fletcher-Reeves) (default) </td><td> CG methods use derivatives. The converge to the optimum of a quadratic function in one step; performance degrades as the objective digresses from quadratic.</td></tr>

<tr><td> "BFGS cg" </td><td> Broyden-Fletcher-Goldfarb-Shanno conjugate gradient        </td><td>  </td></tr>

<tr><td> "PR cg"  </td><td> Polak-Ribiere conjugate gradient  </td><td>  </td></tr>

<tr><td> "Annealing"  </td><td> \ref simanneal "simulated annealing"         </td><td> Slow but works for objectives of arbitrary complexity, including stochastic objectives.</td></tr>

<tr><td> "Newton"</td><td> Newton's method  </td><td> Search by finding a root of the derivative. Expects that gradient is reasonably well-behaved. </td></tr>

<tr><td> "Newton hybrid"</td><td> Newton's method/gradient descent hybrid        </td><td>  Find a root of the derivative via the Hybrid method </td> If Newton proposes stepping outside of a certain interval, use an alternate method. See <a href="https://www.gnu.org/software/gsl/manual/gsl-ref_35.html#SEC494">the GSL manual</a> for discussion.</tr>

<tr><td> "Newton hybrid no scale"</td><td>  Newton's method/gradient descent hybrid with spherical scale</td><td>  As above, but use a simplified trust region. </td></tr>
</table> */
    double      step_size, /**< The initial step size. */
                tolerance, /**< The precision the minimizer uses in its stopping rule. Only vaguely related to the precision of the actual MLE.*/
delta;
    int         max_iterations; /**< Ignored by simulated annealing. Other methods halt (and set the \c "status" element of the output estimate's info page) if
                                 they do this many iterations without finding an optimum. */
    int         verbose; /**<	Give status updates as we go.  This is orthogonal to the 
                                <tt>apop_opts.verbose</tt> setting. */
    double      dim_cycle_tolerance; /**< If zero (the default), the usual procedure.
                             If \f$>0\f$, cycle across dimensions: fix all but the first dimension at the starting
                             point, optimize only the first dim. Then fix the all but the second dim, and optimize the
                             second dim. Continue through all dims, until the log likelihood at the outset of one cycle
                             through the dimensions is within this amount of the previous cycle's log likelihood. There
                             will be at least two cycles.
                             */
//simulated annealing (also uses step_size);
    int         n_tries, iters_fixed_T;
    double      k, t_initial, mu_t, t_min ;
    gsl_rng     *rng;
    apop_data   **path;    /**< If not \c NULL, record each vector tried by the optimizer as one row of this \ref apop_data set.
                              Each row of the \c matrix element holds the vector tried; the corresponding element in the \c vector is the evaluated value at that vector (after out-of-constraints penalties have been subtracted).
                              A new \ref apop_data set is allocated at the pointer you send in. This data set has no names; add them as desired. For a sample use, see \ref maxipage.
*/
} apop_mle_settings;

/** Settings for least-squares type models such as \ref apop_ols or \ref apop_iv */
typedef struct {
    int destroy_data; /**< If \c 'y', then the input data set may be normalized or otherwise mangled. */
    apop_data *instruments; /**< Use for the \ref apop_iv regression, qv. */
    char want_cov; /**< Deprecated. Please use \ref apop_parts_wanted_settings. */
    char want_expected_value; /**< Deprecated. Please use \ref apop_parts_wanted_settings. */
    apop_model *input_distribution; /**< The distribution of \f$P(Y|X)\f$ is specified by the model holding this struct, but the distribution of \f$X\f$ needs to be specified as well for any calculation of \f$P(Y)\f$. See the notes in the RNG section of the \ref apop_ols documentation. */
} apop_lm_settings;

/** The default is for the estimation routine to give some auxiliary information,
  such as a covariance matrix, predicted values, and common hypothesis tests.
  Some uses of a model depend on these items, but if they are a waste
  of time for your purposes, this settings group gives a quick way to bypass them all.

  Adding this settings group to your model without changing any default values---
  \code
  Apop_model_add_group(your_model, apop_parts_wanted);
  \endcode
  ---will turn off all of the auxiliary calculations covered, because the default value
  for all the switches is <tt>'n'</tt>, indicating that all elements are not wanted.

  From there, you can change some of the default <tt>'n'</tt>s to <tt>'y'</tt>s to retain some but not all auxiliary elements.  If you just want the parameters themselves and the covariance matrix:
  \code
  Apop_model_add_group(your_model, apop_parts_wanted, .covariance='y');
  \endcode

  \li Not all models support this, although the models with especially compute-intensive
  auxiliary info do (e.g., the maximum likelihood estimation system). Check the model's documentation. 

  \li Tests may depend on covariance, so <tt>.covariance='n', .tests='y'</tt> may be 
  treated as <tt>.covariance='y', .tests='y'</tt>.
*/
typedef struct {
    //init/copy/free are in apop_mle.c
    char covariance;    /*< If 'y', calculate the covariance matrix. Default 'n'. */
    char predicted;/*< If 'y', calculate the predicted values. This is typically as many
                     items as rows in your data set. Default 'n'. */
    char tests;/*< If 'y', run any hypothesis tests offered by the model's estimation routine. Default 'n'. */
    char info;/*< If 'y', add an info table with elements such as log likelihood or AIC. Default 'n'. */
} apop_parts_wanted_settings;

/** For use by \ref apop_cdf when the CDF is generated via Monte Carlo methods. */
typedef struct {
    int draws;  /**< For random draw methods, how many draws? Default: 10,000.*/
    gsl_rng *rng; /**< For random draw methods. See \ref apop_rng_get_thread on the default. */
    gsl_matrix *draws_made; /**< A store of random draws used to calcuate the CDF. Need only be generated once, and so stored here. */
    int *draws_refcount; /**< For internal use.*/
} apop_cdf_settings;


/** Settings for getting parameter models (i.e. the distribution of parameter estimates) */
typedef struct {
    apop_model *base;
    int index;
    gsl_rng *rng;
    int draws;
} apop_pm_settings;


/** Settings to accompany the \ref apop_pmf. */
typedef struct {
    gsl_vector *cmf;  /**< A cumulative mass function, for the purposes of making random draws.*/
    char draw_index;  /**< If \c 'y', then draws from the PMF return the integer index of the row drawn. 
                           If \c 'n' (the default), then return the data in the vector/matrix elements of the data set. */
    long double total_weight; /**< Keep the total weight, in case the input weights aren't normalized to sum to one. */
    int *cmf_refct;    /**< For internal use, so I can garbage-collect the CMF when needed. */
} apop_pmf_settings;


/** Settings for the \ref apop_kernel_density model. */
typedef struct{
    apop_data *base_data; /**< The data that will be smoothed by the KDE. */
    apop_model *base_pmf; /**< I actually need the data in a \ref apop_pmf. You can give
                            that to me explicitly, or I can wrap the <tt>.base_data</tt> in a PMF.  */
    apop_model *kernel; /**< The distribution to be centered over each data point. Default, 
                                    \ref apop_normal with std dev 1. */
    void (*set_fn)(apop_data*, apop_model*); /**< The function I will use for each data
                                                  point to center the kernel over each point.
            Default: set the upper-left element of the parameter set to the upper-left scalar in the data:
            <tt>apop_data_set(m->parameters, .val= apop_data_get(in));</tt>.
                                                  */
    int own_pmf, own_kernel; /**< For internal use only. */
}apop_kernel_density_settings;

struct apop_mcmc_settings;

/** A proposal distribution for \ref apop_mcmc_settings and its accompanying functions and
information.  By default, these will be \ref apop_multivariate_normal models. The \c
step_fn and \c adapt_fn have to be written around the model and your preferences.
For the defaults, the step function recenters the mean of the distribution around the
last accepted proposal, and the adapt function widens \f$\Sigma\f$ for the Normal if the
accept rate is too low; narrows it if the accept rate is too large.

You may provide an array of proposals. The length of the list of proposals
must match the number of chunks, as per the \c gibbs_chunks setting in the \ref
apop_mcmc_settings group that the array of proposals is a part of. Each proposal must
be initialized to include all elements, and the step and adapt functions probably have
to be written anew for each type of model.
*/
typedef struct apop_mcmc_proposal_s {
    apop_model *proposal; /**< The distribution from which test parameters will be
        drawn. After getting the draw using the \c draw method of the proposal, the base
        model's \c parameters element is filled using \ref apop_data_fill.
        If \c NULL, \ref apop_model_metropolis will use a Multivariate Normal with the
        appropriate dimension, mean zero, and covariance matrix I. If not \c NULL, be sure to
        parameterize your model with an initial position. */

    void (*step_fn)(double const *, struct apop_mcmc_proposal_s*, struct apop_mcmc_settings *); /**< Modifies the parameters of the
        proposal distribution given a successful draw. Typically, this function writes the
        drawn data point to the parameter set. If the draw is a scalar, the default
        function sets the 0th element of the model's \c parameter set with the draw
        (works for the \ref apop_normal and other models). If the draw has multiple
        dimensions, they are all copied to the parameter set, which must have the same
        size. */

    int (*adapt_fn)(struct apop_mcmc_proposal_s *ps, struct apop_mcmc_settings *ms); /**< Called
        every step, to adapt the proposal distribution using information to this point in
        the chain. */

    int accept_count, reject_count;  /**< If there are multiple \ref apop_mcmc_proposal_s structs for 
                                       multiple chunks, These count accepts/rejects for
                                       this chunk. The \ref apop_mcmc_settings group has
                                       a total for the aggregate across all chunks. */
} apop_mcmc_proposal_s;

/** Method settings for a model to be put through Bayesian updating. */
typedef struct apop_mcmc_settings {
    apop_data *data;
    long int periods; /**< For how many steps should the MCMC chain run? */
    double burnin; /**< What <em>percentage</em> of the periods should be ignored
                         as initialization. That is, this is a number between zero and one. */
    int histosegments; /**< If outputting a binned PMF, how many segments should it have? */
    double last_ll; /**< If you have already run MCMC, the last log likelihood in the chain.*/
    apop_model *pmf; /**< If you have already run MCMC, I keep a pointer to the model
            so far here. Use \ref apop_model_metropolis_draw to get one more draw.*/
    apop_model *base_model; /**< The model you provided with a \c log_likelihood or
            \c p element (which need not sum to one). You do not have to set this: if it is
            \c NULL on input to \ref apop_model_metropolis, I will fill it in.*/
    apop_mcmc_proposal_s *proposals; /**< The list of proposals. You can probably use
            the default of adaptive multivariate normals. See the \ref apop_mcmc_proposal_s
            struct for details. */
    int proposal_count; /**< The number of proposal sets; see \c gibbs_chunks below. */
    double target_accept_rate; /**< The desired acceptance rate, for use by adaptive proposals. Default: .35 */
    int accept_count;   /**< After calling \ref apop_model_metropolis, this will have the number of accepted proposals.*/
    int reject_count;   /**< After calling \ref apop_model_metropolis, this will have the number of rejected proposals.*/
    char gibbs_chunks;  /**< See the \ref apop_model_metropolis documentation for discussion.
                          
                          \c 'a': One step draws and accepts/rejects all parameters as a unit<br>

                             \c 'b': draw in blocks: the vector is a block, the matrix
                                is a separate block, the weights are a separate
                                block, and so on through every page of the model
                                parameters. Each block of parameters is drawn and
                                accepted/rejected as a unit. <br>

                             \c '1': draw each parameter and accept/reject separately. One
                                MCMC step consists of a set of draws for every
                                parameter.<br> */
    size_t *block_starts; /**< For internal use */
    int block_count, proposal_is_cp; /**< For internal use. */

    char start_at; /**< If \c '1' (the default), start with a first proposal of all
        1s. Even when this is a far-from-useful starting point, MCMC typically does a good
        job of crawling to better spots early in the chain.<br>
    The default when this is unset is to start at the \c parameters of the \ref apop_model sent in to \ref
    apop_model_metropolis.*/
    void (*base_step_fn)(double const *, struct apop_mcmc_proposal_s*, struct apop_mcmc_settings *); /**< If an \ref apop_mcmc_proposal_s struct has \c NULL \c step_fn, use this. If you don't want a step function, set this to a do-nothing function. */
    int (*base_adapt_fn)(struct apop_mcmc_proposal_s *ps, struct apop_mcmc_settings *ms); /**< If a \ref apop_mcmc_proposal_s has \c NULL \c adapt_fn, use this.  If you don't want an adapt function, set this to a do-nothing function.*/

} apop_mcmc_settings;

/** \cond doxy_ignore */
//Loess, including the old FORTRAN-to-C.
struct loess_struct {
	struct {
		long    n, p;
        double  *y, *x;
		double	*weights;
	} in;
	struct {
	        double  span;
	        long    degree;
	        long    normalize;
	        long    parametric[8];
	        long    drop_square[8];
	        char    *family;
	} model;
	struct {
	        char    *surface;
	        char    *statistics;
	        double  cell;
	        char    *trace_hat;
	        long    iterations;
	} control;
	struct {
		long	*parameter, *a;
		double	*xi, *vert, *vval;
	} kd_tree;
	struct {
		double	*fitted_values;
        double  *fitted_residuals;
		double  enp, s;
		double  one_delta, two_delta;
		double	*pseudovalues;
		double	trace_hat;
		double	*diagonal;
		double	*robust;
		double  *divisor;
	} out;
};
/** \endcond */ //End of Doxygen ignore.

/** The code for the loess system is based on FORTRAN code from 1988,
overhauled in 1992, linked in to Apophenia in 2009. The structure that
does all the work, then, is a \c loess_struct that you should
basically take as opaque. 

The useful settings from that struct re-appear in the \ref
apop_loess_settings struct so you can set them directly, and then the
settings init function will copy your preferences into the working struct.

The documentation for the elements is cut/pasted/modified from Cleveland,
Grosse, and Shyu.
*/
typedef struct {
    apop_data *data;
    struct  loess_struct lo_s; /**< 

<tt>.data</tt>: Mandatory. Your input data set.

<tt>.lo_s.model.span</tt>:	smoothing parameter. Default is 0.75.

<tt>.lo_s.model.degree</tt>: overall degree of locally-fitted polynomial. 1 is
		locally-linear fitting and 2 is locally-quadratic fitting. Default is 2.

<tt>.lo_s.normalize</tt>:	Should numeric predictors
		be normalized?	If \c 'y' - the default - the standard normalization
		is used. If \c 'n', no normalization is carried out.

\c .lo_s.model.parametric:	for two or more numeric predictors, this argument
		specifies those variables that should be
		conditionally-parametric. The argument should be a logical
		vector of length \c p, specified in the order of the predictor
		group ordered in \c x.  Default is a vector of 0's of length \c p.

\c .lo_s.model.drop_square:	for cases with degree = 2, and with two or more
		numeric predictors, this argument specifies those numeric
		predictors whose squares should be dropped from the set of
		fitting variables. The method of specification is the same as
		for parametric.  Default is a vector of 0's of length p.

\c .lo_s.model.family: the assumed distribution of the errors. The values may be 
        <tt>"gaussian"</tt> or <tt>"symmetric"</tt>. The first value is the default.
        If the second value is specified, a robust fitting procedure is used.

\c lo_s.control.surface:	determines whether the fitted surface is computed
        <tt>"directly"</tt> at all points  or whether an <tt>"interpolation"</tt>
        method is used. The default, interpolation, is what most users should use
		unless special circumstances warrant.

\c lo_s.control.statistics:	determines whether the statistical quantities are 
    computed <tt>"exactly"</tt> or approximately, where <tt>"approximate"</tt>
    is the default. The former should only be used for testing the approximation in
    statistical development and is not meant for routine usage because computation
    time can be horrendous.

    \c lo_s.control.cell: if interpolation is used to compute the surface,
    this argument specifies the maximum cell size of the k-d tree. Suppose k =
    floor(n*cell*span) where n is the number of observations.  Then a cell is
    further divided if the number of observations within it is greater than or
    equal to k. default=0.2

\c lo_s.control.trace_hat: Options are <tt>"approximate"</tt>, <tt>"exact"</tt>, and <tt>"wait.to.decide"</tt>.	
    When lo_s.control.surface is <tt>"approximate"</tt>, determines
    the computational method used to compute the trace of the hat
    matrix, which is used in the computation of the statistical
    quantities.  If "exact", an exact computation is done; normally
    this goes quite fast on the fastest machines until n, the number
    of observations is 1000 or more, but for very slow machines,
    things can slow down at n = 300.  If "wait.to.decide" is selected,
    then a default is chosen in loess();  the default is "exact" for
    n < 500 and "approximate" otherwise.  If surface is "exact", an
    exact computation is always done for the trace. Set trace_hat to
    "approximate" for large dataset will substantially reduce the
    computation time.

\c lo_s.model.iterations:	if family is <tt>"symmetric"</tt>, the number of iterations 
    of the robust fitting method.  Default is 0 for
    lo_s.model.family = gaussian; 4 for family=symmetric.

    That's all you can set. Here are some output parameters:

\c fitted_values:	fitted values of the local regression model

\c fitted_residuals:	residuals of the local regression fit

   \c  enp:		equivalent number of parameters.

   \c  s:		estimate of the scale of the residuals.

   \c  one_delta:	a statistical parameter used in the computation of standard errors.

   \c  two_delta:	a statistical parameter used in the computation of standard errors.

   \c  pseudovalues:	adjusted values of the response when robust estimation is used.

\c trace_hat:	trace of the operator hat matrix.

   \c  diagonal:	diagonal of the operator hat matrix.

   \c  robust:		robustness weights for robust fitting.

   \c  divisor:	normalization divisor for numeric predictors.
*/

    int     want_predict_ci; /**< If \c 'y' (the default), calculate the
                                confidence bands for predicted values */
    double  ci_level; /**< If running a prediction, the level at which
                        to calculate the confidence interval. default: 0.95 */
} apop_loess_settings;


    /** \cond doxy_ignore */
typedef struct point {    /* a point in the x,y plane */
  double x,y;             /* x and y coordinates */
  double ey;              /* exp(y-ymax+YCEIL) */
  double cum;             /* integral up to x of rejection envelope */
  int f;                  /* is y an evaluated point of log-density */
  struct point *pl,*pr;   /* envelope points to left and right of x */
} POINT;

/* This includes the envelope info and the metropolis steps. */
typedef struct {  /* attributes of the entire rejection envelope */
  int cpoint;              /* number of POINTs in current envelope */
  int npoint;              /* max number of POINTs allowed in envelope */
  double ymax;             /* the maximum y-value in the current envelope */
  POINT *p;                /* start of storage of envelope POINTs */
  double *convex;          /* adjustment for convexity */
  double metro_xprev;      /* previous Markov chain iterate */
  double metro_yprev;      /* current log density at xprev */
} arms_state;
    /** \endcond */

/** For use with \ref apop_arms_draw, to perform derivative-free adaptive rejection sampling with metropolis step. 

That function generates default values for this struct if you do not attach one to the
model beforehand, via a form like <tt>apop_model_add_group(your_model, apop_arms,
.model=your_model, .xl=8, .xr =14);</tt>. If you initialize it manually via \ref
apop_settings_add_group, the \c model element is mandatory; you'll get a run-time
complaint if you forget it.
*/
typedef struct {
    double *xinit;  /**< A <tt>double*</tt> giving starting values for x in ascending
                      order, e.g., <tt>(double *){1, 10, 100}</tt>.  . Default: -1,
                      0, 1. If this isn't \c NULL, I need at least three items, and
                      the length in \c ninit. */
    double  xl;     /**< Left bound. If you don't give me one, I'll use min[min(xinit)/10, min(xinit)*10].*/
    double  xr;     /**< Right bound. If you don't give me one, I'll use max[max(xinit)/10, max(xinit)*10]. */
    double convex;  /**< Adjustment for convexity */
    int ninit;      /**< The length of \c xinit.*/
    int npoint;     /**< Maximum number of envelope points. I \c malloc space for this many <tt>double</tt>s at the outset. Default = 1e5. */
   char do_metro;   /**< Set to \c 'y' if the metropolis step is required (i.e.,
                           if you're not sure if the function is log-concave).*/
   double xprev;    /**< For internal use; please ignore. Previous value from Markov chain. */
   int neval;       /**< On exit, the number of function evaluations performed */
   arms_state *state;
   apop_model *model; /**< The model from which to draw. Mandatory. Must have either a \c log_likelihood or \c p method.*/
} apop_arms_settings;


/** The settings to accompany the \ref apop_cross model, representing the cross product of two models (or, via recursion, a list of models of arbitrary length).*/
typedef struct {
    char *splitpage;    /**< The name of the page at which to split the data. If \c NULL, I send the entire data set to both models as needed. */
    apop_model *model1; /**< The first model in the stack.*/
    apop_model *model2; /**< The second model.*/
} apop_cross_settings;

typedef struct {
    apop_data *(*base_to_transformed)(apop_data*); /**< The function to transform the model from pre-transform space to post-transform space. */
    apop_data *(*transformed_to_base)(apop_data*); /**< The function to transform from post-transform space back to pre-transform space. If this function does not exist, using a Jacobian-based transformation is probably not mathematically correct. */
    double (*jacobian_to_base)(apop_data*); /**< The derivative of the \c transformed_to_base function. */
    apop_model *base_model;  /**< The pre-transformation model. */
} apop_coordinate_transform_settings;/**< Settings for an \ref apop_coordinate_transform model; see its documentation for notes and an example.
*/

/** For use with the \ref apop_dconstrain model. See its documentation for an example. 
*/
typedef struct {
    apop_model *base_model; /**< The model, before constraint. */
    double (*constraint)(apop_data *, apop_model *); /**< The constraint. Return 1 if the data is in the constraint; zero if out. */
    double (*scaling)(apop_model *); /**< Optional. Return the percent of the model density inside the constraint. */
    gsl_rng *rng; /**< If you don't provide a \c scaling function, I calculate the in-constraint model density via random draws.
                       If no \c rng is provided, I use a default RNG; see \ref apop_rng_get_thread. */
    double scale; /**< After the scaling has been calculated, store it here. If you change the parameters of your base model,
                       set this to zero to have the scaling recalculated. */
    gsl_vector *last_params; /**< The parameters used to calculate \c scale. If these change, recalculate. */
    int draw_ct; /**< How many draws to make for calculating the in-constraint model density via random draws. Current default: 1e4. */
    int refct; /**< For internal use. */
} apop_dconstrain_settings;

typedef struct {
    apop_model *generator_m;
    apop_model *ll_m;
    int draw_ct;
} apop_composition_settings;/**< All of the elements of this struct should be considered private.*/

/** For mixture distributions, typically set up using \ref apop_model_mixture. See
\ref apop_mixture for discussion. Please consider all elements but \c model_list and \c
weights as private and subject to change. See the examples for use of these elements.  
*/
typedef struct {
    gsl_vector *weights;     /**< The likelihood of a draw from each component. Default is equal likelihood
                              for each mixture element. Or set this to a weight vector of your choosing, or set
                              <tt>find_weights='y'</tt> and have <tt>apop_estimate</tt> find optimal weights. */
    apop_model **model_list; /**< A \c NULL-terminated list of component models. */
    int model_count;
    int *param_sizes;  /**< The number of parameters for each model. Useful for unpacking the params. */
    apop_model *cmf;   /**< For internal use by the draw method. */
    int *cmf_refct;    /**< For internal use, so I can garbage-collect the CMF when needed. */
    char find_weights; /**< By default, weights are fixed. Set this b \c 'y' to allow \ref apop_estimate to
                            use an EM algorithm to find the optimal weights.
                            See the documentation for \ref apop_mixture for details. */
    gsl_vector *next_weights; /**< For internal use.*/
} apop_mixture_settings;

    //Models built via call to apop_model_copy_set.

#define apop_model_dcompose(...) Apop_model_set_settings(apop_composition, __VA_ARGS__)
#define apop_model_dconstrain(...) Apop_model_set_settings(apop_dconstrain, __VA_ARGS__)
#define apop_model_coordinate_transform(...) Apop_model_set_settings(apop_coordinate_transform, __VA_ARGS__)

//Doxygen drops whatever is after these declarations, so I put them last.
Apop_settings_declarations(apop_lm)
Apop_settings_declarations(apop_pm)
Apop_settings_declarations(apop_pmf)
Apop_settings_declarations(apop_mle)
Apop_settings_declarations(apop_cdf)
Apop_settings_declarations(apop_arms)
Apop_settings_declarations(apop_mcmc)
Apop_settings_declarations(apop_loess)
Apop_settings_declarations(apop_cross)
Apop_settings_declarations(apop_mixture)
Apop_settings_declarations(apop_dconstrain)
Apop_settings_declarations(apop_composition)
Apop_settings_declarations(apop_parts_wanted)
Apop_settings_declarations(apop_kernel_density)
Apop_settings_declarations(apop_coordinate_transform)

#ifdef	__cplusplus
}
#endif

/** @} */ //End doxygen's all_public grouping

//Part of the intent of a convenience header like this is that you
//don't have to remember what else you're including. So here are 
//some other common GSL headers:
#include <math.h>
#include <gsl/gsl_sort.h>
#include <gsl/gsl_eigen.h>
#include <gsl/gsl_sort_vector.h>
#include <gsl/gsl_permutation.h>
#include <gsl/gsl_integration.h>


================================================
FILE: apop_arms.c
================================================
/** \file 
  adaptive rejection metropolis sampling */

/** (C) Wally Gilks; see documentation below for details.
  Adaptations for Apophenia (c) 2009 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */

#include "apop_internal.h"

#define XEPS  0.00001            /* critical relative x-value difference */
#define YEPS  0.1                /* critical y-value difference */
#define EYEPS 0.001              /* critical relative exp(y) difference */
#define YCEIL 50.                /* maximum y avoiding overflow in exp(y) */

/* declarations for functions defined in this file  (minus those in arms.h). */
void invert(double prob, arms_state *env, POINT *p);
int test(arms_state *state, POINT *p,  apop_arms_settings *params, gsl_rng *r);
int update(arms_state *state, POINT *p,  apop_arms_settings *params);
static void cumulate(arms_state *env);
int meet (POINT *q, arms_state *state, apop_arms_settings *params);
double area(POINT *q);
double expshift(double y, double y0);
double logshift(double y, double y0);
double perfunc(apop_arms_settings*, double x);
void display(FILE *f, arms_state *env, apop_arms_settings *);
int initial (apop_arms_settings* params, arms_state *state);

Apop_settings_copy(apop_arms,
    out->state = malloc(sizeof(arms_state));
    *out->state = *in->state;
)

Apop_settings_free(apop_arms,
    if (in->state){
        free(in->state->p);
        free(in->state);
	}
)

Apop_settings_init(apop_arms,
    if ((in.xl || in.xr) && !in.xinit)
        out->xinit = (double []) {in.xl+GSL_DBL_EPSILON, (in.xl+in.xr)/2., in.xr-GSL_DBL_EPSILON};
    else{
        //Apop_varad_set(xinit, ((double []) {0, 0.5, 1}));
        Apop_varad_set(xinit, ((double []) {-1, 0, 1}));
    }
    Apop_varad_set(ninit, 3);
    Apop_varad_set(xl, GSL_MIN(out->xinit[0]/10., out->xinit[0]*10)-.1);
    Apop_varad_set(xr, GSL_MAX(out->xinit[out->ninit-1]/10., out->xinit[out->ninit-1]*10)+.1);
    Apop_varad_set(convex, 0);
    Apop_varad_set(npoint, 100);
    Apop_varad_set(do_metro, 'y');
    Apop_varad_set(xprev, (out->xinit[0]+out->xinit[out->ninit-1])/2.);
    Apop_varad_set(neval, 1000);
    Apop_assert(out->model, "the model input (e.g.: .model = parent_model) is mandatory.");

  // allocate the state 
    out->state = malloc(sizeof(arms_state));
    Apop_assert(out->state, "Malloc failed. Out of memory?");
    *out->state = (arms_state) { };
    int err = initial(out, out->state);
    Apop_assert_c(!err, NULL, 0, "init failed, error %i. Returning NULL", err);

  /* finish setting up metropolis struct (can only do this after setting up env) */
    if(out->do_metro=='y'){
        /* I don't understand why this is needed.
          if((params->xprev < params->xl) || (params->xprev > params->xr))
            apop_assert(0, 1007, 0, 's', "previous Markov chain iterate out of range")*/
        out->state->metro_xprev = out->xprev;
        out->state->metro_yprev = perfunc(out,out->xprev);
        assert(isfinite(out->state->metro_xprev));
        assert(isfinite(out->state->metro_yprev));
    }
)

void distract_doxygen_arms(){/*Doxygen gets thrown by the settings macros. This decoy function is a workaround. */}

/** Adaptive rejection Metropolis sampling, to make random draws from a univariate distribution.

The author, Wally Gilks, explains on 
http://www.amsta.leeds.ac.uk/~wally.gilks/adaptive.rejection/web_page/Welcome.html , that
``ARS works by constructing an envelope function of the log of the target density, which is then used in rejection sampling (see, for example,  Ripley, 1987). Whenever a point is rejected by ARS, the envelope is updated to correspond more closely to the true log density, thereby reducing the chance of rejecting subsequent points. Fewer ARS rejection steps implies fewer point-evaluations of the log density.''

\li It accepts only functions with univariate inputs. I.e., it will put a single value into a 1x1 \ref apop_data set, and then evaluate the log likelihood at that point. For multivariate situations, see \ref apop_model_metropolis.

\li It is currently the default for the \ref apop_draw function given a univariate model, so you can just call that if you prefer.

\li There are a great number of parameters, in the \c apop_arms_settings structure.  The structure also holds a history of the points tested to date. That means that the system will be more accurate as more draws are made. It also means that if the parameters change, or you use \ref apop_model_copy, you should call <tt>Apop_settings_rm_group(your_model, apop_arms)</tt> to clear the model of points that are not valid for a different situation.
  */
int apop_arms_draw (double *out, gsl_rng *r, apop_model *m){
    apop_arms_settings *params = Apop_settings_get_group(m, apop_arms);
    if (!params) params = Apop_model_add_group(m, apop_arms, .model=m);
  POINT pwork;        /* a working point, not yet incorporated in envelope */
  int msamp=0;        /* the number of x-values currently sampled */
  arms_state *state = params->state; 
  /* now do adaptive rejection */
  do {
    // Sample a new point from piecewise exponential envelope 
    double prob = gsl_rng_uniform(r);
    /* get x-value correponding to a cumulative probability prob */
    assert(isfinite(state->p->x));
    assert(isfinite(state->p->y));
    invert(prob,state,&pwork);

    /* perform rejection (and perhaps metropolis) tests */
    int i = test(state,&pwork, params, r);
    if (i == 1){ // point accepted 
        Apop_notify(3, " point accepted.");
        *out = pwork.x;
        assert(isfinite(pwork.x));
        return 0;
    } else 
      Apop_stopif(i!=0, return 1,-5, "envelope error - violation without metropolis");
    msamp ++;
    Apop_notify(3, " point rejected.");
  } while (msamp < 1e3);
  Apop_notify(1, "I just rejected 1,000 samples. Something is wrong.");
  return 0;
}

int initial (apop_arms_settings* params,  arms_state *env){
// to set up initial envelope

  POINT *q;
  int mpoint = 2*params->ninit + 1;

  Apop_assert_c(params->ninit>=3, 1001, 0, "too few initial points");
  Apop_assert_c(params->npoint >= mpoint, 1002, 0, "too many initial points");
  Apop_assert_c((params->xinit[0] >= params->xl) && (params->xinit[params->ninit-1] <= params->xr),
                     1003, 0, "initial points do not satisfy bounds");
  for(int i=1; i<params->ninit; i++)
      Apop_assert_c(params->xinit[i] > params->xinit[i-1], 1004, 0, "data not ordered");
  Apop_assert_c(params->convex >= 0.0, 1008, 0, "negative convexity parameter");

  env->convex = &params->convex; // copy convexity address to env
  params->neval = 0; // initialise current number of function evaluations

  /* set up space for envelope POINTs */
  env->npoint = params->npoint;
  env->p = malloc(params->npoint*sizeof(POINT));
  Apop_assert(env->p, "malloc of env->p failed. Out of space?");

  /* set up envelope POINTs */
  q = env->p;
  q->x = params->xl; // left bound
  q->f = 0;
  q->pl = NULL;
  q->pr = q+1;
  for(int j=1, k=0; j<mpoint-1; j++){
    q++;
    if(j%2){
        /* point on log density */
        q->x = params->xinit[k++];
        q->y = perfunc(params,q->x);
        Apop_assert(isfinite(q->x), "the initial param is %g", q->x);
        Apop_assert(isfinite(q->y), "f(an initial parameter)= %g", q->y);
        q->f = 1;
    } else // intersection point
        q->f = 0;
    q->pl = q-1;
    q->pr = q+1;
  }
  /* right bound */
  q++;
  q->x = params->xr;
  q->f = 0;
  q->pl = q-1;
  q->pr = NULL;

  assert(isfinite(q->x));
  /* calculate intersection points */
  q = env->p;
  for (int j=0; j<mpoint; j=j+2, q=q+2)
    Apop_assert_c(!meet(q,env, params), 2000, 0, "envelope violation without metropolis");

  cumulate(env); // exponentiate and integrate envelope
  env->cpoint = mpoint; // note number of POINTs currently in envelope
  return 0;
}

void invert(double prob, arms_state *env, POINT *p){
/* to obtain a point corresponding to a given cumulative probability   
   prob    : cumulative probability under envelope   
   *env    : envelope attributes   
   *p      : a working POINT to hold the sampled value */

  double u,xl=0,xr=0,yl,yr,eyl,eyr,prop;

  /* find rightmost point in envelope */
  POINT *q = env->p;
  while(q->pr != NULL)q = q->pr;

  /* find exponential piece containing point implied by prob */
  u = prob * q->cum;
  while(q->pl->cum > u)q = q->pl;

  /* piece found: set left and right POINTs of p, etc. */
  p->pl = q->pl;
  p->pr = q;
  p->f = 0;
  p->cum = u;

  /* calculate proportion of way through integral within this piece */
  prop = (u - q->pl->cum) / (q->cum - q->pl->cum);

  /* get the required x-value */
  if (q->pl->x == q->x){
    /* interval is of zero length */
    p->x = q->x;
    p->y = q->y;
    p->ey = q->ey;
  } else {
    xl = q->pl->x;
    xr = q->x;
    yl = q->pl->y;
    yr = q->y;
    eyl = q->pl->ey;
    eyr = q->ey;
    if(fabs(yr - yl) < YEPS){
      /* linear approximation was used in integration in function cumulate */
      if(fabs(eyr - eyl) > EYEPS*fabs(eyr + eyl))
        p->x = xl + ((xr - xl)/(eyr - eyl)) * (-eyl + sqrt((1. - prop)*eyl*eyl + prop*eyr*eyr));
      else 
        p->x = xl + (xr - xl)*prop;
      p->ey = ((p->x - xl)/(xr - xl)) * (eyr - eyl) + eyl;
      p->y = logshift(p->ey, env->ymax);
    } else {
      /* piece was integrated exactly in function cumulate */
      p->x = xl + ((xr - xl)/(yr - yl))
	      * (-yl + logshift(((1.-prop)*eyl + prop*eyr), env->ymax));
      p->y = ((p->x - xl)/(xr - xl)) * (yr - yl) + yl;
      p->ey = expshift(p->y, env->ymax);
    }
  }
  assert(isfinite(p->x));
  assert(isfinite(p->y));
  assert(isfinite(q->x));
  assert(isfinite(q->y));

  /* guard against imprecision yielding point outside interval */
  Apop_stopif( ((p->x < xl) || (p->x > xr)), return,-5, "imprecision yields point outside interval");
}

int test(arms_state *env, POINT *p, apop_arms_settings *params, gsl_rng *r){
/* to perform rejection, squeezing, and metropolis tests   
   *env        : state data
   *p            : point to be tested   */
assert(p->pl && p->pr);

  double u,y,ysqueez,ynew,yold,znew,zold,w;
  POINT *ql,*qr;
  
  /* for rejection test */
  u = gsl_rng_uniform(r) * p->ey;
  y = logshift(u,env->ymax);

  if(params->do_metro !='y' && (p->pl->pl != NULL) && (p->pr->pr != NULL)){
    /* perform squeezing test */
    ql = p->pl->f ? p->pl : p->pl->pl;
    qr = p->pr->f ? p->pr : p->pr->pr;
    ysqueez = (qr->y * (p->x - ql->x) + ql->y * (qr->x - p->x))
               /(qr->x - ql->x);
    if(y <= ysqueez) // accept point at squeezing step
        return 1;
  }

  /* evaluate log density at point to be tested */
  ynew = perfunc(params,p->x);
assert(isfinite(p->x));
assert(p->pl && p->pr);
Apop_notify(3, "tested (%g, %g); ", p->x, ynew);
  
  /* perform rejection test */
  if(params->do_metro != 'y' || (params->do_metro == 'y' && (y >= ynew))){
    /* update envelope */
    p->y = ynew;
    p->ey = expshift(p->y,env->ymax);
    p->f = 1;
    if(update(env,p, params)) 
        Apop_assert_c(0, -1, 0, "envelope violation without metropolis");
    /* perform rejection test: accept iff y < ynew */
    return (y < ynew);
  }

  /* continue with metropolis step */
  yold = env->metro_yprev;
  /* find envelope piece containing metrop->xprev */
  ql = env->p;
  while(ql->pl != NULL) ql = ql->pl;
  while(ql->pr->x < env->metro_xprev) ql = ql->pr;
  qr = ql->pr;
  /* calculate height of envelope at metrop->xprev */
  w = (env->metro_xprev - ql->x)/(qr->x - ql->x);
  zold = ql->y + w*(qr->y - ql->y);
  znew = p->y;
  if(yold < zold)zold = yold;
  if(ynew < znew)znew = ynew;
  w = ynew-znew-yold+zold;
  w = GSL_MIN(w, 0.0);
  w = (w > -YCEIL) ?  exp(w) : 0.0;
  u = gsl_rng_uniform(r);
  if(u > w){
      /* metropolis says don't move, so replace current point with previous */
      /* markov chain iterate */
      p->x = env->metro_xprev;
      p->y = env->metro_yprev;
      Apop_notify(3, "metro step (%g) rejected with w=%g, "
                "ynew=%g, yold=%g, znew = %g, zold=%g; ", p->x, w, ynew, yold, znew, zold);
      p->ey = expshift(p->y,env->ymax);
assert(isfinite(p->x));
assert(isfinite(p->y));
assert(isfinite(p->ey));
      p->f = 1;
      p->pl = ql;
      p->pr = qr;
  } else {
      /* trial point accepted by metropolis, so update previous markov */
      /* chain iterate */
      env->metro_xprev = p->x;
      env->metro_yprev = ynew;
  }
  return 1;
}

int update(arms_state *env, POINT *p, apop_arms_settings *params){
/* to update envelope to incorporate new point on log density
   *env          : state information
   *p            : point to be incorporated 
*/

  POINT *m,*ql,*qr,*q;

  if(!(p->f) || (env->cpoint > env->npoint - 2))
    /* y-value has not been evaluated or no room for further points */
    return 0; // ignore this point

  /* copy working POINT p to a new POINT q */
  q = env->p + env->cpoint++;
  q->x = p->x;
  q->y = p->y;
  q->f = 1;

  /* allocate an unused POINT for a new intersection */
  m = env->p + env->cpoint++;
  m->f = 0;
  if((p->pl->f) && !(p->pr->f)){
    /* left end of piece is on log density; right end is not */
    /* set up new intersection in interval between p->pl and p */
    m->pl = p->pl;
    m->pr = q;
    q->pl = m;
    q->pr = p->pr;
    m->pl->pr = m;
    q->pr->pl = q;
  } else if (!(p->pl->f) && (p->pr->f)){
    /* left end of interval is not on log density; right end is */
    /* set up new intersection in interval between p and p->pr */
    m->pr = p->pr;
    m->pl = q;
    q->pr = m;
    q->pl = p->pl;
    m->pr->pl = m;
    q->pl->pr = q;
  } else
    Apop_stopif(1, return 1,-5, "unexpected event"); // this should be impossible

  /* now adjust position of q within interval if too close to an endpoint */
  ql = q->pl->pl ? q->pl->pl : q->pl;
  qr = q->pr->pr ? q->pr->pr : q->pr;
  if (q->x < (1. - XEPS) * ql->x + XEPS * qr->x){
    /* q too close to left end of interval */
    q->x = (1. - XEPS) * ql->x + XEPS * qr->x;
    q->y = perfunc(params,q->x);
  } else if (q->x > XEPS * ql->x + (1. - XEPS) * qr->x){
    /* q too close to right end of interval */
    q->x = XEPS * ql->x + (1. - XEPS) * qr->x;
    q->y = perfunc(params,q->x);
  }

  /* revise intersection points */
  if(meet(q->pl,env, params) /* envelope violations without metropolis */
        || meet(q->pr,env, params) 
        || (q->pl->pl != NULL && meet(q->pl->pl->pl,env, params))
        || (q->pr->pr != NULL && meet(q->pr->pr->pr,env, params)))
     return 1;

  /* exponentiate and integrate new envelope */
  cumulate(env);
  return 0;
}

static void cumulate(arms_state *env){
/* to exponentiate and integrate envelope */
/* *env     : envelope attributes */

  POINT *q,*qlmost;

  qlmost = env->p;
  /* find left end of envelope */
  while(qlmost->pl) qlmost = qlmost->pl;

  /* find maximum y-value: search envelope */
  env->ymax = qlmost->y;
  for(q = qlmost->pr; q != NULL; q = q->pr)
    if(q->y > env->ymax)
        env->ymax = q->y;

  /* exponentiate envelope */
  for(q = qlmost; q != NULL; q = q->pr)
      q->ey = expshift(q->y,env->ymax);

  /* integrate exponentiated envelope */
  qlmost->cum = 0.;
  for(q = qlmost->pr; q != NULL; q = q->pr)
      q->cum = q->pl->cum + area(q);
}

int meet (POINT *q, arms_state *env, apop_arms_settings *params){ 
/* To find where two chords intersect 
   q         : to store point of intersection 
   *env      : state attributes 
*/
  double gl=0,gr=0,grl=0,dl=0,dr=0;
  int il=0,ir=0,irl=0;

  Apop_assert(!(q->f), "error 30: this is not an intersection point.");

  /* calculate coordinates of point of intersection */
  if ((q->pl != NULL) && (q->pl->pl->pl != NULL)){
      /* chord gradient can be calculated at left end of interval */
      gl = (q->pl->y - q->pl->pl->pl->y)/(q->pl->x - q->pl->pl->pl->x);
      il = 1;
  } else // no chord gradient on left 
      il = 0;

  if ((q->pr != NULL) && (q->pr->pr->pr != NULL)){
      /* chord gradient can be calculated at right end of interval */
      gr = (q->pr->y - q->pr->pr->pr->y)/(q->pr->x - q->pr->pr->pr->x);
      ir = 1;
  } else // no chord gradient on right
      ir = 0;

  if ((q->pl != NULL) && (q->pr != NULL)){
      /* chord gradient can be calculated across interval */
      grl = (q->pr->y - q->pl->y)/(q->pr->x - q->pl->x);
      irl = 1;
  } else 
      irl = 0;

  if(irl && il && (gl<grl)){
    /* convexity on left exceeds current threshold */
    if(params->do_metro !='y') // envelope violation without metropolis
        return 1;
    gl = gl + (1.0 + *(env->convex)) * (grl - gl); // adjust left gradient 
  }

  if(irl && ir && (gr>grl)){
    /* convexity on right exceeds current threshold */
    if(params->do_metro !='y') // envelope violation without metropolis 
        return 1;
    gr = gr + (1.0 + *(env->convex)) * (grl - gr); // adjust right gradient 
  }

  if(il && irl){
    dr = (gl - grl) * (q->pr->x - q->pl->x);
    if(dr < YEPS) // adjust dr to avoid numerical problems
      dr = YEPS;
  }

  if(ir && irl){
    dl = (grl - gr) * (q->pr->x - q->pl->x);
    if(dl < YEPS) // adjust dl to avoid numerical problems 
      dl = YEPS;
  }

  if(il && ir && irl){
    /* gradients on both sides */
    q->x = (dl * q->pr->x + dr * q->pl->x)/(dl + dr);
    q->y = (dl * q->pr->y + dr * q->pl->y + dl * dr)/(dl + dr);
  } else if (il && irl){
    /* gradient only on left side, but not right hand bound */
    q->x = q->pr->x;
    q->y = q->pr->y + dr;
  } else if (ir && irl){
    /* gradient only on right side, but not left hand bound */
    q->x = q->pl->x;
    q->y = q->pl->y + dl;
  } else if (il)
    q->y = q->pl->y + gl * (q->x - q->pl->x); // right hand bound 
  else if (ir)
    q->y = q->pr->y - gr * (q->pr->x - q->x); // left hand bound 
  else 
     Apop_assert(0, "error 31: gradient on neither side - should be impossible.");
  if(((q->pl != NULL) && (q->x < q->pl->x)) ||
     ((q->pr != NULL) && (q->x > q->pr->x))){
     Apop_assert(0, "error 32: intersection point outside interval (through imprecision)");
  }
  return 0; // successful exit : intersection has been calculated
}

double area(POINT *q){
/* To integrate piece of exponentiated envelope to left of POINT q */ 

  if(q->pl == NULL) // this is leftmost point in envelope
      Apop_stopif(1, return GSL_NAN,-5, "leftmost point in envelope");
  if(q->pl->x == q->x) // interval is zero length
      return 0.;
  if (fabs(q->y - q->pl->y) < YEPS) // integrate straight line piece
      return 0.5*(q->ey + q->pl->ey)*(q->x - q->pl->x);
  // integrate exponential piece 
  return ((q->ey - q->pl->ey)/(q->y - q->pl->y))*(q->x - q->pl->x);
}

double expshift(double y, double y0) {
/* to exponentiate shifted y without underflow */
  if (y - y0 > -2.0 * YCEIL)
      return exp(y - y0 + YCEIL);
  else
      return 0.0;
}

double logshift(double y, double y0){
/* inverse of function expshift */
  return (log(y) + y0 - YCEIL);
}

double perfunc(apop_arms_settings *params, double x){
// to evaluate log density and increment count of evaluations 
    Staticdef( apop_data *, d , apop_data_alloc(1,1));
    d->matrix->data[0] = x;
  double y = apop_log_likelihood(d, params->model);
  Apop_assert(isfinite(y), "Evaluating the log likelihood at %g returned %g.", x, y);
  (params->neval)++; // increment count of function evaluations
  return y;
}


================================================
FILE: apop_asst.m4.c
================================================
/** \file apop_asst.c  The odds and ends bin. 
Copyright (c) 2005--2007, 2010 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */

#include "apop_internal.h"
#include <gsl/gsl_math.h>
#include <gsl/gsl_randist.h>
#include <regex.h>
#ifdef _OPENMP
    #include <omp.h>
    #define omp_threadnum omp_get_thread_num()
#else
    #define omp_threadnum 0

#endif

extern char *apop_nul_string;

//more efficient than xprintf, but a little less versatile.
static void apop_tack_on(char **in, char *addme){
    if (!addme) return;
    size_t inlen = *in? strlen(*in): 0;
    size_t total_len= inlen + strlen(addme);
    *in = realloc(*in, total_len+1);
    strcpy(*in+inlen, addme);
}

typedef int (*apop_fn_riip)(apop_data*, int, int, void*);

/** Join together the \c text grid of an \ref apop_data set into a single string.

For example, say that we have a data set with some text: row 0 has
\c "a0", \c "b0", \c "c0"; row 2 has 
\c "a1", \c "b1", \c "c1"; and so on. We would like to produce

\code
insert into tab values ('a0', 'b0', 'c0');
insert into tab values ('a1', 'b1', 'c1');
...
\endcode

This could be sent to an SQL engine to copy the data to a database (but this is just an example
for demonstration---use \ref apop_data_print to write to a database table).

To construct this single string from the text grid, we would need to add:
\li before the text, <tt>Insert into tab values ('</tt>.
\li between each element on a row: <tt>', '</tt>
\li between rows: <tt>'); \\ninsert into tab values('</tt>
\li at the tail end: <tt>');'

Thus, do the conversion via:
\code
char *insert_string = apop_text_paste(indata,
    .before="Insert into tab values ('",
    .between="', '",
    .between_cols="'); \\ninsert into tab values(',
    .after="');'"
);
\endcode


\param strings  An \ref apop_data set with a grid of text to be combined into a single string
\param between  The text to put in between the rows of the table, such as ", ". (Default is a single space: " ")
\param before   The text to put at the head of the string. For the query example, this would be <tt>.before="select "</tt>. (Default: NULL)
\param after   The text to put at the tail of the string. For the query example, <tt>.after=" from data_table"</tt>. (Default: NULL)
\param between_cols The text to insert between columns of text. See below for an example (Default is set to equal <tt>.between</tt>)
\param prune If you don't want to use the entire text set, you can provide a function to indicate which elements should be pruned out. Some examples:
\code
//Just use column 3
int is_not_col_3(apop_data *indata, int row, int col, void *ignore){
    return col!=3;
}

//Jump over blanks as if they don't exist.
int is_blank(apop_data *indata, int row, int col, void *ignore){
    return strlen(indata->text[row][col])==0;
}
\endcode
\param prune_parameter A void pointer to pass to your \c prune function.

\return A single string with the elements of the \c strings table joined as per your
specification. Allocated by the function, to be freed by you if desired.

  \li If the table of strings is \c NULL or has no text, the output string will have
only the <tt>.before</tt> and <tt>.after</tt> parts with nothing in between.
  \li if <tt> apop_opts.verbose >=3</tt>, then print the pasted text to stderr.
  \li It is sometimes useful to use \c Apop_r and \c Apop_rs to get a view of only
one or a few rows in conjunction with this function.

  \li This function uses the \ref designated syntax for inputs.

This sample snippet generates the SQL for a query using a list of column names (where
the query begins with <tt>select </tt>, ends with <tt>from datatab</tt>, and has commas
in between each element), re-processes the same list to produce the head of an HTML
table, then produces the body of the table with the query result.

\include sql_to_html.c
*/
APOP_VAR_HEAD char *apop_text_paste(apop_data const *strings, char *between, char *before, char *after, char *between_cols, apop_fn_riip prune, void *prune_parameter){
    apop_data const *apop_varad_var(strings, NULL);
    char *apop_varad_var(between, " ");
    char *apop_varad_var(before, NULL);
    char *apop_varad_var(after, NULL);
    char *apop_varad_var(between_cols, between);
    apop_fn_riip apop_varad_var(prune, NULL);
    void *apop_varad_var(prune_parameter, NULL);
APOP_VAR_ENDHEAD
    char *prior_line=NULL, *oneline=NULL, *out = before ? strdup(before) : NULL;
    for (int i=0; i< ((!strings || !*strings->textsize)? 0 : *strings->textsize); i++){
        free(oneline); oneline = NULL;
        for (int j=0; j< strings->textsize[1]; j++){
            if (prune && !prune((apop_data*)strings, i, j, prune_parameter)) continue;
            apop_tack_on(&oneline, strings->text[i][j]);
            if (j <strings->textsize[1]-1)  apop_tack_on(&oneline, between_cols);
        }
        apop_tack_on(&out, prior_line);
        if (prior_line && oneline) apop_tack_on(&out, between);
        free(prior_line);
        prior_line=oneline ? strdup(oneline): NULL;
        //if (i <strings->textsize[0]-1)  apop_tack_on(&out, between);
        //if (oneline)  apop_tack_on(&out, oneline);
    }
    apop_tack_on(&out, oneline); //the final one never got a chance to be prior_line
    apop_tack_on(&out, after);
    Apop_notify(3, "%s", out);
    return out;
}

/** Calculate \f$\sum_{n=1}^N {1\over n^s}\f$

\li There are no doubt efficient shortcuts do doing this, but I use brute force. [Though Knuth's Art of Programming v1 doesn't offer anything, which is strong indication of nonexistence.] To speed things along, I save the results so that they can just be looked up should you request the same calculation. 

\li If \c N is zero or negative, return NaN. Notify the user if <tt>apop_opts.verbosity >=0</tt>

For example: 

\include test_harmonic.c
*/
long double apop_generalized_harmonic(int N, double s){
/* 
Each row in the saved-results structure is an \f$s\f$, and each column is \f$1\dots n\f$, up to the largest \f$n\f$ calculated to date.

When reading the code, remember that the zeroth element holds the value for N=1, and so on.
*/
    Apop_stopif(N<=0, return GSL_NAN, 0, "N is %i, but must be greater than 0.", N);
    static double *  eses	= NULL;
    static int * 	 lengths= NULL;
    static int		 count	= 0;
    static long double ** precalced=NULL;
    int	old_len, i;
    OMP_critical(generalized_harmonic)
    { //Due to memoization, this can't parallelize.
	for (i=0; i< count; i++)
		if (eses == NULL || eses[i] == s) 	
            break;
	if (i == count){	//you need to build the vector from scratch.
		count			++;
        i               = count - 1;
		precalced 		= realloc(precalced, sizeof (long double*) * count);
		lengths 		= realloc(lengths, sizeof (int*) * count);
		eses 			= realloc(eses, sizeof (double) * count);
		precalced[i]	= malloc(sizeof(long double) * N);
		lengths[i]	    = N;
		eses[i]		    = s;
		precalced[i][0]	= 1;
		old_len			= 1;
	}
	else {	//then you found it.
		old_len = lengths[i];
	}
	if (N-1 >= old_len){	//It's there, but you need to extend what you have.
		precalced[i] = realloc(precalced[i], sizeof(long double) * N);
		for (int j = old_len; j<N; j++)
			precalced[i][j] = precalced[i][j-1] + 1/pow((j+1),s);
	}
    }
	return 	precalced[i][N-1];
}

/** Call \c system(), but with <tt>printf</tt>-style arguments. E.g.,
  
\code
char filenames[] = "apop_asst.c apop_asst.o"
apop_system("ls -l %s", filenames);
\endcode

\return The return value of the \c system() call.
 */
int apop_system(const char *fmt, ...){
    char *q;
    va_list argp;
	va_start(argp, fmt);
	Apop_stopif(vasprintf(&q, fmt, argp)==-1,  return -1, 0, "Trouble writing to a string.");
	va_end(argp);
    int out = system(q);
    free(q);
    return out;
}

static int count_parens(const char *string){
    int out = 0;
    int last_was_backslash = 0;
    for(const char *step =string; *step !='\0'; step++){
        if (*step == '\\' && !last_was_backslash){
            last_was_backslash = 1;
            continue;
        }
        if (*step == ')' && !last_was_backslash)
            out++;
        last_was_backslash = 0;
    }
    return out;
}

/** Extract subsets from a string via regular expressions.

This function takes a regular expression and repeatedly applies it to an input string. It returns the count of matches, and optionally returns the matches themselves organized into the \c text grid of an \ref apop_data set.

\li There are three common flavors of regular expression: Basic, Extended,
and Perl-compatible (BRE, ERE, PCRE). I use EREs, as per the specs of
your C library, which should match POSIX's ERE specification. 

For example, "p.val" will match "P value", "p.value", "p values" (and even "tempeval", so be
careful).

If you give a non-\c NULL address in which to place a table of paren-delimited substrings, I'll return them as a row in the text element of the returned \ref apop_data set. I'll return <em>all</em> the matches, filling the first row with substrings from the first application of your regex, then filling the next row with another set of matches (if any), and so on to the end of the string. Useful when parsing a list of items, for example.


\param string        The string to search (no default)
\param regex       The regular expression (no default)
\param substrings   Parens in the regex indicate that I should return matching substrings. Give me the _address_ of an \ref apop_data* set, and I will allocate and fill the text portion with matches. Default= \c NULL, meaning do not return substrings (even if parens exist in the regex). If no match, return an empty \ref apop_data set, so <tt>output->textsize[0]==0</tt>.
\param use_case         Should I be case sensitive, \c 'y' or \c 'n'? (default = \c 'n', which is not the POSIX default.)

\return         Count of matches found. 0 == no match. \c substrings may be allocated and filled if needed.

\li If <tt>apop_opts.stop_on_warning='n'</tt> returns -1 on error (e.g., regex \c NULL or didn't compile).
\li If <tt>strings==NULL</tt>, I return 0---no match---and if \c substrings is provided, set it to \c NULL.

\li Here is the test function. Notice that the substring-pulling
function call passes \c &subs, not plain \c subs. 


\include test_regex.c

\li Each set of matches will be one row of the output data. E.g., given the regex <tt>([A-Za-z])([0-9])</tt>, the column zero of <tt>outdata</tt> will hold letters, and column one will hold numbers.
Use \ref apop_data_transpose to reverse this so that the letters are in <tt>outdata->text[0]</tt> and numbers in <tt>outdata->text[1]</tt>.
*/
APOP_VAR_HEAD int  apop_regex(const char *string, const char* regex, apop_data **substrings, const char use_case){
    const char * apop_varad_var(string, NULL);
    apop_data **apop_varad_var(substrings, NULL);
    if (!string) {
        if (substrings) *substrings=NULL;
        return 0;
    }
    const char * apop_varad_var(regex, NULL);
    Apop_stopif(!regex, return -1, 0, "You gave me a NULL regex.");
    const char apop_varad_var(use_case, 'n');
APOP_VAR_ENDHEAD
    regex_t re;
    int matchcount=count_parens(regex);
    int found, found_ct=0;
    regmatch_t result[matchcount+1];
    int compiled_ok = !regcomp(&re, regex, REG_EXTENDED 
                                            + (use_case=='y' ? 0 : REG_ICASE)
                                            + (substrings ? 0 : REG_NOSUB) );
    Apop_stopif(!compiled_ok, return -1, 0, "This regular expression didn't compile: \"%s\"", regex);

    int matchrow = 0;
    if (substrings) *substrings = apop_data_alloc();
    do {
        found_ct+=
        found    = !regexec(&re, string, matchcount+1, result, matchrow ? REG_NOTBOL : 0);
        if (substrings && found){
            *substrings = apop_text_alloc(*substrings, matchrow+1, matchcount);
            //match zero is the whole string; ignore.
            for (int i=0; i< matchcount; i++){
                if (result[i+1].rm_eo > 0){//GNU peculiarity: match-to-empty marked with -1.
                    int length_of_match = result[i+1].rm_eo - result[i+1].rm_so;
                    if ((*substrings)->text[matchrow][i] != apop_nul_string) free((*substrings)->text[matchrow][i]);
                    (*substrings)->text[matchrow][i] = malloc(strlen(string)+1);
                    memcpy((*substrings)->text[matchrow][i], string + result[i+1].rm_so, length_of_match);
                    (*substrings)->text[matchrow][i][length_of_match] = '\0';
                } //else matches nothing; apop_text_alloc already made this cell this NULL.
            }
            string += result[0].rm_eo; //end of whole match;
            matchrow++;
        }
    } while (substrings && found && string[0]!='\0');
    regfree(&re);
    return found_ct;
}

/** RNG from a Generalized Hypergeometric type B3.

Devroye uses this as the base for many of his distribution-generators, including the Waring.

\li If one of the inputs is <=0, error; return NaN and print a warning.
*/  //Header in stats.h
double apop_rng_GHgB3(gsl_rng * r, double* a){
    Apop_stopif(!((a[0]>0) && (a[1] > 0) && (a[2] > 0)), return NAN, 0, "all inputs must be positive.");
    double aa = gsl_ran_gamma(r, a[0], 1),
		   b  = gsl_ran_gamma(r, a[1], 1),
		   c  = gsl_ran_gamma(r, a[2], 1);
    int	p = gsl_ran_poisson(r, aa*b/c);
	return p;
}

/** The Beta distribution is useful for modeling because it is bounded between zero and one, and can be either unimodal (if the variance is low) or bimodal (if the variance is high), and can have either a slant toward the bottom or top of the range (depending on the mean).

The distribution has two parameters, typically named \f$\alpha\f$ and \f$\beta\f$, which can be difficult to interpret. However, there is a one-to-one mapping between (alpha, beta) pairs and (mean, variance) pairs. Since we have good intuition about the meaning of means and variances, this function takes in a mean and variance, calculates alpha and beta behind the scenes, and returns the appropriate Beta distribution.

\param m
The mean the Beta distribution should have. Notice that m
is in [0,1].

\param v
The variance which the Beta distribution should have. It is in (0, 1/12), where (1/12) is the variance of a Uniform(0,1) distribution. Funny things happen with variance near 1/12 and mean far from 1/2.

\return Returns an \ref apop_model produced by copying the \c apop_beta model and
setting its parameters appropriately.

\exception out->error=='r' Range error: mean is not within [0, 1].
*/
apop_model *apop_beta_from_mean_var(double m, double v){
    Apop_stopif(m>=1|| m<=0, apop_model *out = apop_model_copy(apop_beta);
                        out->error='r'; return out,
                       0, "You asked for a beta distribution "
                        "with mean %g, but the mean of the beta will always "
                        "be strictly between zero and one.", m);
    double k     = (m * (1- m)/ v) -1;
    double alpha = m*k;
    double beta  = k * (1-m);
    return apop_model_set_parameters(apop_beta, alpha, beta);
}

/** \def apop_rng_get_thread
The \c gsl_rng is not itself thread-safe, in the sense that it can not be used
simultaneously by multiple threads. However, if each thread has its own \c gsl_rng,
then each will safely operate independently.

Thus, Apophenia keeps an internal store of RNGs for use by threaded functions. If the
input to this function, \c thread, is greater than any previous input, then the array
of <tt>gsl_rng</tt>s is extended to length \c thread, and each element extended using
<tt>++apop_opts.rng_seed</tt> (i.e., the seed is incremented before use).

This function can be used anywhere a \c gsl_rng would be used.

\param thread_in The number of the RNG to retrieve, starting at zero (which is
how OpenMP numbers its threads). If -1, I'll look up the current thread (via \c
omp_get_thread_num) for you.

See \ref threading for additional notes. In most cases, you want to use <tt>apop_rng_get_thread(-1)</tt>.

\return The appropriate RNG, initialized if necessary.
\hideinitializer
*/
gsl_rng *apop_rng_get_thread_base(int thread){
    static gsl_rng **rngs;
    static int rng_ct = -1;

    if (thread==-1){
        #ifdef OpenMP
            thread = omp_get_thread_num();
        #else
            thread = 0;
        #endif
    }

    OMP_critical(rng_get_thread)
    if (thread > rng_ct)
        {
            rngs = realloc(rngs, sizeof(gsl_rng*)*(thread+1));
            for (int i=rng_ct+1; i<= thread; i++)
                rngs[i] = apop_rng_alloc(++apop_opts.rng_seed);
            rng_ct = thread;
        }
    return rngs[thread];
}

/** Make a set of random draws from a model and write them to an \ref apop_data set.

\param model The model from which draws will be made. Must already be prepared and/or estimated.

\param count The number of draws to make. If \c draw_matrix is not \c NULL, then this is ignored and <tt>count=draw_matrix->matrix->size1</tt>. default=1000.

\param draws If not \c NULL, a pre-allocated data set whose \c matrix element will be filled with draws. 

\return An \ref apop_data set with the matrix filled with \c size draws. If <tt>draw_matrix!=NULL</tt>, then return a pointer to it.

\exception out->error=='m' Input model isn't good for making draws: it is \c NULL, or <tt>m->dsize=0</tt>.

\exception out->error=='s' You gave me a \c draws matrix, but its size is less than the size of a single draw from the data, <tt>model->dsize</tt>.

\exception out->error=='d' Trouble drawing from the distribution for at least one row. That row is set to all \c NAN.

\li Prints a warning if you send in a non-<tt>NULL apop_data</tt> set, but its \c matrix element is \c NULL, when <tt>apop_opts.verbose>=1</tt>.
\li See also \ref apop_draw, which makes a single draw.
\li Random numbers are generated using RNGs from \ref apop_rng_get_thread, qv.

Here is a two-line program to draw a different set of ten Standard Normals on every run (provided runs are more than a second apart):

\include draw_some_normals.c

\li This function uses the \ref designated syntax for inputs.
*/
APOP_VAR_HEAD apop_data *apop_model_draws(apop_model *model, int count, apop_data *draws){
    apop_model * apop_varad_var(model, NULL);
    Apop_stopif(!model, apop_return_data_error(n), 0, "Input model is NULL.");
    Apop_stopif(!model->dsize, apop_return_data_error(n), 0, "Input model has dsize==0.");
    apop_data * apop_varad_var(draws, NULL);
    int apop_varad_var(count, 1000);
    if (draws) {
        Apop_stopif(!draws->matrix, draws->error='m'; return draws, 1, "Input data set's matrix is NULL.");
        Apop_stopif((int)draws->matrix->size2 < model->dsize, draws->error='s'; draws->error='m'; return draws,
                1, "Input data set's matrix column count is less than model->dsize.");
        count = draws->matrix->size1;
    } else
        Apop_stopif(model->dsize<=0, apop_return_data_error(n), 0, "model->dsize<=0, so I don't know the size of matrix to allocate.");
APOP_VAR_ENDHEAD
    apop_data *out = draws ? draws : apop_data_alloc(count, model->dsize);

    OMP_for (int i=0; i< count; i++){
        apop_data *onerow = Apop_r(out, i);
        Apop_stopif(apop_draw(onerow->matrix->data, apop_rng_get_thread(omp_threadnum), model),
                gsl_matrix_set_all(onerow->matrix, GSL_NAN); out->error='d',
                0, "Trouble drawing for row %i. "
                "I set it to all NANs and set out->error='d'.", i);
    }
    return out;
}


================================================
FILE: apop_bootstrap.m4.c
================================================
/** \file apop_bootstrap.c

Copyright (c) 2006--2007 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */

#include "apop_internal.h"

/** Initialize a \c gsl_rng.
 
  Uses the Tausworth routine.

\param  seed    The seed. No need to get funny with it: 0, 1, and 2 will produce wholly different streams.
\return The RNG ready for your use.

\li If you are confident that your code is debugged and would like a new stream of values every time your program runs (provided your runs are more than a second apart), seed with the time:

\include draw_some_normals.c
*/
gsl_rng *apop_rng_alloc(int seed){
    static int first_use = 1;
    if (first_use){
       first_use = 0;
       OMP_critical(rng_env_setup) //GSL makes vague promises about thread-safety
       gsl_rng_env_setup();
    }
    gsl_rng *setme = gsl_rng_alloc(gsl_rng_taus2);
    gsl_rng_set(setme, seed);
    return setme;
}

/** Give me a data set and a model, and I'll give you the jackknifed covariance matrix of the model parameters.

The basic algorithm for the jackknife (glossing over the details): create a sequence of data
sets, each with exactly one observation removed, and then produce a new set of parameter estimates 
using that slightly shortened data set. Then, find the covariance matrix of the derived parameters.

\li Jackknife or bootstrap? As a broad rule of thumb, the jackknife works best on models
    that are closer to linear. The worse a linear approximation does (at the given data),
    the worse the jackknife approximates the variance.

\param in	    The data set. An \ref apop_data set where each row is a single data point.
\param model    An \ref apop_model, that will be used internally by \ref apop_estimate.
            
\exception out->error=='n'   \c NULL input data.
\return         An \c apop_data set whose matrix element is the estimated covariance matrix of the parameters.
\see apop_bootstrap_cov

For example:
\include jack.c
*/
apop_data * apop_jackknife_cov(apop_data *in, apop_model *model){
    Apop_stopif(!in, apop_return_data_error(n), 0, "The data input can't be NULL.");
    Get_vmsizes(in); //msize1, msize2, vsize
    apop_model *e = apop_model_copy(model);
    int i, n = GSL_MAX(msize1, GSL_MAX(vsize, in->textsize[0]));
    apop_model *overall_est = e->parameters ? e : apop_estimate(in, e);//if not estimated, do so
    gsl_vector *overall_params = apop_data_pack(overall_est->parameters);
    gsl_vector_scale(overall_params, n); //do it just once.
    gsl_vector *pseudoval = gsl_vector_alloc(overall_params->size);

    //Copy the original, minus the first row.
    apop_data *subset = apop_data_copy(Apop_rs(in, 1, n-1));
    apop_name *tmpnames = in->names; 
    in->names = NULL;  //save on some copying below.

    apop_data *array_of_boots = apop_data_alloc(n, overall_params->size);

    for(i = -1; i< n-1; i++){
        //Get a view of row i, and copy it to position i-1 in the short matrix.
        if (i >= 0) apop_data_memcpy(Apop_r(subset, i), Apop_r(in, i));
        apop_model *est = apop_estimate(subset, e);
        gsl_vector *estp = apop_data_pack(est->parameters);
        gsl_vector_memcpy(pseudoval, overall_params);// *n above.
        gsl_vector_scale(estp, n-1);
        gsl_vector_sub(pseudoval, estp);
        gsl_matrix_set_row(array_of_boots->matrix, i+1, pseudoval);
        apop_model_free(est);
        gsl_vector_free(estp);
    }
    in->names = tmpnames;
    apop_data *out = apop_data_covariance(array_of_boots);
    gsl_matrix_scale(out->matrix, 1./(n-1.));
    apop_data_free(subset);
    gsl_vector_free(pseudoval);
    apop_data_free(array_of_boots);
    if (e!=overall_est)
        apop_model_free(overall_est);
    apop_model_free(e);
    gsl_vector_free(overall_params);
    return out;
}

/** Give me a data set and a model, and I'll give you the bootstrapped covariance matrix of the parameter estimates.

\param data	    The data set. An \c apop_data set where each row is a single data point. (No default)
\param model    An \ref apop_model, whose \c estimate method will be used here. (No default)
\param iterations How many bootstrap draws should I make? (default: 1,000) 
\param rng        An RNG that you have initialized, probably with \c apop_rng_alloc. (Default: an RNG from \ref apop_rng_get_thread)
\param boot_store  If not \c NULL, put the list of drawn parameter values here, with one parameter set per row. Sample use: 
\code
apop_data *boots;
apop_bootstrap_cov(data, model, .boot_store=&boots);
apop_data_print(boots);
\endcode
The rows are packed via \ref apop_data_pack, so use \ref apop_data_unpack if needed. (Default: \c NULL)
\param ignore_nans If \c 'y' and any of the elements in the estimation return \c NaN, then I will throw out that draw and try again. If \c 'n', then I will write that set of statistics to the list, \c NaN and all. I keep count of throw-aways; if there are more than \c iterations elements thrown out, then I throw an error and return with estimates using data I have so far. That is, I assume that \c NaNs are rare edge cases; if they are as common as good data, you might want to rethink how you are using the bootstrap mechanism. (Default: 'n')
\return         An \c apop_data set whose matrix element is the estimated covariance matrix of the parameters.
\exception out->error=='n'   \c NULL input data.
\exception out->error=='N'   \c too many NaNs.

\li This function uses the \ref designated syntax for inputs.

This example is a sort of demonstration of the Central Limit Theorem. The model is
a simulation, where each call to the estimation routine produces the mean/std dev of
a set of draws from a Uniform Distribution. Because the simulation takes no inputs,
\ref apop_bootstrap_cov simply re-runs the simulation and calculates a sequence of
mean/std dev pairs, and reports the covariance of that generated data set.

\include boot_clt.c

\see apop_jackknife_cov
 */
APOP_VAR_HEAD apop_data * apop_bootstrap_cov(apop_data * data, apop_model *model, gsl_rng *rng, int iterations, char keep_boots, char ignore_nans, apop_data **boot_store) {
    apop_data * apop_varad_var(data, NULL);
    apop_model *model = varad_in.model;
    int apop_varad_var(iterations, 1000);
    gsl_rng * apop_varad_var(rng, apop_rng_get_thread());
    char apop_varad_var(keep_boots, 'n');
    apop_data** apop_varad_var(boot_store, NULL);
    char apop_varad_var(ignore_nans, 'n');
APOP_VAR_ENDHEAD
    Get_vmsizes(data); //vsize, msize1, msize2
    apop_model *e = apop_model_copy(model);
    apop_data *subset = apop_data_copy(data);
    apop_data *array_of_boots = NULL,
              *summary;
    //prevent and infinite regression of covariance calculation.
    Apop_model_add_group(e, apop_parts_wanted); //default wants for nothing.
    size_t i, nan_draws=0;
    apop_name *tmpnames = (data && data->names) ? data->names : NULL; //save on some copying below.
    if (data && data->names) data->names = NULL;

    int height = GSL_MAX(msize1, GSL_MAX(vsize, (data?(*data->textsize):0)));
	for (i=0; i<iterations && nan_draws < iterations; i++){
		for (size_t j=0; j< height; j++){       //create the data set
			size_t randrow	= gsl_rng_uniform_int(rng, height);
            apop_data_memcpy(Apop_r(subset, j), Apop_r(data, randrow));
		}
		//get the parameter estimates.
		apop_model *est = apop_estimate(subset, e);
        gsl_vector *estp = apop_data_pack(est->parameters);
        if (!gsl_isnan(apop_sum(estp))){
            if (i==0){
                array_of_boots	      = apop_data_alloc(iterations, estp->size);
                apop_name_stack(array_of_boots->names, est->parameters->names, 'c', 'v');
                apop_name_stack(array_of_boots->names, est->parameters->names, 'c', 'c');
                apop_name_stack(array_of_boots->names, est->parameters->names, 'c', 'r');
            }
            gsl_matrix_set_row(array_of_boots->matrix, i, estp);
        } else if (ignore_nans=='y'){
            i--; 
            nan_draws++;
        }
        apop_model_free(est);
        gsl_vector_free(estp);
	}
    if(data) data->names = tmpnames;
    apop_data_free(subset);
    apop_model_free(e);
    int set_error=0;
    Apop_stopif(i == 0 && nan_draws == iterations, apop_return_data_error(N),
                1, "I ran into %i NaNs and no not-NaN estimations, and so stopped. "
                       , iterations);
    Apop_stopif(nan_draws == iterations,  set_error++;
            apop_matrix_realloc(array_of_boots->matrix, i, array_of_boots->matrix->size2),
                1, "I ran into %i NaNs, and so stopped. Returning results based "
                       "on %zu bootstrap iterations.", iterations, i);
	summary	= apop_data_covariance(array_of_boots);
    if (boot_store) *boot_store = array_of_boots;
    else            apop_data_free(array_of_boots);
    if (set_error) summary->error = 'N';
	return summary;
}


================================================
FILE: apop_conversions.m4.c
================================================
/** \file apop_conversions.c	The various functions to convert from one format to another. */
/* Copyright (c) 2006--2010, 2012 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */
#include "apop_internal.h"
#include <gsl/gsl_math.h> //GSL_NAN
#include <assert.h>
#include <stdbool.h>
#include <libgen.h>

/*extend a string. this prevents a minor leak you'd get if you did
 asprintf(&q, "%s is a teapot.", q);
 q may be NULL, which prints the string "null", so use the little XN macro below when using this function.

 This is internal to apop. right now. 
*/
void xprintf(char **q, char *format, ...){ 
    va_list ap; 
    char *r = *q; 
    va_start(ap, format); 
    Apop_stopif(vasprintf(q, format, ap)==-1, , 0, "Trouble writing to a string.");
    va_end(ap);
    free(r);
}

/** Copies a one-dimensional array to a <tt>gsl_vector</tt>. The input array is undisturbed.

\param in     An array of <tt>double</tt>s. (No default. Must not be \c NULL);
\param size 	How long \c line is. If this is zero or omitted, I'll
guess using the <tt>sizeof(line)/sizeof(line[0])</tt> trick, which will
work for most arrays allocated using <tt>double []</tt> and won't work
for those allocated using <tt>double *</tt>. (default = auto-guess)
\return   A <tt>gsl_vector</tt>, allocated and filled with a copy of (not a pointer to) the input data.

\li If you send in a \c NULL vector, you get a \c NULL pointer in return. I warn you of this if <tt>apop_opts.verbosity >=1 </tt>.

\li This function uses the \ref designated syntax for inputs.
\see \ref apop_data_falloc
*/ 
APOP_VAR_HEAD gsl_vector * apop_array_to_vector(double *in, int size){
    double * apop_varad_var(in, NULL);
    Apop_assert_c(in, NULL, 1, "You sent me NULL data; returning NULL.");
    int apop_varad_var(size, sizeof(in)/sizeof(in[0]));
APOP_VAR_ENDHEAD
    gsl_vector *out = gsl_vector_alloc(size);
    gsl_vector_view	v = gsl_vector_view_array((double*)in, size);
	gsl_vector_memcpy(out,&(v.vector));
    return out;
}

/** This function copies the data in a vector to a new one-column (or one-row) matrix
and returns the newly-allocated and filled matrix.

  For the reverse, try \ref apop_data_pack.

\param in a \c gsl_vector (No default. If \c NULL, I return \c NULL, with a warning if <tt>apop_opts.verbose >=1 </tt>)
\param row_col If \c 'r', then this will be a row (1 x N) instead of the default, a column (N x 1). (default: \c 'c')
\return a newly-allocated <tt>gsl_matrix</tt> with one column (or row).

\li If you send in a \c NULL vector, you get a \c NULL pointer in return. I warn you of this if <tt>apop_opts.verbosity >=2 </tt>.
\li If \c gsl_matrix_alloc fails you get a \c NULL pointer in return.
\li This function uses the \ref designated syntax for inputs.
*/
APOP_VAR_HEAD gsl_matrix * apop_vector_to_matrix(const gsl_vector *in, char row_col){
    const gsl_vector * apop_varad_var(in, NULL);
    Apop_assert_c(in, NULL, 2, "Converting NULL vector to NULL matrix.");
    char apop_varad_var(row_col, 'c');
APOP_VAR_ENDHEAD
    bool isrow = (row_col == 'r' || row_col == 'R');
    gsl_matrix *out = isrow ? gsl_matrix_alloc(1, in->size)
                            : gsl_matrix_alloc(in->size, 1);
    Apop_assert(out, "gsl_matrix_alloc failed; probably out of memory.");
    (isrow ? gsl_matrix_set_row
           : gsl_matrix_set_col)(out, 0, in);
    return out;
}

static int find_cat_index(char **d, char * r, int start_from, int size){
//used for apop_db_to_crosstab.
    int i = start_from % size;	//i is probably the same or i+1.
	do {
		if(!strcmp(d[i], r)) return i;
		i++;
		i %= size;	//loop around as necessary.
	} while (i!=start_from); 
    Apop_assert_c(0, -2, 0, "Something went wrong in the crosstabbing; couldn't find %s.", r);
}

/**Give the name of a table in the database, and optional names of three of its columns:
the x-dimension, the y-dimension, and the data. The output is a 2D matrix with rows
indexed by 'row' and cols by 'col' and the cells filled with the entry in the 'data' column.

\param tabname The database table I'm querying. Anything that will work inside a \c from clause is OK, such as a subquery in parens. (no default; must not be \c NULL)
\param row The column of the data set that will indicate the rows of the output crosstab (no default; must not be \c NULL)
\param col The column of the data set that will indicate the columns of the output crosstab (no default; must not be \c NULL)
\param data The column of the data set holding the data for the cells of the crosstab (default: <tt>count(*)</tt>)
\param is_aggregate Set to \c 'y' if the \c data is a function like <tt>count(*)</tt>
    or <tt>sum(col)</tt>. That is, set to \c 'y' if querying this would require a <tt>group
    by</tt> clause. (default: if I find an end-paren in \c datacol, \c 'y'; else \c 'n'.)

\li  If the query to get data to fill the table (select row, col, data from
    tabname) returns an empty data set, then I will return a \c NULL data set and if
    <tt>apop_opts.verbosity >= 1</tt> print a warning.

\exception out->error='n' Name not found error.
\exception out->error='q' Query returned an empty table (which might mean that it just failed).

\li The simplest use is to get a tally of how often (r1, r2) appears in the data via <tt>apop_db_to_crosstab("datatab", "r1", "r2")</tt>.
\li If you want a 1-D crosstab, omit the other dimension. Or omit both to get a grand tally of your statistic for the entire table.
\li There is a commnad-line tool, <tt>apop_db_to_crosstab</tt> that calls this function.
\li This function uses the \ref designated syntax for inputs.
*/
APOP_VAR_HEAD apop_data *apop_db_to_crosstab(char const*tabname, char const*row, char const* col, char const*data, char is_aggregate){
    char const* apop_varad_var(tabname, NULL);
    Apop_stopif(!tabname, return NULL, 1, "Missing tabname. Returning NULL.");
    char const* apop_varad_var(row, "1");
    char const* apop_varad_var(col, "1");
    char const* apop_varad_var(data, "count(*)");
    //This '(' balances the end-paren below, keeping m4 from losing the thread.
    //Note the transitional check for "group by", which we should one day remove.
    char apop_varad_var(is_aggregate, (strchr(data, ')') && !strstr(data, "group by"))?'y':'n');
APOP_VAR_ENDHEAD
    gsl_matrix *out=NULL;
    int	i, j=0;
    apop_data *pre_d1=NULL, *pre_d2=NULL, *datachars=NULL;
    apop_data *outdata = apop_data_alloc();

    char* p = apop_opts.db_name_column;
    apop_opts.db_name_column = NULL;//we put this back at the end.
    char *Q;

    Asprintf(&Q, "select %s, %s, %s from %s %s %s %s %s", row, col, data, tabname,
                                    is_aggregate!='n' ? "group by" : "",
                                    is_aggregate!='n' ? row : "",
                                    is_aggregate!='n' ? "," : "",
                                    is_aggregate!='n' ? col : "");
    datachars = apop_query_to_text("%s", Q);
    Apop_stopif(!datachars, free(Q); return NULL, 2, "[%s] returned an empty table.", Q);
    Apop_stopif(datachars->error, free(Q); goto bailout, 0, "error from [%s].", Q);

    //A bit inefficient, but well-encapsulated.
    //Pull the distinct (sorted) list of headers, copy into outdata->names.
    pre_d1 = apop_query_to_text("select distinct %s, 1 from %s order by %s", row, tabname, row);
    Apop_stopif(!pre_d1||pre_d1->error, outdata->error='q'; goto bailout, 0, "Error querying %s from %s.", row, tabname);
    for (i=0; i < pre_d1->textsize[0]; i++)
        apop_name_add(outdata->names, pre_d1->text[i][0], 'r');

	pre_d2 = apop_query_to_text("select distinct %s from %s order by %s", col, tabname, col);
    Apop_stopif(!pre_d2||pre_d2->error, outdata->error='q'; goto bailout, 0, "Error querying %s from %s.", row, tabname);
    for (i=0; i < pre_d2->textsize[0]; i++)
        apop_name_add(outdata->names, pre_d2->text[i][0], 'c');

	out	= gsl_matrix_calloc(pre_d1->textsize[0], pre_d2->textsize[0]);
	for (size_t k =0; k< datachars->textsize[0]; k++){
		i = find_cat_index(outdata->names->row, datachars->text[k][0], i, pre_d1->textsize[0]);
		j = find_cat_index(outdata->names->col, datachars->text[k][1], j, pre_d2->textsize[0]);
        Apop_stopif(i==-2 || j == -2, outdata->error='n'; goto bailout, 0, "Something went wrong in the crosstabbing; "
                                                 "couldn't find %s or %s.", datachars->text[k][0], datachars->text[k][1]);
		gsl_matrix_set(out, i, j, atof(datachars->text[k][2]));
	}
    bailout:
    apop_data_free(pre_d1);
    apop_data_free(pre_d2);
    apop_data_free(datachars);
    outdata->matrix = out;
    apop_opts.db_name_column = p;
	return outdata;
}

/** See \ref apop_db_to_crosstab for the storyline; this is the complement, which takes a
  crosstab and writes its values to the database.

For example, I would take
<table frame=box>                                                                                                              
<tr><td> </td><td> c0</td><td>c1</td></tr>
<tr><td>r0</td><td>2</td><td>3</td></tr> 
<tr><td>r1</td><td>0</td><td>4</td></tr> 
</table> 

and do the following writes to the database:

\code
insert into your_table values ('r0', 'c0', 2);
insert into your_table values ('r0', 'c1', 3);
insert into your_table values ('r1', 'c0', 3);
insert into your_table values ('r1', 'c1', 4);
\endcode


\li If your data set does not have names (or not enough names), I will use the scheme above, filling in names of the form <tt>r0</tt>, <tt>r1</tt>, ... <tt>c0</tt>, <tt>c1</tt>, .... Text columns get their own names, <tt>t0</tt>, <tt>t1</tt>.

\li This function handles only the matrix and text. 
 */
void apop_crosstab_to_db(apop_data *in,  char *tabname, char *row_col_name, 
						char *col_col_name, char *data_col_name){
    apop_name *n = in->names;
    char *colname, *rowname;
    Get_vmsizes(in); //msize1, msize2
    int maxcol= GSL_MAX(msize2, in->textsize[1]);
    char sparerow[msize1 > 0 ? (int)log10(msize1)+1 : 0];
    char sparecol[maxcol > 0 ? (int)log10(maxcol)+1 : 0];
#define DbType apop_opts.db_engine=='m' ? "text" : "character"
#define DbType2 apop_opts.db_engine=='m' ? "double" : "numeric"
	apop_query("CREATE TABLE %s (%s %s, %s %s, %s %s)", tabname, 
                        row_col_name, DbType, col_col_name, DbType, data_col_name, DbType2);
	apop_query("begin");
    for (int i=0; i< msize1; i++){
        rowname = (n->rowct > i) ?  n->row[i] : (sprintf(sparerow, "r%i", i), sparerow);
        for (int j=0; j< msize2; j++){
            colname = (n->colct > j) ? n->col[j] : (sprintf(sparecol, "c%i", j), sparecol);
            double x = gsl_matrix_get(in->matrix, i, j); 
            if (!isnan(x)) apop_query("INSERT INTO %s VALUES ('%s', '%s', %g)", 
                                                tabname, rowname, colname, x);
            else apop_query("INSERT INTO %s VALUES ('%s', '%s', 0/0)", 
                                        tabname, rowname, colname);
        }
    }
    for (int i=0; i< in->textsize[0]; i++){
        rowname = (n->rowct > i) ? n->row[i] : (sprintf(sparerow, "r%i", i), sparerow);
        for (int j=0; j< in->textsize[1]; j++){
            colname = (n->textct > j) ? n->text[j] : (sprintf(sparecol, "t%i", j), sparecol);
            apop_query("INSERT INTO %s VALUES ('%s', '%s', '%s')", tabname, 
                rowname, colname, in->text[i][j]);
        }
    }
	apop_query("commit");
}


/** One often finds data where the column indicates the value of the data point. There may
be two columns, and a mark in the first indicates a miss while a mark in the second is a
hit. Or say that we have the following list of observations:

\code
2 3 3 2 1 1 2 1 1 2 1 1
\endcode
Then we could write this as:
\code
0  1  2  3
----------
0  6  4  2
\endcode
because there are six 1s observed, four 2s observed, and two 3s observed. We call this
rank format, because 1 (or zero) is typically the most common, 2 is second most common, et cetera.

This function takes in a list of observations, and aggregates them into a single row in rank format.

\li For the complement, see \ref apop_data_rank_expand.

\li See also \ref apop_data_to_factors to convert real numbers or text into a
matrix of categories.

\param in The input \ref apop_data set. If \c NULL, return \c NULL.
\param min_bins If this is omitted, the number of bins is simply the largest number
found. So if there are bins {0, 1, 2} and your data set happens to consist of <tt>0 0
1 1 0</tt>, then I won't know to generate results with three bins where the last bin
has a count of zero. Set <tt>.min_bins=2</tt> to ensure that bin is included.

\include test_ranks.c

\li This function uses the \ref designated syntax for inputs.
*/
APOP_VAR_HEAD apop_data * apop_data_rank_compress (apop_data *in, int min_bins){
    apop_data * apop_varad_var(in, NULL);
    if (!in) return NULL;
    int apop_varad_var(min_bins, 0);
APOP_VAR_ENDHEAD
    Get_vmsizes(in);
    int upper_bound = GSL_MAX(in->matrix ? gsl_matrix_max(in->matrix)
Download .txt
gitextract_f7cy6ezx/

├── ChangeLog
├── README
├── apop.m4.h
├── apop_arms.c
├── apop_asst.m4.c
├── apop_bootstrap.m4.c
├── apop_conversions.m4.c
├── apop_data.m4.c
├── apop_db.m4.c
├── apop_db_mysql.c
├── apop_db_sqlite.c
├── apop_fexact.c
├── apop_hist.m4.c
├── apop_internal.h
├── apop_linear_algebra.m4.c
├── apop_linear_constraint.m4.c
├── apop_mapply.m4.c
├── apop_mcmc.m4.c
├── apop_missing_data.m4.c
├── apop_mle.m4.c
├── apop_model.m4.c
├── apop_name.m4.c
├── apop_output.m4.c
├── apop_rake.m4.c
├── apop_regression.m4.c
├── apop_settings.c
├── apop_sort.m4.c
├── apop_stats.m4.c
├── apop_tests.m4.c
├── apop_update.m4.c
├── apop_vtables.c
├── asprintf.c
├── cmd/
│   ├── Makefile.am
│   ├── apop_db_to_crosstab.c
│   ├── apop_plot_query.c
│   └── apop_text_to_db.c
├── configure
├── docs/
│   ├── Makefile.am
│   ├── adjust
│   ├── apop_data_fig.html
│   ├── apop_data_fig.tex
│   ├── documentation.h
│   ├── doxygen.conf.in
│   ├── edit_globals.sed
│   ├── edit_group.sed
│   ├── edit_outline.sed
│   ├── edit_width.sed
│   ├── foot.html
│   ├── head.html
│   ├── make_model_doc.awk
│   ├── model.dot
│   ├── structs.dot
│   ├── tree.js
│   ├── triangle.c
│   └── typical.css
├── eg/
│   ├── Makefile.am
│   ├── apop_map_row.c
│   ├── banana.c
│   ├── binning.c
│   ├── boot_clt.c
│   ├── cross_models.c
│   ├── data_fill.c
│   ├── db_fns.c
│   ├── dconstrain.c
│   ├── dot_products.c
│   ├── draw_some_normals.c
│   ├── draw_to_db.c
│   ├── entropy_model.c
│   ├── entropy_vector.c
│   ├── f_test.c
│   ├── faithful.c
│   ├── fake_logit.c
│   ├── fix_params.c
│   ├── hills2.c
│   ├── iv.c
│   ├── jack.c
│   ├── jacobian.c
│   ├── kernel.c
│   ├── ks_tests.c
│   ├── logit.c
│   ├── ls_tables.c
│   ├── ml_imputation.c
│   ├── normalization_demo.c
│   ├── ols.c
│   ├── ols2.c
│   ├── ols_oneliner.c
│   ├── parameterization.c
│   ├── pmf_test.c
│   ├── simple_subsets.c
│   ├── some_cdfs.c
│   ├── sql_to_html.c
│   ├── t_test_by_rows.c
│   ├── test_distances.c
│   ├── test_fisher.c
│   ├── test_harmonic.c
│   ├── test_kl_divergence.c
│   ├── test_pruning.c
│   ├── test_ranks.c
│   ├── test_regex.c
│   ├── test_updating.c
│   ├── text_demo.c
│   └── transform.c
├── install/
│   ├── COPYING
│   ├── Makefile.am
│   ├── Readme-pkg
│   ├── Readme-pkg-debian
│   ├── acinclude.m4
│   ├── apophenia.pc.in
│   ├── configure.ac
│   ├── prep_variadics.m4
│   ├── push_pkg
│   └── rpm.spec
├── model/
│   ├── Makefile.am
│   ├── apop_bernoulli.c
│   ├── apop_beta.c
│   ├── apop_dirichlet.c
│   ├── apop_exponential.c
│   ├── apop_gamma.c
│   ├── apop_kerneld.c
│   ├── apop_loess.c
│   ├── apop_multinomial.c
│   ├── apop_multivariate_normal.c
│   ├── apop_normal.c
│   ├── apop_ols.c
│   ├── apop_pmf.c
│   ├── apop_poisson.c
│   ├── apop_probit.c
│   ├── apop_t.c
│   ├── apop_uniform.c
│   ├── apop_wishart.c
│   ├── apop_yule.c
│   └── apop_zipf.c
├── tests/
│   ├── Makefile.am
│   ├── Readme
│   ├── amash_vote_analysis.csv
│   ├── data
│   ├── data-mixed
│   ├── db_tests.c
│   ├── distribution_tests.c
│   ├── error_test.c
│   ├── factors.c
│   ├── faith.data
│   ├── lognormal_test.c
│   ├── nist_tests.c
│   ├── printing_sample
│   ├── rake_test.c
│   ├── sort_example.c
│   ├── sort_tests.c
│   ├── test_apop.c
│   ├── test_data
│   ├── test_data2
│   ├── test_data_fixed_width
│   ├── test_data_nans
│   ├── test_kernel_ll.c
│   ├── update_via_rng.c
│   └── utilities_test.in
└── transform/
    ├── Makefile.am
    ├── apop_coordinate_transform.c
    ├── apop_cross.c
    ├── apop_dconstrain.c
    ├── apop_fix_params.c
    └── apop_mixture.c
Download .txt
SYMBOL INDEX (914 symbols across 116 files)

FILE: apop.m4.h
  type apop_name (line 61) | typedef struct{
  type apop_data (line 72) | typedef struct apop_data{
  type apop_settings_type (line 85) | typedef struct {
  type apop_model (line 94) | typedef struct apop_model apop_model;
  type apop_model (line 98) | struct apop_model{
  type apop_opts_type (line 118) | typedef struct{
  type apop_model (line 514) | typedef apop_model *(*apop_update_type)(apop_data *, apop_model* , apop_...
  type apop_mle_settings (line 1191) | typedef struct{
  type apop_lm_settings (line 1243) | typedef struct {
  type apop_parts_wanted_settings (line 1274) | typedef struct {
  type apop_cdf_settings (line 1284) | typedef struct {
  type apop_pm_settings (line 1293) | typedef struct {
  type apop_pmf_settings (line 1302) | typedef struct {
  type apop_kernel_density_settings (line 1312) | typedef struct{
  type apop_mcmc_settings (line 1326) | struct apop_mcmc_settings
  type apop_mcmc_proposal_s (line 1341) | typedef struct apop_mcmc_proposal_s {
  type apop_mcmc_settings (line 1368) | typedef struct apop_mcmc_settings {
  type loess_struct (line 1415) | struct loess_struct {
  type apop_loess_settings (line 1466) | typedef struct {
  type POINT (line 1565) | typedef struct point {    /* a point in the x,y plane */
  type arms_state (line 1574) | typedef struct {  /* attributes of the entire rejection envelope */
  type apop_arms_settings (line 1593) | typedef struct {
  type apop_cross_settings (line 1613) | typedef struct {
  type apop_coordinate_transform_settings (line 1619) | typedef struct {
  type apop_dconstrain_settings (line 1629) | typedef struct {
  type apop_composition_settings (line 1642) | typedef struct {
  type apop_mixture_settings (line 1652) | typedef struct {

FILE: apop_arms.c
  function distract_doxygen_arms (line 75) | void distract_doxygen_arms(){/*Doxygen gets thrown by the settings macro...
  function apop_arms_draw (line 89) | int apop_arms_draw (double *out, gsl_rng *r, apop_model *m){
  function initial (line 120) | int initial (apop_arms_settings* params,  arms_state *env){
  function invert (line 180) | void invert(double prob, arms_state *env, POINT *p){
  function test (line 243) | int test(arms_state *env, POINT *p, apop_arms_settings *params, gsl_rng ...
  function update (line 324) | int update(arms_state *env, POINT *p, apop_arms_settings *params){
  function cumulate (line 391) | static void cumulate(arms_state *env){
  function meet (line 417) | int meet (POINT *q, arms_state *env, apop_arms_settings *params){
  function area (line 500) | double area(POINT *q){
  function expshift (line 513) | double expshift(double y, double y0) {
  function logshift (line 521) | double logshift(double y, double y0){
  function perfunc (line 526) | double perfunc(apop_arms_settings *params, double x){

FILE: apop_asst.m4.c
  function apop_tack_on (line 19) | static void apop_tack_on(char **in, char *addme){
  function APOP_VAR_HEAD (line 98) | APOP_VAR_HEAD char *apop_text_paste(apop_data const *strings, char *betw...
  function apop_generalized_harmonic (line 138) | long double apop_generalized_harmonic(int N, double s){
  function apop_system (line 188) | int apop_system(const char *fmt, ...){
  function count_parens (line 199) | static int count_parens(const char *string){
  function APOP_VAR_HEAD (line 247) | APOP_VAR_HEAD int  apop_regex(const char *string, const char* regex, apo...
  function apop_rng_GHgB3 (line 298) | double apop_rng_GHgB3(gsl_rng * r, double* a){
  function apop_model (line 323) | apop_model *apop_beta_from_mean_var(double m, double v){
  function gsl_rng (line 356) | gsl_rng *apop_rng_get_thread_base(int thread){
  function APOP_VAR_HEAD (line 405) | APOP_VAR_HEAD apop_data *apop_model_draws(apop_model *model, int count, ...

FILE: apop_bootstrap.m4.c
  function gsl_rng (line 18) | gsl_rng *apop_rng_alloc(int seed){
  function apop_data (line 50) | apop_data * apop_jackknife_cov(apop_data *in, apop_model *model){
  function APOP_VAR_HEAD (line 122) | APOP_VAR_HEAD apop_data * apop_bootstrap_cov(apop_data * data, apop_mode...

FILE: apop_conversions.m4.c
  function xprintf (line 15) | void xprintf(char **q, char *format, ...){
  function APOP_VAR_HEAD (line 38) | APOP_VAR_HEAD gsl_vector * apop_array_to_vector(double *in, int size){
  function APOP_VAR_HEAD (line 62) | APOP_VAR_HEAD gsl_matrix * apop_vector_to_matrix(const gsl_vector *in, c...
  function find_cat_index (line 76) | static int find_cat_index(char **d, char * r, int start_from, int size){
  function APOP_VAR_HEAD (line 111) | APOP_VAR_HEAD apop_data *apop_db_to_crosstab(char const*tabname, char co...
  function apop_crosstab_to_db (line 192) | void apop_crosstab_to_db(apop_data *in,  char *tabname, char *row_col_name,
  function APOP_VAR_HEAD (line 261) | APOP_VAR_HEAD apop_data * apop_data_rank_compress (apop_data *in, int mi...
  function apop_data (line 286) | apop_data *apop_data_rank_expand (apop_data *in){
  function gsl_vector (line 310) | gsl_vector *apop_vector_copy(const gsl_vector *in){
  function gsl_matrix (line 328) | gsl_matrix *apop_matrix_copy(const gsl_matrix *in){
  function prep_text_reading (line 414) | static int prep_text_reading(char const *text_file, FILE **infile){
  type line_parse_t (line 431) | typedef struct {int ct; int eof;} line_parse_t;
  function line_parse_t (line 434) | static line_parse_t parse_a_fixed_line(FILE *infile, apop_data *fn, int ...
  type apop_char_info (line 468) | typedef struct{
  function get_next (line 474) | static int get_next(char *buffer, size_t *ptr, FILE *infile){
  function apop_char_info (line 485) | static apop_char_info parse_next_char(char *buffer, size_t *ptr, FILE *f...
  function line_parse_t (line 503) | static line_parse_t parse_a_line(FILE *infile, char *buffer, size_t *ptr...
  function get_field_names (line 566) | static void get_field_names(int has_col_names, char **field_names, FILE ...
  function APOP_VAR_HEAD (line 600) | APOP_VAR_HEAD apop_data * apop_text_to_data(char const*text_file, int ha...
  function APOP_VAR_HEAD (line 691) | APOP_VAR_HEAD void apop_data_unpack(const gsl_vector *in, apop_data *d, ...
  function sizecount (line 728) | static size_t sizecount(const apop_data *in, bool all_pp, bool use_info_...
  function APOP_VAR_HEAD (line 762) | APOP_VAR_HEAD gsl_vector * apop_data_pack(const apop_data *in, gsl_vecto...
  function apop_data (line 859) | apop_data *apop_data_fill_base(apop_data *in, double ap[]){
  function gsl_vector (line 891) | gsl_vector *apop_vector_fill_base(gsl_vector *in, double ap[]){
  function apop_data (line 923) | apop_data *apop_text_fill_base(apop_data *data, char* text[]){
  function tab_create_mysql (line 951) | static int tab_create_mysql(char *tabname, int has_row_names, apop_data ...
  function tab_create_sqlite (line 968) | static int tab_create_sqlite(char *tabname, int has_row_names, apop_data...
  function line_to_insert (line 1021) | static void line_to_insert(line_parse_t L, apop_data const*addme, char c...
  function apop_use_sqlite_prepared_statements (line 1049) | int apop_use_sqlite_prepared_statements(size_t col_ct){
  function apop_prepare_prepared_statements (line 1059) | int apop_prepare_prepared_statements(char const *tabname, size_t col_ct,...
  function APOP_VAR_HEAD (line 1121) | APOP_VAR_HEAD int apop_text_to_db(char const *text_file, char *tabname, ...

FILE: apop_data.m4.c
  function APOP_VAR_HEAD (line 32) | APOP_VAR_HEAD apop_data * apop_data_alloc(const size_t size1, const size...
  function APOP_VAR_HEAD (line 77) | APOP_VAR_HEAD apop_data * apop_data_calloc(const size_t size1, const siz...
  function apop_text_blank (line 113) | static void apop_text_blank(apop_data *in, const size_t row, const size_...
  function apop_text_free (line 127) | void apop_text_free(char ***freeme, int rows, int cols){
  function apop_data_free_base (line 151) | char apop_data_free_base(apop_data *freeme){
  function apop_data_memcpy (line 203) | void apop_data_memcpy(apop_data *out, const apop_data *in){
  function apop_data (line 283) | apop_data *apop_data_copy(const apop_data *in){
  function APOP_VAR_HEAD (line 352) | APOP_VAR_HEAD apop_data *apop_data_stack(apop_data *m1, apop_data * m2, ...
  function apop_data (line 459) | apop_data ** apop_data_split(apop_data *in, int splitpoint, char r_or_c){
  function apop_name_rm_columns (line 627) | static void apop_name_rm_columns(apop_name *n, int *drop){
  function gsl_matrix (line 645) | static gsl_matrix *apop_matrix_rm_columns(gsl_matrix *in, int *drop){
  function apop_data_rm_columns (line 677) | void apop_data_rm_columns(apop_data *d, int *drop){
  function apop_data (line 719) | apop_data* apop_data_prune_columns_base(apop_data *d, char **colnames){
  function APOP_VAR_HEAD (line 766) | APOP_VAR_HEAD double * apop_data_ptr(apop_data *data, int row, int col, ...
  function APOP_VAR_HEAD (line 814) | APOP_VAR_HEAD double apop_data_get(const apop_data *data, size_t row, in...
  function apop_gsl_error_for_set (line 852) | void apop_gsl_error_for_set(const char *reason, const char *file, int li...
  function APOP_VAR_HEAD (line 881) | APOP_VAR_HEAD int apop_data_set(apop_data *data, size_t row, int col, co...
  function apop_data_add_named_elmt (line 944) | void apop_data_add_named_elmt(apop_data *d, char *name, double val){
  function apop_data_add_names_base (line 955) | void apop_data_add_names_base(apop_data *d, const char type, char const ...
  function apop_text_set (line 995) | int apop_text_set(apop_data *in, const size_t row, const size_t col, con...
  function apop_data (line 1023) | apop_data * apop_text_alloc(apop_data *in, const size_t row, const size_...
  function APOP_VAR_HEAD (line 1111) | APOP_VAR_HEAD apop_data * apop_data_transpose(apop_data *in, char transp...
  function gsl_matrix (line 1212) | gsl_matrix * apop_matrix_realloc(gsl_matrix *m, size_t newheight, size_t...
  function gsl_vector (line 1262) | gsl_vector * apop_vector_realloc(gsl_vector *v, size_t newheight){
  function APOP_VAR_HEAD (line 1290) | APOP_VAR_HEAD apop_data * apop_data_get_page(const apop_data * data, con...
  function apop_data (line 1317) | apop_data * apop_data_add_page(apop_data * dataset, apop_data *newpage, ...
  function APOP_VAR_HEAD (line 1357) | APOP_VAR_HEAD apop_data* apop_data_rm_page(apop_data * data, const char ...
  function APOP_VAR_HEAD (line 1413) | APOP_VAR_HEAD apop_data* apop_data_rm_rows(apop_data *in, int *drop, apo...

FILE: apop_db.m4.c
  function get_db_type (line 40) | static void get_db_type(){
  function apop_db_open (line 85) | int apop_db_open(char const *filename){
  type tab_exists_t (line 102) | typedef struct {
  function tab_exists_callback (line 108) | static int tab_exists_callback(void *in, int argc, char **argv, char **w...
  function APOP_VAR_HEAD (line 130) | APOP_VAR_HEAD int apop_table_exists(char const *name, char remove){
  function apop_data (line 251) | apop_data * apop_query_to_text(const char * fmt, ...){
  function db_to_table (line 267) | static int db_to_table(void *qinfo, int argc, char **argv, char **column){
  function apop_data (line 320) | apop_data * apop_query_to_data(const char * fmt, ...){
  function gsl_vector (line 364) | gsl_vector * apop_query_to_vector(const char * fmt, ...){
  function apop_query_to_float (line 406) | double apop_query_to_float(const char * fmt, ...){
  function apop_data (line 453) | apop_data * apop_query_to_mixed_data(const char *typelist, const char * ...
  function qxprintf (line 475) | void qxprintf(char **q, char *format, ...){
  function add_a_number (line 484) | static void add_a_number (char **q, char *comma, double v){
  function run_prepared_statements (line 496) | static int run_prepared_statements(apop_data const *set, sqlite3_stmt *p...
  function apop_data_to_db (line 542) | int apop_data_to_db(const apop_data *set, const char *tabname, const cha...

FILE: apop_db_mysql.c
  function apop_mysql_db_open (line 23) | static int apop_mysql_db_open(char const *in){
  function apop_mysql_db_close (line 34) | static void apop_mysql_db_close(int ignoreme){
  function apop_mysql_query (line 47) | static double apop_mysql_query(char *query){
  function apop_mysql_table_exists (line 54) | static double apop_mysql_table_exists(char const *table, int delme){
  function get_name_row (line 78) | static int get_name_row(unsigned int *num_fields, MYSQL_FIELD *fields){
  function apop_mysql_query_to_float (line 177) | static double apop_mysql_query_to_float(char *query){
  function apop_data (line 193) | apop_data* apop_mysql_mixed_query(char const *intypes, char const *query){

FILE: apop_db_sqlite.c
  type StdDevCtx (line 14) | typedef struct StdDevCtx StdDevCtx;
  type StdDevCtx (line 15) | struct StdDevCtx {
  function twoStep (line 24) | static void twoStep(sqlite3_context *context, int argc, sqlite3_value **...
  function threeStep (line 38) | static void threeStep(sqlite3_context *context, int argc, sqlite3_value ...
  function fourStep (line 54) | static void fourStep(sqlite3_context *context, int argc, sqlite3_value *...
  function stdDevFinalizePop (line 67) | static void stdDevFinalizePop(sqlite3_context *context){
  function varFinalizePop (line 75) | static void varFinalizePop(sqlite3_context *context){
  function stdDevFinalize (line 83) | static void stdDevFinalize(sqlite3_context *context){
  function varFinalize (line 93) | static void varFinalize(sqlite3_context *context){
  function skewFinalize (line 103) | static void skewFinalize(sqlite3_context *context){
  function kurtFinalize (line 114) | static void kurtFinalize(sqlite3_context *context){
  function powFn (line 130) | static void powFn(sqlite3_context *context, int argc, sqlite3_value **ar...
  function rngFn (line 136) | static void rngFn(sqlite3_context *context, int argc, sqlite3_value **ar...
  function sqfn (line 145) | sqfn(sqrt) sqfn(exp) sqfn(log) sqfn(log10) sqfn(sin)

FILE: apop_fexact.c
  type Rboolean (line 24) | typedef enum { FALSE = 0, TRUE /*, MAYBE */ } Rboolean;
  function imax2 (line 25) | int imax2(int a, int b){return (a>b) ? a : b;}
  function imin2 (line 26) | int imin2(int a, int b){return (a<b) ? a : b;}
  function fmax2 (line 27) | float fmax2(float a, float b){return (a>b) ? a : b;}
  function fmin2 (line 28) | float fmin2(float a, float b){return (a<b) ? a : b;}
  function prterr (line 66) | void prterr(int icode, const char *mes) {
  function fexact (line 72) | static void fexact(int *nrow, int *ncol, int *table, int *ldtabl,
  function f2xact (line 308) | static void f2xact(int nrow, int ncol, int *table, int ldtabl,
  function f3xact (line 760) | static double f3xact(int nrow, int *irow, int ncol, int *icol,
  function f4xact (line 1069) | static double f4xact(int nrow, int *irow, int ncol, int *icol, double dspt,
  function f5xact (line 1265) | void f5xact(double *pastp, const double *tol, int *kval, int *key, int *...
  function Rboolean (line 1426) | Rboolean f6xact(int nrow, int *irow, int *kyy, int *key, int *ldkey, int...
  function f7xact (line 1473) | void f7xact(int nrow, int *imax, int *idif, int *k, int *ks, int *iflag) {
  function f8xact (line 1569) | void f8xact(int *irow, int is, int i1, int izero, int *new) {
  function f9xact (line 1606) | static double f9xact(int n, int ntot, int *ir, double *fact) {
  function Rboolean (line 1627) | Rboolean f10act(int nrow, int *irow, int ncol, int *icol, double *val,
  function f11act (line 1684) | void f11act(int *irow, int i1, int i2, int *new) {
  function iwork (line 1700) | static int iwork(int iwkmax, int *iwkpt, int number, int itype) {
  function isort (line 1731) | void isort(int *n, int *ix) {
  function gammds (line 1805) | static double gammds(double *y, double *p, int *ifault) {
  function apop_data (line 1894) | apop_data *apop_test_fisher_exact(apop_data *intab){

FILE: apop_hist.m4.c
  function APOP_VAR_HEAD (line 29) | APOP_VAR_HEAD apop_model *apop_model_to_pmf(apop_model *model, apop_data...
  function apop_data (line 62) | apop_data *apop_histograms_test_goodness_of_fit(apop_model *observed, ap...
  function m_multiply (line 90) | static void m_multiply(long double *A, long double *B, long double *C, i...
  function m_power (line 103) | static void m_power(long double *A, int eA, long double *V, int *eV, int...
  function kolmogorov_2x (line 137) | static double kolmogorov_2x(int n, double d) {
  function psmirnov2x (line 189) | static double psmirnov2x(double x, int m, int n) {
  function apop_data (line 241) | apop_data *apop_test_kolmogorov(apop_model *m1, apop_model *m2){
  function APOP_VAR_HEAD (line 324) | APOP_VAR_HEAD apop_data *apop_data_to_bins(apop_data const *indata, apop...
  function gsl_vector (line 367) | gsl_vector *apop_vector_moving_average(gsl_vector *v, size_t bandwidth){

FILE: apop_linear_algebra.m4.c
  function apop_gsl_error (line 10) | void apop_gsl_error(const char *reason, const char *file, int line, int ...
  function apop_det_and_inv (line 40) | double apop_det_and_inv(const gsl_matrix *in, gsl_matrix **out, int calc...
  function gsl_matrix (line 70) | gsl_matrix * apop_matrix_inverse(const gsl_matrix *in) {
  function apop_matrix_determinant (line 84) | double apop_matrix_determinant(const gsl_matrix *in) {
  function APOP_VAR_HEAD (line 110) | APOP_VAR_HEAD apop_data * apop_matrix_pca(gsl_matrix *data, int const di...
  function l10 (line 147) | static void l10(double *d){ *d = log10(*d); }
  function ln (line 148) | static void ln(double *d){ *d = log(*d); }
  function ex (line 149) | static void ex(double *d){ *d = exp(*d); }
  function apop_vector_log10 (line 154) | void apop_vector_log10(gsl_vector *v){
  function apop_vector_log (line 162) | void apop_vector_log(gsl_vector *v){
  function apop_vector_exp (line 170) | void apop_vector_exp(gsl_vector *v){
  function APOP_VAR_HEAD (line 186) | APOP_VAR_HEAD gsl_vector *apop_vector_stack(gsl_vector *v1, gsl_vector c...
  function APOP_VAR_HEAD (line 242) | APOP_VAR_HEAD gsl_matrix *apop_matrix_stack(gsl_matrix *m1, gsl_matrix c...
  function APOP_VAR_HEAD (line 308) | APOP_VAR_HEAD int apop_vector_bounded(const gsl_vector *in, long double ...
  function gsl_vector (line 322) | static gsl_vector* dot_for_apop_dot(const gsl_matrix *m, const gsl_vecto...
  function APOP_VAR_HEAD (line 380) | APOP_VAR_HEAD apop_data * apop_dot(const apop_data *d1, const apop_data ...

FILE: apop_linear_constraint.m4.c
  function magnitude (line 8) | static double magnitude(gsl_vector *v){
  function find_nearest_point (line 14) | static void find_nearest_point(gsl_vector *V, double k, gsl_vector *B, g...
  function binds (line 28) | static int binds(gsl_vector const *v, double k, gsl_vector const *b, dou...
  function trig_bit (line 34) | static double trig_bit(gsl_vector *dimv, gsl_vector *otherv, double off_...
  function get_candiate (line 51) | static void get_candiate(gsl_vector *beta, apop_data *constraint, int cu...
  function apop_linear_constraint (line 124) | APOP_VAR_HEAD long double  apop_linear_constraint(gsl_vector *beta, apop...

FILE: apop_mapply.m4.c
  function APOP_VAR_HEAD (line 119) | APOP_VAR_HEAD apop_data* apop_map(apop_data *in, apop_fn_d *fn_d, apop_f...
  type threadpass (line 220) | typedef struct {
  function rowloop (line 234) | static void rowloop(threadpass *tc){
  function forloop (line 249) | static void forloop(threadpass *tc){
  function oldforloop (line 264) | static void oldforloop(threadpass *tc){
  function vectorloop (line 275) | static void vectorloop(threadpass *tc){
  function oldvectorloop (line 291) | static void oldvectorloop(threadpass *tc){
  function gsl_vector (line 300) | static gsl_vector*mapply_core(apop_data *d, gsl_matrix *m, gsl_vector *v...
  function gsl_vector (line 329) | gsl_vector *apop_matrix_map(const gsl_matrix *m, double (*fn)(gsl_vector...
  function apop_matrix_apply (line 347) | void apop_matrix_apply(gsl_matrix *m, void (*fn)(gsl_vector*)){
  function gsl_vector (line 365) | gsl_vector *apop_vector_map(const gsl_vector *v, double (*fn)(double)){
  function apop_vector_apply (line 382) | void apop_vector_apply(gsl_vector *v, void (*fn)(double*)){
  function apop_matrix_map_all_vector_subfn (line 386) | static void apop_matrix_map_all_vector_subfn(const gsl_vector *in, gsl_v...
  function gsl_matrix (line 400) | gsl_matrix * apop_matrix_map_all(const gsl_matrix *in, double (*fn)(doub...
  function apop_matrix_apply_all (line 420) | void apop_matrix_apply_all(gsl_matrix *in, void (*fn)(double *)){
  function apop_vector_map_sum (line 435) | double apop_vector_map_sum(const gsl_vector *in, double(*fn)(double)){
  function apop_matrix_map_all_sum (line 449) | double apop_matrix_map_all_sum(const gsl_matrix *in, double (*fn)(double)){
  function apop_matrix_map_sum (line 463) | double apop_matrix_map_sum(const gsl_matrix *in, double (*fn)(gsl_vector...
  function APOP_VAR_HEAD (line 485) | APOP_VAR_HEAD double apop_map_sum(apop_data *in, apop_fn_d *fn_d, apop_f...

FILE: apop_mcmc.m4.c
  function step_to_vector (line 11) | static void step_to_vector(double const *d, apop_mcmc_proposal_s *ps, ap...
  function sigma_adapt (line 18) | int sigma_adapt(apop_mcmc_proposal_s *ps, apop_mcmc_settings *ms){
  function setup_normal_proposals (line 66) | static void setup_normal_proposals(apop_mcmc_proposal_s *s, int tsize, a...
  function set_block_count_and_block_starts (line 76) | static void set_block_count_and_block_starts(apop_data *in,
  function one_step (line 104) | static void one_step(apop_data *d, gsl_vector *draw, apop_model *m, apop...
  function apop_model_metropolis_draw (line 167) | int apop_model_metropolis_draw(double *out, gsl_rng* rng, apop_model *mo...
  function main_mcmc_loop (line 198) | void main_mcmc_loop(apop_data *d, apop_model *m, apop_data *out, gsl_vec...
  function APOP_VAR_HEAD (line 281) | APOP_VAR_HEAD apop_model *apop_model_metropolis(apop_data *d, gsl_rng *r...

FILE: apop_missing_data.m4.c
  function APOP_VAR_HEAD (line 33) | APOP_VAR_HEAD apop_data * apop_data_listwise_delete(apop_data *d, char i...
  function i_est (line 90) | static void i_est(apop_data *d, apop_model *ml_model){
  function i_ll (line 95) | static long double i_ll(apop_data *d, apop_model *ml_model){
  function i_p (line 100) | static long double i_p(apop_data *d, apop_model *ml_model){
  function i_constraint (line 106) | static long double i_constraint(apop_data *d, apop_model *ml_model){
  function apop_model (line 132) | apop_model * apop_ml_impute(apop_data *d,  apop_model* mvn){

FILE: apop_mle.m4.c
  type grad_params (line 17) | typedef struct {
  type infostruct (line 22) | typedef struct {
  type apop_model_for_infomatrix_struct (line 146) | typedef struct {
  function apop_fn_for_infomatrix (line 152) | static long double apop_fn_for_infomatrix(apop_data *d, apop_model *m){
  function APOP_VAR_HEAD (line 187) | APOP_VAR_HEAD apop_data * apop_model_hessian(apop_data * data, apop_mode...
  function APOP_VAR_HEAD (line 239) | APOP_VAR_HEAD apop_data * apop_model_numerical_covariance(apop_data * da...
  function tracepath (line 269) | static void tracepath(const gsl_vector *beta, double value, apop_data **...
  function negshell (line 296) | static double negshell (const gsl_vector *beta, void * in){
  function dnegshell (line 332) | static int dnegshell (const gsl_vector *beta, void * in, gsl_vector * g){
  function fdf_shell (line 362) | static void fdf_shell(const gsl_vector *beta, void *i, double *f, gsl_ve...
  function mle_sigint (line 368) | static void mle_sigint(int){ ctrl_c ++; }
  function setup_starting_point (line 370) | static int setup_starting_point(apop_mle_settings *mp, gsl_vector *x){
  function add_info_criteria (line 378) | void add_info_criteria(apop_data *d, apop_model *m, apop_model *est, dou...
  function auxinfo (line 395) | static void auxinfo(apop_data *params, infostruct *i, int status, double...
  function apop_maximum_likelihood_w_d (line 411) | static void apop_maximum_likelihood_w_d(apop_data * data, infostruct *i){
  function apop_maximum_likelihood_no_d (line 475) | static void apop_maximum_likelihood_no_d(apop_data * data, infostruct * i){
  function get_ll (line 531) | static double get_ll(apop_data *d, apop_model *est){
  function dim_cycle (line 538) | static void dim_cycle(apop_data *d, apop_model *est, infostruct info){
  function get_desires (line 574) | void get_desires(apop_model *m, infostruct *info){
  function check_method (line 586) | int check_method (char *m){
  function apop_maximum_likelihood (line 635) | void apop_maximum_likelihood(apop_data * data, apop_model *dist){
  function APOP_VAR_HEAD (line 708) | APOP_VAR_HEAD apop_model * apop_estimate_restart (apop_model *e, apop_mo...
  function annealing_energy (line 757) | static double annealing_energy(void *in) {
  function annealing_distance (line 762) | static double annealing_distance(void *xin, void *yin) {
  function annealing_check_constraint (line 771) | static void annealing_check_constraint(infostruct *i){
  function annealing_step (line 777) | static void annealing_step(const gsl_rng * r, void *in, double step_size){
  function annealing_print (line 802) | static void annealing_print(void *xp) {
  function annealing_print2 (line 806) | static void annealing_print2(void *xp) { return; }
  function annealing_memcpy (line 808) | static void annealing_memcpy(void *xp, void *yp){
  function annealing_free (line 821) | static void annealing_free(void *xp){
  function set_start (line 827) | static double set_start(double in){ return in ? in : 1; }
  function anneal_sigint (line 830) | static void anneal_sigint(int){ longjmp(anneal_jump,1); }
  function apop_annealing (line 832) | static void apop_annealing(infostruct *i){
  function apop_model (line 885) | static apop_model * find_roots (infostruct p) {

FILE: apop_model.m4.c
  function apop_model (line 20) | apop_model * apop_model_clear(apop_data * data, apop_model *model){
  function apop_model_free (line 55) | void apop_model_free (apop_model * free_me){
  function APOP_VAR_HEAD (line 119) | APOP_VAR_HEAD void apop_model_print (apop_model * model, FILE *output_pi...
  function apop_model_show (line 137) | void apop_model_show (apop_model * print_me){
  function apop_model (line 155) | apop_model * apop_model_copy(apop_model *in){
  function apop_model (line 207) | apop_model *apop_model_set_parameters_base(apop_model *in, double ap[]){
  function apop_model (line 229) | apop_model *apop_estimate(apop_data *d, apop_model *m){
  function apop_p (line 242) | double apop_p(apop_data *d, apop_model *m){
  function apop_log_likelihood (line 257) | double apop_log_likelihood(apop_data *d, apop_model *m){
  function apop_score (line 290) | void apop_score(apop_data *d, gsl_vector *out, apop_model *m){
  function apop_draw (line 413) | int apop_draw(double *out, gsl_rng *r, apop_model *m){
  function apop_prep (line 447) | void apop_prep(apop_data *d, apop_model *m){
  function disnan (line 452) | static double disnan(double in) {return gsl_isnan(in);}
  function apop_data (line 482) | apop_data *apop_predict(apop_data *d, apop_model *m){
  function lte (line 497) | static int lte(gsl_vector *v, gsl_vector *ref){
  function apop_cdf (line 527) | double apop_cdf(apop_data *d, apop_model *m){

FILE: apop_name.m4.c
  function apop_name (line 23) | apop_name * apop_name_alloc(void){
  function apop_name_hash (line 31) | static unsigned long apop_name_hash(char const *str){
  function apop_name_add (line 49) | int apop_name_add(apop_name * n, char const *add_me, char type){
  function apop_name_print (line 97) | void apop_name_print(apop_name * n){
  function apop_name_free (line 128) | void  apop_name_free(apop_name * free_me){
  function APOP_VAR_HEAD (line 151) | APOP_VAR_HEAD void  apop_name_stack(apop_name * n1, apop_name *nadd, cha...
  function apop_name (line 190) | apop_name * apop_name_copy(apop_name *in){
  function apop_name_find (line 209) | int apop_name_find(const apop_name *n, const char *name, const char type){

FILE: apop_output.m4.c
  function apop_prep_output (line 50) | int apop_prep_output(char const *output_name, FILE ** output_pipe, char ...
  function white_pad (line 77) | static void white_pad(int ct){
  function apop_data_show (line 96) | void apop_data_show(const apop_data *in){
  function p_fn (line 177) | void p_fn(FILE * f, double data){
  function print_core_v (line 182) | static void print_core_v(const gsl_vector *data, char *separator, Output...
  function APOP_VAR_HEAD (line 205) | APOP_VAR_HEAD void apop_vector_print(gsl_vector *data, Output_declares){
  function apop_vector_show (line 220) | void apop_vector_show(const gsl_vector *data){
  function get_max_strlen (line 224) | static int get_max_strlen(char **names, size_t len){
  function a_pipe (line 232) | static void a_pipe(FILE *f, char displaytype){
  function apop_data_print_core (line 237) | static void apop_data_print_core(const apop_data *data, FILE *f, char di...
  function APOP_VAR_HEAD (line 324) | APOP_VAR_HEAD void apop_data_print(const apop_data *data, Output_declares){
  function APOP_VAR_HEAD (line 349) | APOP_VAR_HEAD void apop_matrix_print(const gsl_matrix *data, Output_decl...
  function apop_matrix_show (line 363) | void apop_matrix_show(const gsl_matrix *data){

FILE: apop_rake.m4.c
  type mnode_t (line 41) | typedef struct {
  function find_val (line 49) | static int find_val(double findme, mnode_t *nodecol){
  function index_add_node (line 57) | int index_add_node(mnode_t **mnodes, size_t dim, size_t row, double val,...
  function mnode_t (line 65) | mnode_t **index_generate(apop_data const *in, apop_data const *in2){
  function index_free (line 94) | void index_free(mnode_t **in){
  function value_loop (line 111) | static void value_loop(mnode_t *icon[], int *indices, mnode_t **values,
  function index_foreach (line 129) | void index_foreach(mnode_t *index[], index_apply_f f, void *args){
  function index_get_element_list (line 151) | void index_get_element_list(mnode_t *const * index, bool *d, size_t len,...
  type rake_t (line 163) | typedef struct {
  function rakeinfo_grow (line 175) | static void rakeinfo_grow(rake_t *r){
  function rakeinfo_free (line 182) | static void rakeinfo_free(rake_t r){
  function scaling (line 193) | static void scaling(size_t const *elmts, size_t const n,  gsl_vector *we...
  function one_set_of_values (line 209) | static void one_set_of_values(mnode_t *const * const margincons, int ctr...
  function main_loop (line 250) | static void main_loop(int config_ct, rake_t *rakeinfo, int k){
  function generate_margin_index (line 260) | void generate_margin_index(mnode_t **icon, const apop_data *margin, mnod...
  function cleanup (line 269) | void cleanup(mnode_t **index, rake_t rakeinfos[], int contrast_ct){
  function c_loglin (line 289) | static void c_loglin(const apop_data *config, const apop_data *indata,
  function apop_data (line 330) | apop_data **generate_list_of_contrasts(char *const *contras_in, int cont...
  function apop_data (line 339) | apop_data *get_var_list(char const *margin_table, char const *count_col,...
  function get_var_index (line 363) | static int get_var_index(char *const *all_vars, int len, char *findme){
  function nan_to_zero (line 371) | void nan_to_zero(double *in){ if (gsl_isnan(*in)) *in=0;}
  function nudge_zeros (line 373) | double nudge_zeros(apop_data *in, void *nudge){
  function find_in_allvars (line 379) | int find_in_allvars(char const *in, apop_data const *allvars){
  function setup_nonzero_contrast (line 394) | static int setup_nonzero_contrast(char const *margin_table,
  function APOP_VAR_HEAD (line 525) | APOP_VAR_HEAD apop_data * apop_rake(char const *margin_table, char * con...

FILE: apop_regression.m4.c
  function apop_estimate_parameter_tests (line 8) | void apop_estimate_parameter_tests (apop_model *est){
  function compare_doubles (line 38) | static int compare_doubles (const void *a, const void *b) {
  function strcmpwrap (line 47) | static int strcmpwrap(const void *a, const void *b){
  function gsl_vector (line 62) | gsl_vector * apop_vector_unique_elements(const gsl_vector *v){
  function apop_data (line 89) | apop_data * apop_text_unique_elements(const apop_data *d, size_t col){
  function APOP_VAR_HEAD (line 153) | APOP_VAR_HEAD apop_data *apop_data_get_factor_names(apop_data *data, int...
  function apop_data (line 165) | apop_data * create_factor_list(apop_data *d, int col, char type){
  function apop_data (line 197) | static apop_data * dummies_and_factors_core(apop_data *d, int col, char ...
  function APOP_VAR_HEAD (line 326) | APOP_VAR_HEAD apop_data * apop_data_to_dummies(apop_data *d, int col, ch...
  function APOP_VAR_HEAD (line 423) | APOP_VAR_HEAD apop_data *apop_data_to_factors(apop_data *data, char inty...
  function apop_data (line 474) | apop_data *apop_text_to_factors(apop_data *d, size_t textcol, int datacol){
  function apop_data (line 522) | apop_data *apop_estimate_coefficient_of_determination (apop_model *m){

FILE: apop_settings.c
  function get_settings_ct (line 6) | static size_t get_settings_ct(apop_model *model){
  function apop_settings_hash (line 15) | static unsigned long apop_settings_hash(char *str){
  function apop_settings_remove_group (line 26) | void apop_settings_remove_group(apop_model *m, char *delme){
  function apop_model (line 60) | apop_model *apop_settings_group_alloc_wm(apop_model *model, char *type, ...
  function apop_settings_copy_group (line 90) | void apop_settings_copy_group(apop_model *outm, apop_model *inm, char *c...

FILE: apop_sort.m4.c
  function find_smallest_larger_than (line 7) | static double find_smallest_larger_than(apop_data const *sort_order, dou...
  function generate_sort_order (line 45) | static void generate_sort_order(apop_data const *data, apop_data const *...
  function find_min_unsorted (line 65) | static int find_min_unsorted(size_t *sorted, size_t height, size_t min){
  function compare_strings (line 75) | static int compare_strings(const void *a, const void *b) {
  function rearrange (line 83) | static void rearrange(apop_data *data, size_t height, size_t *perm){
  function APOP_VAR_HEAD (line 142) | APOP_VAR_HEAD apop_data *apop_data_sort(apop_data *data, apop_data *sort...

FILE: apop_stats.m4.c
  function apop_vector_sum (line 15) | long double apop_vector_sum(const gsl_vector *in){
  function apop_vector_skew (line 40) | double apop_vector_skew(const gsl_vector *in){
  function apop_vector_kurtosis (line 52) | double apop_vector_kurtosis(const gsl_vector *in){
  function wskewkurt (line 60) | static double wskewkurt(const gsl_vector *v, const gsl_vector *w, const ...
  function APOP_VAR_HEAD (line 88) | APOP_VAR_HEAD double apop_vector_skew_pop(gsl_vector const *v, gsl_vecto...
  function APOP_VAR_HEAD (line 120) | APOP_VAR_HEAD double apop_vector_kurtosis_pop(gsl_vector const *v, gsl_v...
  function apop_vector_var_m (line 144) | double apop_vector_var_m(const gsl_vector *in, const double mean){
  function APOP_VAR_HEAD (line 162) | APOP_VAR_HEAD double apop_vector_correlation(const gsl_vector *ina, cons...
  function APOP_VAR_HEAD (line 198) | APOP_VAR_HEAD double apop_vector_distance(const gsl_vector *ina, const g...
  function APOP_VAR_HEAD (line 268) | APOP_VAR_HEAD void apop_vector_normalize(gsl_vector *in, gsl_vector **ou...
  function apop_matrix_sum (line 310) | long double apop_matrix_sum(const gsl_matrix *m){
  function apop_matrix_mean (line 324) | double apop_matrix_mean(const gsl_matrix *data){
  function apop_matrix_mean_and_var (line 355) | void apop_matrix_mean_and_var(const gsl_matrix *data, double *mean, doub...
  function apop_data (line 386) | apop_data * apop_data_summarize(apop_data *indata){
  function APOP_VAR_HEAD (line 449) | APOP_VAR_HEAD double * apop_vector_percentiles(gsl_vector *data, char ro...
  function APOP_VAR_HEAD (line 477) | APOP_VAR_HEAD double apop_vector_mean(gsl_vector const *v, gsl_vector co...
  function APOP_VAR_HEAD (line 508) | APOP_VAR_HEAD double apop_vector_var(gsl_vector const *v, gsl_vector con...
  function APOP_VAR_HEAD (line 536) | APOP_VAR_HEAD double apop_vector_cov(const gsl_vector *v1, const gsl_vec...
  function apop_data (line 578) | apop_data *apop_data_covariance(const apop_data *in){
  function apop_data (line 602) | apop_data *apop_data_correlation(const apop_data *in){
  function apop_vector_entropy (line 639) | long double apop_vector_entropy(gsl_vector *in){
  function norment (line 658) | static long double norment(apop_model *m){
  function get_ll (line 663) | double get_ll(apop_data *d, void *m){ return apop_log_likelihood(d, m); }
  function apop_model_entropy (line 683) | APOP_VAR_HEAD long double apop_model_entropy(apop_model *in, int draws){
  function apop_kl_divergence (line 731) | APOP_VAR_HEAD long double apop_kl_divergence(apop_model *from, apop_mode...
  function apop_multivariate_gamma (line 787) | long double apop_multivariate_gamma(double a, int p){
  function apop_multivariate_lngamma (line 799) | long double apop_multivariate_lngamma(double a, int p){
  function find_eigens (line 807) | static void find_eigens(gsl_matrix **subject, gsl_vector *eigenvals, gsl...
  function diagonal_copy (line 814) | static void diagonal_copy(gsl_vector *v, gsl_matrix *m, char in_or_out){
  function diagonal_size (line 820) | static double diagonal_size(gsl_matrix *m){
  function biggest_elmt (line 825) | static double biggest_elmt(gsl_matrix *d){
  function APOP_VAR_HEAD (line 845) | APOP_VAR_HEAD int apop_matrix_is_positive_semidefinite(gsl_matrix *m, ch...
  function vfabs (line 859) | void vfabs(double *x){*x = fabs(*x);}
  function apop_matrix_to_positive_semidefinite (line 871) | double apop_matrix_to_positive_semidefinite(gsl_matrix *m){

FILE: apop_tests.m4.c
  function apop_data (line 6) | static apop_data * produce_t_test_output(int df, double stat, double diff){
  function apop_data (line 54) | apop_data *	apop_t_test(gsl_vector *a, gsl_vector *b){
  function apop_data (line 91) | apop_data * apop_paired_t_test(gsl_vector *a, gsl_vector *b){
  function APOP_VAR_HEAD (line 138) | APOP_VAR_HEAD apop_data * apop_f_test (apop_model *est, apop_data *contr...
  function one_chi_sq (line 219) | static double one_chi_sq(apop_data *d, int row, int col, int n){
  function apop_data (line 235) | apop_data * apop_test_anova_independence(apop_data *d){
  function apop_data (line 255) | static apop_data* apop_anova_one_way(char *table, char *data, char *grou...
  function APOP_VAR_HEAD (line 308) | APOP_VAR_HEAD apop_data* apop_anova(char *table, char *data, char *group...
  function APOP_VAR_HEAD (line 432) | APOP_VAR_HEAD double apop_test(double statistic, char *distribution, dou...

FILE: apop_update.m4.c
  function product_ll (line 23) | static long double product_ll(apop_data *d, apop_model *m){
  function product_constraint (line 31) | static long double product_constraint(apop_data *data, apop_model *m){
  function apop_model (line 45) | static apop_model *betabinom(apop_data *data, apop_model *prior, apop_mo...
  function countup (line 61) | double countup(double in){return in!=0;}
  function apop_model (line 63) | static apop_model *betabernie(apop_data *data, apop_model *prior, apop_m...
  function apop_model (line 72) | static apop_model *gammaexpo(apop_data *data, apop_model *prior, apop_mo...
  function apop_model (line 83) | static apop_model *gammapoisson(apop_data *data, apop_model *prior, apop...
  function apop_model (line 96) | static apop_model *normnorm(apop_data *data, apop_model *prior, apop_mod...
  function APOP_VAR_HEAD (line 183) | APOP_VAR_HEAD apop_model * apop_update(apop_data *data, apop_model *prio...

FILE: apop_vtables.c
  type apop_vtable_elmt_s (line 15) | typedef struct {
  type apop_vtable_s (line 20) | typedef struct {
  function apop_settings_hash (line 35) | static unsigned long apop_settings_hash(char const *str){
  function apop_vtable_s (line 42) | static apop_vtable_s *find_tab(unsigned long h, int *ctr){
  function apop_vtable_drop (line 51) | int apop_vtable_drop(char const *tabname, unsigned long hash){
  function apop_vtable_add (line 68) | int apop_vtable_add(char const *tabname, void *fn_in, unsigned long hash){

FILE: asprintf.c
  type arg_type (line 86) | typedef enum {
  type argument (line 123) | typedef struct {
  type arguments (line 165) | typedef struct {
  type char_directive (line 193) | typedef struct {
  type char_directives (line 209) | typedef struct {
  function asprintf (line 241) | int asprintf (char **resultp, const char *format, ...) {
  function printf_fetchargs (line 254) | int printf_fetchargs (va_list args, arguments *a) {
  function PRINTF_PARSE (line 457) | int
  function local_wcslen (line 943) | static size_t local_wcslen (const wchar_t *s) {
  function CHAR_T (line 985) | CHAR_T * VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *f...
  function vasprintf (line 1712) | int vasprintf (char **resultp, const char *format, va_list args) {

FILE: cmd/apop_db_to_crosstab.c
  function main (line 9) | int main(int argc, char **argv){

FILE: cmd/apop_plot_query.c
  function plot_histogram (line 16) | void plot_histogram(gsl_vector *data, FILE *f, size_t bin_count, char *w...
  function FILE (line 38) | FILE *open_output(char *outfile, int sf){
  function gsl_matrix (line 67) | gsl_matrix *query(char *d, char *q, int no_plot){
  function print_out (line 80) | void print_out(FILE *f, char *outfile, gsl_matrix *m){
  function main (line 91) | int main(int argc, char **argv){

FILE: cmd/apop_text_to_db.c
  function main (line 21) | int main(int argc, char **argv){

FILE: docs/tree.js
  function showBranch (line 6) | function showBranch(branch){
  function swapFolder (line 14) | function swapFolder(img){
  function changeSheets (line 22) | function changeSheets(whichSheet){
  function showAll (line 28) | function showAll(){
  function closeAll (line 35) | function closeAll(){

FILE: docs/triangle.c
  function main (line 3) | int main(){

FILE: eg/apop_map_row.c
  function set_vector_to_even (line 10) | double set_vector_to_even(apop_data * r, int index){
  function set_weight_to_index (line 15) | double set_weight_to_index(apop_data * r, int index){
  function weight_given_even (line 20) | double weight_given_even(apop_data *r){
  function main (line 24) | int main(){

FILE: eg/banana.c
  type coeff_struct (line 3) | typedef struct {
  function banana (line 7) | long double banana (double *params, coeff_struct *in){
  function ll (line 12) | long double ll (apop_data *d, apop_model *in){
  function main (line 16) | int main(){

FILE: eg/binning.c
  function main (line 8) | int main(){

FILE: eg/boot_clt.c
  function sim_step (line 4) | void sim_step(apop_data *none, apop_model *m){
  function main (line 18) | int main(){

FILE: eg/cross_models.c
  function cross_normals (line 9) | void cross_normals(){
  function norm_cross_poisson (line 39) | void norm_cross_poisson(){
  function main (line 87) | int main(){

FILE: eg/data_fill.c
  function with_fixed_numbers (line 3) | void with_fixed_numbers(){
  function with_a_list (line 11) | void with_a_list(){
  function main (line 20) | int main(){

FILE: eg/db_fns.c
  function test_all (line 7) | double test_all(apop_data *row){
  function main (line 15) | int main(){

FILE: eg/dconstrain.c
  function over_zero (line 4) | double over_zero(apop_data *in, apop_model *m){
  function in_bounds (line 9) | double in_bounds(apop_model *m){
  function main (line 15) | int main(){

FILE: eg/dot_products.c
  function main (line 9) | int main(){

FILE: eg/draw_some_normals.c
  function main (line 4) | int main(){

FILE: eg/draw_to_db.c
  function process_one (line 4) | double process_one(gsl_rng *r){
  function process_two (line 8) | double process_two(gsl_rng *r){
  function main (line 12) | int main(){

FILE: eg/entropy_model.c
  function mask (line 19) | long double mask(apop_data *d, apop_model *m){
  function main (line 23) | int main(){

FILE: eg/entropy_vector.c
  function entropy_base_2 (line 5) | long double entropy_base_2(gsl_vector *x) {
  function main (line 9) | int main(){

FILE: eg/f_test.c
  function test_f (line 14) | void test_f(apop_model *est){
  function main (line 33) | int main(){

FILE: eg/faithful.c
  function show_mix (line 14) | void show_mix(apop_model *in){
  function main (line 23) | int main(){

FILE: eg/fake_logit.c
  function write_data (line 8) | void write_data(){
  function main (line 26) | int main(){

FILE: eg/fix_params.c
  function main (line 3) | int main(){

FILE: eg/hills2.c
  function apop_model (line 9) | apop_model *produce_fixed_mvn(double x, double y){
  function main (line 18) | int main(){

FILE: eg/iv.c
  function add_noise (line 23) | void add_noise(gsl_vector *in, gsl_rng *r, double size){
  function test_for_unbiased_parameter_estimates (line 36) | void test_for_unbiased_parameter_estimates(apop_model *m, double toleran...
  function main (line 41) | int main(){

FILE: eg/jack.c
  function main (line 3) | int main(){

FILE: eg/jacobian.c
  function apop_data (line 8) | apop_data *draw_exponentiated_normal(double mu, double sigma, double dra...
  function apop_data (line 18) | apop_data *rev(apop_data *in){ return apop_map(in, .fn_d=log, .part='a'); }
  function inv (line 21) | double inv(double in){return 1./in;}
  function rev_j (line 22) | double rev_j(apop_data *in){ return fabs(apop_map_sum(in, .fn_d=inv, .pa...
  function main (line 24) | int main(){

FILE: eg/kernel.c
  function set_uniform_edges (line 23) | void set_uniform_edges(apop_data * r, apop_model *unif){
  function plot (line 28) | void plot(apop_model *k, apop_model *k2){
  function apop_data (line 40) | apop_data *draw_some_data(){
  function main (line 47) | int main(){

FILE: eg/ks_tests.c
  function apop_model (line 5) | apop_model * model_to_pmfs(apop_model *m1, int size){
  function main (line 10) | int main(){

FILE: eg/logit.c
  function main (line 11) | int main(){

FILE: eg/ls_tables.c
  function print_table_list (line 3) | void print_table_list(char *db_file){
  function main (line 11) | int main(int argc, char **argv){

FILE: eg/ml_imputation.c
  function compare_mvn_estimates (line 3) | static void compare_mvn_estimates(apop_model *L, apop_model *R, double t...
  function test_ml_imputation (line 9) | void test_ml_imputation(gsl_rng *r){
  function main (line 44) | int main(){

FILE: eg/normalization_demo.c
  function main (line 3) | int main(void){

FILE: eg/ols.c
  function main (line 9) | int main(){

FILE: eg/ols2.c
  function main (line 4) | int main(void){

FILE: eg/ols_oneliner.c
  function main (line 8) | int main(){ apop_model_print(apop_estimate(apop_text_to_data( DATADIR "/...

FILE: eg/parameterization.c
  function main (line 6) | int main(){

FILE: eg/pmf_test.c
  function pack_p (line 3) | long double pack_p (apop_data *d, apop_model *m){
  function pack_prep (line 13) | void pack_prep(apop_data *d, apop_model *m){
  function pack_constraint (line 20) | long double pack_constraint(apop_data *d, apop_model *m){
  function main (line 28) | int main(){

FILE: eg/simple_subsets.c
  function main (line 9) | int main(){

FILE: eg/some_cdfs.c
  function main (line 3) | int main(){

FILE: eg/sql_to_html.c
  function main (line 3) | int main(){

FILE: eg/t_test_by_rows.c
  function offset_rng (line 5) | void offset_rng(double *v){*v = gsl_rng_uniform(apop_rng_get_thread()) +...
  function find_tstat (line 6) | double find_tstat(gsl_vector *in){ return apop_mean(in)/sqrt(apop_var(in...
  function conf (line 7) | double conf(double in, void *df){ return gsl_cdf_tdist_P(in, *(int *)df);}
  function mu (line 10) | double mu(gsl_vector *in){ return apop_vector_mean(in);}
  function main (line 12) | int main(){

FILE: eg/test_distances.c
  function main (line 4) | int main(){

FILE: eg/test_fisher.c
  function main (line 3) | int main() {

FILE: eg/test_harmonic.c
  function main (line 3) | int main(){

FILE: eg/test_kl_divergence.c
  function fake_p (line 3) | long double fake_p (apop_data *d, apop_model *m){
  function main (line 7) | int main(){

FILE: eg/test_pruning.c
  function main (line 4) | int main(){

FILE: eg/test_ranks.c
  function main (line 6) | int main(){

FILE: eg/test_regex.c
  function main (line 2) | int main(){

FILE: eg/test_updating.c
  function distances (line 4) | void distances(gsl_vector *v1, gsl_vector *v2, double tol){
  function main (line 10) | int main(){

FILE: eg/text_demo.c
  function main (line 3) | int main(){

FILE: eg/transform.c
  function greater_than_zero (line 5) | double greater_than_zero(apop_data *d, apop_model *m){
  function main (line 9) | int main(){

FILE: model/apop_bernoulli.c
  function bernie_ll (line 13) | static double bernie_ll(double x, void * pin){
  function bernoulli_log_likelihood (line 18) | static long double bernoulli_log_likelihood(apop_data *d, apop_model *pa...
  function nonzero (line 24) | static double nonzero (double in) { return in !=0; }
  function bernoulli_estimate (line 31) | static void bernoulli_estimate(apop_data * data,  apop_model *est){
  function bernoulli_constraint (line 42) | static long double bernoulli_constraint(apop_data *data, apop_model *inm...
  function bernoulli_rng (line 50) | static int bernoulli_rng(double *out, gsl_rng *r, apop_model* eps){
  function bernoulli_cdf (line 55) | static long double bernoulli_cdf(apop_data *d, apop_model *params){
  function bernie_print (line 68) | static void bernie_print(apop_model *m, FILE *out){
  function bernie_prep (line 72) | static void bernie_prep(apop_data *data, apop_model *params){

FILE: model/apop_beta.c
  function beta_estimate (line 19) | static void beta_estimate(apop_data * data,  apop_model *est){
  type ab_type (line 41) | typedef struct{
  function betamap (line 46) | static double betamap(double x, void *abin) {
  function beta_log_likelihood (line 56) | static long double beta_log_likelihood(apop_data *d, apop_model *p){
  function dbeta_callback (line 64) | static double dbeta_callback(double x){ return log(1-x); }
  function beta_dlog_likelihood (line 66) | static void beta_dlog_likelihood(apop_data *d, gsl_vector *gradient, apo...
  function beta_constraint (line 77) | static long double beta_constraint(apop_data *data, apop_model *v){
  function beta_cdf (line 82) | static long double beta_cdf(apop_data *d, apop_model *params){
  function beta_rng (line 90) | static int beta_rng(double *out, gsl_rng *r, apop_model* eps){
  function beta_prep (line 101) | static void beta_prep(apop_data *data, apop_model *params){

FILE: model/apop_dirichlet.c
  function dirichletlnmap (line 13) | static double dirichletlnmap(gsl_vector *v, void *pin) {
  function dirichlet_log_likelihood (line 19) | static long double dirichlet_log_likelihood(apop_data *d, apop_model *p){
  function dirichlet_dlog_likelihood (line 28) | static void dirichlet_dlog_likelihood(apop_data *d, gsl_vector *gradient...
  function dirichlet_constraint (line 40) | static long double dirichlet_constraint(apop_data *data, apop_model *v){
  function dirichlet_rng (line 46) | static int dirichlet_rng(double *out, gsl_rng *r, apop_model* eps){
  function dirichlet_prep (line 51) | static void dirichlet_prep(apop_data *data, apop_model *params){

FILE: model/apop_exponential.c
  function beta_greater_than_x_constraint (line 25) | static long double beta_greater_than_x_constraint(apop_data *data, apop_...
  function exponential_log_likelihood (line 30) | static long double exponential_log_likelihood(apop_data *d, apop_model *p){
  function exponential_dlog_likelihood (line 39) | static void exponential_dlog_likelihood(apop_data *d, gsl_vector *gradie...
  function exponential_estimate (line 49) | static void exponential_estimate(apop_data * data,  apop_model *est){
  function expo_cdf (line 59) | static long double expo_cdf(apop_data *d, apop_model *params){
  function exponential_rng (line 68) | static int exponential_rng(double *out, gsl_rng* r, apop_model *p){
  function exponential_prep (line 73) | static void exponential_prep(apop_data *data, apop_model *params){

FILE: model/apop_gamma.c
  function gamma_constraint (line 23) | static long double gamma_constraint(apop_data *data, apop_model *v){
  type abstruct (line 29) | typedef struct {double a, b, ln_ga_plus_a_ln_b;} abstruct;
  function apply_for_gamma (line 32) | static double apply_for_gamma(double x, void *abin) {
  function gamma_log_likelihood (line 37) | static long double gamma_log_likelihood(apop_data *d, apop_model *p){
  function a_callback (line 51) | static double a_callback(double x, void *ab){ return log(x)- *(double*)a...
  function b_callback (line 53) | static double b_callback(double x, void *abv){
  function gamma_dlog_likelihood (line 58) | static void gamma_dlog_likelihood(apop_data *d, gsl_vector *gradient, ap...
  function gamma_rng (line 71) | static int gamma_rng( double *out, gsl_rng* r, apop_model *p){
  function gamma_cdf (line 76) | static long double gamma_cdf(apop_data *d, apop_model *params){
  function gamma_prep (line 85) | static void gamma_prep(apop_data *data, apop_model *params){
  function gamma_est (line 96) | static void gamma_est(apop_data *data, apop_model *m){

FILE: model/apop_kerneld.c
  function apop_set_first_param (line 52) | static void apop_set_first_param(apop_data *in, apop_model *m){
  function apop_kernel_estimate (line 77) | static void apop_kernel_estimate(apop_data *d, apop_model *m){
  function kernel_cdf (line 84) | static long double kernel_cdf(apop_data *d, apop_model *m){
  function kernel_ll (line 104) | static long double kernel_ll(apop_data *d, apop_model *m){
  function kernel_draw (line 144) | static int kernel_draw(double *d, gsl_rng *r, apop_model *m){

FILE: model/apop_loess.c
  type logical (line 77) | typedef long int logical;
  type integer (line 78) | typedef long int integer;
  function dswap (line 92) | void dswap(const integer N, double *x, double *y){ cblas_dswap(N, x, 1, ...
  function dnrm2 (line 94) | double dnrm2(const integer *N, const double *x){ return cblas_dnrm2(*N, ...
  function ddot_ (line 96) | double ddot_(const integer *N, const double *x, const integer *incx, con...
  function daxpy_ (line 99) | void daxpy_(integer *N, const double *alpha, const double *x, integer *i...
  function dcopy_ (line 102) | void dcopy_(const integer *N, const double *x, const integer incx, doubl...
  function dscal (line 105) | void dscal(integer *N, const double alpha, double *x){ cblas_dscal(*N, a...
  function drotg_ (line 107) | static void drotg_(double *a,double *b, double *c, double *s){ cblas_dro...
  function drot_ (line 109) | void drot_(const integer *N, double *x, const integer *incx, double *y, ...
  function integer (line 113) | static integer pow_ii(integer x, integer n) { return gsl_pow_int(x, n); }
  function d_sign (line 115) | static double d_sign(double *a, double *b) {
  function dqrsl_ (line 232) | static void dqrsl_(double *x, integer *ldx, integer *n, integer * k, dou...
  function dsvdc_ (line 451) | static void dsvdc_(double *x, integer *ldx, integer *n, integer * p, dou...
  function loess_error (line 836) | static void loess_error(int i){ //used to be ehg182.
  function ehg183_ (line 868) | static void ehg183_(char *s, integer *i, integer n, integer inc) {
  function ehg184_ (line 878) | static void ehg184_(char *s, double *x, integer n, integer inc) {
  function integer (line 904) | static integer ifloor(double x) {
  function ehg126_ (line 911) | static void ehg126_(integer *d__, integer *n, integer *vc, double *x, do...
  function ehg125_ (line 952) | static void ehg125_(integer *p, integer *nv, double *v, integer *vhit, i...
  function find_kth_smallest (line 1004) | static void find_kth_smallest(integer il, integer ir, integer k, integer...
  function integer (line 1061) | static integer idamax(integer n, double *dx, integer incx) {
  function ehg124_ (line 1093) | static void ehg124_(integer *ll, integer *uu, integer d__, integer n, in...
  function ehg127_ (line 1193) | static void ehg127_(double *q, integer *n, integer *d__, integer *nf, do...
  function ehg129_ (line 1334) | static void ehg129_(integer *l, integer *u, integer *d__, double *x, int...
  function ehg131_ (line 1357) | static void ehg131_(double *x, double *y, double *rw, double *trl,
  function ehg133_ (line 1425) | static void ehg133_(integer *n, integer *d__, integer *vc, integer *nvma...
  function set_cs (line 1452) | static void set_cs(integer d, integer i, double *c1, double *c2, double ...
  function ehg141_ (line 1472) | static void ehg141_(double *trl, integer *n, integer *deg, integer *k, i...
  function lowesc_ (line 1499) | static void lowesc_(integer *n, double *l, double *ll, double *trl, doub...
  function ehg169_ (line 1533) | static void ehg169_(integer d__, integer *vc, integer *nc, integer *ncma...
  function ehg176_ (line 1582) | static double ehg176_(double *z) {
  function lowesa_ (line 1631) | static void lowesa_(double *trl, integer *n, integer *d__,
  function ehg191_ (line 1644) | static void ehg191_(integer *m, double *z__, double *l, integer *d__, in...
  function ehg196_ (line 1695) | static void ehg196_(integer tau, integer d__, double f, double *trl) {
  function ehg197 (line 1706) | static void ehg197(integer deg, integer d__, double f, integer *dk, doub...
  function hermite_prep (line 1716) | void hermite_prep(double h, double *phi0, double *phi1, double *psi0, do...
  function xibar_search (line 1723) | int xibar_search(const integer *a, const integer t[], const double* xi, ...
  function ehg128_ (line 1741) | static double ehg128_(double *z__, integer *d__, integer *ncmax, integer...
  function ehg136_ (line 1955) | static void ehg136_(double *u, integer *lm, integer *m, integer *n, inte...
  function ehg137_ (line 2054) | static void ehg137_(double *z__, integer *kappa, integer *leaf, integer ...
  function ehg139_ (line 2103) | static void ehg139_(double *v, integer *nvmax, integer *nv, integer *n, ...
  function dqrdc_ (line 2247) | static void dqrdc_(double *x, integer *ldx, integer *n, integer *p, doub...
  function lowesb_ (line 2462) | static void lowesb_(double *xx, double *yy, double *ww, double *diagl, d...
  function lowesd_ (line 2487) | static void lowesd_(integer *iv, integer *liv, integer *lv, double *v,
  function lowese_ (line 2565) | static void lowese_(integer *iv, integer *liv, integer *lv, double *wv, ...
  function lowesf_ (line 2579) | static void lowesf_(double *xx, double *yy, double *ww, integer *iv, int...
  function lowesl_ (line 2608) | static void lowesl_(integer *iv, integer *liv, integer *lv, double *wv, ...
  function lowesw_ (line 2631) | static void lowesw_(double *res, integer *n, double *rw, integer *pi) {
  function pseudovals (line 2666) | static void pseudovals(integer n, double *y, double *yhat, double *pwgts...
  function loess_workspace (line 2709) | static void loess_workspace(long D, long N, double	span, long degree,
  function loess_free (line 2731) | static void loess_free() {
  function loess_dfit (line 2736) | static void loess_dfit( double	*y, double *x, double *x_evaluate, double...
  function loess_dfitse (line 2744) | static void loess_dfitse( double	*y, double *x, double *x_evaluate, doub...
  function loess_grow (line 2757) | static void loess_grow(long	const * restrict parameter,long const*restri...
  function loess_ifit (line 2804) | static void loess_ifit(long const * restrict parameter, long const *rest...
  function loess_ise (line 2812) | static void loess_ise( double	*y, double *x, double *x_evaluate, double ...
  function loess_prune (line 2822) | static void loess_prune( long	*parameter, long *a, double	*xi, double *v...
  type pred_struct (line 2856) | struct pred_struct {
  function predict (line 2865) | void predict(double  *new_x, long M, struct loess_struct *lo, struct pre...
  function pred_free_mem (line 2954) | void pred_free_mem(struct	pred_struct	*pre){
  function comp (line 2962) | int comp(const void *d1_in, const void *d2_in) {
  function condition (line 2973) | static void condition(char	**surface, char *new_stat, char **trace_hat_i...
  function loess_raw (line 2997) | static void loess_raw( double	*y, double *x, double *weights, double *ro...
  function loess_ (line 3062) | static void loess_(double *y, double *x_, long *size_info, double *weights,
  function loess (line 3182) | void loess( struct	loess_struct	*lo) {
  function loess_free_mem (line 3222) | void loess_free_mem(struct loess_struct *lo) {
  function loess_summary (line 3239) | void loess_summary(struct loess_struct lo, FILE *ap) {
  function ibeta (line 3259) | double ibeta(double x, double a, double b) {
  function invigauss_quick (line 3365) | double invigauss_quick(double p) {
  function invibeta_quick (line 3385) | static double invibeta_quick(double p, double a, double b) {
  function invibeta (line 3398) | static double invibeta(double p,double  a,double  b) {
  function qt (line 3478) | static double qt(double p, double df) {
  type loess_struct (line 3487) | struct loess_struct
  type loess_struct (line 3488) | struct  loess_struct
  type loess_struct (line 3514) | struct loess_struct
  type loess_struct (line 3548) | struct loess_struct
  function apop_data (line 3570) | apop_data * loess_predict (apop_data *in, apop_model *m){
  function onerow (line 3605) | static double onerow(gsl_vector *v, void *sd){
  function loess_ll (line 3610) | static long double loess_ll(apop_data *d, apop_model *m){
  function apop_loess_est (line 3617) | static void apop_loess_est(apop_data *d, apop_model *out){
  function apop_loess_print (line 3642) | static void apop_loess_print(apop_model *in, FILE *out){
  function loess_prep (line 3646) | static void loess_prep(apop_data *data, apop_model *params){

FILE: model/apop_multinomial.c
  function binomial_cdf (line 35) | static long double binomial_cdf(apop_data *d, apop_model *est){
  function make_covar (line 44) | static void make_covar(apop_model *est){
  function multinomial_constraint (line 66) | static long double multinomial_constraint(apop_data *data, apop_model *b){
  function binomial_ll (line 87) | static double binomial_ll(gsl_vector *hits, void *paramv){
  function multinomial_ll (line 91) | static double multinomial_ll(gsl_vector *v, void *params){
  function multinomial_log_likelihood (line 100) | static long double multinomial_log_likelihood(apop_data *d, apop_model *...
  function multinomial_rng (line 130) | static int multinomial_rng(double *out, gsl_rng *r, apop_model* est){
  function multinomial_show (line 159) | static void multinomial_show(apop_model *est, FILE *out){
  function avs (line 168) | double avs(gsl_vector *v){return (double) apop_vector_sum(v);}
  function multinomial_estimate (line 173) | static void multinomial_estimate(apop_data * data,  apop_model *est){
  function multinom_prep (line 192) | static void multinom_prep(apop_data *data, apop_model *params){

FILE: model/apop_multivariate_normal.c
  function x_prime_sigma_x (line 19) | static double x_prime_sigma_x(gsl_vector *x, gsl_matrix *sigma){
  function apop_multinormal_ll (line 28) | static long double apop_multinormal_ll(apop_data *data, apop_model * m){
  function a_mean (line 53) | static double a_mean(gsl_vector * in){ return apop_vector_mean(in); }
  function multivariate_normal_estimate (line 56) | static void multivariate_normal_estimate(apop_data * data, apop_model *p){
  function mvnrng (line 65) | static int mvnrng(double *out, gsl_rng *r, apop_model *eps){
  function mvn_prep (line 85) | static void mvn_prep(apop_data *d, apop_model *m){
  function mvn_constraint (line 91) | static long double mvn_constraint(apop_data *d, apop_model *m){

FILE: model/apop_normal.c
  function positive_sigma_constraint (line 30) | static long double positive_sigma_constraint(apop_data *data, apop_model...
  function apply_me (line 38) | static double apply_me(double x, void *mu){ return x - *(double *)mu; }
  function apply_me2 (line 40) | static double apply_me2(double x, void *mu){ return gsl_pow_2(x - *(doub...
  function normal_log_likelihood (line 42) | static long double normal_log_likelihood(apop_data *d, apop_model *params){
  function get_mu_var (line 52) | void get_mu_var(apop_data *data, double *mu_out, double *var_out){
  function normal_estimate (line 77) | static void normal_estimate(apop_data * data, apop_model *est){
  function normal_cdf (line 99) | static long double normal_cdf(apop_data *d, apop_model *params){
  function normal_dlog_likelihood (line 108) | static void normal_dlog_likelihood(apop_data *d, gsl_vector *gradient, a...
  function apop_data (line 122) | apop_data * normal_predict(apop_data *dummy, apop_model *m){
  function normal_rng (line 136) | static int normal_rng(double *out, gsl_rng *r, apop_model *p){
  function normal_prep (line 141) | static void normal_prep(apop_data *data, apop_model *params){
  function lnx_minus_mu_squared (line 167) | static double lnx_minus_mu_squared(double x, void *mu_in){
  function lognormal_log_likelihood (line 171) | static long double lognormal_log_likelihood(apop_data *d, apop_model *pa...
  function lognormal_estimate (line 184) | static void lognormal_estimate(apop_data * data, apop_model *est){
  function lognormal_cdf (line 208) | static long double lognormal_cdf(apop_data *d, apop_model *params){
  function apop_data (line 219) | apop_data * lognormal_predict(apop_data *dummy, apop_model *m){
  function diff_sq (line 226) | double diff_sq(double x, void *mu){ return gsl_pow_2(log(x) - *(double*)...
  function lognormal_dlog_likelihood (line 228) | static void lognormal_dlog_likelihood(apop_data *d, gsl_vector *gradient...
  function lognormal_rng (line 239) | static int lognormal_rng(double *out, gsl_rng *r, apop_model *p){
  function lognormal_prep (line 244) | static void lognormal_prep(apop_data *data, apop_model *params){

FILE: model/apop_ols.c
  function prep_names (line 72) | static void prep_names (apop_model *e){
  function ols_shuffle (line 97) | static void ols_shuffle(apop_data *d){
  function ols_prep (line 110) | static void ols_prep(apop_data *d, apop_model *m){
  function ols_log_likelihood (line 129) | static long double ols_log_likelihood (apop_data *d, apop_model *p){
  function ols_score (line 175) | static void ols_score(apop_data *d, gsl_vector *gradient, apop_model *p){
  function xpxinvxpy (line 208) | static void xpxinvxpy(apop_data const*data, gsl_matrix *xpx, apop_data c...
  function ols_rng (line 273) | static int ols_rng(double *out, gsl_rng *r, apop_model *m){
  function apop_estimate_OLS (line 307) | static void apop_estimate_OLS(apop_data *inset, apop_model *ep){
  function apop_data (line 359) | apop_data *ols_predict(apop_data *in, apop_model *m){
  function apop_model (line 368) | apop_model *ols_param_models(apop_data *d, apop_model *m){
  function ols_print (line 385) | void ols_print(apop_model *m, FILE *ap){
  function apop_data (line 427) | static apop_data *prep_z(apop_data *x, apop_data *instruments){
  function apop_estimate_IV (line 447) | static void apop_estimate_IV(apop_data *inset, apop_model *ep){

FILE: model/apop_pmf.c
  function estim (line 79) | static void estim (apop_data *d, apop_model *out){
  function setup_cmf (line 92) | static void setup_cmf(apop_model *m){
  function draw (line 134) | static int draw (double *out, gsl_rng *r, apop_model *m){
  function are_equal (line 190) | static int are_equal(apop_data *left, apop_data *right){
  function find_in_data (line 225) | static int find_in_data(apop_data *searchme, apop_data *findme){//findme...
  function pmf_p (line 233) | static long double pmf_p(apop_data *d, apop_model *m){
  function pmf_cmf (line 270) | static long double pmf_cmf(apop_data *d, apop_model *m){
  function pmf_print (line 285) | static void pmf_print(apop_model *est, FILE *out){ apop_data_print(est->...
  function pmf_prep (line 287) | static void pmf_prep(apop_data * data, apop_model *model){
  function apop_data (line 340) | apop_data *apop_data_pmf_compress(apop_data *in){

FILE: model/apop_poisson.c
  function apply_me (line 14) | static double apply_me(double x, void *in){
  function poisson_log_likelihood (line 21) | static long double poisson_log_likelihood(apop_data *d, apop_model * p){
  function data_mean (line 30) | static double data_mean(apop_data *d){
  function poisson_estimate (line 42) | static void poisson_estimate(apop_data * data,  apop_model *est){
  function positive_beta_constraint (line 61) | static long double positive_beta_constraint(apop_data *returned_beta, ap...

FILE: model/apop_probit.c
  function apop_data (line 32) | static apop_data *get_category_table(apop_data *d){
  function probit_prep (line 42) | static void probit_prep(apop_data *d, apop_model *m){
  function biprobit_ll_row (line 83) | static double biprobit_ll_row(apop_data *r){
  function biprobit_log_likelihood (line 91) | static long double biprobit_log_likelihood(apop_data *d, apop_model *p){
  function unordered (line 101) | static double unordered(double in){ return in == val; }
  function multiprobit_log_likelihood (line 104) | static long double multiprobit_log_likelihood(apop_data *d, apop_model *p){
  function probit_dlog_likelihood (line 130) | static void probit_dlog_likelihood(apop_data *d, gsl_vector *gradient, a...
  function apop_data (line 166) | static apop_data *multilogit_expected(apop_data *in, apop_model *m){
  function logit_prep (line 201) | static void logit_prep(apop_data *d, apop_model *m){
  function find_index (line 206) | static size_t find_index(double in, double *m, size_t max){
  function one_logit_row (line 212) | double one_logit_row(apop_data *thisobservation, void *factor_list){
  function multilogit_log_likelihood (line 231) | static long double multilogit_log_likelihood(apop_data *d, apop_model *p){
  function get_draw_size (line 292) | static size_t get_draw_size(apop_model *in){
  function logit_rng (line 303) | static int logit_rng(double *out, gsl_rng *r, apop_model *m){

FILE: model/apop_t.c
  function apop_t_estimate (line 8) | static void apop_t_estimate(apop_data *d, apop_model *m){
  function one_t (line 25) | static double one_t(double in, void *params){
  function apop_tdist_llike (line 32) | static long double apop_tdist_llike(apop_data *d, apop_model *m){
  function apop_t_dist_draw (line 40) | int apop_t_dist_draw(double *out, gsl_rng *r, apop_model *m){
  function apop_t_dist_cdf (line 49) | static long double apop_t_dist_cdf(apop_data *in, apop_model *m){
  function apop_t_dist_constraint (line 58) | static long double apop_t_dist_constraint(apop_data *beta, apop_model *m){

FILE: model/apop_uniform.c
  function getminmax (line 18) | static void getminmax(apop_data *d, double *min, double *max){
  function unif_ll (line 26) | static long double unif_ll(apop_data *d, apop_model *m){
  function unif_p (line 36) | static long double unif_p(apop_data *d, apop_model *m){
  function uniform_estimate (line 47) | static void uniform_estimate(apop_data * data,  apop_model *est){
  function unif_cdf (line 55) | static long double unif_cdf(apop_data *d, apop_model *m){
  function uniform_rng (line 66) | static int uniform_rng(double *out, gsl_rng *r, apop_model* eps){
  function improper_uniform_estimate (line 91) | static void improper_uniform_estimate(apop_data * data,  apop_model *m){ }
  function improper_unif_ll (line 93) | static long double improper_unif_ll(apop_data *d, apop_model *m){ return...
  function improper_unif_cdf (line 94) | static long double improper_unif_cdf(apop_data *d, apop_model *m){ retur...
  function improper_unif_p (line 95) | static long double improper_unif_p (apop_data *d, apop_model *m){ return...
  function improper_uniform_rng (line 97) | static int improper_uniform_rng(double *out, gsl_rng *r, apop_model* eps){

FILE: model/apop_wishart.c
  function pos_def (line 7) | static long double pos_def(apop_data *data, apop_model *candidate){
  type wishartstruct_t (line 11) | typedef struct{
  function one_wishart_row (line 17) | static double one_wishart_row(gsl_vector *in, void *ws_in){
  function wishart_ll (line 35) | static long double wishart_ll(apop_data *in, apop_model *m){
  function apop_wishart_draw (line 52) | static int apop_wishart_draw(double *out, gsl_rng *r, apop_model *m){
  function wishart_constraint (line 103) | static long double wishart_constraint(apop_data *d, apop_model *m){
  function wishart_prep (line 113) | static void wishart_prep(apop_data *d, apop_model *m){
  function fixed_wishart_ll (line 118) | static long double fixed_wishart_ll(apop_data *in, apop_model *m){
  function wishart_estimate (line 130) | static void wishart_estimate(apop_data *d, apop_model *m){

FILE: model/apop_yule.c
  function yule_constraint (line 23) | static long double yule_constraint(apop_data *returned_beta, apop_model ...
  function apply_me (line 30) | static double apply_me(double pt, void *bb){
  function dapply_me (line 38) | static double dapply_me(double pt, void *bb){ return -gsl_sf_psi(pt+*(do...
  function yule_log_likelihood (line 40) | static long double yule_log_likelihood(apop_data *d, apop_model *m){
  function yule_dlog_likelihood (line 50) | static void yule_dlog_likelihood(apop_data *d, gsl_vector *gradient, apo...
  function yule_rng (line 63) | static int yule_rng( double *out, gsl_rng * r, apop_model *a){
  function yule_prep (line 71) | static void yule_prep(apop_data *data, apop_model *params){

FILE: model/apop_zipf.c
  function zipf_constraint (line 24) | static long double zipf_constraint(apop_data *returned_beta, apop_model ...
  function zipf_log_likelihood (line 31) | static long double zipf_log_likelihood(apop_data *d, apop_model *m){
  function zipf_rng (line 45) | static int zipf_rng(double *out, gsl_rng* r, apop_model *param){

FILE: tests/db_tests.c
  function test_data_to_db (line 33) | void test_data_to_db() {
  function test_uniform (line 51) | void test_uniform(apop_data *d){
  function db_to_text (line 75) | void db_to_text(){
  function test_blank_db_queries (line 133) | void test_blank_db_queries(){
  function test_nan_data (line 148) | void test_nan_data(){
  function test_printing (line 184) | static void test_printing(){
  function test_crosstabbing (line 230) | void test_crosstabbing() {
  function main (line 260) | int main(){

FILE: tests/distribution_tests.c
  function tfloor (line 26) | void tfloor(apop_model *dce){
  function estimate_model (line 30) | int estimate_model(apop_data *data, apop_model *dist, char *method, apop...
  function test_one_distribution (line 78) | void test_one_distribution(gsl_rng *r, apop_model *model, apop_model *tr...
  function test_cdf (line 108) | void test_cdf(gsl_rng *r, apop_model *m){//m is parameterized
  function test_distributions (line 132) | void test_distributions(gsl_rng *r){
  function got_bored (line 198) | static void got_bored(){ exit(0); }
  function main (line 200) | int main(int argc, char **argv){

FILE: tests/error_test.c
  function check_log (line 19) | void check_log(char*fn_to_check, char*msg){
  function check_data_error (line 26) | void check_data_error(apop_data *in, char should_be, char *fn_to_check, ...
  function reset_log (line 31) | void reset_log(){
  function main (line 38) | int main(){

FILE: tests/factors.c
  function main (line 8) | int main(){

FILE: tests/lognormal_test.c
  function test_lognormal (line 4) | void test_lognormal(gsl_rng *r){
  function main (line 39) | int main(){ test_lognormal(apop_rng_alloc(24)); }

FILE: tests/nist_tests.c
  function pontius (line 20) | void pontius(){
  function wampler1 (line 36) | void wampler1(){
  function numacc4 (line 49) | void numacc4(){
  function main (line 58) | int main(){

FILE: tests/rake_test.c
  function rake_check (line 5) | void rake_check(apop_model *base, apop_model *fitted){
  function test_raking_further (line 21) | void test_raking_further(){
  function weights_are_one (line 61) | double weights_are_one(apop_data *in){assert(gsl_vector_get(in->weights,...
  function equal_or_absent (line 62) | double equal_or_absent(apop_data *in){
  function compare_results (line 69) | double compare_results(apop_data *in, void *other, int index){
  function main (line 75) | int main(){

FILE: tests/sort_example.c
  function get_distance (line 14) | double get_distance(gsl_vector *v) {return apop_vector_distance(v);}
  function main (line 16) | int main(){

FILE: tests/sort_tests.c
  function check_sorting1 (line 3) | void check_sorting1(apop_data *d){
  function check_sorting2 (line 19) | void check_sorting2(apop_data *d){

FILE: tests/test_apop.c
  function v_pow10 (line 72) | void v_pow10(double *in){ *in = pow(10,*in);}
  function log_for_map (line 73) | double log_for_map(gsl_vector *v){apop_vector_log(v); return apop_sum(v);}
  function log_by_val (line 74) | double log_by_val(double x){return x;}
  function log_and_exp (line 76) | static void log_and_exp(gsl_rng *r){
  function test_percentiles (line 110) | void test_percentiles(){
  function test_score (line 127) | void test_score(){
  function test_normalizations (line 157) | void test_normalizations(gsl_vector *v){
  function test_skew_and_kurt (line 176) | void test_skew_and_kurt(gsl_rng *r){
  function test_listwise_delete (line 196) | void test_listwise_delete(){
  function wmt (line 262) | static void wmt(gsl_vector *v, gsl_vector *v2, gsl_vector *w, gsl_vector...
  function test_weigted_moments (line 271) | void test_weigted_moments(){
  function test_split_and_stack (line 297) | void test_split_and_stack(gsl_rng *r){
  function test_predicted_and_residual (line 446) | void test_predicted_and_residual(apop_model *est){
  function test_OLS (line 465) | void test_OLS(gsl_rng *r){
  function test_inversion (line 489) | void test_inversion(gsl_rng *r){
  function test_summarize (line 513) | void test_summarize(){
  function test_dot (line 527) | void test_dot(){
  function fill_p (line 552) | static void fill_p(apop_data *d, gsl_rng *r){
  function check_p (line 566) | static void check_p(apop_data *d, apop_data *dout){
  function apop_pack_test (line 580) | void apop_pack_test(gsl_rng *r){
  function test_model_fix_parameters (line 614) | void test_model_fix_parameters(gsl_rng *r){
  function test_linear_constraint (line 654) | void test_linear_constraint(){
  function broken_est (line 690) | static void broken_est(apop_data *d, apop_model *m){
  function super_broken_est (line 699) | static void super_broken_est(apop_data *d, apop_model *m){
  function test_jackknife (line 709) | void test_jackknife(gsl_rng *r){
  function test_multivariate_normal (line 751) | void test_multivariate_normal(){
  function common_binomial_bit (line 774) | static void common_binomial_bit(apop_model *out, int n, double p){
  function test_binomial (line 782) | void test_binomial(gsl_rng *r){
  function test_rownames (line 795) | void test_rownames(){
  function get_factor_index (line 817) | int get_factor_index(apop_data *flist, char *findme){
  function check_for_dummies (line 826) | static void check_for_dummies(apop_data *d, apop_data *dum, int offset){
  function dummies_and_factors (line 841) | void dummies_and_factors(){
  function test_vector_moving_average (line 858) | void test_vector_moving_average(){
  function test_transpose (line 873) | void test_transpose(){
  function apop_data (line 889) | apop_data *generate_probit_logit_sample (gsl_vector* true_params, gsl_rn...
  function test_unique_elements (line 909) | void test_unique_elements(){
  function test_probit_and_logit (line 935) | void test_probit_and_logit(gsl_rng *r){
  function test_resize (line 961) | void test_resize(){
  function test_mvn_gamma (line 989) | void test_mvn_gamma(){
  function test_default_rng (line 994) | void test_default_rng(gsl_rng *r) {
  function ran_uniform (line 1006) | double ran_uniform(double in, void *r){ return gsl_rng_uniform(r);}
  function negate (line 1007) | double negate(double in){ return -in;}
  function test_posdef (line 1009) | void test_posdef(gsl_rng *r){
  function set_to_index (line 1027) | static double set_to_index(double in, int index){ return index;}
  function is_even (line 1028) | static double is_even(double in){ return !((int)in%2);}
  function is_odd (line 1029) | static double is_odd(double in){ return (int)in%2;}
  function nan_even (line 1030) | static double nan_even(double in){ return is_even(in) ? GSL_NAN : in; }
  function row_manipulations (line 1032) | void row_manipulations(){
  function test_pmf (line 1048) | void test_pmf(){
  function test_arms (line 1072) | void test_arms(gsl_rng *r){
  function test_pmf_compress (line 1102) | void test_pmf_compress(gsl_rng *r){
  function test_vtables (line 1151) | void test_vtables(){
  function test_weighted_regression (line 1165) | void test_weighted_regression(apop_data *d, apop_model *e){
  function test_ols_offset (line 1174) | void test_ols_offset(gsl_rng *r){
  function main (line 1208) | int main(int argc, char **argv){

FILE: tests/test_kernel_ll.c
  function sum_of_parts (line 7) | long double sum_of_parts(apop_data *d1, apop_data *target){
  function go (line 19) | void go(apop_data *d1, apop_data *d2){
  function main (line 29) | int main(){

FILE: tests/update_via_rng.c
  function fake_ll (line 31) | long double fake_ll (apop_data *d, apop_model *m){
  function apop_data (line 35) | apop_data *apop_data_pmf_expand(apop_data *in, int factor){
  function deciles (line 50) | void deciles(apop_model *m1, apop_model *m2, double max){
  function betabinom (line 60) | void betabinom(){
  function gammafish (line 86) | void gammafish(){
  function make_draws (line 111) | void make_draws(){
  function main (line 131) | int main(){

FILE: transform/apop_coordinate_transform.c
  type apop_data (line 51) | typedef apop_data *(*d_to_d)(apop_data*);

FILE: transform/apop_cross.c
  type twop_s (line 36) | typedef struct {
  function twop_s (line 47) | twop_s unpack_a_draw(apop_data *d, apop_cross_settings *s){
  function twop_s (line 60) | static twop_s get_second(apop_data *d, char *splitpage, apop_cross_setti...
  function repaste (line 81) | static void repaste(twop_s dd){
  function cross_print (line 88) | void cross_print(apop_model *m, FILE *out){
  function cross_est (line 103) | static void cross_est(apop_data *d, apop_model *m){
  function cross_ll (line 112) | static long double cross_ll(apop_data *d, apop_model *m){
  function cross_p (line 121) | static long double cross_p(apop_data *d, apop_model *m){
  function cross_draw (line 129) | static int cross_draw(double *d, gsl_rng *r, apop_model *m){
  function apop_model (line 142) | apop_model *apop_model_cross_base(apop_model *mlist[]){

FILE: transform/apop_dconstrain.c
  function get_scaling (line 42) | static double get_scaling(apop_model *m){
  function dc_prep (line 67) | static void dc_prep(apop_data *d, apop_model *m){
  function dc_rng (line 81) | static int dc_rng(double *out, gsl_rng *r, apop_model *m){
  function constr (line 91) | static double constr(apop_data *d, void *csin){
  function is_stale (line 96) | static bool is_stale(apop_dconstrain_settings *cs, apop_model *m){ //do ...
  function dc_ll (line 119) | static long double dc_ll(apop_data *indata, apop_model* m){

FILE: transform/apop_fix_params.c
  function find_nans (line 13) | static double find_nans(double in){ return isnan(in); }
  function addin (line 15) | static void addin(apop_data *predict, size_t i, int j, size_t page){
  function find_missing (line 28) | static void find_missing(const apop_data *data, apop_data *predict, size...
  function apop_data (line 42) | static apop_data *apop_predict_table_prep(apop_data *in){
  function apop_data_predict_fill (line 67) | static void apop_data_predict_fill(apop_data *data, apop_data *predict){
  type apop_fix_params_settings (line 86) | typedef struct {
  function unpack (line 93) | static void unpack(apop_data *out, apop_model *m){
  function pack (line 101) | static void pack(apop_data *in, apop_model *m){
  function fix_params_draw (line 145) | static int fix_params_draw(double *out, gsl_rng* r, apop_model *eps){
  function fixed_est (line 151) | static void fixed_est(apop_data * data, apop_model *params){
  function fixed_param_show (line 158) | static void fixed_param_show(apop_model *m, FILE *out){
  function fixed_param_prep (line 170) | static void fixed_param_prep(apop_data *data, apop_model *params){
  function set_starting_point (line 182) | void set_starting_point(apop_data * in_params, apop_model * model_out, d...
  function apop_model (line 232) | apop_model * apop_model_fix_params(apop_model *model_in){
  function apop_model (line 275) | apop_model * apop_model_fix_params_get_base(apop_model *fixed_model){

FILE: transform/apop_mixture.c
  function apop_model (line 120) | apop_model *apop_model_mixture_base(apop_model **inlist){
  function mixture_show (line 141) | void mixture_show(apop_model *m, FILE *out){
  function mixture_prep (line 155) | static void mixture_prep(apop_data * data, apop_model *model){
  function unpack (line 174) | void unpack(apop_model *min){
  function apop_data (line 198) | apop_data* get_lls(apop_data *d, apop_model *m){
  function sum_exp_vector (line 222) | static long double sum_exp_vector(gsl_vector const *onerow){
  function mixture_log_likelihood (line 230) | static long double mixture_log_likelihood(apop_data *d, apop_model *mode...
  function mixture_draw (line 278) | static int mixture_draw (double *out, gsl_rng *r, apop_model *m){
  function mixture_cdf (line 293) | static long double mixture_cdf(apop_data *d, apop_model *model_in){
  function mixture_constraint (line 302) | static long double mixture_constraint(apop_data *data, apop_model *model...
Condensed preview — 162 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,743K chars).
[
  {
    "path": "ChangeLog",
    "chars": 48289,
    "preview": "Since April 2014, this changelog includes only those changes that break existing code or are especially notable. For a f"
  },
  {
    "path": "README",
    "chars": 2486,
    "preview": "Apophenia is an open statistical library for working with data sets and statistical or simulation models. It provides fu"
  },
  {
    "path": "apop.m4.h",
    "chars": 87723,
    "preview": "/** \\file  */\n/* Copyright (c) 2005--2014 by Ben Klemens.  Licensed under the GPLv2; see COPYING. */\n\n/* Here are the he"
  },
  {
    "path": "apop_arms.c",
    "chars": 19288,
    "preview": "/** \\file \n  adaptive rejection metropolis sampling */\n\n/** (C) Wally Gilks; see documentation below for details.\n  Adap"
  },
  {
    "path": "apop_asst.m4.c",
    "chars": 19498,
    "preview": "/** \\file apop_asst.c  The odds and ends bin. \nCopyright (c) 2005--2007, 2010 by Ben Klemens.  Licensed under the GPLv2;"
  },
  {
    "path": "apop_bootstrap.m4.c",
    "chars": 8869,
    "preview": "/** \\file apop_bootstrap.c\n\nCopyright (c) 2006--2007 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */\n\n#inclu"
  },
  {
    "path": "apop_conversions.m4.c",
    "chars": 56957,
    "preview": "/** \\file apop_conversions.c\tThe various functions to convert from one format to another. */\n/* Copyright (c) 2006--2010"
  },
  {
    "path": "apop_data.m4.c",
    "chars": 70581,
    "preview": "/** \\file \nThe apop_data structure joins together a gsl_matrix, apop_name, and a table of strings. */\n/* Copyright (c) 2"
  },
  {
    "path": "apop_db.m4.c",
    "chars": 28657,
    "preview": "/** \\file apop_db.c\tAn easy front end to SQLite. Includes a few nice\nfeatures like a variance, skew, and kurtosis aggreg"
  },
  {
    "path": "apop_db_mysql.c",
    "chars": 10540,
    "preview": "/** \\file apop_db_mysql.c\nThis file is included directly into \\ref apop_db.c. It is read only if APOP_USE_MYSQL is defin"
  },
  {
    "path": "apop_db_sqlite.c",
    "chars": 13528,
    "preview": "/** \\file apop_db_sqlite.c\nThis file is included directly into \\ref apop_db.c.\n\nCopyright (c) 2006--2007 by Ben Klemens."
  },
  {
    "path": "apop_fexact.c",
    "chars": 55911,
    "preview": "/** \\file apop_fexact.c\n\n   Fisher's exact test for contingency tables \n\n   This file primarily consists of an algorithm"
  },
  {
    "path": "apop_hist.m4.c",
    "chars": 16634,
    "preview": "/** \\file apop_hist.c */\n/* Functions that work with PMFs and histograms.\n\nCopyright (c) 2006--2007, 2010, 2013 by Ben K"
  },
  {
    "path": "apop_internal.h",
    "chars": 3834,
    "preview": "/* These are functions used here and there to write Apophenia. They're\n not incredibly useful, or even very good form, s"
  },
  {
    "path": "apop_linear_algebra.m4.c",
    "chars": 21870,
    "preview": "/** \\file apop_linear_algebra.c\tAssorted things to do with matrices,\nsuch as take determinants or do singular value deco"
  },
  {
    "path": "apop_linear_constraint.m4.c",
    "chars": 8839,
    "preview": "/** \\file apop_linear_constraint.c \n  \\c apop_linear_constraint finds a point that meets a set of linear constraints. Th"
  },
  {
    "path": "apop_mapply.m4.c",
    "chars": 25100,
    "preview": "/** \\file apop_mapply.c vector/matrix map/apply.  */\n/* Copyright (c) 2007, 2009 by Ben Klemens.  Licensed under the GPL"
  },
  {
    "path": "apop_mcmc.m4.c",
    "chars": 16545,
    "preview": "/** \\file \n  Markov Chain Monte Carlo. */ \n/* Copyright (c) 2014 by Ben Klemens. Licensed under the GNU GPL v2; see COPY"
  },
  {
    "path": "apop_missing_data.m4.c",
    "chars": 6586,
    "preview": "/** \\file apop_missing_data.c Some missing data handlers. */\n/* Copyright (c) 2007, 2009 by Ben Klemens.  Licensed under"
  },
  {
    "path": "apop_mle.m4.c",
    "chars": 41462,
    "preview": "/** \\file apop_mle.c */\n/*Copyright (c) 2006--2010 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */\n#include "
  },
  {
    "path": "apop_model.m4.c",
    "chars": 26587,
    "preview": "/** \\file apop_model.c\t sets up the estimate structure which outputs from the various regressions and MLEs.*/\n/* Copyrig"
  },
  {
    "path": "apop_name.m4.c",
    "chars": 8956,
    "preview": "/** \\file apop_name.c */\n/* Copyright (c) 2006--2009 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */\n\n#inclu"
  },
  {
    "path": "apop_output.m4.c",
    "chars": 15160,
    "preview": "/** \\file \n  Some printing and output interface functions. */\n/* Copyright (c) 2006--2007, 2009 by Ben Klemens.  License"
  },
  {
    "path": "apop_rake.m4.c",
    "chars": 29576,
    "preview": "//#define __USE_POSIX //for strtok_r\n#include \"apop_internal.h\"\n#include <stdbool.h>\n#include <gsl/gsl_sort_vector.h>\nvo"
  },
  {
    "path": "apop_regression.m4.c",
    "chars": 26739,
    "preview": "/** \\file apop_regression.c\tGenerally, if it assumes something is  Normally distributed, it's here.*/\n/* Copyright (c) 2"
  },
  {
    "path": "apop_settings.c",
    "chars": 4859,
    "preview": "/** \\file \n         Specifying model characteristics and details of estimation methods. */\n/* Copyright (c) 2008--2009, "
  },
  {
    "path": "apop_sort.m4.c",
    "chars": 10315,
    "preview": "/** \\file apop_sort.c\nCopyright (c) 2013 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */\n\n#include \"apop_int"
  },
  {
    "path": "apop_stats.m4.c",
    "chars": 41641,
    "preview": "/** \\file apop_stats.c\tBasic moments and some distributions. */\n/* Copyright (c) 2006--2007, 2013 by Ben Klemens.  Licen"
  },
  {
    "path": "apop_tests.m4.c",
    "chars": 25471,
    "preview": "/** \\file apop_tests.c\t */\n/* Copyright (c) 2007 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n */\n#include "
  },
  {
    "path": "apop_update.m4.c",
    "chars": 11789,
    "preview": "/** \\file \n  The \\ref apop_update function.  */ \n/* Copyright (c) 2006--2009, 2014 by Ben Klemens. Licensed under the GP"
  },
  {
    "path": "apop_vtables.c",
    "chars": 3157,
    "preview": "#include <stdlib.h>\n#include <string.h>\n#include \"apop_internal.h\" //just for OMP_critical\n\n#ifdef _OPENMP\n#include <omp"
  },
  {
    "path": "asprintf.c",
    "chars": 44364,
    "preview": "    /** \\cond doxy_ignore */\n/* Formatted output to strings.\n   Copyright (C) 1999, 2002 Free Software Foundation, Inc.\n"
  },
  {
    "path": "cmd/Makefile.am",
    "chars": 200,
    "preview": "#The programs\nbin_PROGRAMS = \\\n\tapop_text_to_db \\\n\tapop_db_to_crosstab \\\n\tapop_plot_query\n\nAM_CFLAGS = \\\n\t-I $(top_srcdi"
  },
  {
    "path": "cmd/apop_db_to_crosstab.c",
    "chars": 2098,
    "preview": "/** \\file \nCommand line utility to convert a three-column table to a crosstab.*/\n\n/*Copyright (c) 2005--2007, 2013 by Be"
  },
  {
    "path": "cmd/apop_plot_query.c",
    "chars": 4926,
    "preview": "/** \\file \n Command line utility to take in a query and produce a plot of its output via Gnuplot.\n\nCopyright (c) 2006--2"
  },
  {
    "path": "cmd/apop_text_to_db.c",
    "chars": 3839,
    "preview": "/** \\file \n A command line script to read a text file into a database.\n\nCopyright (c) 2006--2007, 2013 by Ben Klemens.  "
  },
  {
    "path": "configure",
    "chars": 1312,
    "preview": "#!/bin/bash\n\nversion=1.0\nworkdir=apophenia-$version\n\necho This configure script uses Autotools to generate a build direc"
  },
  {
    "path": "docs/Makefile.am",
    "chars": 1821,
    "preview": "\n#The Doxygen documentation, which you'll have to call yourself (via make doc).\n\nGVZDOT = /usr/bin/dot\n\ndefault:\n\n## adh"
  },
  {
    "path": "docs/adjust",
    "chars": 3156,
    "preview": "#Use GNU sed to make modifications to the LaTeX version before producing a PDF\n\n#But first, some HTML tweaks:\n# Backgrou"
  },
  {
    "path": "docs/apop_data_fig.html",
    "chars": 1104,
    "preview": "<table frame=box>\n<tr>\n<td>Rowname</td><td>Vector</td><td> Matrix</td><td> Text</td><td>Weights</td>\n</tr><tr valign=bot"
  },
  {
    "path": "docs/apop_data_fig.tex",
    "chars": 583,
    "preview": "\\begin{tabular}{ccccc}\nRowname& Vector&  Matrix&  Text& Weights\\\\\n\\fbox{\n\\begin{tabular}{c}\n\\phantom{hi}\\\\\n\"Steven\"\\\\\n\"S"
  },
  {
    "path": "docs/documentation.h",
    "chars": 163034,
    "preview": "/* Apophenia's narrative documentation\nCopyright (c) 2005--2013 by Ben Klemens.  Licensed under the GPLv2; see COPYING. "
  },
  {
    "path": "docs/doxygen.conf.in",
    "chars": 103170,
    "preview": "# Doxyfile 1.8.9.1\n\n# This file describes the settings to be used by the documentation system\n# doxygen (www.doxygen.org"
  },
  {
    "path": "docs/edit_globals.sed",
    "chars": 252,
    "preview": "/index_x/s/- x -/ /\n/index_a/s/- a -/ /\n/Here is a list of all/d\n/<span>[a-z]<\\/span><\\/a><\\/li>/d\n/div class=\"contents\""
  },
  {
    "path": "docs/edit_group.sed",
    "chars": 1311,
    "preview": "s/Enumeration Type Documentation/Model Documentation/\ns/<h2>Enumerations/<h2>Models/\n/<h2>Models/,/<h2>Functions/{\n    s"
  },
  {
    "path": "docs/edit_outline.sed",
    "chars": 412,
    "preview": "s|Outlineheader \\([^ ]*\\)\\(.*\\)</p>|<h2><a class=\"anchor\" name=\"\\1\"><div class=\"trigger\" onClick=\"showBranch('\\1d');swap"
  },
  {
    "path": "docs/edit_width.sed",
    "chars": 28,
    "preview": "s|<td width=\"100%\"></td>||g\n"
  },
  {
    "path": "docs/foot.html",
    "chars": 15,
    "preview": "</body></html>\n"
  },
  {
    "path": "docs/head.html",
    "chars": 2179,
    "preview": "<!-- HTML header for doxygen 1.8.9.1-->\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.or"
  },
  {
    "path": "docs/make_model_doc.awk",
    "chars": 7297,
    "preview": "#!/usr/bin/awk\n\n# The goal: uniform model documentation for all the models that ship with Apophenia.\n# \n# Doxygen provid"
  },
  {
    "path": "docs/model.dot",
    "chars": 444,
    "preview": "\n\ndigraph {\n    node [shape=\"rect\"];\n\n\n\"info\" [\n        label = \"{Info |{name|data}|{params| vbase}|{...}}\"\n        shap"
  },
  {
    "path": "docs/structs.dot",
    "chars": 5246,
    "preview": "digraph {\n    node [shape=\"rect\"];\n\n    \"model\" [\n        label = <\n        <table border=\"0\" cellborder=\"0\">\n        <t"
  },
  {
    "path": "docs/tree.js",
    "chars": 1042,
    "preview": "var openImg = new Image();\nopenImg.src = \"down.png\";\nvar closedImg = new Image();\nclosedImg.src = \"right.png\";\n\nfunction"
  },
  {
    "path": "docs/triangle.c",
    "chars": 433,
    "preview": "#include <apop.h>\n\nint main(){\n    apop_data *d = apop_data_falloc((8,3),   \n            1,  0,  0,\n           .8, .1,  "
  },
  {
    "path": "docs/typical.css",
    "chars": 8457,
    "preview": "/*.memitem:before {content:\"\\00A\\00A\\00A\\00A\"}*/\n\n.memitem {\nborder: 2px solid #a6cb5e;\nborder-radius: 8px;\npadding: 2px"
  },
  {
    "path": "eg/Makefile.am",
    "chars": 573,
    "preview": "\nEXTRA_DIST = \\\n\tapop_map_row.c \\\n\tbanana.c \\\n\tbinning.c \\\n\tcross_models.c \\\n\tdb_fns.c \\\n\tdconstrain.c \\\n\tdot_products.c"
  },
  {
    "path": "eg/apop_map_row.c",
    "chars": 1060,
    "preview": "#include <apop.h>\n/* This sample code sets the elements of a data set's vector to one\n   if the index is even.  Then, vi"
  },
  {
    "path": "eg/banana.c",
    "chars": 1233,
    "preview": "#include <apop.h>\n\ntypedef struct {\n    double scaling;\n} coeff_struct;\n\nlong double banana (double *params, coeff_struc"
  },
  {
    "path": "eg/binning.c",
    "chars": 1238,
    "preview": "#define _GNU_SOURCE\n#include <apop.h>\n\n#define printdata(dataset)           \\\n        printf(\"\\n-----------\\n\\n\"); \\\n   "
  },
  {
    "path": "eg/boot_clt.c",
    "chars": 1165,
    "preview": "#include <apop.h>\n\n// Find the μ/σ  of a set of 10 draws from a Uniform(-1, 1)\nvoid sim_step(apop_data *none, apop_model"
  },
  {
    "path": "eg/cross_models.c",
    "chars": 4112,
    "preview": "#include <apop.h>\n\n/* In this initial example, build a cross product of two Normal(2,.1) distributions.\nMake 10,000 draw"
  },
  {
    "path": "eg/data_fill.c",
    "chars": 520,
    "preview": "#include <apop.h>\n\nvoid with_fixed_numbers(){\n    apop_data *a =apop_data_alloc(2,2,2);\n    double    eight   = 8.0;\n   "
  },
  {
    "path": "eg/db_fns.c",
    "chars": 2629,
    "preview": "#include <apop.h>\n\n#define Diff(L, R) assert(fabs((L)-(R)<1e-4));\n#define Diff2(L, R) assert(fabs((L)-(R)<1e-3));\n#defin"
  },
  {
    "path": "eg/dconstrain.c",
    "chars": 2031,
    "preview": "#include <apop.h>\n\n//The constraint function.\ndouble over_zero(apop_data *in, apop_model *m){\n    return apop_data_get(i"
  },
  {
    "path": "eg/dot_products.c",
    "chars": 2061,
    "preview": "/* A demonstration of dot products and various useful \n   transformations among types. */\n\n#include <apop.h>\n\ndouble eps"
  },
  {
    "path": "eg/draw_some_normals.c",
    "chars": 251,
    "preview": "#include <apop.h>\n#include <time.h>\n\nint main(){\n    apop_opts.rng_seed = time(NULL);\n    apop_data_print(\n            a"
  },
  {
    "path": "eg/draw_to_db.c",
    "chars": 1505,
    "preview": "#include <apop.h>\n\n//Your processes are probably a bit more complex.\ndouble process_one(gsl_rng *r){\n    return gsl_rng_"
  },
  {
    "path": "eg/entropy_model.c",
    "chars": 1293,
    "preview": "#include <apop.h>\n#define Diff(left, right, eps) Apop_stopif(fabs((left)-(right))>(eps), \\\n        abort(), 0, \"%g is to"
  },
  {
    "path": "eg/entropy_vector.c",
    "chars": 1747,
    "preview": "#include <apop.h>\n\n#define Diff(left, right, eps) Apop_stopif(fabs((left)-(right))>(eps), abort(), 0, \"%g is too differe"
  },
  {
    "path": "eg/f_test.c",
    "chars": 1546,
    "preview": "#ifdef Datadir\n#define DATADIR Datadir\n#else\n#define DATADIR \".\"\n#endif\n\n#include <apop.h>\n\n#define Diff(L, R, eps) {dou"
  },
  {
    "path": "eg/faithful.c",
    "chars": 1961,
    "preview": "\n#ifdef Datadir\n#define DATADIR Datadir\n#else\n#define DATADIR \".\"\n#endif\n\n#include <apop.h>\n\n/* This replacement for apo"
  },
  {
    "path": "eg/fake_logit.c",
    "chars": 1225,
    "preview": "#include <apop.h>\n#include <unistd.h>\n\nchar *testfile = \"logit_test_data\";\n\n//generate a fake data set.\n//Notice how the"
  },
  {
    "path": "eg/fix_params.c",
    "chars": 882,
    "preview": "#include <apop.h>\n\nint main(){\n    size_t ct = 5e4;\n\n    //set up the model & params\n    apop_data *params = apop_data_f"
  },
  {
    "path": "eg/hills2.c",
    "chars": 1621,
    "preview": "#include <apop.h>\n\n/* \nUse apop_model_mixture to generate a hump-filled distribution, then find \nthe most likely data po"
  },
  {
    "path": "eg/iv.c",
    "chars": 3947,
    "preview": "/* Instrumental variables are often used to deal with variables measured with noise, so\nthis example produces a data set"
  },
  {
    "path": "eg/jack.c",
    "chars": 648,
    "preview": "#include <apop.h>\n\nint main(){\n    int draw_ct = 1000;\n    apop_model *m = apop_model_set_parameters(apop_normal, 1, 3);"
  },
  {
    "path": "eg/jacobian.c",
    "chars": 2075,
    "preview": "/* A Lognormal distribution is a transform of the Normal distribution, where \n the data space of the Normal is exponenti"
  },
  {
    "path": "eg/kernel.c",
    "chars": 2120,
    "preview": "/* This program draws ten random data points, and then produces two kernel density\nestimates: one based on the Normal di"
  },
  {
    "path": "eg/ks_tests.c",
    "chars": 1278,
    "preview": "#include <apop.h>\n//This program finds the p-value of a K-S test between\n//500 draws from a N(0, 1) and a N(x, 1), where"
  },
  {
    "path": "eg/logit.c",
    "chars": 1120,
    "preview": "// See http://modelingwithdata.org/arch/00000160.htm for context and analysis.\n\n#ifdef Datadir\n#define DATADIR Datadir\n#"
  },
  {
    "path": "eg/ls_tables.c",
    "chars": 537,
    "preview": "#include <apop.h>\n\nvoid print_table_list(char *db_file){\n    apop_db_open(db_file);\n    apop_data *tab_list= apop_query_"
  },
  {
    "path": "eg/ml_imputation.c",
    "chars": 1775,
    "preview": "#include <apop.h>\n\nstatic void compare_mvn_estimates(apop_model *L, apop_model *R, double tolerance){\n    gsl_vector_sub"
  },
  {
    "path": "eg/normalization_demo.c",
    "chars": 668,
    "preview": "#include <apop.h>\n\nint main(void){\ngsl_vector  *in, *out;\n\nin = gsl_vector_calloc(3);\napop_vector_fill(in, 0, 1, 2);\n\npr"
  },
  {
    "path": "eg/ols.c",
    "chars": 315,
    "preview": "#ifdef Datadir\n#define DATADIR Datadir\n#else\n#define DATADIR \".\"\n#endif\n\n#include <apop.h>\n\nint main(){\n    apop_text_to"
  },
  {
    "path": "eg/ols2.c",
    "chars": 950,
    "preview": "#include <apop.h>\n#include <unistd.h>\n\nint main(void){\n    char *datafile = (access(\"ss08pdc.csv\", R_OK)!=-1) ? \"ss08pdc"
  },
  {
    "path": "eg/ols_oneliner.c",
    "chars": 189,
    "preview": "#ifdef Datadir\n#define DATADIR Datadir\n#else\n#define DATADIR \".\"\n#endif\n\n#include <apop.h>\nint main(){ apop_model_print("
  },
  {
    "path": "eg/parameterization.c",
    "chars": 1654,
    "preview": "#include <apop.h>\n\n#define print_draws(mm) apop_data_print(apop_model_draws(mm, 20),\\\n                                  "
  },
  {
    "path": "eg/pmf_test.c",
    "chars": 1164,
    "preview": "#include <apop.h>\n\nlong double pack_p (apop_data *d, apop_model *m){\n    double loss = 0;\n    gsl_vector *v = apop_data_"
  },
  {
    "path": "eg/simple_subsets.c",
    "chars": 784,
    "preview": "#ifdef Datadir\n#define DATADIR Datadir\n#else\n#define DATADIR \".\"\n#endif\n\n#include <apop.h>\n\nint main(){\n    apop_table_e"
  },
  {
    "path": "eg/some_cdfs.c",
    "chars": 3037,
    "preview": "#include <apop.h>\n\nint main(){\n    //Set up an apop_data set with only one number.\n    //Most of these functions will on"
  },
  {
    "path": "eg/sql_to_html.c",
    "chars": 1100,
    "preview": "#include <apop.h>\n\nint main(){\n    apop_query(\"create table datatab(name, age, sex);\"\n                \"insert into datat"
  },
  {
    "path": "eg/t_test_by_rows.c",
    "chars": 1475,
    "preview": "#include <apop.h>\n\ndouble row_offset;\n\nvoid offset_rng(double *v){*v = gsl_rng_uniform(apop_rng_get_thread()) + row_offs"
  },
  {
    "path": "eg/test_distances.c",
    "chars": 672,
    "preview": "#include <apop.h>\n\n/* Test distance calculations using a 3-4-5 triangle */\nint main(){\n    gsl_vector *v1 = gsl_vector_a"
  },
  {
    "path": "eg/test_fisher.c",
    "chars": 398,
    "preview": "#include <apop.h>\n\nint main() {\n    /* This test is thanks to Nick Eriksson, who sent it to me in the form of a bug repo"
  },
  {
    "path": "eg/test_harmonic.c",
    "chars": 252,
    "preview": "#include <apop.h>\n\nint main(){\n    double out = apop_generalized_harmonic(270, 0.0);\n\tassert (out == 270);\n\tout\t= apop_g"
  },
  {
    "path": "eg/test_kl_divergence.c",
    "chars": 1020,
    "preview": "#include <apop.h>\n\nlong double fake_p (apop_data *d, apop_model *m){\n    return apop_pmf->p(d, m);\n}\n\nint main(){\n    gs"
  },
  {
    "path": "eg/test_pruning.c",
    "chars": 883,
    "preview": "#include <apop.h>\n\n// This sample produces a dummy times table, gets a summary, and prunes the summary table.\nint main()"
  },
  {
    "path": "eg/test_ranks.c",
    "chars": 977,
    "preview": "/* A round trip: generate Zipf-distributed draws, summarize them to a single list of\nrankings, then expand the rankings "
  },
  {
    "path": "eg/test_regex.c",
    "chars": 1419,
    "preview": "#include <apop.h>\nint main(){\n    char string1[] = \"Hello. I am a string.\";\n    assert(apop_regex(string1, \"hell\"));\n   "
  },
  {
    "path": "eg/test_updating.c",
    "chars": 1974,
    "preview": "#include <apop.h>\n\n//For the test suite.\nvoid distances(gsl_vector *v1, gsl_vector *v2, double tol){\n    double error = "
  },
  {
    "path": "eg/text_demo.c",
    "chars": 1236,
    "preview": "#include <apop.h>\n\nint main(){\n    apop_query(\"create table data (name, city, state);\"\n            \"insert into data val"
  },
  {
    "path": "eg/transform.c",
    "chars": 903,
    "preview": "#include <apop.h>\n\n// For defining the bounds the data-constraining function\n// needs to enforce.\ndouble greater_than_ze"
  },
  {
    "path": "install/COPYING",
    "chars": 18002,
    "preview": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc."
  },
  {
    "path": "install/Makefile.am",
    "chars": 1924,
    "preview": "ACLOCAL_AMFLAGS = -I m4\n\nAUTOMAKE_OPTIONS = \\\n\tdist-xz \\\n\tdist-bzip2 \\\n\tdist-zip\n\nAM_DISTCHECK_CONFIGURE_FLAGS ?= \\\n\t--d"
  },
  {
    "path": "install/Readme-pkg",
    "chars": 1610,
    "preview": "Apophenia is an open statistical library for working with data sets and statistical or simulation models. It provides fu"
  },
  {
    "path": "install/Readme-pkg-debian",
    "chars": 814,
    "preview": "The Debian [1] package for the Apophenia Statistical C Library\nis currently maintained by the Debian Science Team [2,3]:"
  },
  {
    "path": "install/acinclude.m4",
    "chars": 25680,
    "preview": "# Part one decides whether to use -pthread or -lpthread\n# Part two is for __attribute__\n# Part three is gl_LD_VERSION_SC"
  },
  {
    "path": "install/apophenia.pc.in",
    "chars": 320,
    "preview": "prefix=@prefix@\nexec_prefix=@exec_prefix@\nbindir=@bindir@\nlibdir=@libdir@\nincludedir=@includedir@\n\nName: Apophenia\nDescr"
  },
  {
    "path": "install/configure.ac",
    "chars": 2470,
    "preview": "# Process this file with autoconf to produce a configure script.\n\nm4_define([m4_apop_version], [m4_esyscmd_s(date +%Y%m%"
  },
  {
    "path": "install/prep_variadics.m4",
    "chars": 2584,
    "preview": "m4_divert(-1)\n\nThese are the macros to filter C files to produce the headers for the compound\nliteral-based variadic fun"
  },
  {
    "path": "install/push_pkg",
    "chars": 847,
    "preview": "version=1.0\nworkdir=apophenia-$version\ngit checkout -b pkg-`git log -1 | grep commit | cut -f2 -d' ' | head -c 8`\n./conf"
  },
  {
    "path": "install/rpm.spec",
    "chars": 1384,
    "preview": "Vendor:       Ben Klemens\nName:         apophenia\nVersion:      1.0\nRelease:      1\nLicense:      GPLv2 w/Affero-type ad"
  },
  {
    "path": "model/Makefile.am",
    "chars": 527,
    "preview": "\nnoinst_LTLIBRARIES = libapopmodel.la\n\nlibapopmodel_la_SOURCES = \\\n\tapop_bernoulli.c \\\n\tapop_beta.c \\\n\tapop_dirichlet.c "
  },
  {
    "path": "model/apop_bernoulli.c",
    "chars": 3209,
    "preview": "/* The Bernoulli distribution as an \\ref apop_model.\nCopyright (c) 2007--2009 by Ben Klemens.  Licensed under the GPLv2;"
  },
  {
    "path": "model/apop_beta.c",
    "chars": 4059,
    "preview": "/* \\file apop_beta.c  The Beta distribution \nCopyright (c) 2006--2007, 2013 by Ben Klemens.  Licensed under the GPLv2; s"
  },
  {
    "path": "model/apop_dirichlet.c",
    "chars": 2846,
    "preview": "/* The Dirichlet distribution \nCopyright (c) 2009 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n\n\\amodel apo"
  },
  {
    "path": "model/apop_exponential.c",
    "chars": 3472,
    "preview": "/* The Exponential distribution.\n Copyright (c) 2005--2009 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n\n \\"
  },
  {
    "path": "model/apop_gamma.c",
    "chars": 4266,
    "preview": "/* The gamma distribution.\nCopyright (c) 2005--2007, 2009 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n\n\\am"
  },
  {
    "path": "model/apop_kerneld.c",
    "chars": 7150,
    "preview": "/** \\file */\n/* The kernel density estimate (meta-)model.\n\nCopyright (c) 2007, 2010, 2013 by Ben Klemens.  Licensed unde"
  },
  {
    "path": "model/apop_loess.c",
    "chars": 127776,
    "preview": "/* Functions to calculate loess regressions. \n\nProvenance:\n   * Originally written in FORTRAN `77 by Cleveland, Devlin, "
  },
  {
    "path": "model/apop_multinomial.c",
    "chars": 10747,
    "preview": "/* The binomial distribution as an \\c apop_model.\nCopyright (c) 2006--2007, 2010--11 by Ben Klemens.  Licensed under the"
  },
  {
    "path": "model/apop_multivariate_normal.c",
    "chars": 4619,
    "preview": "/* apop_multivariate_normal.c  The multivariate Normal distribution.\nCopyright (c) 2007 by Ben Klemens.  Licensed under "
  },
  {
    "path": "model/apop_normal.c",
    "chars": 10471,
    "preview": "/* The Normal and Lognormal distributions.\n Copyright (c) 2005--2009 by Ben Klemens.  Licensed under the GPLv2; see COPY"
  },
  {
    "path": "model/apop_ols.c",
    "chars": 24975,
    "preview": "/* OLS models. Much of the real work is done in apop_regression.c.\nCopyright (c) 2005--2007, 2010 by Ben Klemens.  Licen"
  },
  {
    "path": "model/apop_pmf.c",
    "chars": 15576,
    "preview": "/* Probability mass functions \nCopyright (c) 2011 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n\n\\amodel apo"
  },
  {
    "path": "model/apop_poisson.c",
    "chars": 3633,
    "preview": "/* The Poisson distribution.\n Copyright (c) 2006--2007, 2010 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n "
  },
  {
    "path": "model/apop_probit.c",
    "chars": 17095,
    "preview": "/* Probit and Logit. \nCopyright (c) 2005--2008, 2010 by Ben Klemens.  Licensed under the GPLv2; see COPYING. \n\n\\amodel a"
  },
  {
    "path": "model/apop_t.c",
    "chars": 5201,
    "preview": "/* apop_t.c: the t-distribution, for modeling purposes.\nCopyright (c) 2009, 2013 by Ben Klemens.  Licensed under the GPL"
  },
  {
    "path": "model/apop_uniform.c",
    "chars": 4635,
    "preview": "/* apop_uniform.c \n Copyright (c) 2007, 2009 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  */\n\n#include \"apop"
  },
  {
    "path": "model/apop_wishart.c",
    "chars": 7989,
    "preview": "/* apop_wishart.c: the Wishart distribution, for modeling purposes.\nCopyright (c) 2009 by Ben Klemens.  Licensed under t"
  },
  {
    "path": "model/apop_yule.c",
    "chars": 3077,
    "preview": "/* The Yule distribution. A special case of the Waring.\n\nCopyright (c) 2005--2007, 2009, 2011 by Ben Klemens.  Licensed "
  },
  {
    "path": "model/apop_zipf.c",
    "chars": 2487,
    "preview": "/* The Zipf distribution.\n\nCopyright (c) 2005--2009, 2011 by Ben Klemens.  Licensed under the GPLv2; see COPYING.\n\n\\amod"
  },
  {
    "path": "tests/Makefile.am",
    "chars": 2230,
    "preview": "\nif EXTENDED_TESTS\nEXTRA_TESTS = distribution_tests \\\n\tlognormal_test \\\n\trake_test \\\n\ttest_kernel_ll \\\n\tupdate_via_rng \\"
  },
  {
    "path": "tests/Readme",
    "chars": 175,
    "preview": "Much of this directory runs tests from NIST. You can look at\nnist_tests.c to see the level of precision at which various"
  },
  {
    "path": "tests/amash_vote_analysis.csv",
    "chars": 18778,
    "preview": "# Votes for the Amash amendment. Complied by Josh Tauberer of govtrack.us\r\n# From http://razor.occams.info/pubdocs/amash"
  },
  {
    "path": "tests/data",
    "chars": 66,
    "preview": "Y, X_1, X_2, X_3\n2,3,4,5\n1,2,9,3\n4,7,9,0\n2,4,8,16\n1,4,2,9\n9,8,7,6\n"
  },
  {
    "path": "tests/data-mixed",
    "chars": 371,
    "preview": "rsid | chr  | a_allele | b_allele | aa   | ab   | bb   | treatment \nrs1933024|1|A|G|0|37|1830|cases\nrs11497407|1|A|G|0|3"
  },
  {
    "path": "tests/db_tests.c",
    "chars": 10654,
    "preview": "/*\nThese are database-related tests. If you have mySQL/mariaDB set up correctly (see below) then you can run them both f"
  },
  {
    "path": "tests/distribution_tests.c",
    "chars": 9196,
    "preview": "/* These are tests of distributions. The basic idea is to \n --assume a true set of parameters\n --generate a fake data se"
  },
  {
    "path": "tests/error_test.c",
    "chars": 3097,
    "preview": "#include <apop.h>\n#if _POSIX_C_SOURCE >= 200809L\n#define HAVE_FMEMOPEN\n#endif\nFILE *fmemopen(void *buf, size_t size, con"
  },
  {
    "path": "tests/factors.c",
    "chars": 916,
    "preview": "#include <apop.h>\n\n/* We promise users that they can copy factors from one data set to the next. But if the\nsecond data "
  },
  {
    "path": "tests/faith.data",
    "chars": 3461,
    "preview": "#The \"old faithful\" data, pulled from R. If you have a copy of R on hand, use ?faithful for the full documentation.\n#eru"
  },
  {
    "path": "tests/lognormal_test.c",
    "chars": 1619,
    "preview": "#include <apop.h>\n#define Diff(L, R, eps) {double left=(L), right=(R); Apop_stopif(isnan(left-right) || fabs((left)-(rig"
  },
  {
    "path": "tests/nist_tests.c",
    "chars": 2452,
    "preview": "/* These are stats tests from NIST. See http://www.itl.nist.gov/div898/strd/\nNotice that I use various levels of toleran"
  },
  {
    "path": "tests/printing_sample",
    "chars": 988,
    "preview": "    2\t    4\t    6\t    8\n    3\t    7\t  nan\t    6\n    3\t  nan\t    1\t    7\n    9\t    0\t    8\t    1\n\nand a full vector+matri"
  },
  {
    "path": "tests/rake_test.c",
    "chars": 6064,
    "preview": "#include <apop.h>\n\n#define Diff(L, R, eps) Apop_assert_n(fabs((L)-(R))<(eps), \"%g is too different from %g (abitrary lim"
  },
  {
    "path": "tests/sort_example.c",
    "chars": 2080,
    "preview": "#ifdef Datadir\n#define DATADIR Datadir\n#else\n#define DATADIR \".\"\n#endif\n\n#include <apop.h>\n#include <unistd.h>\n#ifdef Te"
  },
  {
    "path": "tests/sort_tests.c",
    "chars": 1536,
    "preview": "//for inclusion into sort_example.c\n\nvoid check_sorting1(apop_data *d){\n    double last_val = -INFINITY;\n    double last"
  },
  {
    "path": "tests/test_apop.c",
    "chars": 51945,
    "preview": "/*\nHere are assorted unit tests, some mechanical and some much more computation-intensive.\n\nThe mechanical tests often d"
  },
  {
    "path": "tests/test_data",
    "chars": 45,
    "preview": "a, \"b\",c,\"d\"\n2,4,6,8\n3,7,1,6\n3,1,1,7\n9,0,8,1\n"
  },
  {
    "path": "tests/test_data2",
    "chars": 388,
    "preview": "visits, date\n12, 0\n18, 1\n20, 2\n18, 3\n11, 4\n11, 5\n14, 6\n17, 7\n11, 8\n10, 9\n15, 10\n13, 11\n13, 12\n20, 13\n24, 14\n19, 15\n22, 1"
  },
  {
    "path": "tests/test_data_fixed_width",
    "chars": 28,
    "preview": "123A#C3.14159\n-21 BC2.71828\n"
  },
  {
    "path": "tests/test_data_nans",
    "chars": 82,
    "preview": "a,b,c,d, head\n2,4,6,8, first\n3,7,nan,6, second\n3,\"NaN\",1,7, third\n9,0,8,1, fourth\n"
  },
  {
    "path": "tests/test_kernel_ll.c",
    "chars": 1337,
    "preview": "/* The kernel log likelihood is somewhat convoluted, to retain numeric precision. This\ntest compares the result to the d"
  },
  {
    "path": "tests/update_via_rng.c",
    "chars": 5315,
    "preview": "/* Test three methods for the entries in the conjugate prior table:\n\n--using the conjugate priors\n--using Metropolis-Has"
  },
  {
    "path": "tests/utilities_test.in",
    "chars": 2175,
    "preview": "#!/bin/sh\n\nAPOP_DATA_DIR=@abs_top_srcdir@/tests\nAPOP_CMD_DIR=@top_builddir@/cmd\n\nBC=@BC@\nSQLITE3=@SQLITE3@\n\nAPOP_PLOT_QU"
  },
  {
    "path": "transform/Makefile.am",
    "chars": 308,
    "preview": "\nnoinst_LTLIBRARIES = libapoptransform.la\n\nlibapoptransform_la_SOURCES = \\\n\tapop_dconstrain.c\\\n\tapop_fix_params.c \\\n\tapo"
  },
  {
    "path": "transform/apop_coordinate_transform.c",
    "chars": 2413,
    "preview": "#include \"apop_internal.h\"\n\n/* \\amodel apop_coordinate_transform Apply a coordinate transformation of the data to\nproduc"
  },
  {
    "path": "transform/apop_cross.c",
    "chars": 6190,
    "preview": "/* Cross product of distributions.\n Copyright (c) 2013 by Ben Klemens.  Licensed under the GPLv2; see COPYING.  \n\n\\amode"
  },
  {
    "path": "transform/apop_dconstrain.c",
    "chars": 6072,
    "preview": "#include \"apop_internal.h\"\n#include <stdbool.h>\n\n/* \\amodel apop_dconstrain A model that constrains the base model to wi"
  },
  {
    "path": "transform/apop_fix_params.c",
    "chars": 12424,
    "preview": "/** \\file \n Set some of the parameters of a model to fixed values.*/\n\n/* There's only one public function here. Its head"
  },
  {
    "path": "transform/apop_mixture.c",
    "chars": 15405,
    "preview": "/** \\file \n */\n/*\n\\amodel apop_mixture The mixture model transformation: a linear combination of multiple models.  \n\nUse"
  }
]

About this extraction

This page contains the full source code of the b-k/apophenia GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 162 files (1.6 MB), approximately 489.7k tokens, and a symbol index with 914 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!